Commit b65d93992e6c7721cde0f250d7f6503864085c15

Authored by xp.Huang
2 parents 0ada30a6 a6ad7242

Merge branch 'fix/device-import' into 'main_dev'

fix: 变更导入网关子设备导入时组织关联网关逻辑

See merge request yunteng/thingskit-front!1120
@@ -49,6 +49,7 @@ enum DeviceUrl { @@ -49,6 +49,7 @@ enum DeviceUrl {
49 GET_DEVICE_ATTRIBUTE = '/device/attributes', 49 GET_DEVICE_ATTRIBUTE = '/device/attributes',
50 GET_DEVICE = '/device/list', 50 GET_DEVICE = '/device/list',
51 GET_DEVICE_RELATION = '/device/device/relation', 51 GET_DEVICE_RELATION = '/device/device/relation',
  52 + GET_GATEWAY_LIST = '/device/gateway/list',
52 } 53 }
53 54
54 /** 55 /**
@@ -240,6 +241,15 @@ export const sendCommandTwoway = (params: SendCommandParams) => { @@ -240,6 +241,15 @@ export const sendCommandTwoway = (params: SendCommandParams) => {
240 ); 241 );
241 }; 242 };
242 243
  244 +export const getMeetTheConditionsGatewayDevice = (
  245 + params?: Partial<Record<'organizationId' | 'transportType', string>>
  246 +) => {
  247 + return defHttp.get<DeviceRecord[]>({
  248 + url: DeviceUrl.GET_GATEWAY_LIST,
  249 + params,
  250 + });
  251 +};
  252 +
243 export const getDeviceRelation = (params: { deviceId: string; isSlave: boolean }) => { 253 export const getDeviceRelation = (params: { deviceId: string; isSlave: boolean }) => {
244 return defHttp.get<string>({ 254 return defHttp.get<string>({
245 url: DeviceUrl.GET_DEVICE_RELATION, 255 url: DeviceUrl.GET_DEVICE_RELATION,
1 import { Options } from './type'; 1 import { Options } from './type';
2 -import { getMeetTheConditionsDevice } from '/@/api/dataBoard'; 2 +import { getMeetTheConditionsGatewayDevice } from '/@/api/dataBoard';
3 import { queryDeviceProfileBy } from '/@/api/device/deviceManager'; 3 import { queryDeviceProfileBy } from '/@/api/device/deviceManager';
4 import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel'; 4 import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
5 import { findDictItemByCode } from '/@/api/system/dict'; 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 import { BasicColumn } from '/@/components/Table'; 7 import { BasicColumn } from '/@/components/Table';
9 -import { copyTransFun } from '/@/utils/fnUtils'; 8 +import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
10 import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; 9 import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
11 import XLSX, { CellObject } from 'xlsx'; 10 import XLSX, { CellObject } from 'xlsx';
12 11
  12 +useComponentRegister('OrgTreeSelect', OrgTreeSelect);
  13 +
13 export enum FieldsEnum { 14 export enum FieldsEnum {
14 ORGANIZATION_ID = 'organizationId', 15 ORGANIZATION_ID = 'organizationId',
15 DEVICE_TYPE = 'deviceTypeEnum', 16 DEVICE_TYPE = 'deviceTypeEnum',
@@ -23,6 +24,8 @@ export enum FieldsEnum { @@ -23,6 +24,8 @@ export enum FieldsEnum {
23 IS_TCP_DEVICE_PROFILE = 'isTcpDeviceProfile', 24 IS_TCP_DEVICE_PROFILE = 'isTcpDeviceProfile',
24 TRANSPORT_TYPE = 'transportType', 25 TRANSPORT_TYPE = 'transportType',
25 PRODUCTION_NAME = 'productionName', 26 PRODUCTION_NAME = 'productionName',
  27 +
  28 + GATEWAY_ORGANIZATION_ID = 'gatewayOrganizationId',
26 } 29 }
27 30
28 export enum DelimiterEnum { 31 export enum DelimiterEnum {
@@ -108,30 +111,6 @@ export enum CredentialsNameEnum { @@ -108,30 +111,6 @@ export enum CredentialsNameEnum {
108 111
109 export const basicInfoForm: FormSchema[] = [ 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 field: FieldsEnum.DEVICE_TYPE, 114 field: FieldsEnum.DEVICE_TYPE,
136 label: '设备类型', 115 label: '设备类型',
137 component: 'ApiSelect', 116 component: 'ApiSelect',
@@ -150,6 +129,7 @@ export const basicInfoForm: FormSchema[] = [ @@ -150,6 +129,7 @@ export const basicInfoForm: FormSchema[] = [
150 [FieldsEnum.DEVICE_TYPE_NAME]: value ? options.label : null, 129 [FieldsEnum.DEVICE_TYPE_NAME]: value ? options.label : null,
151 [FieldsEnum.TK_DEVICE_PROFILE_ID]: null, 130 [FieldsEnum.TK_DEVICE_PROFILE_ID]: null,
152 [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null, 131 [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null,
  132 + [FieldsEnum.ORGANIZATION_ID]: null,
153 }); 133 });
154 clearValidate(); 134 clearValidate();
155 }, 135 },
@@ -181,6 +161,7 @@ export const basicInfoForm: FormSchema[] = [ @@ -181,6 +161,7 @@ export const basicInfoForm: FormSchema[] = [
181 [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null, 161 [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null,
182 [FieldsEnum.TRANSPORT_TYPE]: options?.transportType, 162 [FieldsEnum.TRANSPORT_TYPE]: options?.transportType,
183 [FieldsEnum.PRODUCTION_NAME]: options?.label, 163 [FieldsEnum.PRODUCTION_NAME]: options?.label,
  164 + [FieldsEnum.ORGANIZATION_ID]: null,
184 }); 165 });
185 }, 166 },
186 showSearch: true, 167 showSearch: true,
@@ -203,30 +184,29 @@ export const basicInfoForm: FormSchema[] = [ @@ -203,30 +184,29 @@ export const basicInfoForm: FormSchema[] = [
203 show: false, 184 show: false,
204 }, 185 },
205 { 186 {
  187 + field: FieldsEnum.GATEWAY_ORGANIZATION_ID,
  188 + label: '',
  189 + component: 'Input',
  190 + show: false,
  191 + },
  192 + {
206 field: FieldsEnum.GATEWAY_TB_DEVICE_ID, 193 field: FieldsEnum.GATEWAY_TB_DEVICE_ID,
207 component: 'ApiSelect', 194 component: 'ApiSelect',
208 label: '网关设备', 195 label: '网关设备',
209 ifShow: ({ model }) => model[FieldsEnum.DEVICE_TYPE] === DeviceTypeEnum.SENSOR, 196 ifShow: ({ model }) => model[FieldsEnum.DEVICE_TYPE] === DeviceTypeEnum.SENSOR,
210 required: true, 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 return { 200 return {
215 api: async () => { 201 api: async () => {
216 try { 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 } catch (error) { 210 } catch (error) {
231 return []; 211 return [];
232 } 212 }
@@ -239,6 +219,28 @@ export const basicInfoForm: FormSchema[] = [ @@ -239,6 +219,28 @@ export const basicInfoForm: FormSchema[] = [
239 return options.label.includes(inputValue); 219 return options.label.includes(inputValue);
240 }, 220 },
241 placeholder: '请选择网关设备', 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 },