1
|
1
|
import { Options } from './type';
|
2
|
|
-import { getMeetTheConditionsDevice } from '/@/api/dataBoard';
|
|
2
|
+import { getMeetTheConditionsGatewayDevice } from '/@/api/dataBoard';
|
3
|
3
|
import { queryDeviceProfileBy } from '/@/api/device/deviceManager';
|
4
|
4
|
import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
|
5
|
5
|
import { findDictItemByCode } from '/@/api/system/dict';
|
6
|
|
-import { getOrganizationList } from '/@/api/system/system';
|
7
|
|
-import { FormSchema } from '/@/components/Form';
|
|
6
|
+import { FormSchema, useComponentRegister } from '/@/components/Form';
|
8
|
7
|
import { BasicColumn } from '/@/components/Table';
|
9
|
|
-import { copyTransFun } from '/@/utils/fnUtils';
|
|
8
|
+import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
|
10
|
9
|
import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
|
11
|
10
|
import XLSX, { CellObject } from 'xlsx';
|
12
|
11
|
|
|
12
|
+useComponentRegister('OrgTreeSelect', OrgTreeSelect);
|
|
13
|
+
|
13
|
14
|
export enum FieldsEnum {
|
14
|
15
|
ORGANIZATION_ID = 'organizationId',
|
15
|
16
|
DEVICE_TYPE = 'deviceTypeEnum',
|
...
|
...
|
@@ -23,6 +24,8 @@ export enum FieldsEnum { |
23
|
24
|
IS_TCP_DEVICE_PROFILE = 'isTcpDeviceProfile',
|
24
|
25
|
TRANSPORT_TYPE = 'transportType',
|
25
|
26
|
PRODUCTION_NAME = 'productionName',
|
|
27
|
+
|
|
28
|
+ GATEWAY_ORGANIZATION_ID = 'gatewayOrganizationId',
|
26
|
29
|
}
|
27
|
30
|
|
28
|
31
|
export enum DelimiterEnum {
|
...
|
...
|
@@ -108,30 +111,6 @@ export enum CredentialsNameEnum { |
108
|
111
|
|
109
|
112
|
export const basicInfoForm: FormSchema[] = [
|
110
|
113
|
{
|
111
|
|
- field: FieldsEnum.ORGANIZATION_ID,
|
112
|
|
- label: '所属组织',
|
113
|
|
- component: 'ApiTreeSelect',
|
114
|
|
- rules: [{ required: true, message: '所属组织为必填项' }],
|
115
|
|
- componentProps: ({ formModel, formActionType }) => {
|
116
|
|
- const { setFieldsValue } = formActionType;
|
117
|
|
- return {
|
118
|
|
- maxLength: 250,
|
119
|
|
- placeholder: '请选择所属组织',
|
120
|
|
- api: async () => {
|
121
|
|
- const data = (await getOrganizationList()) as unknown as Recordable[];
|
122
|
|
- copyTransFun(data);
|
123
|
|
- return data;
|
124
|
|
- },
|
125
|
|
- getPopupContainer: () => document.body,
|
126
|
|
- onChange(e) {
|
127
|
|
- if (e != formModel?.[FieldsEnum.ORGANIZATION_ID]) {
|
128
|
|
- setFieldsValue({ [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null });
|
129
|
|
- }
|
130
|
|
- },
|
131
|
|
- };
|
132
|
|
- },
|
133
|
|
- },
|
134
|
|
- {
|
135
|
114
|
field: FieldsEnum.DEVICE_TYPE,
|
136
|
115
|
label: '设备类型',
|
137
|
116
|
component: 'ApiSelect',
|
...
|
...
|
@@ -150,6 +129,7 @@ export const basicInfoForm: FormSchema[] = [ |
150
|
129
|
[FieldsEnum.DEVICE_TYPE_NAME]: value ? options.label : null,
|
151
|
130
|
[FieldsEnum.TK_DEVICE_PROFILE_ID]: null,
|
152
|
131
|
[FieldsEnum.GATEWAY_TB_DEVICE_ID]: null,
|
|
132
|
+ [FieldsEnum.ORGANIZATION_ID]: null,
|
153
|
133
|
});
|
154
|
134
|
clearValidate();
|
155
|
135
|
},
|
...
|
...
|
@@ -181,6 +161,7 @@ export const basicInfoForm: FormSchema[] = [ |
181
|
161
|
[FieldsEnum.GATEWAY_TB_DEVICE_ID]: null,
|
182
|
162
|
[FieldsEnum.TRANSPORT_TYPE]: options?.transportType,
|
183
|
163
|
[FieldsEnum.PRODUCTION_NAME]: options?.label,
|
|
164
|
+ [FieldsEnum.ORGANIZATION_ID]: null,
|
184
|
165
|
});
|
185
|
166
|
},
|
186
|
167
|
showSearch: true,
|
...
|
...
|
@@ -203,30 +184,29 @@ export const basicInfoForm: FormSchema[] = [ |
203
|
184
|
show: false,
|
204
|
185
|
},
|
205
|
186
|
{
|
|
187
|
+ field: FieldsEnum.GATEWAY_ORGANIZATION_ID,
|
|
188
|
+ label: '',
|
|
189
|
+ component: 'Input',
|
|
190
|
+ show: false,
|
|
191
|
+ },
|
|
192
|
+ {
|
206
|
193
|
field: FieldsEnum.GATEWAY_TB_DEVICE_ID,
|
207
|
194
|
component: 'ApiSelect',
|
208
|
195
|
label: '网关设备',
|
209
|
196
|
ifShow: ({ model }) => model[FieldsEnum.DEVICE_TYPE] === DeviceTypeEnum.SENSOR,
|
210
|
197
|
required: true,
|
211
|
|
- componentProps: ({ formModel }) => {
|
212
|
|
- const organizationId = formModel[FieldsEnum.ORGANIZATION_ID];
|
213
|
|
- const transportType = formModel[FieldsEnum.TRANSPORT_TYPE];
|
|
198
|
+ componentProps: ({ formModel, formActionType }) => {
|
|
199
|
+ const transportType: string = formModel[FieldsEnum.TRANSPORT_TYPE];
|
214
|
200
|
return {
|
215
|
201
|
api: async () => {
|
216
|
202
|
try {
|
217
|
|
- if (!organizationId) return;
|
218
|
|
- const result = await getMeetTheConditionsDevice({
|
219
|
|
- deviceType: DeviceTypeEnum.GATEWAY,
|
220
|
|
- organizationId,
|
|
203
|
+ const result = await getMeetTheConditionsGatewayDevice({ transportType });
|
|
204
|
+ return result.map((item) => {
|
|
205
|
+ return {
|
|
206
|
+ ...item,
|
|
207
|
+ name: item.alias || item.name,
|
|
208
|
+ };
|
221
|
209
|
});
|
222
|
|
- return result
|
223
|
|
- .map((item) => {
|
224
|
|
- return {
|
225
|
|
- ...item,
|
226
|
|
- name: item.alias || item.name,
|
227
|
|
- };
|
228
|
|
- })
|
229
|
|
- .filter((item) => item.transportType === transportType);
|
230
|
210
|
} catch (error) {
|
231
|
211
|
return [];
|
232
|
212
|
}
|
...
|
...
|
@@ -239,6 +219,28 @@ export const basicInfoForm: FormSchema[] = [ |
239
|
219
|
return options.label.includes(inputValue);
|
240
|
220
|
},
|
241
|
221
|
placeholder: '请选择网关设备',
|
|
222
|
+ onChange(_value: string, option: DeviceRecord) {
|
|
223
|
+ const { setFieldsValue } = formActionType;
|
|
224
|
+ setFieldsValue({
|
|
225
|
+ [FieldsEnum.GATEWAY_ORGANIZATION_ID]: option?.organizationId,
|
|
226
|
+ [FieldsEnum.ORGANIZATION_ID]: null,
|
|
227
|
+ });
|
|
228
|
+ },
|
|
229
|
+ };
|
|
230
|
+ },
|
|
231
|
+ },
|
|
232
|
+ {
|
|
233
|
+ field: FieldsEnum.ORGANIZATION_ID,
|
|
234
|
+ label: '所属组织',
|
|
235
|
+ component: 'OrgTreeSelect',
|
|
236
|
+ rules: [{ required: true, message: '所属组织为必填项' }],
|
|
237
|
+ componentProps: ({ formModel }) => {
|
|
238
|
+ return {
|
|
239
|
+ apiTreeSelectProps: {
|
|
240
|
+ params: {
|
|
241
|
+ organizationId: formModel?.[FieldsEnum.GATEWAY_ORGANIZATION_ID],
|
|
242
|
+ },
|
|
243
|
+ },
|
242
|
244
|
};
|
243
|
245
|
},
|
244
|
246
|
},
|
...
|
...
|
|