config.ts
3.33 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
import { TaskTargetEnum } from '../../config';
import { getMeetTheConditionsDevice } from '/@/api/dataBoard';
import { getDevicesByDeviceIds } from '/@/api/device/deviceManager';
import { TaskRecordType } from '/@/api/task/model';
import { FormSchema } from '/@/components/Form';
import { createPickerSearch } from '/@/utils/pickerSearch';
export interface FormValue extends Record<FormFieldsEnum, any> {
[FormFieldsEnum.TASK_RECORD]: string;
}
export enum FormFieldsEnum {
EXECUTE_TARGET_TYPE = 'executeTarget',
TASK_TYPE = 'taskType',
TARGET_IDS = 'targetIds',
TASK_RECORD = 'taskRecord',
TB_DEVICE_ID = 'tbDeviceId',
}
export enum TargetType {
ALL = 'ALL',
ASSIGN = 'ASSIGN',
}
export enum TargetNameType {
ALL = '所有目标设备',
ASSIGN = '指定目标设备',
}
export const formSchemas: FormSchema[] = [
{
field: 'taskName',
component: 'Input',
label: '任务名称',
slot: 'taskName',
},
{
field: FormFieldsEnum.TASK_TYPE,
component: 'Input',
label: '任务类型',
slot: 'taskType',
},
{
field: FormFieldsEnum.TASK_RECORD,
component: 'Input',
label: '任务详情',
show: false,
},
{
field: FormFieldsEnum.EXECUTE_TARGET_TYPE,
component: 'RadioGroup',
label: '选择目标类型',
helpMessage: [
'您可以对该任务关联的所有设备批量执行任务,也可以指定其中的一个或多个关联的设备来执行任务。',
],
defaultValue: TargetType.ALL,
componentProps: {
options: [
{ label: TargetNameType.ALL, value: TargetType.ALL },
{ label: TargetNameType.ASSIGN, value: TargetType.ASSIGN },
],
},
},
{
field: FormFieldsEnum.TB_DEVICE_ID,
component: 'Input',
label: '',
show: false,
},
{
field: FormFieldsEnum.TARGET_IDS,
component: 'ApiSelect',
label: '指定目标设备',
ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_TARGET_TYPE] === TargetType.ASSIGN,
rules: [{ required: true, message: '请选择指定目标设备', type: 'array' }],
componentProps: ({ formModel }) => {
const record = JSON.parse(formModel[FormFieldsEnum.TASK_RECORD]) as TaskRecordType;
const tbDeviceId = formModel[FormFieldsEnum.TB_DEVICE_ID];
const isDevices = record.targetType === TaskTargetEnum.DEVICES;
const { executeTarget } = record;
const { organizationId, data } = executeTarget;
return {
api: async () => {
try {
if (isDevices) {
const result = await getDevicesByDeviceIds(data!);
return result.data.map((item) => ({
label: item.alias || item.name,
value: item.tbDeviceId,
disabled: tbDeviceId ? item.tbDeviceId !== tbDeviceId : false,
}));
} else {
const result = await getMeetTheConditionsDevice({
organizationId,
deviceProfileId: data![0],
});
return result.map((item) => ({
label: item.alias || item.name,
value: item.tbDeviceId,
}));
}
} catch (error) {
return [];
}
},
mode: 'multiple',
...createPickerSearch(),
placeholder: '请选择设备',
getPopupContainer: () => document.body,
};
},
},
];