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
|
|
...
|
...
|
|