starfish-form-custom 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{formAction-a969e2cf.mjs → formAction-5fbc8d53.mjs} +1 -1
- package/dist/{index-d613dbb1.mjs → index-2249b02f.mjs} +2 -2
- package/dist/{index-e4264580.mjs → index-a4faf6fb.mjs} +1 -1
- package/dist/{index-2e818bbe.mjs → index-e0c4eec0.mjs} +1 -1
- package/dist/{main-c64812d2.mjs → main-7d7122a6.mjs} +20 -20
- package/dist/{starfish-form-1b37792d.mjs → starfish-form-96426334.mjs} +15 -5
- package/dist/starfish-form.mjs +1 -1
- package/dist/types/form/src/main.d.ts +9 -0
- package/dist/types/form/src/starfish-form.vue.d.ts +9 -0
- package/package.json +1 -1
- package/src/layout/grid.vue +0 -1
- package/src/layout/table.vue +114 -59
- package/src/starfish-form.vue +301 -249
- package/stats.html +1 -1
package/src/starfish-form.vue
CHANGED
|
@@ -1,288 +1,340 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="starfish-dynamicform">
|
|
3
|
-
<el-form
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
<el-form
|
|
4
|
+
ref="ruleForm"
|
|
5
|
+
v-bind="$attrs"
|
|
6
|
+
:model="formResult"
|
|
7
|
+
:rules="rules"
|
|
8
|
+
label-width="120px"
|
|
9
|
+
class="demo-ruleForm"
|
|
10
|
+
size="default"
|
|
11
|
+
:validate-on-rule-change="false"
|
|
12
|
+
>
|
|
13
|
+
<template v-for="item in allFormList">
|
|
14
|
+
<el-form-item
|
|
15
|
+
:prop="item.data.fieldName"
|
|
16
|
+
v-if="!item.layout && item.show"
|
|
17
|
+
:key="item.id"
|
|
18
|
+
>
|
|
19
|
+
<component
|
|
20
|
+
ref="controlObj"
|
|
21
|
+
@change="handleControlChange"
|
|
22
|
+
:is="item.ControlType"
|
|
23
|
+
v-bind="globalConfig"
|
|
24
|
+
:readonly="readonly"
|
|
25
|
+
:item="item"
|
|
26
|
+
:data="formResult || '{}'"
|
|
27
|
+
:drag="false"
|
|
28
|
+
size="default"
|
|
29
|
+
></component>
|
|
7
30
|
</el-form-item>
|
|
8
31
|
<template v-else-if="item.show">
|
|
9
|
-
<component
|
|
32
|
+
<component
|
|
33
|
+
ref="controlObj"
|
|
34
|
+
@change="handleControlChange"
|
|
35
|
+
:is="item.ControlType"
|
|
36
|
+
:key="item.id"
|
|
37
|
+
v-bind="globalConfig"
|
|
38
|
+
:readonly="readonly"
|
|
39
|
+
:item="item"
|
|
40
|
+
:data="formResult || '{}'"
|
|
41
|
+
:drag="false"
|
|
42
|
+
size="default"
|
|
43
|
+
></component>
|
|
10
44
|
</template>
|
|
11
45
|
</template>
|
|
12
46
|
</el-form>
|
|
13
47
|
</div>
|
|
14
48
|
</template>
|
|
15
49
|
<script lang="ts">
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
import {
|
|
51
|
+
defineComponent,
|
|
52
|
+
ref,
|
|
53
|
+
onMounted,
|
|
54
|
+
getCurrentInstance,
|
|
55
|
+
toRaw,
|
|
56
|
+
PropType,
|
|
57
|
+
} from "vue";
|
|
58
|
+
export default defineComponent({
|
|
59
|
+
name: "Dynamicform",
|
|
60
|
+
props: {
|
|
61
|
+
allFormList: {
|
|
62
|
+
type: Array as PropType<any>,
|
|
63
|
+
default() {
|
|
64
|
+
return [];
|
|
25
65
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
66
|
+
},
|
|
67
|
+
formResult: {
|
|
68
|
+
type: Object,
|
|
69
|
+
default() {
|
|
70
|
+
return {};
|
|
31
71
|
},
|
|
32
|
-
globalConfig: {
|
|
33
|
-
type: Object,
|
|
34
|
-
default() {
|
|
35
|
-
return {};
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
72
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
globalConfig: {
|
|
74
|
+
type: Object,
|
|
75
|
+
default() {
|
|
76
|
+
return {};
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
readonly: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
setup(props: any, { emit }) {
|
|
85
|
+
const { proxy } = getCurrentInstance() as any;
|
|
86
|
+
const rules: any = ref({});
|
|
87
|
+
const ruleForm = ref();
|
|
88
|
+
const controlObj = ref();
|
|
89
|
+
props.allFormList?.forEach((item: any) => {
|
|
90
|
+
getRules(item);
|
|
91
|
+
});
|
|
47
92
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
93
|
+
function getFormListRules(rules: any[]) {
|
|
94
|
+
const result: any[] = [];
|
|
95
|
+
if (Array.isArray(rules) && rules && rules.length > 0) {
|
|
96
|
+
rules.forEach((item) => {
|
|
97
|
+
if (item.type == "enum") {
|
|
98
|
+
const func = eval(`(${item.value})`);
|
|
99
|
+
result.push({
|
|
100
|
+
validator: func,
|
|
101
|
+
trigger: "blur",
|
|
102
|
+
});
|
|
103
|
+
} else if (item.type == "func") {
|
|
104
|
+
const mainData = props.formResult;
|
|
105
|
+
const func = eval(
|
|
106
|
+
`((rule, value, callback, mainData = mainData) => {${item.value.func}})`
|
|
107
|
+
);
|
|
108
|
+
result.push({
|
|
109
|
+
validator: func,
|
|
110
|
+
trigger: "blur",
|
|
111
|
+
});
|
|
112
|
+
console.log("mainData", mainData);
|
|
113
|
+
} else if (item.type == "high") {
|
|
114
|
+
if (item.value.ruleType == 5) {
|
|
61
115
|
result.push({
|
|
62
|
-
validator:
|
|
63
|
-
trigger:
|
|
116
|
+
validator: eval(item.value.validor),
|
|
117
|
+
trigger: item.value.trigger,
|
|
64
118
|
});
|
|
65
|
-
|
|
66
|
-
} else if (item.type == "high") {
|
|
67
|
-
if (item.value.ruleType == 5) {
|
|
68
|
-
result.push({
|
|
69
|
-
validator: eval(item.value.validor),
|
|
70
|
-
trigger: item.value.trigger,
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// let high = JSON.parse(JSON.stringify(item.value));
|
|
75
|
-
// delete high.ruleType;
|
|
76
|
-
result.push(item.value);
|
|
119
|
+
return;
|
|
77
120
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
121
|
+
// let high = JSON.parse(JSON.stringify(item.value));
|
|
122
|
+
// delete high.ruleType;
|
|
123
|
+
result.push(item.value);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
81
126
|
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
82
129
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
130
|
+
function getRules(item: any) {
|
|
131
|
+
if (!item.layout) {
|
|
132
|
+
let rule: any[] = [];
|
|
133
|
+
if (item.data.required) {
|
|
134
|
+
rule.push({
|
|
135
|
+
required: true,
|
|
136
|
+
message: "请输入" + item.data.label,
|
|
137
|
+
trigger: "blur",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// 新增 minLength 校验
|
|
141
|
+
if (
|
|
142
|
+
typeof item.data.minLength === "number" &&
|
|
143
|
+
item.data.minLength > 0
|
|
144
|
+
) {
|
|
145
|
+
rule.push({
|
|
146
|
+
validator: (rule: any, value: any, callback: any) => {
|
|
147
|
+
if (
|
|
148
|
+
typeof value === "string" &&
|
|
149
|
+
value.length < item.data.minLength
|
|
150
|
+
) {
|
|
151
|
+
callback(
|
|
152
|
+
new Error(
|
|
153
|
+
`${item.data.label}最少输入${item.data.minLength}个字符`
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
callback();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
trigger: "blur",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (typeof item.data.rule == "string") {
|
|
164
|
+
rule = rule.concat(proxy.$Flex.tryParseJson(item.data.rule));
|
|
165
|
+
} else {
|
|
166
|
+
rule = rule.concat(getFormListRules(item.data.rule));
|
|
167
|
+
}
|
|
168
|
+
// 特殊的jsoneditor表单要单独处理
|
|
169
|
+
if (item.data.json) {
|
|
170
|
+
rule.push(...proxy.$Flex.getJsonValidate());
|
|
171
|
+
}
|
|
172
|
+
rules.value[item.data.fieldName] = rule;
|
|
173
|
+
} else if (item.layout) {
|
|
174
|
+
if (item.ControlType == "Grid") {
|
|
175
|
+
item.data.columns.forEach((colItem: any) => {
|
|
176
|
+
colItem.list.forEach((listItem: any) => {
|
|
177
|
+
getRules(listItem);
|
|
114
178
|
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// 特殊的jsoneditor表单要单独处理
|
|
122
|
-
if (item.data.json) {
|
|
123
|
-
rule.push(...proxy.$Flex.getJsonValidate());
|
|
124
|
-
}
|
|
125
|
-
rules.value[item.data.fieldName] = rule;
|
|
126
|
-
} else if (item.layout) {
|
|
127
|
-
if (item.ControlType == "Grid") {
|
|
128
|
-
item.data.columns.forEach((colItem: any) => {
|
|
129
|
-
colItem.list.forEach((listItem: any) => {
|
|
179
|
+
});
|
|
180
|
+
} else if (item.ControlType == "TableLayout") {
|
|
181
|
+
const trs = item.data.trs;
|
|
182
|
+
trs.forEach((trItem: any) => {
|
|
183
|
+
trItem.tds.forEach((tdItem: any) => {
|
|
184
|
+
tdItem.list.forEach((listItem: any) => {
|
|
130
185
|
getRules(listItem);
|
|
131
186
|
});
|
|
132
187
|
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
} else if (item.ControlType == "Collapse" || item.ControlType == "Tabs") {
|
|
143
|
-
const items = item.data.items;
|
|
144
|
-
items.forEach((colItem: any) => {
|
|
145
|
-
colItem.list.forEach((listItem: any) => {
|
|
146
|
-
getRules(listItem);
|
|
147
|
-
});
|
|
188
|
+
});
|
|
189
|
+
} else if (
|
|
190
|
+
item.ControlType == "Collapse" ||
|
|
191
|
+
item.ControlType == "Tabs"
|
|
192
|
+
) {
|
|
193
|
+
const items = item.data.items;
|
|
194
|
+
items.forEach((colItem: any) => {
|
|
195
|
+
colItem.list.forEach((listItem: any) => {
|
|
196
|
+
getRules(listItem);
|
|
148
197
|
});
|
|
149
|
-
}
|
|
198
|
+
});
|
|
150
199
|
}
|
|
151
200
|
}
|
|
201
|
+
}
|
|
152
202
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
item.show = true;
|
|
203
|
+
const handleControlChange = () => {
|
|
204
|
+
const allFormLists: any = props.allFormList;
|
|
205
|
+
allFormLists.forEach((item: any) => {
|
|
206
|
+
if (item.data.showRule === "{}") {
|
|
207
|
+
item.show = true;
|
|
208
|
+
} else {
|
|
209
|
+
try {
|
|
210
|
+
if (Array.isArray(item.data.showRule)) {
|
|
211
|
+
item.show = conditionChange(
|
|
212
|
+
transformData(toRaw(item.data.showRule))
|
|
213
|
+
);
|
|
214
|
+
} else {
|
|
215
|
+
item.show = conditionChange(toRaw(item.data.showRule));
|
|
167
216
|
}
|
|
217
|
+
} catch (e) {
|
|
218
|
+
item.show = true;
|
|
168
219
|
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
executeFunc("updated");
|
|
223
|
+
emit("change");
|
|
224
|
+
};
|
|
225
|
+
function transformData(data: any) {
|
|
226
|
+
/**普通模式转为高级模式的数据结构,方便复用 */
|
|
227
|
+
const r: any = [];
|
|
228
|
+
data.forEach((item: any) => {
|
|
229
|
+
r.push({
|
|
230
|
+
type: "andgroup",
|
|
231
|
+
result: item.map((d: any) => {
|
|
232
|
+
return {
|
|
233
|
+
type: "data",
|
|
234
|
+
data: d,
|
|
235
|
+
};
|
|
236
|
+
}),
|
|
169
237
|
});
|
|
170
|
-
|
|
171
|
-
|
|
238
|
+
});
|
|
239
|
+
const result = {
|
|
240
|
+
type: "orgroup",
|
|
241
|
+
result: r,
|
|
172
242
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}),
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
function conditionChange(data: any) {
|
|
246
|
+
if (data.type == "andgroup") {
|
|
247
|
+
const result = data.result
|
|
248
|
+
.map((item: any) => {
|
|
249
|
+
const r = conditionChange(item);
|
|
250
|
+
return r;
|
|
251
|
+
})
|
|
252
|
+
.find((item: boolean) => {
|
|
253
|
+
return item == false;
|
|
185
254
|
});
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
} else {
|
|
235
|
-
isShow = result.value.includes(value);
|
|
236
|
-
}
|
|
237
|
-
break;
|
|
238
|
-
case "not in":
|
|
239
|
-
if (Array.isArray(value)) {
|
|
240
|
-
value.find((item) => {
|
|
241
|
-
if (!result.value.include(item)) {
|
|
242
|
-
isShow = !result.value.includes(item);
|
|
243
|
-
return item;
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
} else {
|
|
247
|
-
isShow = !result.value.includes(value);
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
return isShow;
|
|
255
|
+
return result === undefined ? true : result;
|
|
256
|
+
} else if (data.type == "orgroup") {
|
|
257
|
+
const result = data.result
|
|
258
|
+
.map((item: any) => {
|
|
259
|
+
const r = conditionChange(item);
|
|
260
|
+
return r;
|
|
261
|
+
})
|
|
262
|
+
.find((item: boolean) => {
|
|
263
|
+
return item == true;
|
|
264
|
+
});
|
|
265
|
+
return result === undefined ? false : result;
|
|
266
|
+
} else if (data.type == "data") {
|
|
267
|
+
const result = data.data;
|
|
268
|
+
const formResults: any = props.formResult;
|
|
269
|
+
const value = formResults[result.field];
|
|
270
|
+
let isShow = false;
|
|
271
|
+
switch (result.logic) {
|
|
272
|
+
case "=":
|
|
273
|
+
isShow = value == result.value;
|
|
274
|
+
break;
|
|
275
|
+
case "!=":
|
|
276
|
+
isShow = value != result.value;
|
|
277
|
+
break;
|
|
278
|
+
case "in":
|
|
279
|
+
if (Array.isArray(value)) {
|
|
280
|
+
value.find((item) => {
|
|
281
|
+
if (result.value.include(item)) {
|
|
282
|
+
isShow = result.value.includes(item);
|
|
283
|
+
return item;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
} else {
|
|
287
|
+
isShow = result.value.includes(value);
|
|
288
|
+
}
|
|
289
|
+
break;
|
|
290
|
+
case "not in":
|
|
291
|
+
if (Array.isArray(value)) {
|
|
292
|
+
value.find((item) => {
|
|
293
|
+
if (!result.value.include(item)) {
|
|
294
|
+
isShow = !result.value.includes(item);
|
|
295
|
+
return item;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
isShow = !result.value.includes(value);
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
252
302
|
}
|
|
303
|
+
return isShow;
|
|
253
304
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
305
|
+
}
|
|
306
|
+
function reset() {
|
|
307
|
+
ruleForm.value.resetFields();
|
|
308
|
+
}
|
|
309
|
+
function getValidate() {
|
|
310
|
+
return new Promise((resolve) => {
|
|
311
|
+
ruleForm.value.validate((valide: boolean) => {
|
|
312
|
+
resolve(valide);
|
|
262
313
|
});
|
|
263
|
-
}
|
|
264
|
-
onMounted(() => {
|
|
265
|
-
handleControlChange();
|
|
266
|
-
executeFunc("mounted");
|
|
267
314
|
});
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
315
|
+
}
|
|
316
|
+
onMounted(() => {
|
|
317
|
+
handleControlChange();
|
|
318
|
+
executeFunc("mounted");
|
|
319
|
+
});
|
|
320
|
+
function executeFunc(funcName: string) {
|
|
321
|
+
const mountedAction = props.globalConfig.action?.find((item: any) => {
|
|
322
|
+
if (item.type == funcName) {
|
|
323
|
+
return item;
|
|
276
324
|
}
|
|
325
|
+
});
|
|
326
|
+
if (mountedAction) {
|
|
327
|
+
eval(`(function(){${mountedAction.funcStr}}).call(proxy)`);
|
|
277
328
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
}
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
rules,
|
|
332
|
+
ruleForm,
|
|
333
|
+
controlObj,
|
|
334
|
+
handleControlChange,
|
|
335
|
+
reset,
|
|
336
|
+
getValidate,
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
});
|
|
288
340
|
</script>
|