index.ts
5.08 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
81
82
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { FormSchema, useComponentRegister } from '/@/components/Form';
import { findDictItemByCode } from '/@/api/system/dict';
import { getDeviceProfile } from '/@/api/alarm/position';
import { BasicInfoFormField, DataSourceType } from '../enum';
import { DeviceRecord } from '/@/api/device/model/deviceModel';
import { useMessage } from '/@/hooks/web/useMessage';
import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
useComponentRegister('OrgTreeSelect', OrgTreeSelect);
export const stepConfig = ['选择流转方式', '完善配置参数'];
export const removeFieldByModeForm = ['name', 'description'];
const handleGroupDevice = (options: DeviceRecord[]) => {
const map = new Map<string, string[]>();
options.forEach((item) => {
if (map.has(item.profileId)) {
const deviceList = map.get(item.profileId)!;
deviceList.push(item.tbDeviceId);
} else {
map.set(item.profileId, [item.tbDeviceId]);
}
});
const value = Array.from(map.entries()).map(([product, devices]) => ({ product, devices }));
return value;
};
//表单通用配置
export const modelFormPublicConfig = {
labelWidth: 120,
actionColOptions: {
span: 14,
},
showResetButton: false,
showSubmitButton: false,
};
const { createMessage } = useMessage();
export const modeForm = (disabled: boolean): FormSchema[] => {
return [
{
field: BasicInfoFormField.CONVERT_CONFIG_ID,
label: '',
component: 'Input',
show: false,
},
{
field: BasicInfoFormField.DATA_SOURCE_TYPE,
label: '数据源',
component: 'RadioGroup',
defaultValue: DataSourceType.ALL,
componentProps: {
options: [
{ label: '全部', value: DataSourceType.ALL },
{ label: '产品', value: DataSourceType.PRODUCT },
{ label: '设备', value: DataSourceType.DEVICE },
],
},
},
{
required: true,
field: BasicInfoFormField.ORGANIZATION_ID,
label: '所属组织',
colProps: { span: 24 },
component: 'OrgTreeSelect',
},
{
field: BasicInfoFormField.DATA_SOURCE_PRODUCT,
label: '数据源产品',
component: 'TransferModal',
rules: [{ required: true, message: '数据源产品为必选项', type: 'array' }],
ifShow: ({ model }) => {
return model[BasicInfoFormField.DATA_SOURCE_TYPE] !== DataSourceType.ALL;
},
valueField: 'value',
changeEvent: 'update:value',
componentProps: ({ formActionType }) => {
const { setFieldsValue } = formActionType;
return {
api: getDeviceProfile,
labelField: 'name',
valueField: 'tbProfileId',
disabled,
selectProps: {
disabled,
placeholder: '请选择产品',
},
transferProps: {
listStyle: { height: '400px' },
showSearch: true,
filterOption: (inputValue: string, option: Recordable) => {
const upperCaseInputValue = inputValue.toUpperCase();
const upperCaseOptionValue = option.name.toUpperCase();
return upperCaseOptionValue.includes(upperCaseInputValue);
},
},
onChange: () => {
setFieldsValue({
[BasicInfoFormField.DATA_SOURCE_DEVICE]: [],
[BasicInfoFormField.CONVERT_CONFIG_ID]: null,
});
},
};
},
},
{
field: BasicInfoFormField.DATA_SOURCE_DEVICE,
label: '数据源设备',
component: 'TransferTableModal',
ifShow: ({ model }) => {
return model[BasicInfoFormField.DATA_SOURCE_TYPE] === DataSourceType.DEVICE;
},
valueField: 'value',
changeEvent: 'update:value',
rules: [{ required: true, message: '数据源设备为必选项', type: 'array' }],
componentProps: ({ formModel }) => {
const convertConfigId = formModel[BasicInfoFormField.CONVERT_CONFIG_ID];
const deviceProfileIds = formModel[BasicInfoFormField.DATA_SOURCE_PRODUCT];
const organizationId = formModel[BasicInfoFormField.ORGANIZATION_ID];
return {
disabled,
params: { convertConfigId, deviceProfileIds, organizationId },
transformValue: handleGroupDevice,
openModalValidate: () => {
if (!deviceProfileIds || !deviceProfileIds?.length) {
createMessage.warning('请选择数据源设备');
}
return deviceProfileIds && deviceProfileIds?.length;
},
};
},
},
{
field: 'type',
label: '转换方式',
component: 'ApiSelect',
required: true,
colProps: {
span: 24,
},
componentProps({}) {
return {
api: findDictItemByCode,
params: {
dictCode: 'convert_data_to',
},
labelField: 'itemText',
valueField: 'itemValue',
};
},
},
{
field: 'remark',
label: '描述',
colProps: { span: 24 },
component: 'Input',
componentProps: {
maxLength: 255,
placeholder: '请输入描述',
},
},
];
};