|
1
|
|
-import { getAllAvailableDeviceByOrgId } from '/@/api/dataBoard';
|
|
2
|
|
-import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
|
|
|
1
|
+import { getAllDeviceByOrg, getDeviceAttributes, getGatewaySlaveDevice } from '/@/api/dataBoard';
|
|
|
2
|
+import { MasterDeviceList } from '/@/api/dataBoard/model';
|
|
3
|
3
|
import { getOrganizationList } from '/@/api/system/system';
|
|
4
|
4
|
import { FormSchema } from '/@/components/Form';
|
|
5
|
5
|
import { copyTransFun } from '/@/utils/fnUtils';
|
|
6
|
|
-import { to } from '/@/utils/to';
|
|
|
6
|
+
|
|
|
7
|
+export enum BasicConfigField {
|
|
|
8
|
+ NAME = 'name',
|
|
|
9
|
+ REMARK = 'remark',
|
|
|
10
|
+}
|
|
|
11
|
+
|
|
|
12
|
+const getDeviceAttribute = async (deviceId: string) => {
|
|
|
13
|
+ try {
|
|
|
14
|
+ const data = await getDeviceAttributes({ deviceId });
|
|
|
15
|
+ if (data) return data.map((item) => ({ label: item, value: item }));
|
|
|
16
|
+ } catch (error) {}
|
|
|
17
|
+ return [];
|
|
|
18
|
+};
|
|
7
|
19
|
|
|
8
|
20
|
export enum DataSourceField {
|
|
|
21
|
+ IS_GATEWAY_DEVICE = 'isGatewayDevice',
|
|
|
22
|
+ ORIGINATION_ID = 'organizationId',
|
|
9
|
23
|
DEVICE_ID = 'deviceId',
|
|
|
24
|
+ SLAVE_DEVICE_ID = 'slaveDeviceId',
|
|
|
25
|
+ ATTRIBUTE = 'attribute',
|
|
|
26
|
+ ATTRIBUTE_RENAME = 'attributeRename',
|
|
|
27
|
+ DEVICE_NAME = 'deviceName',
|
|
|
28
|
+ DEVICE_RENAME = 'deviceRename',
|
|
10
|
29
|
}
|
|
11
|
30
|
|
|
12
|
31
|
export const basicSchema: FormSchema[] = [
|
|
13
|
32
|
{
|
|
14
|
|
- field: 'name',
|
|
|
33
|
+ field: BasicConfigField.NAME,
|
|
15
|
34
|
label: '组件名称',
|
|
16
|
35
|
component: 'Input',
|
|
17
|
36
|
componentProps: {
|
|
...
|
...
|
@@ -19,7 +38,7 @@ export const basicSchema: FormSchema[] = [ |
|
19
|
38
|
},
|
|
20
|
39
|
},
|
|
21
|
40
|
{
|
|
22
|
|
- field: 'remark',
|
|
|
41
|
+ field: BasicConfigField.REMARK,
|
|
23
|
42
|
label: '组件备注',
|
|
24
|
43
|
component: 'InputTextArea',
|
|
25
|
44
|
componentProps: {
|
|
...
|
...
|
@@ -30,10 +49,22 @@ export const basicSchema: FormSchema[] = [ |
|
30
|
49
|
|
|
31
|
50
|
export const dataSourceSchema: FormSchema[] = [
|
|
32
|
51
|
{
|
|
33
|
|
- field: 'organizationId',
|
|
|
52
|
+ field: DataSourceField.IS_GATEWAY_DEVICE,
|
|
|
53
|
+ component: 'Switch',
|
|
|
54
|
+ label: '是否是网关设备',
|
|
|
55
|
+ show: false,
|
|
|
56
|
+ },
|
|
|
57
|
+ {
|
|
|
58
|
+ field: DataSourceField.DEVICE_NAME,
|
|
|
59
|
+ component: 'Input',
|
|
|
60
|
+ label: '设备名',
|
|
|
61
|
+ show: false,
|
|
|
62
|
+ },
|
|
|
63
|
+ {
|
|
|
64
|
+ field: DataSourceField.ORIGINATION_ID,
|
|
34
|
65
|
component: 'ApiTreeSelect',
|
|
35
|
66
|
label: '组织',
|
|
36
|
|
- colProps: { span: 6 },
|
|
|
67
|
+ colProps: { span: 8 },
|
|
37
|
68
|
componentProps({ formActionType }) {
|
|
38
|
69
|
const { setFieldsValue } = formActionType;
|
|
39
|
70
|
return {
|
|
...
|
...
|
@@ -44,32 +75,47 @@ export const dataSourceSchema: FormSchema[] = [ |
|
44
|
75
|
return data;
|
|
45
|
76
|
},
|
|
46
|
77
|
onChange() {
|
|
47
|
|
- setFieldsValue({ deviceId: null, attribute: null });
|
|
|
78
|
+ setFieldsValue({
|
|
|
79
|
+ [DataSourceField.DEVICE_ID]: null,
|
|
|
80
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
|
81
|
+ [DataSourceField.SLAVE_DEVICE_ID]: null,
|
|
|
82
|
+ [DataSourceField.IS_GATEWAY_DEVICE]: false,
|
|
|
83
|
+ });
|
|
48
|
84
|
},
|
|
49
|
85
|
getPopupContainer: () => document.body,
|
|
50
|
86
|
};
|
|
51
|
87
|
},
|
|
52
|
88
|
},
|
|
53
|
89
|
{
|
|
54
|
|
- field: 'deviceId',
|
|
|
90
|
+ field: DataSourceField.DEVICE_ID,
|
|
55
|
91
|
component: 'ApiSelect',
|
|
56
|
92
|
label: '设备',
|
|
57
|
|
- colProps: { span: 5 },
|
|
|
93
|
+ colProps: { span: 8 },
|
|
58
|
94
|
componentProps({ formModel, formActionType }) {
|
|
59
|
95
|
const { setFieldsValue } = formActionType;
|
|
60
|
|
- const orgId = formModel['organizationId'];
|
|
|
96
|
+ const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
|
61
|
97
|
return {
|
|
62
|
98
|
api: async () => {
|
|
63
|
|
- if (orgId) {
|
|
64
|
|
- const [, data] = await to<Record<'id' | 'name', string>[]>(
|
|
65
|
|
- getAllAvailableDeviceByOrgId(orgId)
|
|
66
|
|
- );
|
|
67
|
|
- if (data) return data.map((item) => ({ label: item.name, value: item.id }));
|
|
|
99
|
+ if (organizationId) {
|
|
|
100
|
+ try {
|
|
|
101
|
+ const data = await getAllDeviceByOrg(organizationId);
|
|
|
102
|
+ if (data)
|
|
|
103
|
+ return data.map((item) => ({
|
|
|
104
|
+ label: item.name,
|
|
|
105
|
+ value: item.id,
|
|
|
106
|
+ deviceType: item.deviceType,
|
|
|
107
|
+ }));
|
|
|
108
|
+ } catch (error) {}
|
|
68
|
109
|
}
|
|
69
|
110
|
return [];
|
|
70
|
111
|
},
|
|
71
|
|
- onChange() {
|
|
72
|
|
- setFieldsValue({ attribute: null });
|
|
|
112
|
+ onChange(_value, record: Record<'value' | 'label' | 'deviceType', string>) {
|
|
|
113
|
+ setFieldsValue({
|
|
|
114
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
|
115
|
+ [DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
|
|
|
116
|
+ [DataSourceField.SLAVE_DEVICE_ID]: null,
|
|
|
117
|
+ [DataSourceField.DEVICE_NAME]: record?.label,
|
|
|
118
|
+ });
|
|
73
|
119
|
},
|
|
74
|
120
|
placeholder: '请选择设备',
|
|
75
|
121
|
getPopupContainer: () => document.body,
|
|
...
|
...
|
@@ -77,19 +123,68 @@ export const dataSourceSchema: FormSchema[] = [ |
|
77
|
123
|
},
|
|
78
|
124
|
},
|
|
79
|
125
|
{
|
|
80
|
|
- field: 'attribute',
|
|
|
126
|
+ field: DataSourceField.SLAVE_DEVICE_ID,
|
|
|
127
|
+ label: '网关子设备',
|
|
|
128
|
+ component: 'ApiSelect',
|
|
|
129
|
+ colProps: { span: 8 },
|
|
|
130
|
+ ifShow({ model }) {
|
|
|
131
|
+ return model['isGatewayDevice'];
|
|
|
132
|
+ },
|
|
|
133
|
+ dynamicRules({ model }) {
|
|
|
134
|
+ return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }];
|
|
|
135
|
+ },
|
|
|
136
|
+ componentProps({ formModel, formActionType }) {
|
|
|
137
|
+ const { setFieldsValue } = formActionType;
|
|
|
138
|
+ const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
|
|
139
|
+ const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
|
|
140
|
+ const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
|
141
|
+ return {
|
|
|
142
|
+ api: async () => {
|
|
|
143
|
+ if (organizationId && isGatewayDevice) {
|
|
|
144
|
+ try {
|
|
|
145
|
+ const data = await getGatewaySlaveDevice({ organizationId, masterId: deviceId });
|
|
|
146
|
+ if (data)
|
|
|
147
|
+ return data.map((item) => ({
|
|
|
148
|
+ label: item.name,
|
|
|
149
|
+ value: item.id,
|
|
|
150
|
+ deviceType: item.deviceType,
|
|
|
151
|
+ }));
|
|
|
152
|
+ } catch (error) {}
|
|
|
153
|
+ }
|
|
|
154
|
+ return [];
|
|
|
155
|
+ },
|
|
|
156
|
+ onChange(_value, record: Record<'value' | 'label' | 'deviceType', string>) {
|
|
|
157
|
+ setFieldsValue({
|
|
|
158
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
|
159
|
+ [DataSourceField.DEVICE_NAME]: record?.label,
|
|
|
160
|
+ });
|
|
|
161
|
+ },
|
|
|
162
|
+ placeholder: '请选择网关子设备',
|
|
|
163
|
+ getPopupContainer: () => document.body,
|
|
|
164
|
+ };
|
|
|
165
|
+ },
|
|
|
166
|
+ },
|
|
|
167
|
+ {
|
|
|
168
|
+ field: DataSourceField.ATTRIBUTE,
|
|
81
|
169
|
component: 'ApiSelect',
|
|
82
|
170
|
label: '属性',
|
|
83
|
|
- colProps: { span: 5 },
|
|
|
171
|
+ colProps: { span: 8 },
|
|
84
|
172
|
componentProps({ formModel }) {
|
|
85
|
|
- const orgId = formModel['organizationId'];
|
|
86
|
|
- const deviceId = formModel['deviceId'];
|
|
|
173
|
+ const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
|
|
174
|
+ const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
|
|
175
|
+ const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
|
176
|
+ const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
|
87
|
177
|
return {
|
|
88
|
178
|
api: async () => {
|
|
89
|
|
- if (orgId && deviceId) {
|
|
90
|
|
- const [, data] = await to<string[]>(getAttribute(orgId, deviceId));
|
|
91
|
|
- // TODO attribute exist null
|
|
92
|
|
- if (data) return data.filter(Boolean).map((item) => ({ label: item, value: item }));
|
|
|
179
|
+ if (organizationId && deviceId) {
|
|
|
180
|
+ try {
|
|
|
181
|
+ if (isGatewayDevice && slaveDeviceId) {
|
|
|
182
|
+ return await getDeviceAttribute(slaveDeviceId);
|
|
|
183
|
+ }
|
|
|
184
|
+ if (!isGatewayDevice) {
|
|
|
185
|
+ return await getDeviceAttribute(deviceId);
|
|
|
186
|
+ }
|
|
|
187
|
+ } catch (error) {}
|
|
93
|
188
|
}
|
|
94
|
189
|
return [];
|
|
95
|
190
|
},
|
|
...
|
...
|
@@ -99,19 +194,19 @@ export const dataSourceSchema: FormSchema[] = [ |
|
99
|
194
|
},
|
|
100
|
195
|
},
|
|
101
|
196
|
{
|
|
102
|
|
- field: 'deviceRename',
|
|
|
197
|
+ field: DataSourceField.DEVICE_RENAME,
|
|
103
|
198
|
component: 'Input',
|
|
104
|
199
|
label: '设备',
|
|
105
|
|
- colProps: { span: 4 },
|
|
|
200
|
+ colProps: { span: 8 },
|
|
106
|
201
|
componentProps: {
|
|
107
|
202
|
placeholder: '设备重命名',
|
|
108
|
203
|
},
|
|
109
|
204
|
},
|
|
110
|
205
|
{
|
|
111
|
|
- field: 'attributeRename',
|
|
|
206
|
+ field: DataSourceField.ATTRIBUTE_RENAME,
|
|
112
|
207
|
component: 'Input',
|
|
113
|
208
|
label: '属性',
|
|
114
|
|
- colProps: { span: 4 },
|
|
|
209
|
+ colProps: { span: 8 },
|
|
115
|
210
|
componentProps: {
|
|
116
|
211
|
placeholder: '属性重命名',
|
|
117
|
212
|
},
|
...
|
...
|
|