mixin.js
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { dyOptionsList } from '@/components/Generator/generator/comConfig'
export default {
data() {
return {
key: +new Date(),
formConf: {}
}
},
methods: {
fillFormData(form, data) {
const loop = list => {
for (let i = 0; i < list.length; i++) {
let item = list[i]
if (item.__vModel__) {
const val = data[item.__vModel__]
if (val !== undefined) item.__config__.defaultValue = val
}
if (item.__config__ && item.__config__.nccKey !== 'table' && item.__config__.children && Array.isArray(item.__config__.children)) {
loop(item.__config__.children)
}
}
}
loop(form.fields)
},
setFormData(prop, value) {
if (!prop) return
let dataForm = this.$refs.dynamicForm.dataForm
this.$set(dataForm, prop, value)
this.fillFormData(this.formConf, dataForm)
this.key = +new Date()
},
setShowOrHide(prop, value) {
const newVal = !!value
this.comSet('noShow', prop, !newVal)
},
setRequired(prop, value) {
const newVal = !!value
this.comSet('required', prop, newVal)
},
setDisabled(prop, value) {
const newVal = !!value
this.comSet('disabled', prop, newVal)
},
setFieldOptions(prop, value) {
const newVal = Array.isArray(value) ? value : []
this.comSet('options', prop, newVal)
},
comSet(field, prop, value) {
if (!prop) return
const loop = list => {
for (let i = 0; i < list.length; i++) {
let item = list[i]
if (item.__vModel__ && item.__vModel__ === prop) {
switch (field) {
case 'disabled':
item[field] = value
break;
case 'options':
if (dyOptionsList.indexOf(item.__config__.nccKey) > -1) {
let isTreeSelect = item.__config__.nccKey === 'treeSelect' || item.__config__.nccKey === 'cascader'
isTreeSelect ? item.options = value : item.__slot__.options = value
}
break;
default:
item.__config__[field] = value
break;
}
}
if (item.__config__ && item.__config__.nccKey !== 'table' && item.__config__.children && Array.isArray(item.__config__.children)) {
loop(item.__config__.children)
}
}
}
loop(this.formConf.fields)
let dataForm = this.$refs.dynamicForm.dataForm
this.fillFormData(this.formConf, dataForm)
this.key = +new Date()
}
}
}