Commit 0ada30a6a9aa82209799d2b737c800e31f3c785a

Authored by xp.Huang
2 parents 784ab5d2 4099c23a

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

fix: 修复更改设备类型为网关子设备时关联网关设备组织关系

See merge request yunteng/thingskit-front!1119
@@ -186,6 +186,7 @@ export interface DeviceRecord { @@ -186,6 +186,7 @@ export interface DeviceRecord {
186 alias?: string; 186 alias?: string;
187 brand?: string; 187 brand?: string;
188 deviceProfileId: string; 188 deviceProfileId: string;
  189 + organizationId: string;
189 deviceProfile: { 190 deviceProfile: {
190 default: boolean; 191 default: boolean;
191 name: string; 192 name: string;
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 import { ApiTreeSelect } from '/@/components/Form'; 2 import { ApiTreeSelect } from '/@/components/Form';
3 import { Button } from 'ant-design-vue'; 3 import { Button } from 'ant-design-vue';
4 import { getOrganizationList } from '/@/api/system/system'; 4 import { getOrganizationList } from '/@/api/system/system';
5 - import { computed, ref, unref } from 'vue'; 5 + import { computed, ref, unref, watch } from 'vue';
6 import OrganizationDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; 6 import OrganizationDrawer from '/@/views/system/organization/OrganizationDrawer.vue';
7 import { useDrawer } from '/@/components/Drawer'; 7 import { useDrawer } from '/@/components/Drawer';
8 import { OrganizationListItem } from '/@/api/system/model/systemModel'; 8 import { OrganizationListItem } from '/@/api/system/model/systemModel';
@@ -79,6 +79,11 @@ @@ -79,6 +79,11 @@
79 needReload.value = true; 79 needReload.value = true;
80 timespan.value = Date.now(); 80 timespan.value = Date.now();
81 }; 81 };
  82 +
  83 + watch(
  84 + () => props.apiTreeSelectProps,
  85 + () => handleReload()
  86 + );
82 </script> 87 </script>
83 88
84 <template> 89 <template>
@@ -4,10 +4,10 @@ import { getGatewayDevice, queryDeviceProfileBy } from '/@/api/device/deviceMana @@ -4,10 +4,10 @@ import { getGatewayDevice, queryDeviceProfileBy } from '/@/api/device/deviceMana
4 import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const'; 4 import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const';
5 import { JSONEditorValidator } from '/@/components/CodeEditor/src/JSONEditor'; 5 import { JSONEditorValidator } from '/@/components/CodeEditor/src/JSONEditor';
6 import { JSONEditor } from '/@/components/CodeEditor'; 6 import { JSONEditor } from '/@/components/CodeEditor';
7 -import { DeviceTypeEnum } from '/@/api/device/model/deviceModel'; 7 +import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
8 import { getModelServices } from '/@/api/device/modelOfMatter'; 8 import { getModelServices } from '/@/api/device/modelOfMatter';
9 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; 9 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
10 -import { h, nextTick, toRaw, unref } from 'vue'; 10 +import { h, toRaw, unref } from 'vue';
11 import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/components/ObjectModelValidateForm/ObjectModelValidateForm.vue'; 11 import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/components/ObjectModelValidateForm/ObjectModelValidateForm.vue';
12 import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum'; 12 import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum';
13 import { TaskTypeEnum } from '/@/views/task/center/config'; 13 import { TaskTypeEnum } from '/@/views/task/center/config';
@@ -15,9 +15,6 @@ import { AddressTypeEnum } from '/@/views/task/center/components/PollCommandInpu @@ -15,9 +15,6 @@ import { AddressTypeEnum } from '/@/views/task/center/components/PollCommandInpu
15 import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; 15 import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue';
16 import { createImgPreview } from '/@/components/Preview'; 16 import { createImgPreview } from '/@/components/Preview';
17 import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter'; 17 import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter';
18 -  
19 -import { getOrganizationList } from '/@/api/system/system';  
20 -import { copyTransFun } from '/@/utils/fnUtils';  
21 import LockControlGroup from '/@/components/Form/src/components/LockControlGroup.vue'; 18 import LockControlGroup from '/@/components/Form/src/components/LockControlGroup.vue';
22 import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect'; 19 import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
23 20
@@ -305,7 +302,7 @@ export const step1Schemas: FormSchema[] = [ @@ -305,7 +302,7 @@ export const step1Schemas: FormSchema[] = [
305 ifShow: ({ values }) => values.deviceType === 'SENSOR', 302 ifShow: ({ values }) => values.deviceType === 'SENSOR',
306 componentProps: ({ formModel, formActionType }) => { 303 componentProps: ({ formModel, formActionType }) => {
307 const { transportType } = formModel; 304 const { transportType } = formModel;
308 - const { validateFields } = formActionType; 305 + const { setFieldsValue } = formActionType;
309 if (!transportType) return {}; 306 if (!transportType) return {};
310 return { 307 return {
311 api: async (params: Recordable) => { 308 api: async (params: Recordable) => {
@@ -320,22 +317,23 @@ export const step1Schemas: FormSchema[] = [ @@ -320,22 +317,23 @@ export const step1Schemas: FormSchema[] = [
320 params: { 317 params: {
321 transportType, 318 transportType,
322 }, 319 },
  320 + placeholder: '请选择网关设备',
323 valueField: 'tbDeviceId', 321 valueField: 'tbDeviceId',
324 labelField: 'alias', 322 labelField: 'alias',
325 - onChange: async (value, options) => {  
326 - await nextTick();  
327 - if (value) {  
328 - const data = await getOrganizationList({ organizationId: options?.organizationId });  
329 - copyTransFun(data as any as any[]);  
330 - formModel.organizationList = data; 323 + onChange: async (_value: string, option: DeviceRecord) => {
  324 + setFieldsValue({ sensorOrganizationId: option?.organizationId, organizationId: null });
  325 + },
  326 + onOptionsChange(options: (DeviceRecord & Record<'value', string>)[]) {
  327 + if (formModel?.deviceType === DeviceTypeEnum.SENSOR && formModel?.gatewayId) {
  328 + const result = options.find((item) => item.value === formModel?.gatewayId);
  329 + result && setFieldsValue({ sensorOrganizationId: result?.organizationId });
331 } 330 }
332 - validateFields(['gatewayId']);  
333 }, 331 },
334 }; 332 };
335 }, 333 },
336 }, 334 },
337 { 335 {
338 - field: 'organizationList', 336 + field: 'sensorOrganizationId',
339 label: '依据网关设备请求的组织数组', 337 label: '依据网关设备请求的组织数组',
340 component: 'Input', 338 component: 'Input',
341 ifShow: false, 339 ifShow: false,
@@ -354,6 +352,13 @@ export const step1Schemas: FormSchema[] = [ @@ -354,6 +352,13 @@ export const step1Schemas: FormSchema[] = [
354 return { 352 return {
355 component: 'OrgTreeSelect', 353 component: 'OrgTreeSelect',
356 defaultLockStatus: !!formModel?.isUpdate, 354 defaultLockStatus: !!formModel?.isUpdate,
  355 + componentProps: {
  356 + apiTreeSelectProps: {
  357 + params: {
  358 + organizationId: formModel?.sensorOrganizationId,
  359 + },
  360 + },
  361 + },
357 }; 362 };
358 }, 363 },
359 }, 364 },