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
| import { buildBitUUID } from '@jnpf/utils';
|
| import { cloneDeep } from 'lodash-es';
|
| import { formConf as defaultFormConf, inputComponents, selectComponents, systemComponents } from '#/components/FormGenerator/src/helper/componentMap';
| import { dyOptionsList } from '#/components/FormGenerator/src/helper/config';
|
| export function buildAiFields(aiModelList) {
| // 可支持组件
| const componentList = cloneDeep([...inputComponents, ...selectComponents, ...systemComponents]);
| // 处理组件字段
| const processField = (child, tableName?, isSubTable = false) => {
| const component = componentList.find((o) => o.__config__.jnpfKey === child.fieldComponent) || componentList[0];
| const field: any = {
| ...component,
| __config__: {
| ...component.__config__,
| label: child.fieldTitle,
| formId: `formItem${buildBitUUID()}`,
| renderKey: Date.now(),
| isSubTable,
| },
| __vModel__: child.fieldName,
| };
| if (isSubTable) field.__config__.parentVModel = tableName;
| if (dyOptionsList.includes(component.__config__.jnpfKey)) field.options = child.fieldOptions || [];
| return field;
| };
| // 处理组件
| const handleItemModel: any = (item) => {
| if (item.isMain) {
| return item.fields.map((child) => processField(child));
| } else {
| const tableComponent: any = componentList.find((o) => o.__config__.jnpfKey === 'table');
| const children = item.fields.map((child) => processField(child, item.tableName, true));
| return {
| ...tableComponent,
| __config__: {
| ...tableComponent.__config__,
| label: item.tableTitle,
| children,
| },
| __vModel__: `tableField${buildBitUUID()}`,
| };
| }
| };
| return aiModelList.flatMap((element) => handleItemModel(element)) || [];
| }
| export function buildAiFormData(aiModelList) {
| // 表单默认数据
| const defaultDataForm = {
| id: '',
| fullName: '',
| enCode: '',
| type: 1,
| webType: 2,
| dbLinkId: '0',
| sortCode: 0,
| state: 1,
| category: '',
| description: '',
| interfaceId: '',
| interfaceName: '',
| interfaceParam: '',
| columnData: null,
| appColumnData: null,
| tables: '[]',
| };
| const formData = cloneDeep(defaultFormConf);
| formData.fields = buildAiFields(aiModelList) || [];
| return { ...defaultDataForm, formData: JSON.stringify(formData) };
| }
|
|