index.ts
9.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import { FormSchema } from '/@/components/Form';
import { findDictItemByCode } from '/@/api/system/dict';
import { h, unref } from 'vue';
import { getDeviceProfile } from '/@/api/alarm/position';
import { BasicColumn, BasicTableProps } from '/@/components/Table';
import { devicePage } from '/@/api/device/deviceManager';
import { Tag } from 'ant-design-vue';
import { DeviceRecord } from '/@/api/device/model/deviceModel';
import { FETCH_SETTING } from '/@/components/Table/src/const';
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
import { useMessage } from '/@/hooks/web/useMessage';
import {
BasicInfoFormField,
DataSourceType,
DeviceStatusEnum,
DeviceStatusNameEnum,
DeviceTypeNameEnum,
} from '../enum';
export const stepConfig = ['选择流转方式', '完善配置参数'];
export const removeFieldByModeForm = ['name', 'description'];
//表单通用配置
export const modelFormPublicConfig = {
labelWidth: 120,
actionColOptions: {
span: 14,
},
showResetButton: false,
showSubmitButton: false,
};
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;
};
const deviceTableFormSchema: FormSchema[] = [
{
field: 'name',
label: '设备名称',
component: 'Input',
colProps: { span: 9 },
componentProps: {
placeholder: '请输入设备名称',
},
},
{
field: 'deviceType',
label: '设备类型',
component: 'ApiSelect',
colProps: { span: 9 },
componentProps: {
placeholder: '请选择设备类型',
api: findDictItemByCode,
params: {
dictCode: 'device_type',
},
labelField: 'itemText',
valueField: 'itemValue',
},
},
];
const { clipboardRef, isSuccessRef } = useCopyToClipboard();
const { createMessage } = useMessage();
const deviceTableColumn: BasicColumn[] = [
{
title: '状态',
dataIndex: 'deviceState',
customRender: ({ text }) => {
return h(
Tag,
{
color:
text === DeviceStatusEnum.INACTIVE
? 'warning'
: text === DeviceStatusEnum.OFFLINE
? 'error'
: 'success',
},
() => DeviceStatusNameEnum[text]
);
},
},
{
title: '别名/设备名称',
dataIndex: 'name',
customRender: ({ record }) => {
return h('div', [
h(
'div',
{
class: 'cursor-pointer',
onClick: () => {
clipboardRef.value = record.name;
if (unref(isSuccessRef)) createMessage.success('复制成功~');
},
},
[
record.alias && h('div', { class: 'truncate' }, record.alias),
h('div', { class: 'text-blue-400 truncate' }, record.name),
]
),
]);
},
},
{
title: '设备类型',
dataIndex: 'deviceType',
customRender: ({ text }) => {
return h(Tag, { color: 'success' }, () => DeviceTypeNameEnum[text]);
},
},
{
title: '所属产品',
dataIndex: 'deviceProfile.name',
},
{
title: '所属组织',
dataIndex: 'organizationDTO.name',
},
];
const TransferTableProps: BasicTableProps = {
formConfig: {
layout: 'inline',
labelWidth: 80,
schemas: deviceTableFormSchema,
actionColOptions: { span: 6 },
},
size: 'small',
maxHeight: 240,
useSearchForm: true,
columns: deviceTableColumn,
showIndexColumn: false,
fetchSetting: FETCH_SETTING,
} as BasicTableProps;
export const modeForm = (submitFn?: Function): 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 },
],
},
},
{
field: BasicInfoFormField.DATA_SOURCE_PRODUCT,
label: '数据源产品',
component: 'TransferModal',
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',
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]: [] });
},
};
},
},
{
field: BasicInfoFormField.DATA_SOURCE_DEVICE,
label: '数据源设备',
component: 'TransferTableModal',
ifShow: ({ model }) => {
return model[BasicInfoFormField.DATA_SOURCE_TYPE] === DataSourceType.DEVICE;
},
valueField: 'value',
changeEvent: 'update:value',
componentProps: ({ formActionType }) => {
const { getFieldsValue } = formActionType;
const values = getFieldsValue();
const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
return {
labelField: 'name',
valueField: 'tbDeviceId',
primaryKey: 'tbDeviceId',
pendingTableProps: {
...TransferTableProps,
api: devicePage,
beforeFetch: (params) => {
const values = getFieldsValue();
const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
if (convertConfigId) {
Object.assign(params, { convertConfigId, selected: false });
}
return { ...params, deviceProfileIds };
},
} as BasicTableProps,
selectedTableProps: {
...TransferTableProps,
// api
api: !!(convertConfigId && devices) ? devicePage : undefined,
beforeFetch: (params) => {
const values = getFieldsValue();
const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
if (convertConfigId) {
Object.assign(params, { convertConfigId, selected: true });
}
return { ...params, deviceProfileIds };
},
} as BasicTableProps,
initSelectedOptions: async ({ setSelectedTotal }) => {
const values = getFieldsValue();
const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
if (convertConfigId && devices) {
const { items, total } = await devicePage({
page: 1,
pageSize: 10,
convertConfigId: values[BasicInfoFormField.CONVERT_CONFIG_ID],
deviceProfileIds,
selected: true,
});
setSelectedTotal(total);
return items;
}
return [];
},
onSelectedAfter: async () => {
submitFn && (await submitFn(false));
},
onRemoveAfter: async ({ reloadSelected }) => {
submitFn && (await submitFn(false));
reloadSelected();
},
transformValue: (_selectedRowKeys: string[], selectedRows: DeviceRecord[]) => {
return handleGroupDevice(selectedRows);
},
};
},
},
{
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: '请输入描述',
},
},
];
};