Commit 0ada30a6a9aa82209799d2b737c800e31f3c785a
Merge branch 'fix/device-update' into 'main_dev'
fix: 修复更改设备类型为网关子设备时关联网关设备组织关系 See merge request yunteng/thingskit-front!1119
Showing
3 changed files
with
26 additions
and
15 deletions
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | import { ApiTreeSelect } from '/@/components/Form'; |
| 3 | 3 | import { Button } from 'ant-design-vue'; |
| 4 | 4 | import { getOrganizationList } from '/@/api/system/system'; |
| 5 | - import { computed, ref, unref } from 'vue'; | |
| 5 | + import { computed, ref, unref, watch } from 'vue'; | |
| 6 | 6 | import OrganizationDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; |
| 7 | 7 | import { useDrawer } from '/@/components/Drawer'; |
| 8 | 8 | import { OrganizationListItem } from '/@/api/system/model/systemModel'; |
| ... | ... | @@ -79,6 +79,11 @@ |
| 79 | 79 | needReload.value = true; |
| 80 | 80 | timespan.value = Date.now(); |
| 81 | 81 | }; |
| 82 | + | |
| 83 | + watch( | |
| 84 | + () => props.apiTreeSelectProps, | |
| 85 | + () => handleReload() | |
| 86 | + ); | |
| 82 | 87 | </script> |
| 83 | 88 | |
| 84 | 89 | <template> | ... | ... |
| ... | ... | @@ -4,10 +4,10 @@ import { getGatewayDevice, queryDeviceProfileBy } from '/@/api/device/deviceMana |
| 4 | 4 | import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const'; |
| 5 | 5 | import { JSONEditorValidator } from '/@/components/CodeEditor/src/JSONEditor'; |
| 6 | 6 | import { JSONEditor } from '/@/components/CodeEditor'; |
| 7 | -import { DeviceTypeEnum } from '/@/api/device/model/deviceModel'; | |
| 7 | +import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel'; | |
| 8 | 8 | import { getModelServices } from '/@/api/device/modelOfMatter'; |
| 9 | 9 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
| 10 | -import { h, nextTick, toRaw, unref } from 'vue'; | |
| 10 | +import { h, toRaw, unref } from 'vue'; | |
| 11 | 11 | import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/components/ObjectModelValidateForm/ObjectModelValidateForm.vue'; |
| 12 | 12 | import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum'; |
| 13 | 13 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
| ... | ... | @@ -15,9 +15,6 @@ import { AddressTypeEnum } from '/@/views/task/center/components/PollCommandInpu |
| 15 | 15 | import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; |
| 16 | 16 | import { createImgPreview } from '/@/components/Preview'; |
| 17 | 17 | import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter'; |
| 18 | - | |
| 19 | -import { getOrganizationList } from '/@/api/system/system'; | |
| 20 | -import { copyTransFun } from '/@/utils/fnUtils'; | |
| 21 | 18 | import LockControlGroup from '/@/components/Form/src/components/LockControlGroup.vue'; |
| 22 | 19 | import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect'; |
| 23 | 20 | |
| ... | ... | @@ -305,7 +302,7 @@ export const step1Schemas: FormSchema[] = [ |
| 305 | 302 | ifShow: ({ values }) => values.deviceType === 'SENSOR', |
| 306 | 303 | componentProps: ({ formModel, formActionType }) => { |
| 307 | 304 | const { transportType } = formModel; |
| 308 | - const { validateFields } = formActionType; | |
| 305 | + const { setFieldsValue } = formActionType; | |
| 309 | 306 | if (!transportType) return {}; |
| 310 | 307 | return { |
| 311 | 308 | api: async (params: Recordable) => { |
| ... | ... | @@ -320,22 +317,23 @@ export const step1Schemas: FormSchema[] = [ |
| 320 | 317 | params: { |
| 321 | 318 | transportType, |
| 322 | 319 | }, |
| 320 | + placeholder: '请选择网关设备', | |
| 323 | 321 | valueField: 'tbDeviceId', |
| 324 | 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 | 337 | label: '依据网关设备请求的组织数组', |
| 340 | 338 | component: 'Input', |
| 341 | 339 | ifShow: false, |
| ... | ... | @@ -354,6 +352,13 @@ export const step1Schemas: FormSchema[] = [ |
| 354 | 352 | return { |
| 355 | 353 | component: 'OrgTreeSelect', |
| 356 | 354 | defaultLockStatus: !!formModel?.isUpdate, |
| 355 | + componentProps: { | |
| 356 | + apiTreeSelectProps: { | |
| 357 | + params: { | |
| 358 | + organizationId: formModel?.sensorOrganizationId, | |
| 359 | + }, | |
| 360 | + }, | |
| 361 | + }, | |
| 357 | 362 | }; |
| 358 | 363 | }, |
| 359 | 364 | }, | ... | ... |