tianheng-ui 0.1.81 → 0.1.84
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +72 -15
- package/lib/theme-chalk/fonts/formMaking-iconfont.svg +155 -155
- package/lib/theme-chalk/fonts/th-iconfont.css +2402 -2402
- package/lib/theme-chalk/js/axios.js +87 -87
- package/lib/tianheng-ui.js +13 -13
- package/package.json +87 -86
- package/packages/CodeEditor/index.vue +3 -2
- package/packages/FormMaking/GenerateForm.vue +392 -392
- package/packages/FormMaking/Upload/index.vue +571 -571
- package/packages/FormMaking/WidgetFooter.vue +16 -0
- package/packages/FormMaking/WidgetForm.vue +145 -146
- package/packages/FormMaking/WidgetTools.vue +21 -16
- package/packages/FormMaking/custom/config.js +120 -2
- package/packages/FormMaking/custom/configs/number.vue +0 -5
- package/packages/FormMaking/custom/configs/page-table.vue +146 -0
- package/packages/FormMaking/custom/index.js +1 -1
- package/packages/FormMaking/custom/items/page-table.vue +250 -0
- package/packages/FormMaking/custom/register.js +43 -43
- package/packages/FormMaking/iconfont/demo.css +539 -539
- package/packages/FormMaking/iconfont/demo_index.html +1159 -1159
- package/packages/FormMaking/iconfont/formMaking-iconfont.css +189 -189
- package/packages/FormMaking/iconfont/formMaking-iconfont.svg +155 -155
- package/packages/FormMaking/index.js +33 -33
- package/packages/FormMaking/index.vue +6 -1
- package/packages/FormMaking/lang/en-US.js +187 -187
- package/packages/FormMaking/lang/zh-CN.js +187 -187
- package/packages/FormMaking/network/axios.js +88 -88
- package/packages/FormMaking/styles/index.scss +216 -216
- package/packages/FormMaking/util/generateCode.js +427 -157
- package/packages/FormMaking/util/index.js +98 -98
- package/packages/TableMaking/network/axios.js +88 -88
- package/packages/TableMaking/widgetConfig.vue +1 -1
@@ -1,392 +1,392 @@
|
|
1
|
-
<template>
|
2
|
-
<div v-if="formConfig.config && showForm">
|
3
|
-
<el-form
|
4
|
-
class="generateForm"
|
5
|
-
:class="{ isHideLabel: formConfig.config.hideLabel }"
|
6
|
-
:style="{ width: formConfig.config.width }"
|
7
|
-
:model="models"
|
8
|
-
:label-suffix="formConfig.config.labelSuffix"
|
9
|
-
:label-position="formConfig.config.labelPosition"
|
10
|
-
:label-width="formConfig.config.labelWidth + 'px'"
|
11
|
-
:size="formConfig.config.size"
|
12
|
-
ref="generateForm"
|
13
|
-
>
|
14
|
-
<genetate-form-item
|
15
|
-
v-for="item in formConfig.list"
|
16
|
-
:key="item.key"
|
17
|
-
:widget="item"
|
18
|
-
:model.sync="
|
19
|
-
item.type === 'grid' && !item.options.isEntity
|
20
|
-
? models
|
21
|
-
: models[item.model]
|
22
|
-
"
|
23
|
-
:models="models"
|
24
|
-
:slotKeys="slotKeys"
|
25
|
-
:config="formConfig.config"
|
26
|
-
:componentsData="componentsData"
|
27
|
-
@input-change="handleInputChange"
|
28
|
-
@button-submit="handleButtonSubmit"
|
29
|
-
>
|
30
|
-
<template v-for="name in slotKeys" :slot="name">
|
31
|
-
<slot :name="name" />
|
32
|
-
</template>
|
33
|
-
</genetate-form-item>
|
34
|
-
</el-form>
|
35
|
-
</div>
|
36
|
-
</template>
|
37
|
-
|
38
|
-
<script>
|
39
|
-
import GenetateFormItem from "./GenerateFormItem";
|
40
|
-
import * as Axios from "./network/axios";
|
41
|
-
import appConfig from "./config/index";
|
42
|
-
import { deepClone, getProperty, setProperty } from "./util/index";
|
43
|
-
|
44
|
-
export default {
|
45
|
-
name: "thFormGenerate",
|
46
|
-
components: { GenetateFormItem },
|
47
|
-
props: {
|
48
|
-
businessId: {
|
49
|
-
type: String,
|
50
|
-
default: ""
|
51
|
-
},
|
52
|
-
formId: String,
|
53
|
-
query: Object,
|
54
|
-
oauthConfig: {
|
55
|
-
type: Object,
|
56
|
-
default: () => {
|
57
|
-
return {};
|
58
|
-
}
|
59
|
-
},
|
60
|
-
config: {
|
61
|
-
type: Object,
|
62
|
-
default: () => {
|
63
|
-
return {};
|
64
|
-
}
|
65
|
-
},
|
66
|
-
value: {
|
67
|
-
type: Object,
|
68
|
-
default: () => {
|
69
|
-
return {};
|
70
|
-
}
|
71
|
-
},
|
72
|
-
slotKeys: {
|
73
|
-
type: Array,
|
74
|
-
default: () => {
|
75
|
-
return [];
|
76
|
-
}
|
77
|
-
}
|
78
|
-
},
|
79
|
-
data() {
|
80
|
-
return {
|
81
|
-
formConfig: this.config,
|
82
|
-
models: this.value,
|
83
|
-
componentsData: [],
|
84
|
-
axios: null,
|
85
|
-
showForm: false
|
86
|
-
};
|
87
|
-
},
|
88
|
-
computed: {
|
89
|
-
formWidth() {
|
90
|
-
if (this.formConfig.config.width) return this.formConfig.config.width;
|
91
|
-
return "";
|
92
|
-
}
|
93
|
-
},
|
94
|
-
watch: {
|
95
|
-
config(val) {
|
96
|
-
this.setConfig(val);
|
97
|
-
},
|
98
|
-
value(val) {
|
99
|
-
if (val) this.models = val;
|
100
|
-
console.log("watch models =>", this.models);
|
101
|
-
}
|
102
|
-
},
|
103
|
-
created() {},
|
104
|
-
mounted() {
|
105
|
-
sessionStorage.setItem(
|
106
|
-
appConfig.storageKeys.oauthConfig,
|
107
|
-
JSON.stringify(this.oauthConfig)
|
108
|
-
);
|
109
|
-
this.axios = Axios.init(this.oauthConfig);
|
110
|
-
|
111
|
-
this.generateModle(this.formConfig.list, this.models);
|
112
|
-
console.log("mounted models =>", this.models);
|
113
|
-
this.handleMountedRemotData();
|
114
|
-
this.showForm = true;
|
115
|
-
},
|
116
|
-
methods: {
|
117
|
-
generateModle(genList, modelObj) {
|
118
|
-
if (!genList) return;
|
119
|
-
genList.map(item => {
|
120
|
-
if (item.type === "grid") {
|
121
|
-
if (item.options.isEntity) {
|
122
|
-
const dic = {};
|
123
|
-
modelObj[item.model] = dic;
|
124
|
-
|
125
|
-
item.options.columns.forEach(item => {
|
126
|
-
this.generateModle(item.list, dic, item.model);
|
127
|
-
});
|
128
|
-
} else {
|
129
|
-
item.options.columns.forEach(item => {
|
130
|
-
this.generateModle(item.list, modelObj);
|
131
|
-
});
|
132
|
-
}
|
133
|
-
} else if (item.type === "tabs") {
|
134
|
-
const dic = {};
|
135
|
-
modelObj[item.model] = dic;
|
136
|
-
|
137
|
-
item.options.columns.forEach(item2 => {
|
138
|
-
dic[item2.value] = {};
|
139
|
-
this.generateModle(item2.list, dic[item2.value]);
|
140
|
-
});
|
141
|
-
} else if (item.type === "table" || item.type === "list") {
|
142
|
-
!item.options.defaultValue && (item.options.defaultValue = []);
|
143
|
-
modelObj[item.model] = deepClone(item.options.defaultValue);
|
144
|
-
this.generateModle(item.options.columns);
|
145
|
-
} else if (item.type === "blank" && modelObj) {
|
146
|
-
const value =
|
147
|
-
getProperty(this.value, item.model) ||
|
148
|
-
{ String: "", Object: {}, Array: [] }[item.options.defaultType];
|
149
|
-
// setProperty(modelObj, item.model, value);
|
150
|
-
this.$set(modelObj, item.model, value);
|
151
|
-
this.generateRules(item);
|
152
|
-
} else if (modelObj) {
|
153
|
-
const value =
|
154
|
-
getProperty(this.value, item.model) ||
|
155
|
-
JSON.parse(JSON.stringify(item.options.defaultValue));
|
156
|
-
// setProperty(modelObj, item.model, value);
|
157
|
-
this.$set(modelObj, item.model, value);
|
158
|
-
this.generateRules(item);
|
159
|
-
} else {
|
160
|
-
this.generateRules(item);
|
161
|
-
}
|
162
|
-
});
|
163
|
-
},
|
164
|
-
generateRules(item) {
|
165
|
-
// 配置正则校验
|
166
|
-
if (item.rules) {
|
167
|
-
item.rules.forEach(rule => {
|
168
|
-
if (rule.patternStr) {
|
169
|
-
rule.pattern = new RegExp(rule.patternStr);
|
170
|
-
}
|
171
|
-
});
|
172
|
-
} else {
|
173
|
-
item.rules = [];
|
174
|
-
}
|
175
|
-
// 配置必填项校验
|
176
|
-
// if (item.options.required) {
|
177
|
-
// item.rules.push({
|
178
|
-
// required: true,
|
179
|
-
// message: "必需项",
|
180
|
-
// trigger: "change"
|
181
|
-
// });
|
182
|
-
// }
|
183
|
-
this.hendleElementRemoteData(item);
|
184
|
-
},
|
185
|
-
// 获取组件的远端数据
|
186
|
-
hendleElementRemoteData(item) {
|
187
|
-
if (!item.options.remote || !item.options.remote.open) return;
|
188
|
-
if (item.type === "upload" || item.type === "button") return;
|
189
|
-
|
190
|
-
let api = "";
|
191
|
-
if (item.options.remote.api.constructor === String) {
|
192
|
-
api = this.formConfig.config.network[item.options.remote.api];
|
193
|
-
} else {
|
194
|
-
api = deepClone(item.options.remote.api);
|
195
|
-
}
|
196
|
-
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
197
|
-
|
198
|
-
const requestConfig = {
|
199
|
-
url: api.url,
|
200
|
-
method: api.method,
|
201
|
-
headers: { ...api.headers, businessId: this.businessId }
|
202
|
-
};
|
203
|
-
|
204
|
-
// 因为是组件的远端接口,优先级:默认值 > 路由参数
|
205
|
-
const params = {};
|
206
|
-
for (let e of api.inParams) {
|
207
|
-
const value =
|
208
|
-
e.defaultValue || getProperty(this.query, e.pAlias) || null;
|
209
|
-
setProperty(params, e.pAlias, value);
|
210
|
-
}
|
211
|
-
if (api.needPage) {
|
212
|
-
params.pageNum = params.pageNum || 1;
|
213
|
-
params.pageSize = params.pageSize || 20;
|
214
|
-
}
|
215
|
-
if (["get", "delete"].includes(api.method.toLowerCase()))
|
216
|
-
requestConfig.params = params;
|
217
|
-
else requestConfig.data = params;
|
218
|
-
|
219
|
-
this.axios(requestConfig).then(res => {
|
220
|
-
const resultData = res.data.records ? res.data.records : res.data;
|
221
|
-
if (item.type === "descriptions" || item.type === "workflow") {
|
222
|
-
item.options.defaultValue = resultData;
|
223
|
-
} else {
|
224
|
-
const props = {
|
225
|
-
value: item.options.remote.props.value || "value",
|
226
|
-
label: item.options.remote.props.label || "label",
|
227
|
-
children: item.options.remote.props.children || "children"
|
228
|
-
};
|
229
|
-
const initOptions = list => {
|
230
|
-
return list.map(element => {
|
231
|
-
const dic = {
|
232
|
-
value: element[props.value],
|
233
|
-
label: element[props.label]
|
234
|
-
};
|
235
|
-
if (element[props.children] && element[props.children].length) {
|
236
|
-
dic.children = initOptions(element[props.children]);
|
237
|
-
}
|
238
|
-
return dic;
|
239
|
-
});
|
240
|
-
};
|
241
|
-
item.options.options = initOptions(resultData);
|
242
|
-
}
|
243
|
-
});
|
244
|
-
},
|
245
|
-
handleMountedRemotData() {
|
246
|
-
if (!this.formConfig.config.mounted.api) return;
|
247
|
-
|
248
|
-
let api = "";
|
249
|
-
if (this.formConfig.config.mounted.api.constructor === String) {
|
250
|
-
api = this.formConfig.config.network[
|
251
|
-
this.formConfig.config.mounted.api
|
252
|
-
];
|
253
|
-
} else {
|
254
|
-
api = deepClone(this.formConfig.config.mounted.api);
|
255
|
-
}
|
256
|
-
|
257
|
-
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
258
|
-
|
259
|
-
const requestConfig = {
|
260
|
-
url: api.url,
|
261
|
-
method: api.method,
|
262
|
-
headers: { ...api.headers, businessId: this.businessId }
|
263
|
-
};
|
264
|
-
const params = {};
|
265
|
-
for (let e of api.inParams) {
|
266
|
-
const value =
|
267
|
-
e.defaultValue ||
|
268
|
-
getProperty(this.models, e.pAlias) ||
|
269
|
-
getProperty(this.query, e.pAlias) ||
|
270
|
-
null;
|
271
|
-
setProperty(params, e.pAlias, value);
|
272
|
-
}
|
273
|
-
if (api.needPage) {
|
274
|
-
params.pageNum = params.pageNum || 1;
|
275
|
-
params.pageSize = params.pageSize || 20;
|
276
|
-
}
|
277
|
-
if (["get", "delete"].includes(api.method.toLowerCase()))
|
278
|
-
requestConfig.params = params;
|
279
|
-
else requestConfig.data = params;
|
280
|
-
|
281
|
-
this.axios(requestConfig).then(res => {
|
282
|
-
const resultData = api.needPage ? res.data.records : res.data;
|
283
|
-
this.models = Object.assign(this.models, resultData);
|
284
|
-
});
|
285
|
-
},
|
286
|
-
handleButtonSubmit(element) {
|
287
|
-
if (!element.options.remote.api)
|
288
|
-
return this.$emit("button-submit", element);
|
289
|
-
|
290
|
-
let api = "";
|
291
|
-
if (element.options.remote.api.constructor === String) {
|
292
|
-
api = this.formConfig.config.network[element.options.remote.api];
|
293
|
-
} else {
|
294
|
-
api = deepClone(element.options.remote.api);
|
295
|
-
}
|
296
|
-
|
297
|
-
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
298
|
-
|
299
|
-
let params = {};
|
300
|
-
const initParams = list => {
|
301
|
-
list.map(item => {
|
302
|
-
if (item.children) {
|
303
|
-
initParams(item.children);
|
304
|
-
} else {
|
305
|
-
const value =
|
306
|
-
item.defaultValue ||
|
307
|
-
getProperty(this.models, item.pAlias) ||
|
308
|
-
null;
|
309
|
-
setProperty(params, item.pAlias, value);
|
310
|
-
}
|
311
|
-
});
|
312
|
-
};
|
313
|
-
api.inParams && initParams(api.inParams);
|
314
|
-
if (api.needPage) {
|
315
|
-
params.pageNum = params.pageNum || 1;
|
316
|
-
params.pageSize = params.pageNum || 20;
|
317
|
-
}
|
318
|
-
|
319
|
-
const requestConfig = {
|
320
|
-
url: api.url,
|
321
|
-
method: api.method,
|
322
|
-
headers: {
|
323
|
-
...api.headers,
|
324
|
-
formId: this.formId,
|
325
|
-
businessId: this.businessId
|
326
|
-
}
|
327
|
-
};
|
328
|
-
if (["get", "delete"].includes(api.method.toLowerCase()))
|
329
|
-
requestConfig.params = params;
|
330
|
-
else requestConfig.data = params;
|
331
|
-
|
332
|
-
this.$refs.generateForm.validate(valid => {
|
333
|
-
if (!valid) return;
|
334
|
-
element.options.loading = true;
|
335
|
-
this.axios(requestConfig)
|
336
|
-
.then(res => {
|
337
|
-
element.options.loading = false;
|
338
|
-
this.$emit("button-submit", element);
|
339
|
-
})
|
340
|
-
.catch(err => {
|
341
|
-
element.options.loading = false;
|
342
|
-
});
|
343
|
-
});
|
344
|
-
},
|
345
|
-
handleInputChange(value, field) {
|
346
|
-
this.$emit("change", field, value, this.models);
|
347
|
-
},
|
348
|
-
reset() {
|
349
|
-
this.$refs.generateForm.resetFields();
|
350
|
-
},
|
351
|
-
getData() {
|
352
|
-
return new Promise((resolve, reject) => {
|
353
|
-
this.$refs.generateForm.validate(valid => {
|
354
|
-
if (valid) {
|
355
|
-
resolve(this.models);
|
356
|
-
} else {
|
357
|
-
reject(new Error("表单数据校验失败").message);
|
358
|
-
}
|
359
|
-
});
|
360
|
-
});
|
361
|
-
},
|
362
|
-
setConfig(json) {
|
363
|
-
this.formConfig = json;
|
364
|
-
this.generateModle(this.formConfig.list, this.models);
|
365
|
-
this.handleMountedRemotData();
|
366
|
-
}
|
367
|
-
}
|
368
|
-
};
|
369
|
-
</script>
|
370
|
-
|
371
|
-
<style lang="less" scoped>
|
372
|
-
.generateForm {
|
373
|
-
margin: 0 auto;
|
374
|
-
/deep/ .widget-form-list-table > .el-form-item__content {
|
375
|
-
.el-form-item__label {
|
376
|
-
display: none;
|
377
|
-
}
|
378
|
-
.el-form-item__content {
|
379
|
-
margin-left: 0 !important;
|
380
|
-
}
|
381
|
-
}
|
382
|
-
|
383
|
-
.isHideLabel {
|
384
|
-
.el-form-item__label {
|
385
|
-
display: none;
|
386
|
-
}
|
387
|
-
.el-form-item__content {
|
388
|
-
margin-left: 0 !important;
|
389
|
-
}
|
390
|
-
}
|
391
|
-
}
|
392
|
-
</style>
|
1
|
+
<template>
|
2
|
+
<div v-if="formConfig.config && showForm">
|
3
|
+
<el-form
|
4
|
+
class="generateForm"
|
5
|
+
:class="{ isHideLabel: formConfig.config.hideLabel }"
|
6
|
+
:style="{ width: formConfig.config.width }"
|
7
|
+
:model="models"
|
8
|
+
:label-suffix="formConfig.config.labelSuffix"
|
9
|
+
:label-position="formConfig.config.labelPosition"
|
10
|
+
:label-width="formConfig.config.labelWidth + 'px'"
|
11
|
+
:size="formConfig.config.size"
|
12
|
+
ref="generateForm"
|
13
|
+
>
|
14
|
+
<genetate-form-item
|
15
|
+
v-for="item in formConfig.list"
|
16
|
+
:key="item.key"
|
17
|
+
:widget="item"
|
18
|
+
:model.sync="
|
19
|
+
item.type === 'grid' && !item.options.isEntity
|
20
|
+
? models
|
21
|
+
: models[item.model]
|
22
|
+
"
|
23
|
+
:models="models"
|
24
|
+
:slotKeys="slotKeys"
|
25
|
+
:config="formConfig.config"
|
26
|
+
:componentsData="componentsData"
|
27
|
+
@input-change="handleInputChange"
|
28
|
+
@button-submit="handleButtonSubmit"
|
29
|
+
>
|
30
|
+
<template v-for="name in slotKeys" :slot="name">
|
31
|
+
<slot :name="name" />
|
32
|
+
</template>
|
33
|
+
</genetate-form-item>
|
34
|
+
</el-form>
|
35
|
+
</div>
|
36
|
+
</template>
|
37
|
+
|
38
|
+
<script>
|
39
|
+
import GenetateFormItem from "./GenerateFormItem";
|
40
|
+
import * as Axios from "./network/axios";
|
41
|
+
import appConfig from "./config/index";
|
42
|
+
import { deepClone, getProperty, setProperty } from "./util/index";
|
43
|
+
|
44
|
+
export default {
|
45
|
+
name: "thFormGenerate",
|
46
|
+
components: { GenetateFormItem },
|
47
|
+
props: {
|
48
|
+
businessId: {
|
49
|
+
type: String,
|
50
|
+
default: ""
|
51
|
+
},
|
52
|
+
formId: String,
|
53
|
+
query: Object,
|
54
|
+
oauthConfig: {
|
55
|
+
type: Object,
|
56
|
+
default: () => {
|
57
|
+
return {};
|
58
|
+
}
|
59
|
+
},
|
60
|
+
config: {
|
61
|
+
type: Object,
|
62
|
+
default: () => {
|
63
|
+
return {};
|
64
|
+
}
|
65
|
+
},
|
66
|
+
value: {
|
67
|
+
type: Object,
|
68
|
+
default: () => {
|
69
|
+
return {};
|
70
|
+
}
|
71
|
+
},
|
72
|
+
slotKeys: {
|
73
|
+
type: Array,
|
74
|
+
default: () => {
|
75
|
+
return [];
|
76
|
+
}
|
77
|
+
}
|
78
|
+
},
|
79
|
+
data() {
|
80
|
+
return {
|
81
|
+
formConfig: this.config,
|
82
|
+
models: this.value,
|
83
|
+
componentsData: [],
|
84
|
+
axios: null,
|
85
|
+
showForm: false
|
86
|
+
};
|
87
|
+
},
|
88
|
+
computed: {
|
89
|
+
formWidth() {
|
90
|
+
if (this.formConfig.config.width) return this.formConfig.config.width;
|
91
|
+
return "";
|
92
|
+
}
|
93
|
+
},
|
94
|
+
watch: {
|
95
|
+
config(val) {
|
96
|
+
this.setConfig(val);
|
97
|
+
},
|
98
|
+
value(val) {
|
99
|
+
if (val) this.models = val;
|
100
|
+
console.log("watch models =>", this.models);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
created() {},
|
104
|
+
mounted() {
|
105
|
+
sessionStorage.setItem(
|
106
|
+
appConfig.storageKeys.oauthConfig,
|
107
|
+
JSON.stringify(this.oauthConfig)
|
108
|
+
);
|
109
|
+
this.axios = Axios.init(this.oauthConfig);
|
110
|
+
|
111
|
+
this.generateModle(this.formConfig.list, this.models);
|
112
|
+
console.log("mounted models =>", this.models);
|
113
|
+
this.handleMountedRemotData();
|
114
|
+
this.showForm = true;
|
115
|
+
},
|
116
|
+
methods: {
|
117
|
+
generateModle(genList, modelObj) {
|
118
|
+
if (!genList) return;
|
119
|
+
genList.map(item => {
|
120
|
+
if (item.type === "grid") {
|
121
|
+
if (item.options.isEntity) {
|
122
|
+
const dic = {};
|
123
|
+
modelObj[item.model] = dic;
|
124
|
+
|
125
|
+
item.options.columns.forEach(item => {
|
126
|
+
this.generateModle(item.list, dic, item.model);
|
127
|
+
});
|
128
|
+
} else {
|
129
|
+
item.options.columns.forEach(item => {
|
130
|
+
this.generateModle(item.list, modelObj);
|
131
|
+
});
|
132
|
+
}
|
133
|
+
} else if (item.type === "tabs") {
|
134
|
+
const dic = {};
|
135
|
+
modelObj[item.model] = dic;
|
136
|
+
|
137
|
+
item.options.columns.forEach(item2 => {
|
138
|
+
dic[item2.value] = {};
|
139
|
+
this.generateModle(item2.list, dic[item2.value]);
|
140
|
+
});
|
141
|
+
} else if (item.type === "table" || item.type === "list") {
|
142
|
+
!item.options.defaultValue && (item.options.defaultValue = []);
|
143
|
+
modelObj[item.model] = deepClone(item.options.defaultValue);
|
144
|
+
this.generateModle(item.options.columns);
|
145
|
+
} else if (item.type === "blank" && modelObj) {
|
146
|
+
const value =
|
147
|
+
getProperty(this.value, item.model) ||
|
148
|
+
{ String: "", Object: {}, Array: [] }[item.options.defaultType];
|
149
|
+
// setProperty(modelObj, item.model, value);
|
150
|
+
this.$set(modelObj, item.model, value);
|
151
|
+
this.generateRules(item);
|
152
|
+
} else if (modelObj) {
|
153
|
+
const value =
|
154
|
+
getProperty(this.value, item.model) ||
|
155
|
+
JSON.parse(JSON.stringify(item.options.defaultValue || ''));
|
156
|
+
// setProperty(modelObj, item.model, value);
|
157
|
+
this.$set(modelObj, item.model, value);
|
158
|
+
this.generateRules(item);
|
159
|
+
} else {
|
160
|
+
this.generateRules(item);
|
161
|
+
}
|
162
|
+
});
|
163
|
+
},
|
164
|
+
generateRules(item) {
|
165
|
+
// 配置正则校验
|
166
|
+
if (item.rules) {
|
167
|
+
item.rules.forEach(rule => {
|
168
|
+
if (rule.patternStr) {
|
169
|
+
rule.pattern = new RegExp(rule.patternStr);
|
170
|
+
}
|
171
|
+
});
|
172
|
+
} else {
|
173
|
+
item.rules = [];
|
174
|
+
}
|
175
|
+
// 配置必填项校验
|
176
|
+
// if (item.options.required) {
|
177
|
+
// item.rules.push({
|
178
|
+
// required: true,
|
179
|
+
// message: "必需项",
|
180
|
+
// trigger: "change"
|
181
|
+
// });
|
182
|
+
// }
|
183
|
+
this.hendleElementRemoteData(item);
|
184
|
+
},
|
185
|
+
// 获取组件的远端数据
|
186
|
+
hendleElementRemoteData(item) {
|
187
|
+
if (!item.options.remote || !item.options.remote.open) return;
|
188
|
+
if (item.type === "upload" || item.type === "button") return;
|
189
|
+
|
190
|
+
let api = "";
|
191
|
+
if (item.options.remote.api.constructor === String) {
|
192
|
+
api = this.formConfig.config.network[item.options.remote.api];
|
193
|
+
} else {
|
194
|
+
api = deepClone(item.options.remote.api);
|
195
|
+
}
|
196
|
+
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
197
|
+
|
198
|
+
const requestConfig = {
|
199
|
+
url: api.url,
|
200
|
+
method: api.method,
|
201
|
+
headers: { ...api.headers, businessId: this.businessId }
|
202
|
+
};
|
203
|
+
|
204
|
+
// 因为是组件的远端接口,优先级:默认值 > 路由参数
|
205
|
+
const params = {};
|
206
|
+
for (let e of api.inParams) {
|
207
|
+
const value =
|
208
|
+
e.defaultValue || getProperty(this.query, e.pAlias) || null;
|
209
|
+
setProperty(params, e.pAlias, value);
|
210
|
+
}
|
211
|
+
if (api.needPage) {
|
212
|
+
params.pageNum = params.pageNum || 1;
|
213
|
+
params.pageSize = params.pageSize || 20;
|
214
|
+
}
|
215
|
+
if (["get", "delete"].includes(api.method.toLowerCase()))
|
216
|
+
requestConfig.params = params;
|
217
|
+
else requestConfig.data = params;
|
218
|
+
|
219
|
+
this.axios(requestConfig).then(res => {
|
220
|
+
const resultData = res.data.records ? res.data.records : res.data;
|
221
|
+
if (item.type === "descriptions" || item.type === "workflow") {
|
222
|
+
item.options.defaultValue = resultData;
|
223
|
+
} else {
|
224
|
+
const props = {
|
225
|
+
value: item.options.remote.props.value || "value",
|
226
|
+
label: item.options.remote.props.label || "label",
|
227
|
+
children: item.options.remote.props.children || "children"
|
228
|
+
};
|
229
|
+
const initOptions = list => {
|
230
|
+
return list.map(element => {
|
231
|
+
const dic = {
|
232
|
+
value: element[props.value],
|
233
|
+
label: element[props.label]
|
234
|
+
};
|
235
|
+
if (element[props.children] && element[props.children].length) {
|
236
|
+
dic.children = initOptions(element[props.children]);
|
237
|
+
}
|
238
|
+
return dic;
|
239
|
+
});
|
240
|
+
};
|
241
|
+
item.options.options = initOptions(resultData);
|
242
|
+
}
|
243
|
+
});
|
244
|
+
},
|
245
|
+
handleMountedRemotData() {
|
246
|
+
if (!this.formConfig.config.mounted.api) return;
|
247
|
+
|
248
|
+
let api = "";
|
249
|
+
if (this.formConfig.config.mounted.api.constructor === String) {
|
250
|
+
api = this.formConfig.config.network[
|
251
|
+
this.formConfig.config.mounted.api
|
252
|
+
];
|
253
|
+
} else {
|
254
|
+
api = deepClone(this.formConfig.config.mounted.api);
|
255
|
+
}
|
256
|
+
|
257
|
+
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
258
|
+
|
259
|
+
const requestConfig = {
|
260
|
+
url: api.url,
|
261
|
+
method: api.method,
|
262
|
+
headers: { ...api.headers, businessId: this.businessId }
|
263
|
+
};
|
264
|
+
const params = {};
|
265
|
+
for (let e of api.inParams) {
|
266
|
+
const value =
|
267
|
+
e.defaultValue ||
|
268
|
+
getProperty(this.models, e.pAlias) ||
|
269
|
+
getProperty(this.query, e.pAlias) ||
|
270
|
+
null;
|
271
|
+
setProperty(params, e.pAlias, value);
|
272
|
+
}
|
273
|
+
if (api.needPage) {
|
274
|
+
params.pageNum = params.pageNum || 1;
|
275
|
+
params.pageSize = params.pageSize || 20;
|
276
|
+
}
|
277
|
+
if (["get", "delete"].includes(api.method.toLowerCase()))
|
278
|
+
requestConfig.params = params;
|
279
|
+
else requestConfig.data = params;
|
280
|
+
|
281
|
+
this.axios(requestConfig).then(res => {
|
282
|
+
const resultData = api.needPage ? res.data.records : res.data;
|
283
|
+
this.models = Object.assign(this.models, resultData);
|
284
|
+
});
|
285
|
+
},
|
286
|
+
handleButtonSubmit(element) {
|
287
|
+
if (!element.options.remote.api)
|
288
|
+
return this.$emit("button-submit", element);
|
289
|
+
|
290
|
+
let api = "";
|
291
|
+
if (element.options.remote.api.constructor === String) {
|
292
|
+
api = this.formConfig.config.network[element.options.remote.api];
|
293
|
+
} else {
|
294
|
+
api = deepClone(element.options.remote.api);
|
295
|
+
}
|
296
|
+
|
297
|
+
if (!api) return this.$message.warning("未知的接口,请检查配置信息");
|
298
|
+
|
299
|
+
let params = {};
|
300
|
+
const initParams = list => {
|
301
|
+
list.map(item => {
|
302
|
+
if (item.children) {
|
303
|
+
initParams(item.children);
|
304
|
+
} else {
|
305
|
+
const value =
|
306
|
+
item.defaultValue ||
|
307
|
+
getProperty(this.models, item.pAlias) ||
|
308
|
+
null;
|
309
|
+
setProperty(params, item.pAlias, value);
|
310
|
+
}
|
311
|
+
});
|
312
|
+
};
|
313
|
+
api.inParams && initParams(api.inParams);
|
314
|
+
if (api.needPage) {
|
315
|
+
params.pageNum = params.pageNum || 1;
|
316
|
+
params.pageSize = params.pageNum || 20;
|
317
|
+
}
|
318
|
+
|
319
|
+
const requestConfig = {
|
320
|
+
url: api.url,
|
321
|
+
method: api.method,
|
322
|
+
headers: {
|
323
|
+
...api.headers,
|
324
|
+
formId: this.formId,
|
325
|
+
businessId: this.businessId
|
326
|
+
}
|
327
|
+
};
|
328
|
+
if (["get", "delete"].includes(api.method.toLowerCase()))
|
329
|
+
requestConfig.params = params;
|
330
|
+
else requestConfig.data = params;
|
331
|
+
|
332
|
+
this.$refs.generateForm.validate(valid => {
|
333
|
+
if (!valid) return;
|
334
|
+
element.options.loading = true;
|
335
|
+
this.axios(requestConfig)
|
336
|
+
.then(res => {
|
337
|
+
element.options.loading = false;
|
338
|
+
this.$emit("button-submit", element);
|
339
|
+
})
|
340
|
+
.catch(err => {
|
341
|
+
element.options.loading = false;
|
342
|
+
});
|
343
|
+
});
|
344
|
+
},
|
345
|
+
handleInputChange(value, field) {
|
346
|
+
this.$emit("change", field, value, this.models);
|
347
|
+
},
|
348
|
+
reset() {
|
349
|
+
this.$refs.generateForm.resetFields();
|
350
|
+
},
|
351
|
+
getData() {
|
352
|
+
return new Promise((resolve, reject) => {
|
353
|
+
this.$refs.generateForm.validate(valid => {
|
354
|
+
if (valid) {
|
355
|
+
resolve(this.models);
|
356
|
+
} else {
|
357
|
+
reject(new Error("表单数据校验失败").message);
|
358
|
+
}
|
359
|
+
});
|
360
|
+
});
|
361
|
+
},
|
362
|
+
setConfig(json) {
|
363
|
+
this.formConfig = json;
|
364
|
+
this.generateModle(this.formConfig.list, this.models);
|
365
|
+
this.handleMountedRemotData();
|
366
|
+
}
|
367
|
+
}
|
368
|
+
};
|
369
|
+
</script>
|
370
|
+
|
371
|
+
<style lang="less" scoped>
|
372
|
+
.generateForm {
|
373
|
+
margin: 0 auto;
|
374
|
+
/deep/ .widget-form-list-table > .el-form-item__content {
|
375
|
+
.el-form-item__label {
|
376
|
+
display: none;
|
377
|
+
}
|
378
|
+
.el-form-item__content {
|
379
|
+
margin-left: 0 !important;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
|
383
|
+
.isHideLabel {
|
384
|
+
.el-form-item__label {
|
385
|
+
display: none;
|
386
|
+
}
|
387
|
+
.el-form-item__content {
|
388
|
+
margin-left: 0 !important;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
}
|
392
|
+
</style>
|