Skip to content

Commit

Permalink
perf(GenerateForm): 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Oct 10, 2020
1 parent 7d38b81 commit 7a8da09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 56 deletions.
68 changes: 20 additions & 48 deletions src/components/FormDesigner/GenerateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ export default class GenerateForm extends Vue {
created() {
// 根据数据结构生成给子组件的数据源
this.generateModle(this.data.list);
this.setFormReadOnly(this.data.list);
this.setFormHidden(this.data.list);
}
generateModle(genList) {
Expand Down Expand Up @@ -215,7 +213,26 @@ export default class GenerateForm extends Vue {
} else {
this.setDefaultValue(genList[i]);
}
const row = genList[i];
// Props单独设置只读
if (this.setReadOnly) {
const { whiteList, blackList } = this.setReadOnly;
// 默认空对象 代表全部只读
if (whiteList == null && blackList == null) {
row.options.disabled = true;
} else if (blackList && !blackList.includes(row.model)) {
row.options.disabled = true;
} else if (whiteList && whiteList.includes(row.model)) {
row.options.disabled = true;
}
}
// Props 单独设置隐藏
if (this.setHidden) {
// 默认空对象 代表全部只读
if (this.setHidden.includes(row.model)) {
row.hidden = true;
}
}
if (this.rules[genList[i].model]) {
this.rules[genList[i].model] = [
...this.rules[genList[i].model],
Expand Down Expand Up @@ -271,51 +288,6 @@ export default class GenerateForm extends Vue {
}
}
// 设置只读
setFormReadOnly(genList) {
// 遍历设计的结构
if (this.setReadOnly) {
for (let i = 0; i < genList.length; i += 1) {
if (genList[i].type === 'grid') {
genList[i].columns.forEach((item) => {
this.setFormReadOnly(item.list);
});
} else {
const { whiteList, blackList } = this.setReadOnly;
const row = genList[i];
// 默认空对象 代表全部只读
if (whiteList == null && blackList == null) {
row.options.disabled = true;
} else if (blackList && !blackList.includes(row.model)) {
row.options.disabled = true;
} else if (whiteList && whiteList.includes(row.model)) {
row.options.disabled = true;
}
}
}
}
}
// 设置隐藏
setFormHidden(genList) {
// 遍历设计的结构
if (this.setHidden) {
for (let i = 0; i < genList.length; i += 1) {
if (genList[i].type === 'grid') {
genList[i].columns.forEach((item) => {
this.setFormHidden(item.list);
});
} else {
const row = genList[i];
// 默认空对象 代表全部只读
if (this.setHidden.includes(row.model)) {
row.hidden = true;
}
}
}
}
}
// 多选情况下数组转字符串
formValueToString() {
const model = { ...this.models };
Expand Down
8 changes: 0 additions & 8 deletions src/components/FormDesigner/GenerateFormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,6 @@ export default class GenerateFormItem extends Vue {
},
],
}).then((res) => {
const arr = res.data.list.map(t => t.codevalue);
if (new Set(arr).size !== arr.length) {
this.$notify({
title: `字典[${this.widget.name}]的key重复`,
message: '请勿添加重复的字典key',
duration: 20000,
});
}
if (this.widget.type === 'cascader') {
this.widget.options.remoteOptions = JSON.parse(res.data.list[0].codevalue);
// 请求完成后再渲染组件
Expand Down

0 comments on commit 7a8da09

Please sign in to comment.