Showing
4 changed files
with
31 additions
and
9 deletions
@@ -6,10 +6,13 @@ export interface ProductAndDevice { | @@ -6,10 +6,13 @@ export interface ProductAndDevice { | ||
6 | profileId: string | 6 | profileId: string |
7 | transportType?: string | 7 | transportType?: string |
8 | deviceType?: string | 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 | export interface ConfigurationContentType { | 18 | export interface ConfigurationContentType { |
@@ -37,9 +37,11 @@ const contentDataStore = useContentDataStoreWithOut() | @@ -37,9 +37,11 @@ const contentDataStore = useContentDataStoreWithOut() | ||
37 | export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { | 37 | export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { |
38 | const { getNodeData, getCellInfo } = usePublicFormContext() | 38 | const { getNodeData, getCellInfo } = usePublicFormContext() |
39 | const { dataSourceJson } = unref(getNodeData) || {} | 39 | const { dataSourceJson } = unref(getNodeData) || {} |
40 | - const { deviceProfileId, deviceInfo } = dataSourceJson || {} | 40 | + const { deviceProfileId, deviceInfo, deviceId } = dataSourceJson || {} |
41 | // transportType:判断是什么类型的设备 code:设备地址码 deviceType:设备类型 | 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 | const isTemplate = contentDataStore.isTemplate // 判断是否是模板 | 45 | const isTemplate = contentDataStore.isTemplate // 判断是否是模板 |
44 | return [ | 46 | return [ |
45 | { | 47 | { |
@@ -62,7 +62,6 @@ export const formSchemas = (componentKey?: string): FormSchema[] => { | @@ -62,7 +62,6 @@ export const formSchemas = (componentKey?: string): FormSchema[] => { | ||
62 | filterOption: (inputValue: string, option: DeviceItemType) => { | 62 | filterOption: (inputValue: string, option: DeviceItemType) => { |
63 | option.alias?.includes?.(inputValue) || option.name?.includes?.(inputValue) | 63 | option.alias?.includes?.(inputValue) || option.name?.includes?.(inputValue) |
64 | }, | 64 | }, |
65 | - | ||
66 | } | 65 | } |
67 | }, | 66 | }, |
68 | }, | 67 | }, |
1 | import { defineStore } from 'pinia' | 1 | import { defineStore } from 'pinia' |
2 | +import { toRaw, unref } from 'vue' | ||
2 | import { store } from '..' | 3 | import { store } from '..' |
3 | import type { NodeDataType } from '@/api/node/model' | 4 | import type { NodeDataType } from '@/api/node/model' |
4 | import type { ProductAndDevice } from '@/api/content/model' | 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 | interface ContentDataStoreType { | 13 | interface ContentDataStoreType { |
7 | contentData: NodeDataType[] | 14 | contentData: NodeDataType[] |
8 | configurationId: Nullable<string> | 15 | configurationId: Nullable<string> |
@@ -11,6 +18,7 @@ interface ContentDataStoreType { | @@ -11,6 +18,7 @@ interface ContentDataStoreType { | ||
11 | isTemplate?: number | null | string | 18 | isTemplate?: number | null | string |
12 | configurationContentList?: any | 19 | configurationContentList?: any |
13 | configurationContentId: Nullable<string> | 20 | configurationContentId: Nullable<string> |
21 | + diveceDetailMap: Record<string, DeviceList> | ||
14 | } | 22 | } |
15 | 23 | ||
16 | export const useContentDataStore = defineStore('app-content-data', { | 24 | export const useContentDataStore = defineStore('app-content-data', { |
@@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', { | @@ -22,6 +30,7 @@ export const useContentDataStore = defineStore('app-content-data', { | ||
22 | productAndDevice: [], | 30 | productAndDevice: [], |
23 | configurationContentList: [], | 31 | configurationContentList: [], |
24 | configurationContentId: null, | 32 | configurationContentId: null, |
33 | + diveceDetailMap: {}, | ||
25 | }), | 34 | }), |
26 | actions: { | 35 | actions: { |
27 | 36 | ||
@@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', { | @@ -47,8 +56,17 @@ export const useContentDataStore = defineStore('app-content-data', { | ||
47 | this.isTemplate = string | 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 |