...
|
...
|
@@ -4,6 +4,8 @@ import { FormSchema } from '/@/components/Form'; |
4
|
4
|
import { copyTransFun } from '/@/utils/fnUtils';
|
5
|
5
|
import { DeviceAttributeParams, MasterDeviceList } from '/@/api/dataBoard/model';
|
6
|
6
|
import { FrontComponent } from '../../const/const';
|
|
7
|
+import { getDeviceProfile } from '/@/api/alarm/position';
|
|
8
|
+import { getModelServices } from '/@/api/device/modelOfMatter';
|
7
|
9
|
|
8
|
10
|
export enum BasicConfigField {
|
9
|
11
|
NAME = 'name',
|
...
|
...
|
@@ -18,13 +20,22 @@ const getDeviceAttribute = async (params: DeviceAttributeParams) => { |
18
|
20
|
return [];
|
19
|
21
|
};
|
20
|
22
|
|
|
23
|
+const getDeviceService = async (deviceProfileId: string) => {
|
|
24
|
+ try {
|
|
25
|
+ const data = await getModelServices({ deviceProfileId });
|
|
26
|
+ if (data)
|
|
27
|
+ return data.map((item) => ({ ...item, label: item.functionName, value: item.identifier }));
|
|
28
|
+ } catch (error) {}
|
|
29
|
+ return [];
|
|
30
|
+};
|
|
31
|
+
|
21
|
32
|
export enum DataSourceField {
|
22
|
33
|
IS_GATEWAY_DEVICE = 'gatewayDevice',
|
|
34
|
+ TRANSPORT_TYPE = 'transportType',
|
23
|
35
|
ORIGINATION_ID = 'organizationId',
|
24
|
36
|
DEVICE_ID = 'deviceId',
|
25
|
37
|
SLAVE_DEVICE_ID = 'slaveDeviceId',
|
26
|
38
|
DEVICE_PROFILE_ID = 'deviceProfileId',
|
27
|
|
- SLAVE_DEVICE_PROFILE_ID = 'slaveDeviceProfileId',
|
28
|
39
|
ATTRIBUTE = 'attribute',
|
29
|
40
|
ATTRIBUTE_RENAME = 'attributeRename',
|
30
|
41
|
DEVICE_NAME = 'deviceName',
|
...
|
...
|
@@ -33,16 +44,25 @@ export enum DataSourceField { |
33
|
44
|
LATITUDE_ATTRIBUTE = 'latitudeAttribute',
|
34
|
45
|
}
|
35
|
46
|
|
36
|
|
-const isControlComponent = (frontId: FrontComponent) => {
|
|
47
|
+export const isControlComponent = (frontId: FrontComponent) => {
|
37
|
48
|
const list = [
|
38
|
49
|
FrontComponent.CONTROL_COMPONENT_SLIDING_SWITCH,
|
39
|
50
|
FrontComponent.CONTROL_COMPONENT_SWITCH_WITH_ICON,
|
40
|
51
|
FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH,
|
41
|
52
|
];
|
42
|
|
- if (list.includes(frontId)) {
|
43
|
|
- return true;
|
44
|
|
- }
|
45
|
|
- return false;
|
|
53
|
+ return list.includes(frontId);
|
|
54
|
+};
|
|
55
|
+
|
|
56
|
+export const isMapComponent = (frontId: FrontComponent) => {
|
|
57
|
+ const list = [
|
|
58
|
+ FrontComponent.MAP_COMPONENT_TRACK_HISTORY,
|
|
59
|
+ FrontComponent.MAP_COMPONENT_TRACK_REAL,
|
|
60
|
+ ];
|
|
61
|
+ return list.includes(frontId);
|
|
62
|
+};
|
|
63
|
+
|
|
64
|
+const isTcpProfile = (transportType: string) => {
|
|
65
|
+ return transportType === 'TCP';
|
46
|
66
|
};
|
47
|
67
|
|
48
|
68
|
export const basicSchema: FormSchema[] = [
|
...
|
...
|
@@ -81,6 +101,45 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
81
|
101
|
show: false,
|
82
|
102
|
},
|
83
|
103
|
{
|
|
104
|
+ field: DataSourceField.TRANSPORT_TYPE,
|
|
105
|
+ component: 'Input',
|
|
106
|
+ label: '设备配置类型',
|
|
107
|
+ show: false,
|
|
108
|
+ },
|
|
109
|
+ {
|
|
110
|
+ field: DataSourceField.DEVICE_PROFILE_ID,
|
|
111
|
+ component: 'ApiSelect',
|
|
112
|
+ label: '产品',
|
|
113
|
+ colProps: { span: 8 },
|
|
114
|
+ rules: [{ required: true, message: '产品为必填项' }],
|
|
115
|
+ componentProps: ({ formActionType, formModel }) => {
|
|
116
|
+ const { setFieldsValue } = formActionType;
|
|
117
|
+ const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
|
|
118
|
+ return {
|
|
119
|
+ api: async () => {
|
|
120
|
+ const list = await getDeviceProfile();
|
|
121
|
+ if (deviceProfileId) {
|
|
122
|
+ const record = list.find((item) => item.id === deviceProfileId);
|
|
123
|
+ setFieldsValue({ [DataSourceField.TRANSPORT_TYPE]: record?.transportType });
|
|
124
|
+ }
|
|
125
|
+ return list;
|
|
126
|
+ },
|
|
127
|
+ labelField: 'name',
|
|
128
|
+ valueField: 'id',
|
|
129
|
+ onChange: (_, option: Record<'transportType', string>) => {
|
|
130
|
+ console.log(option);
|
|
131
|
+ setFieldsValue({
|
|
132
|
+ [DataSourceField.DEVICE_ID]: null,
|
|
133
|
+ [DataSourceField.ATTRIBUTE]: null,
|
|
134
|
+ [DataSourceField.SLAVE_DEVICE_ID]: null,
|
|
135
|
+ [DataSourceField.IS_GATEWAY_DEVICE]: false,
|
|
136
|
+ [DataSourceField.TRANSPORT_TYPE]: option.transportType,
|
|
137
|
+ });
|
|
138
|
+ },
|
|
139
|
+ };
|
|
140
|
+ },
|
|
141
|
+ },
|
|
142
|
+ {
|
84
|
143
|
field: DataSourceField.ORIGINATION_ID,
|
85
|
144
|
component: 'ApiTreeSelect',
|
86
|
145
|
label: '组织',
|
...
|
...
|
@@ -101,8 +160,6 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
101
|
160
|
[DataSourceField.ATTRIBUTE]: null,
|
102
|
161
|
[DataSourceField.SLAVE_DEVICE_ID]: null,
|
103
|
162
|
[DataSourceField.IS_GATEWAY_DEVICE]: false,
|
104
|
|
- [DataSourceField.DEVICE_PROFILE_ID]: null,
|
105
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
106
|
163
|
});
|
107
|
164
|
},
|
108
|
165
|
getPopupContainer: () => document.body,
|
...
|
...
|
@@ -124,16 +181,13 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
124
|
181
|
componentProps({ formModel, formActionType }) {
|
125
|
182
|
const { setFieldsValue } = formActionType;
|
126
|
183
|
const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
127
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
|
184
|
+ const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
|
|
185
|
+
|
128
|
186
|
return {
|
129
|
187
|
api: async () => {
|
130
|
188
|
if (organizationId) {
|
131
|
189
|
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
|
|
- }
|
|
190
|
+ const data = await getAllDeviceByOrg(organizationId, deviceProfileId);
|
137
|
191
|
if (data)
|
138
|
192
|
return data.map((item) => ({
|
139
|
193
|
...item,
|
...
|
...
|
@@ -150,9 +204,7 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
150
|
204
|
setFieldsValue({
|
151
|
205
|
[DataSourceField.ATTRIBUTE]: null,
|
152
|
206
|
[DataSourceField.IS_GATEWAY_DEVICE]: record?.deviceType === 'GATEWAY',
|
153
|
|
- [DataSourceField.DEVICE_PROFILE_ID]: record?.deviceProfileId,
|
154
|
207
|
[DataSourceField.SLAVE_DEVICE_ID]: null,
|
155
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: null,
|
156
|
208
|
[DataSourceField.DEVICE_NAME]: record?.label,
|
157
|
209
|
});
|
158
|
210
|
},
|
...
|
...
|
@@ -162,19 +214,18 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
162
|
214
|
},
|
163
|
215
|
},
|
164
|
216
|
{
|
165
|
|
- field: DataSourceField.SLAVE_DEVICE_PROFILE_ID,
|
166
|
|
- component: 'Input',
|
167
|
|
- label: '',
|
168
|
|
- show: false,
|
169
|
|
- },
|
170
|
|
- {
|
171
|
217
|
field: DataSourceField.SLAVE_DEVICE_ID,
|
172
|
218
|
label: '网关子设备',
|
173
|
219
|
component: 'ApiSelect',
|
174
|
220
|
colProps: { span: 8 },
|
175
|
221
|
rules: [{ required: true, message: '网关子设备为必填项' }],
|
|
222
|
+ show: false,
|
176
|
223
|
ifShow({ model }) {
|
177
|
|
- return model[DataSourceField.IS_GATEWAY_DEVICE];
|
|
224
|
+ const transportType = model[DataSourceField.TRANSPORT_TYPE];
|
|
225
|
+ return (
|
|
226
|
+ !(isControlComponent(frontId as FrontComponent) && isTcpProfile(transportType)) &&
|
|
227
|
+ model[DataSourceField.IS_GATEWAY_DEVICE]
|
|
228
|
+ );
|
178
|
229
|
},
|
179
|
230
|
dynamicRules({ model }) {
|
180
|
231
|
return [
|
...
|
...
|
@@ -186,16 +237,12 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
186
|
237
|
const organizationId = formModel[DataSourceField.ORIGINATION_ID];
|
187
|
238
|
const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
188
|
239
|
const deviceId = formModel[DataSourceField.DEVICE_ID];
|
189
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
|
240
|
+
|
190
|
241
|
return {
|
191
|
242
|
api: async () => {
|
192
|
243
|
if (organizationId && isGatewayDevice) {
|
193
|
244
|
try {
|
194
|
245
|
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
|
246
|
if (data)
|
200
|
247
|
return data.map((item) => ({
|
201
|
248
|
...item,
|
...
|
...
|
@@ -210,7 +257,6 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
210
|
257
|
onChange(_value, record: MasterDeviceList) {
|
211
|
258
|
setFieldsValue({
|
212
|
259
|
[DataSourceField.ATTRIBUTE]: null,
|
213
|
|
- [DataSourceField.SLAVE_DEVICE_PROFILE_ID]: record.deviceProfileId,
|
214
|
260
|
[DataSourceField.DEVICE_NAME]: record?.label,
|
215
|
261
|
});
|
216
|
262
|
},
|
...
|
...
|
@@ -226,33 +272,30 @@ export const dataSourceSchema = (frontId?: FrontComponent): FormSchema[] => { |
226
|
272
|
colProps: { span: 8 },
|
227
|
273
|
rules: [{ required: true, message: '属性为必填项' }],
|
228
|
274
|
componentProps({ formModel }) {
|
229
|
|
- const isGatewayDevice = formModel[DataSourceField.IS_GATEWAY_DEVICE];
|
230
|
|
- const deviceId = formModel[DataSourceField.DEVICE_ID];
|
231
|
275
|
const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
|
232
|
|
- const slaveDeviceId = formModel[DataSourceField.SLAVE_DEVICE_ID];
|
233
|
|
- const slaveDeviceProfileId = formModel[DataSourceField.SLAVE_DEVICE_PROFILE_ID];
|
|
276
|
+ const transportType = formModel[DataSourceField.TRANSPORT_TYPE];
|
234
|
277
|
|
235
|
278
|
return {
|
236
|
279
|
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
|
|
- }
|
|
280
|
+ try {
|
|
281
|
+ if (isControlComponent(frontId as FrontComponent) && isTcpProfile(transportType)) {
|
|
282
|
+ return await getDeviceService(deviceProfileId);
|
|
283
|
+ }
|
|
284
|
+
|
|
285
|
+ if (deviceProfileId) {
|
|
286
|
+ return await getDeviceAttribute({
|
|
287
|
+ deviceProfileId,
|
|
288
|
+ dataType: isControlComponent(frontId!) ? 'BOOL' : undefined,
|
|
289
|
+ });
|
|
290
|
+ }
|
|
291
|
+ } catch (error) {}
|
|
292
|
+
|
253
|
293
|
return [];
|
254
|
294
|
},
|
255
|
|
- placeholder: '请选择属性',
|
|
295
|
+ placeholder:
|
|
296
|
+ isControlComponent(frontId as FrontComponent) && isTcpProfile(transportType)
|
|
297
|
+ ? '请选择服务'
|
|
298
|
+ : '请选择属性',
|
256
|
299
|
getPopupContainer: () => document.body,
|
257
|
300
|
};
|
258
|
301
|
},
|
...
|
...
|
|