...
|
...
|
@@ -2,18 +2,17 @@ import { getAllDeviceByOrg, getDeviceAttributes, getGatewaySlaveDevice } from '/ |
2
|
2
|
import { getOrganizationList } from '/@/api/system/system';
|
3
|
3
|
import { FormSchema } from '/@/components/Form';
|
4
|
4
|
import { copyTransFun } from '/@/utils/fnUtils';
|
5
|
|
-import { OnChangeHookParams } from '/@/components/Form/src/components/ApiSearchSelect.vue';
|
6
|
|
-import { unref } from 'vue';
|
7
|
|
-import { MasterDeviceList } from '/@/api/dataBoard/model';
|
|
5
|
+import { DeviceAttributeParams, MasterDeviceList } from '/@/api/dataBoard/model';
|
|
6
|
+import { FrontComponent } from '../../const/const';
|
8
|
7
|
|
9
|
8
|
export enum BasicConfigField {
|
10
|
9
|
NAME = 'name',
|
11
|
10
|
REMARK = 'remark',
|
12
|
11
|
}
|
13
|
12
|
|
14
|
|
-const getDeviceAttribute = async (deviceProfileId: string) => {
|
|
13
|
+const getDeviceAttribute = async (params: DeviceAttributeParams) => {
|
15
|
14
|
try {
|
16
|
|
- const data = await getDeviceAttributes({ deviceProfileId });
|
|
15
|
+ const data = await getDeviceAttributes(params);
|
17
|
16
|
if (data) return data.map((item) => ({ label: item.name, value: item.identifier }));
|
18
|
17
|
} catch (error) {}
|
19
|
18
|
return [];
|
...
|
...
|
@@ -34,6 +33,18 @@ export enum DataSourceField { |
34
|
33
|
LATITUDE_ATTRIBUTE = 'latitudeAttribute',
|
35
|
34
|
}
|
36
|
35
|
|
|
36
|
+const isControlComponent = (frontId: FrontComponent) => {
|
|
37
|
+ const list = [
|
|
38
|
+ FrontComponent.CONTROL_COMPONENT_SLIDING_SWITCH,
|
|
39
|
+ FrontComponent.CONTROL_COMPONENT_SWITCH_WITH_ICON,
|
|
40
|
+ FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH,
|
|
41
|
+ ];
|
|
42
|
+ if (list.includes(frontId)) {
|
|
43
|
+ return true;
|
|
44
|
+ }
|
|
45
|
+ return false;
|
|
46
|
+};
|
|
47
|
+
|
37
|
48
|
export const basicSchema: FormSchema[] = [
|
38
|
49
|
{
|
39
|
50
|
field: BasicConfigField.NAME,
|
...
|
...
|
@@ -55,420 +66,214 @@ export const basicSchema: FormSchema[] = [ |
55
|
66
|
},
|
56
|
67
|
];
|
57
|
68
|
|
58
|
|
-export const dataSourceSchema: FormSchema[] = [
|
59
|
|
- {
|
60
|
|
- field: DataSourceField.IS_GATEWAY_DEVICE,
|
61
|
|
- component: 'Switch',
|
62
|
|
- label: '是否是网关设备',
|
63
|
|
- show: false,
|
64
|
|
- },
|
65
|
|
- {
|
66
|
|
- field: DataSourceField.DEVICE_NAME,
|
67
|
|
- component: 'Input',
|
68
|
|
- label: '设备名',
|
69
|
|
- show: false,
|
70
|
|
- },
|
71
|
|
- {
|
72
|
|
- field: DataSourceField.ORIGINATION_ID,
|
73
|
|
- component: 'ApiTreeSelect',
|
74
|
|
- label: '组织',
|
75
|
|
- colProps: { span: 8 },
|
76
|
|
- rules: [{ required: true, message: '组织为必填项' }],
|
77
|
|
- componentProps({ formActionType }) {
|
78
|
|
- const { setFieldsValue } = formActionType;
|
79
|
|
- return {
|
80
|
|
- placeholder: '请选择组织',
|
81
|
|
- api: async () => {
|
82
|
|
- const data = await getOrganizationList();
|
83
|
|
- copyTransFun(data as any as any[]);
|
84
|
|
- return data;
|
85
|
|
- },
|
86
|
|
- onChange() {
|
87
|
|
- setFieldsValue({
|
88
|
|
- [DataSourceField.DEVICE_ID]: null,
|
89
|
|
- [DataSourceField.ATTRIBUTE]: null,
|
90
|
|
- [DataSourceField.SLAVE_DEVICE_ID]: null,
|
91
|
|
- [DataSourceField.IS_GATEWAY_DEVICE]: false,
|
92
|
|
- [DataSourceField.DEVICE_PROFILE_ID]: null,
|
93
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
94
|
|
- });
|
95
|
|
- },
|
96
|
|
- getPopupContainer: () => document.body,
|
97
|
|
- };
|
|
69
|
+export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => {
|
|
70
|
+ return [
|
|
71
|
+ {
|
|
72
|
+ field: DataSourceField.IS_GATEWAY_DEVICE,
|
|
73
|
+ component: 'Switch',
|
|
74
|
+ label: '是否是网关设备',
|
|
75
|
+ show: false,
|
98
|
76
|
},
|
99
|
|
- },
|
100
|
|
- {
|
101
|
|
- field: DataSourceField.DEVICE_PROFILE_ID,
|
102
|
|
- component: 'Input',
|
103
|
|
- label: '',
|
104
|
|
- show: false,
|
105
|
|
- },
|
106
|
|
- {
|
107
|
|
- field: DataSourceField.DEVICE_ID,
|
108
|
|
- component: 'ApiSelect',
|
109
|
|
- label: '设备',
|
110
|
|
- colProps: { span: 8 },
|
111
|
|
- rules: [{ required: true, message: '设备名称为必填项' }],
|
112
|
|
- componentProps({ formModel, formActionType }) {
|
113
|
|
- const { setFieldsValue } = formActionType;
|
114
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
115
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
116
|
|
- return {
|
117
|
|
- api: async () => {
|
118
|
|
- if (organizationId) {
|
119
|
|
- try {
|
120
|
|
- const data = await getAllDeviceByOrg(organizationId);
|
121
|
|
- if (deviceId) {
|
122
|
|
- const record = data.find((item) => item.id === deviceId);
|
123
|
|
- setFieldsValue({ [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId });
|
124
|
|
- }
|
125
|
|
- if (data)
|
126
|
|
- return data.map((item) => ({
|
127
|
|
- ...item,
|
128
|
|
- label: item.name,
|
129
|
|
- value: item.id,
|
130
|
|
- deviceType: item.deviceType,
|
131
|
|
- }));
|
132
|
|
- } catch (error) {}
|
133
|
|
- }
|
134
|
|
- return [];
|
135
|
|
- },
|
136
|
|
-
|
137
|
|
- onChange(_value, record: MasterDeviceList) {
|
138
|
|
- setFieldsValue({
|
139
|
|
- [DataSourceField.ATTRIBUTE]: null,
|
140
|
|
- [DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
|
141
|
|
- [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId,
|
142
|
|
- [DataSourceField.SLAVE_DEVICE_ID]: null,
|
143
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
144
|
|
- [DataSourceField.DEVICE_NAME]: record?.label,
|
145
|
|
- });
|
146
|
|
- },
|
147
|
|
- placeholder: '请选择设备',
|
148
|
|
- getPopupContainer: () => document.body,
|
149
|
|
- };
|
|
77
|
+ {
|
|
78
|
+ field: DataSourceField.DEVICE_NAME,
|
|
79
|
+ component: 'Input',
|
|
80
|
+ label: '设备名',
|
|
81
|
+ show: false,
|
150
|
82
|
},
|
151
|
|
- },
|
152
|
|
- {
|
153
|
|
- field: DataSourceField.SLAVE_DEVICE_PROFILE_ID,
|
154
|
|
- component: 'Input',
|
155
|
|
- label: '',
|
156
|
|
- show: false,
|
157
|
|
- },
|
158
|
|
- {
|
159
|
|
- field: DataSourceField.SLAVE_DEVICE_ID,
|
160
|
|
- label: '网关子设备',
|
161
|
|
- component: 'ApiSelect',
|
162
|
|
- colProps: { span: 8 },
|
163
|
|
- rules: [{ required: true, message: '网关子设备为必填项' }],
|
164
|
|
- ifShow({ model }) {
|
165
|
|
- return model[DataSourceField.IS_GATEWAY_DEVICE];
|
|
83
|
+ {
|
|
84
|
+ field: DataSourceField.ORIGINATION_ID,
|
|
85
|
+ component: 'ApiTreeSelect',
|
|
86
|
+ label: '组织',
|
|
87
|
+ colProps: { span: 8 },
|
|
88
|
+ rules: [{ required: true, message: '组织为必填项' }],
|
|
89
|
+ componentProps({ formActionType }) {
|
|
90
|
+ const { setFieldsValue } = formActionType;
|
|
91
|
+ return {
|
|
92
|
+ placeholder: '请选择组织',
|
|
93
|
+ api: async () => {
|
|
94
|
+ const data = await getOrganizationList();
|
|
95
|
+ copyTransFun(data as any as any[]);
|
|
96
|
+ return data;
|
|
97
|
+ },
|
|
98
|
+ onChange() {
|
|
99
|
+ setFieldsValue({
|
|
100
|
+ [DataSourceField.DEVICE_ID]: null,
|
|
101
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
102
|
+ [DataSourceField.SLAVE_DEVICE_ID]: null,
|
|
103
|
+ [DataSourceField.IS_GATEWAY_DEVICE]: false,
|
|
104
|
+ [DataSourceField.DEVICE_PROFILE_ID]: null,
|
|
105
|
+ [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
|
106
|
+ });
|
|
107
|
+ },
|
|
108
|
+ getPopupContainer: () => document.body,
|
|
109
|
+ };
|
|
110
|
+ },
|
166
|
111
|
},
|
167
|
|
- dynamicRules({ model }) {
|
168
|
|
- return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }];
|
|
112
|
+ {
|
|
113
|
+ field: DataSourceField.DEVICE_PROFILE_ID,
|
|
114
|
+ component: 'Input',
|
|
115
|
+ label: '',
|
|
116
|
+ show: false,
|
169
|
117
|
},
|
170
|
|
- componentProps({ formModel, formActionType }) {
|
171
|
|
- const { setFieldsValue } = formActionType;
|
172
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
173
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
174
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
175
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
176
|
|
- return {
|
177
|
|
- api: async () => {
|
178
|
|
- if (organizationId && isGatewayDevice) {
|
179
|
|
- try {
|
180
|
|
- const data = await getGatewaySlaveDevice({ organizationId, masterId: deviceId });
|
181
|
|
- if (slaveDeviceId) {
|
182
|
|
- const record = data.find((item) => item.id === slaveDeviceId);
|
183
|
|
- setFieldsValue({ [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId });
|
184
|
|
- }
|
185
|
|
- if (data)
|
186
|
|
- return data.map((item) => ({
|
187
|
|
- ...item,
|
188
|
|
- label: item.name,
|
189
|
|
- value: item.id,
|
190
|
|
- deviceType: item.deviceType,
|
191
|
|
- }));
|
192
|
|
- } catch (error) {}
|
193
|
|
- }
|
194
|
|
- return [];
|
195
|
|
- },
|
196
|
|
- onChange(_value, record: MasterDeviceList) {
|
197
|
|
- setFieldsValue({
|
198
|
|
- [DataSourceField.ATTRIBUTE]: null,
|
199
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: record.deviceProfileId,
|
200
|
|
- [DataSourceField.DEVICE_NAME]: record?.label,
|
201
|
|
- });
|
202
|
|
- },
|
203
|
|
- placeholder: '请选择网关子设备',
|
204
|
|
- getPopupContainer: () => document.body,
|
205
|
|
- };
|
206
|
|
- },
|
207
|
|
- },
|
208
|
|
- {
|
209
|
|
- field: DataSourceField.ATTRIBUTE,
|
210
|
|
- component: 'ApiSelect',
|
211
|
|
- label: '属性',
|
212
|
|
- colProps: { span: 8 },
|
213
|
|
- rules: [{ required: true, message: '属性为必填项' }],
|
214
|
|
- componentProps({ formModel }) {
|
215
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
216
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
217
|
|
- const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
|
218
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
219
|
|
- const slaveDeviceProfileId = formModel[DataSourceField.SLAVE_DEVICE_PROFILE_ID];
|
|
118
|
+ {
|
|
119
|
+ field: DataSourceField.DEVICE_ID,
|
|
120
|
+ component: 'ApiSelect',
|
|
121
|
+ label: '设备',
|
|
122
|
+ colProps: { span: 8 },
|
|
123
|
+ rules: [{ required: true, message: '设备名称为必填项' }],
|
|
124
|
+ componentProps({ formModel, formActionType }) {
|
|
125
|
+ const { setFieldsValue } = formActionType;
|
|
126
|
+ const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
|
127
|
+ const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
128
|
+ return {
|
|
129
|
+ api: async () => {
|
|
130
|
+ if (organizationId) {
|
|
131
|
+ try {
|
|
132
|
+ const data = await getAllDeviceByOrg(organizationId);
|
|
133
|
+ if (deviceId) {
|
|
134
|
+ const record = data.find((item) => item.id === deviceId);
|
|
135
|
+ setFieldsValue({ [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId });
|
|
136
|
+ }
|
|
137
|
+ if (data)
|
|
138
|
+ return data.map((item) => ({
|
|
139
|
+ ...item,
|
|
140
|
+ label: item.name,
|
|
141
|
+ value: item.id,
|
|
142
|
+ deviceType: item.deviceType,
|
|
143
|
+ }));
|
|
144
|
+ } catch (error) {}
|
|
145
|
+ }
|
|
146
|
+ return [];
|
|
147
|
+ },
|
220
|
148
|
|
221
|
|
- return {
|
222
|
|
- api: async () => {
|
223
|
|
- if (deviceId) {
|
224
|
|
- try {
|
225
|
|
- if (isGatewayDevice && slaveDeviceId && slaveDeviceProfileId) {
|
226
|
|
- return await getDeviceAttribute(slaveDeviceProfileId);
|
227
|
|
- }
|
228
|
|
- if (!isGatewayDevice && deviceProfileId) {
|
229
|
|
- return await getDeviceAttribute(deviceProfileId);
|
230
|
|
- }
|
231
|
|
- } catch (error) {}
|
232
|
|
- }
|
233
|
|
- return [];
|
234
|
|
- },
|
235
|
|
- placeholder: '请选择属性',
|
236
|
|
- getPopupContainer: () => document.body,
|
237
|
|
- };
|
|
149
|
+ onChange(_value, record: MasterDeviceList) {
|
|
150
|
+ setFieldsValue({
|
|
151
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
152
|
+ [DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
|
|
153
|
+ [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId,
|
|
154
|
+ [DataSourceField.SLAVE_DEVICE_ID]: null,
|
|
155
|
+ [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
|
156
|
+ [DataSourceField.DEVICE_NAME]: record?.label,
|
|
157
|
+ });
|
|
158
|
+ },
|
|
159
|
+ placeholder: '请选择设备',
|
|
160
|
+ getPopupContainer: () => document.body,
|
|
161
|
+ };
|
|
162
|
+ },
|
238
|
163
|
},
|
239
|
|
- },
|
240
|
|
- {
|
241
|
|
- field: DataSourceField.DEVICE_RENAME,
|
242
|
|
- component: 'Input',
|
243
|
|
- label: '设备',
|
244
|
|
- colProps: { span: 8 },
|
245
|
|
- componentProps: {
|
246
|
|
- placeholder: '设备重命名',
|
|
164
|
+ {
|
|
165
|
+ field: DataSourceField.SLAVE_DEVICE_PROFILE_ID,
|
|
166
|
+ component: 'Input',
|
|
167
|
+ label: '',
|
|
168
|
+ show: false,
|
247
|
169
|
},
|
248
|
|
- },
|
249
|
|
- {
|
250
|
|
- field: DataSourceField.ATTRIBUTE_RENAME,
|
251
|
|
- component: 'Input',
|
252
|
|
- label: '属性',
|
253
|
|
- colProps: { span: 8 },
|
254
|
|
- componentProps: {
|
255
|
|
- placeholder: '属性重命名',
|
|
170
|
+ {
|
|
171
|
+ field: DataSourceField.SLAVE_DEVICE_ID,
|
|
172
|
+ label: '网关子设备',
|
|
173
|
+ component: 'ApiSelect',
|
|
174
|
+ colProps: { span: 8 },
|
|
175
|
+ rules: [{ required: true, message: '网关子设备为必填项' }],
|
|
176
|
+ ifShow({ model }) {
|
|
177
|
+ return model[DataSourceField.IS_GATEWAY_DEVICE];
|
|
178
|
+ },
|
|
179
|
+ dynamicRules({ model }) {
|
|
180
|
+ return [
|
|
181
|
+ { required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' },
|
|
182
|
+ ];
|
|
183
|
+ },
|
|
184
|
+ componentProps({ formModel, formActionType }) {
|
|
185
|
+ const { setFieldsValue } = formActionType;
|
|
186
|
+ const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
|
187
|
+ const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
|
188
|
+ const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
189
|
+ const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
|
190
|
+ return {
|
|
191
|
+ api: async () => {
|
|
192
|
+ if (organizationId && isGatewayDevice) {
|
|
193
|
+ try {
|
|
194
|
+ const data = await getGatewaySlaveDevice({ organizationId, masterId: deviceId });
|
|
195
|
+ if (slaveDeviceId) {
|
|
196
|
+ const record = data.find((item) => item.id === slaveDeviceId);
|
|
197
|
+ setFieldsValue({ [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId });
|
|
198
|
+ }
|
|
199
|
+ if (data)
|
|
200
|
+ return data.map((item) => ({
|
|
201
|
+ ...item,
|
|
202
|
+ label: item.name,
|
|
203
|
+ value: item.id,
|
|
204
|
+ deviceType: item.deviceType,
|
|
205
|
+ }));
|
|
206
|
+ } catch (error) {}
|
|
207
|
+ }
|
|
208
|
+ return [];
|
|
209
|
+ },
|
|
210
|
+ onChange(_value, record: MasterDeviceList) {
|
|
211
|
+ setFieldsValue({
|
|
212
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
213
|
+ [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: record.deviceProfileId,
|
|
214
|
+ [DataSourceField.DEVICE_NAME]: record?.label,
|
|
215
|
+ });
|
|
216
|
+ },
|
|
217
|
+ placeholder: '请选择网关子设备',
|
|
218
|
+ getPopupContainer: () => document.body,
|
|
219
|
+ };
|
|
220
|
+ },
|
256
|
221
|
},
|
257
|
|
- },
|
258
|
|
-];
|
|
222
|
+ {
|
|
223
|
+ field: DataSourceField.ATTRIBUTE,
|
|
224
|
+ component: 'ApiSelect',
|
|
225
|
+ label: '属性',
|
|
226
|
+ colProps: { span: 8 },
|
|
227
|
+ rules: [{ required: true, message: '属性为必填项' }],
|
|
228
|
+ componentProps({ formModel }) {
|
|
229
|
+ const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
|
230
|
+ const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
231
|
+ const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
|
|
232
|
+ const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
|
233
|
+ const slaveDeviceProfileId = formModel[DataSourceField.SLAVE_DEVICE_PROFILE_ID];
|
259
|
234
|
|
260
|
|
-export const controlFormSchema: FormSchema[] = [
|
261
|
|
- {
|
262
|
|
- field: DataSourceField.DEVICE_RENAME,
|
263
|
|
- component: 'Input',
|
264
|
|
- label: '设备',
|
265
|
|
- colProps: { span: 8 },
|
266
|
|
- componentProps: {
|
267
|
|
- placeholder: '设备重命名',
|
268
|
|
- },
|
269
|
|
- },
|
270
|
|
- {
|
271
|
|
- field: DataSourceField.ATTRIBUTE_RENAME,
|
272
|
|
- component: 'Input',
|
273
|
|
- label: '属性',
|
274
|
|
- colProps: { span: 8 },
|
275
|
|
- componentProps: {
|
276
|
|
- placeholder: '属性重命名',
|
277
|
|
- },
|
278
|
|
- },
|
279
|
|
-];
|
280
|
|
-
|
281
|
|
-export const mapFormSchema: FormSchema[] = [
|
282
|
|
- {
|
283
|
|
- field: DataSourceField.IS_GATEWAY_DEVICE,
|
284
|
|
- component: 'Switch',
|
285
|
|
- label: '是否是网关设备',
|
286
|
|
- show: false,
|
287
|
|
- },
|
288
|
|
- {
|
289
|
|
- field: DataSourceField.DEVICE_NAME,
|
290
|
|
- component: 'Input',
|
291
|
|
- label: '设备名',
|
292
|
|
- show: false,
|
293
|
|
- },
|
294
|
|
- {
|
295
|
|
- field: DataSourceField.ORIGINATION_ID,
|
296
|
|
- component: 'ApiTreeSelect',
|
297
|
|
- label: '组织',
|
298
|
|
- colProps: { span: 8 },
|
299
|
|
- rules: [{ required: true, message: '组织为必填项' }],
|
300
|
|
- componentProps({ formActionType }) {
|
301
|
|
- const { setFieldsValue } = formActionType;
|
302
|
|
- return {
|
303
|
|
- placeholder: '请选择组织',
|
304
|
|
- api: async () => {
|
305
|
|
- const data = await getOrganizationList();
|
306
|
|
- copyTransFun(data as any as any[]);
|
307
|
|
- return data;
|
308
|
|
- },
|
309
|
|
- onChange() {
|
310
|
|
- setFieldsValue({
|
311
|
|
- [DataSourceField.DEVICE_ID]: null,
|
312
|
|
- [DataSourceField.LATITUDE_ATTRIBUTE]: null,
|
313
|
|
- [DataSourceField.LONGITUDE_ATTRIBUTE]: null,
|
314
|
|
- [DataSourceField.SLAVE_DEVICE_ID]: null,
|
315
|
|
- [DataSourceField.IS_GATEWAY_DEVICE]: false,
|
316
|
|
- });
|
317
|
|
- },
|
318
|
|
- getPopupContainer: () => document.body,
|
319
|
|
- };
|
320
|
|
- },
|
321
|
|
- },
|
322
|
|
- {
|
323
|
|
- field: DataSourceField.DEVICE_ID,
|
324
|
|
- component: 'ApiSelect',
|
325
|
|
- label: '设备',
|
326
|
|
- colProps: { span: 8 },
|
327
|
|
- rules: [{ required: true, message: '设备名称为必填项' }],
|
328
|
|
- componentProps({ formModel, formActionType }) {
|
329
|
|
- const { setFieldsValue } = formActionType;
|
330
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
331
|
|
- return {
|
332
|
|
- api: async () => {
|
333
|
|
- if (organizationId) {
|
334
|
|
- try {
|
335
|
|
- const data = await getAllDeviceByOrg(organizationId);
|
336
|
|
- if (data)
|
337
|
|
- return data.map((item) => ({
|
338
|
|
- label: item.name,
|
339
|
|
- value: item.id,
|
340
|
|
- deviceType: item.deviceType,
|
341
|
|
- }));
|
342
|
|
- } catch (error) {}
|
343
|
|
- }
|
344
|
|
- return [];
|
345
|
|
- },
|
346
|
|
- onChange(_value, record: Record<'value' | 'label' | 'deviceType', string>) {
|
347
|
|
- setFieldsValue({
|
348
|
|
- [DataSourceField.LONGITUDE_ATTRIBUTE]: null,
|
349
|
|
- [DataSourceField.LATITUDE_ATTRIBUTE]: null,
|
350
|
|
- [DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
|
351
|
|
- [DataSourceField.SLAVE_DEVICE_ID]: null,
|
352
|
|
- [DataSourceField.DEVICE_NAME]: record?.label,
|
353
|
|
- });
|
354
|
|
- },
|
355
|
|
- placeholder: '请选择设备',
|
356
|
|
- getPopupContainer: () => document.body,
|
357
|
|
- };
|
358
|
|
- },
|
359
|
|
- },
|
360
|
|
- {
|
361
|
|
- field: DataSourceField.SLAVE_DEVICE_ID,
|
362
|
|
- label: '网关子设备',
|
363
|
|
- component: 'ApiSelect',
|
364
|
|
- colProps: { span: 8 },
|
365
|
|
- rules: [{ required: true, message: '网关子设备为必填项' }],
|
366
|
|
- ifShow({ model }) {
|
367
|
|
- return model[DataSourceField.IS_GATEWAY_DEVICE];
|
368
|
|
- },
|
369
|
|
- dynamicRules({ model }) {
|
370
|
|
- return [{ required: model[DataSourceField.IS_GATEWAY_DEVICE], message: '请选择网关子设备' }];
|
|
235
|
+ return {
|
|
236
|
+ api: async () => {
|
|
237
|
+ if (deviceId) {
|
|
238
|
+ try {
|
|
239
|
+ if (isGatewayDevice && slaveDeviceId && slaveDeviceProfileId) {
|
|
240
|
+ return await getDeviceAttribute({
|
|
241
|
+ deviceProfileId: slaveDeviceProfileId,
|
|
242
|
+ dataType: isControlComponent(frontId!) ? 'BOOL' : undefined,
|
|
243
|
+ });
|
|
244
|
+ }
|
|
245
|
+ if (!isGatewayDevice && deviceProfileId) {
|
|
246
|
+ return await getDeviceAttribute({
|
|
247
|
+ deviceProfileId,
|
|
248
|
+ dataType: isControlComponent(frontId!) ? 'BOOL' : undefined,
|
|
249
|
+ });
|
|
250
|
+ }
|
|
251
|
+ } catch (error) {}
|
|
252
|
+ }
|
|
253
|
+ return [];
|
|
254
|
+ },
|
|
255
|
+ placeholder: '请选择属性',
|
|
256
|
+ getPopupContainer: () => document.body,
|
|
257
|
+ };
|
|
258
|
+ },
|
371
|
259
|
},
|
372
|
|
- componentProps({ formModel, formActionType }) {
|
373
|
|
- const { setFieldsValue } = formActionType;
|
374
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
375
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
376
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
377
|
|
- return {
|
378
|
|
- api: async () => {
|
379
|
|
- if (organizationId && isGatewayDevice) {
|
380
|
|
- try {
|
381
|
|
- const data = await getGatewaySlaveDevice({ organizationId, masterId: deviceId });
|
382
|
|
- if (data)
|
383
|
|
- return data.map((item) => ({
|
384
|
|
- label: item.name,
|
385
|
|
- value: item.id,
|
386
|
|
- deviceType: item.deviceType,
|
387
|
|
- }));
|
388
|
|
- } catch (error) {}
|
389
|
|
- }
|
390
|
|
- return [];
|
391
|
|
- },
|
392
|
|
- onChange(_value, record: Record<'value' | 'label' | 'deviceType', string>) {
|
393
|
|
- setFieldsValue({
|
394
|
|
- [DataSourceField.LATITUDE_ATTRIBUTE]: null,
|
395
|
|
- [DataSourceField.LONGITUDE_ATTRIBUTE]: null,
|
396
|
|
- [DataSourceField.DEVICE_NAME]: record?.label,
|
397
|
|
- });
|
398
|
|
- },
|
399
|
|
- placeholder: '请选择网关子设备',
|
400
|
|
- getPopupContainer: () => document.body,
|
401
|
|
- };
|
|
260
|
+ {
|
|
261
|
+ field: DataSourceField.DEVICE_RENAME,
|
|
262
|
+ component: 'Input',
|
|
263
|
+ label: '设备',
|
|
264
|
+ colProps: { span: 8 },
|
|
265
|
+ componentProps: {
|
|
266
|
+ placeholder: '设备重命名',
|
|
267
|
+ },
|
402
|
268
|
},
|
403
|
|
- },
|
404
|
|
- {
|
405
|
|
- field: DataSourceField.LONGITUDE_ATTRIBUTE,
|
406
|
|
- component: 'ApiSearchSelect',
|
407
|
|
- label: '经度属性',
|
408
|
|
- colProps: { span: 8 },
|
409
|
|
- rules: [{ required: true, message: '属性为必填项' }],
|
410
|
|
- componentProps({ formModel }) {
|
411
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
412
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
413
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
414
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
415
|
|
- return {
|
416
|
|
- api: async () => {
|
417
|
|
- if (organizationId && deviceId) {
|
418
|
|
- try {
|
419
|
|
- if (isGatewayDevice && slaveDeviceId) {
|
420
|
|
- return await getDeviceAttribute(slaveDeviceId);
|
421
|
|
- }
|
422
|
|
- if (!isGatewayDevice) {
|
423
|
|
- return await getDeviceAttribute(deviceId);
|
424
|
|
- }
|
425
|
|
- } catch (error) {}
|
426
|
|
- }
|
427
|
|
- return [];
|
428
|
|
- },
|
429
|
|
- placeholder: '请选择经度属性',
|
430
|
|
- dropdownVisibleChangeHook: ({ options }: OnChangeHookParams) => {
|
431
|
|
- options.value = unref(options).filter(
|
432
|
|
- (item) => item.value !== formModel[DataSourceField.LATITUDE_ATTRIBUTE]
|
433
|
|
- );
|
434
|
|
- },
|
435
|
|
- getPopupContainer: () => document.body,
|
436
|
|
- };
|
437
|
|
- },
|
438
|
|
- },
|
439
|
|
- {
|
440
|
|
- field: DataSourceField.LATITUDE_ATTRIBUTE,
|
441
|
|
- component: 'ApiSearchSelect',
|
442
|
|
- label: '纬度属性',
|
443
|
|
- colProps: { span: 8 },
|
444
|
|
- rules: [{ required: true, message: '属性为必填项' }],
|
445
|
|
- componentProps({ formModel }) {
|
446
|
|
- const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
447
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
448
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
449
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
450
|
|
- return {
|
451
|
|
- api: async () => {
|
452
|
|
- if (organizationId && deviceId) {
|
453
|
|
- try {
|
454
|
|
- if (isGatewayDevice && slaveDeviceId) {
|
455
|
|
- return getDeviceAttribute(slaveDeviceId);
|
456
|
|
- }
|
457
|
|
- if (!isGatewayDevice) {
|
458
|
|
- return await getDeviceAttribute(deviceId);
|
459
|
|
- }
|
460
|
|
- } catch (error) {}
|
461
|
|
- }
|
462
|
|
- return [];
|
463
|
|
- },
|
464
|
|
- dropdownVisibleChangeHook: ({ options }: OnChangeHookParams) => {
|
465
|
|
- options.value = unref(options).filter(
|
466
|
|
- (item) => item.value !== formModel[DataSourceField.LONGITUDE_ATTRIBUTE]
|
467
|
|
- );
|
468
|
|
- },
|
469
|
|
- placeholder: '请选择纬度属性',
|
470
|
|
- getPopupContainer: () => document.body,
|
471
|
|
- };
|
|
269
|
+ {
|
|
270
|
+ field: DataSourceField.ATTRIBUTE_RENAME,
|
|
271
|
+ component: 'Input',
|
|
272
|
+ label: '属性',
|
|
273
|
+ colProps: { span: 8 },
|
|
274
|
+ componentProps: {
|
|
275
|
+ placeholder: '属性重命名',
|
|
276
|
+ },
|
472
|
277
|
},
|
473
|
|
- },
|
474
|
|
-]; |
|
278
|
+ ];
|
|
279
|
+}; |
...
|
...
|
|