Commit b68a8c5decd6510a4278e2de4fa188e8630cdeea

Authored by loveumiko
1 parent dffdac6d

fix: 修改参数下发问题

... ... @@ -6,10 +6,13 @@ export interface ProductAndDevice {
6 6 profileId: string
7 7 transportType?: string
8 8 deviceType?: string
9   - deviceList: {
10   - deviceId: string
11   - name: string
12   - }[]
  9 + deviceList: DeviceList[]
  10 +}
  11 +
  12 +interface DeviceList {
  13 + deviceId: string
  14 + name: string
  15 + codeType: string
13 16 }
14 17
15 18 export interface ConfigurationContentType {
... ...
... ... @@ -37,9 +37,11 @@ const contentDataStore = useContentDataStoreWithOut()
37 37 export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
38 38 const { getNodeData, getCellInfo } = usePublicFormContext()
39 39 const { dataSourceJson } = unref(getNodeData) || {}
40   - const { deviceProfileId, deviceInfo } = dataSourceJson || {}
  40 + const { deviceProfileId, deviceInfo, deviceId } = dataSourceJson || {}
41 41 // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型
42   - const { transportType, deviceType, codeType } = deviceInfo || {}
  42 + let codeType: string | null = ''
  43 + const { transportType, deviceType, codeType: deviceCodeType } = deviceInfo || {}
  44 + codeType = deviceCodeType || (deviceId ? contentDataStore.diveceDetailMap?.[deviceId].codeType : null)
43 45 const isTemplate = contentDataStore.isTemplate // 判断是否是模板
44 46 return [
45 47 {
... ...
... ... @@ -62,7 +62,6 @@ export const formSchemas = (componentKey?: string): FormSchema[] => {
62 62 filterOption: (inputValue: string, option: DeviceItemType) => {
63 63 option.alias?.includes?.(inputValue) || option.name?.includes?.(inputValue)
64 64 },
65   -
66 65 }
67 66 },
68 67 },
... ...
1 1 import { defineStore } from 'pinia'
  2 +import { toRaw, unref } from 'vue'
2 3 import { store } from '..'
3 4 import type { NodeDataType } from '@/api/node/model'
4 5 import type { ProductAndDevice } from '@/api/content/model'
5 6
  7 +interface DeviceList {
  8 + deviceId: string
  9 + name: string
  10 + codeType: string
  11 +}
  12 +
6 13 interface ContentDataStoreType {
7 14 contentData: NodeDataType[]
8 15 configurationId: Nullable<string>
... ... @@ -11,6 +18,7 @@ interface ContentDataStoreType {
11 18 isTemplate?: number | null | string
12 19 configurationContentList?: any
13 20 configurationContentId: Nullable<string>
  21 + diveceDetailMap: Record<string, DeviceList>
14 22 }
15 23
16 24 export const useContentDataStore = defineStore('app-content-data', {
... ... @@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', {
22 30 productAndDevice: [],
23 31 configurationContentList: [],
24 32 configurationContentId: null,
  33 + diveceDetailMap: {},
25 34 }),
26 35 actions: {
27 36
... ... @@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', {
47 56 this.isTemplate = string
48 57 },
49 58
50   - setProductAndDevice(string: ProductAndDevice[]) {
51   - return this.productAndDevice = string
  59 + setProductAndDevice(list: ProductAndDevice[]) {
  60 + this.productAndDevice = list
  61 + this.doBuildDeviceMap()
  62 + return list
  63 + },
  64 +
  65 + doBuildDeviceMap() {
  66 + const list = this.productAndDevice.map(item => toRaw(unref(item.deviceList))).flat(1)
  67 + this.diveceDetailMap = list.reduce((prev, next) => {
  68 + return { ...prev, [next?.deviceId]: next }
  69 + }, {} as Record<'string', ProductAndDevice>)
52 70 },
53 71 },
54 72
... ...