Skip to content

Commit

Permalink
feat:发布v1.1.13版本
Browse files Browse the repository at this point in the history
  • Loading branch information
lisiyizu committed Mar 19, 2021
1 parent fc6f12a commit 469cabe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kummy/el-form-schema",
"version": "1.1.10",
"version": "1.1.13",
"author": "kummy",
"license": "MIT",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions src/packages/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ const fieldsetComponent = (createElement, dataItem, nodes) => {
]
};

//
// 优化解决 a.arr[0].c 的等复杂情况
const getObjectByPath = (obj, path) => {
const pathArr = path.split('.');
return pathArr.reduce((prev, next) => {
return prev ? prev[next] : undefined;
}, obj);
const pathArr = path.split('.').map(item => {
return (item.includes('[')) ? item.replace(']','').split('[') : item;
}).flat(true);
return pathArr.reduce((prev, next) => {
return prev ? prev[next] : undefined;
}, obj);
}

// 简单深度拷贝
Expand Down
2 changes: 1 addition & 1 deletion src/packages/el-form-schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default {
* @description: 获取节点的所有字段域
*/
getValidateProps (field) {
const val = field.includes('.') ? getObjectByPath(this.formValues, field) : eval(`this.formValues.${field}`);
const val = getObjectByPath(this.formValues, field);
if (typeof val !== 'object' && !Array.isArray(val)) {
return [field];
} else if (Array.isArray(val)) {
Expand Down
38 changes: 2 additions & 36 deletions vuepressdocs/.vuepress/components/example/slot/demo2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@
>
</el-form-item>
</template>
<template slot="arr.components.arr2.operator" slot-scope="scope">
<el-form-item label="">
<el-button
:disabled="scope.delDisabled"
@click="deleteArrItem2(scope)"
>删除-slot</el-button
>
<el-button
type="primary"
:disabled="scope.addDisabled"
@click="addArrItem2(scope)"
>新增-slot</el-button
>
</el-form-item>
</template>
<el-form-item>
<el-button @click="submit" type="primary">提交</el-button>
<el-button @click="reset">重置</el-button>
Expand Down Expand Up @@ -441,29 +426,10 @@ export default {
},
addArrItem({ get, prop, keys, row, index }) {
console.log(prop, keys, row, index);
this.$refs["el-form-schema"].validateField(`${prop}[${index}]`, valid => {
if (!valid) {
get(prop).push(keys);
}
this.$refs["el-form-schema"].validateFieldPromise(`${prop}[${index}]`).then(valid => {
if(valid) get(prop).push(keys);
});
},
deleteArrItem2({ get, prop, keys, row, index }) {
console.log(prop, keys, row, index);
get(prop).splice(index, 1);
},
addArrItem2({ get, prop, keys, row, index }) {
console.log(prop, keys, row, index);
this.$refs["el-form-schema"]
.validateFieldPromise(`${prop}[${index}]`)
.then(valid => {
if (valid) {
get(prop).push(keys);
this.$message.success("新增成功!");
} else {
this.$message.warning("请先完成必填项~");
}
});
},
arrayData(count) {
return Array(count)
.fill({})
Expand Down

0 comments on commit 469cabe

Please sign in to comment.