basicConfiguration.ts
3.07 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
import { byOganizationIdGetMasterDevice, getAttribute } from '/@/api/ruleengine/ruleengineApi';
import { getOrganizationList } from '/@/api/system/system';
import { FormSchema } from '/@/components/Form';
import { copyTransFun } from '/@/utils/fnUtils';
import { to } from '/@/utils/to';
export enum DataSourceField {
DEVICE_ID = 'deviceId',
}
export const basicSchema: FormSchema[] = [
{
field: 'name',
label: '组件名称',
component: 'Input',
componentProps: {
placeholder: '请输入组件名称',
},
},
{
field: 'remark',
label: '组件备注',
component: 'InputTextArea',
componentProps: {
placeholder: '请输入组件备注',
},
},
];
export const dataSourceSchema: FormSchema[] = [
{
field: 'organizationId',
component: 'ApiTreeSelect',
label: '组织',
colProps: { span: 6 },
componentProps({ formActionType }) {
const { setFieldsValue } = formActionType;
return {
placeholder: '请选择组织',
api: async () => {
const data = await getOrganizationList();
copyTransFun(data as any as any[]);
return data;
},
onChange() {
setFieldsValue({ device: null, attr: null });
},
getPopupContainer: () => document.body,
};
},
},
{
field: 'deviceId',
component: 'ApiSelect',
label: '设备',
colProps: { span: 5 },
componentProps({ formModel, formActionType }) {
const { setFieldsValue } = formActionType;
const orgId = formModel['organizationId'];
return {
api: async () => {
if (orgId) {
const [, data] = await to<Record<'id' | 'name', string>[]>(
byOganizationIdGetMasterDevice(orgId)
);
if (data) return data.map((item) => ({ label: item.name, value: item.id }));
}
return [];
},
onChange() {
setFieldsValue({ attr: null });
},
placeholder: '请选择设备',
getPopupContainer: () => document.body,
};
},
},
{
field: 'attribute',
component: 'ApiSelect',
label: '属性',
colProps: { span: 5 },
componentProps({ formModel }) {
const orgId = formModel['organizationId'];
const deviceId = formModel['deviceId'];
return {
api: async () => {
if (orgId && deviceId) {
const [, data] = await to<string[]>(getAttribute(orgId, deviceId));
// TODO attribute exist null
if (data) return data.filter(Boolean).map((item) => ({ label: item, value: item }));
}
return [];
},
placeholder: '请选择属性',
getPopupContainer: () => document.body,
};
},
},
{
field: 'deviceRename',
component: 'Input',
label: '设备',
colProps: { span: 4 },
componentProps: {
placeholder: '设备重命名',
},
},
{
field: 'attributeRename',
component: 'Input',
label: '属性',
colProps: { span: 4 },
componentProps: {
placeholder: '属性重命名',
},
},
];