adtec-core-package 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adtec-core-package",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  import { ElMessage } from 'element-plus'
2
2
  import SysDictCacheApi from '../api/SysDictCacheApi'
3
3
  import type { ISysDictDataCacheVo } from '../interface/ISysDictDataCacheVo'
4
- import { dictStore } from '../stores/dictStore'
4
+ import { type dictDataMapVoType, dictStore } from '../stores/dictStore'
5
5
 
6
6
  export default function useDictHooks(dictTypes: string[]) {
7
7
  const dictStores = dictStore()
@@ -11,28 +11,26 @@ export default function useDictHooks(dictTypes: string[]) {
11
11
  //判断是否存在缓存数据,如果存在则不请求接口
12
12
  const dictKeySet = new Set(Object.keys(dictStores.dictMap))
13
13
  const uncachedDictTypes = dictTypes.filter((dictType) => !dictKeySet.has(dictType))
14
- if (!uncachedDictTypes.length) return
15
- const data = await SysDictCacheApi.batchGetSysDictDataCacheVo(uncachedDictTypes)
16
- dictStores.dictMap = { ...dictStores.dictMap, ...data }
17
- // 获取默认值
18
- Object.keys(data).forEach((item: string) => {
19
- findDefaultValue(data[item], item)
20
- const dataMap = new Map<string, ISysDictDataCacheVo>()
21
- packageDictDataMap(dataMap, data[item])
22
- dictStores.dictDataMap.set(item, dataMap)
23
- })
14
+ if (uncachedDictTypes.length) {
15
+ const data = await SysDictCacheApi.batchGetSysDictDataCacheVo(dictTypes)
16
+ dictStores.dictMap = { ...dictStores.dictMap, ...data }
17
+ // 获取默认值
18
+ Object.keys(data).forEach((item: string) => {
19
+ findDefaultValue(data[item], item)
20
+ const dataMap: dictDataMapVoType = {}
21
+ packageDictDataMap(dataMap, data[item])
22
+ dictStores.dictDataMap[item] = dataMap
23
+ })
24
+ }
24
25
  } catch (error: any) {
25
26
  ElMessage.error(error.msg || error.message)
26
27
  }
27
28
  }
28
29
 
29
- const packageDictDataMap = async (
30
- map: Map<string, ISysDictDataCacheVo>,
31
- list?: ISysDictDataCacheVo[],
32
- ) => {
30
+ const packageDictDataMap = async (map: dictDataMapVoType, list?: ISysDictDataCacheVo[]) => {
33
31
  if (list && list.length) {
34
32
  list.forEach((item: ISysDictDataCacheVo) => {
35
- map.set(item.value, { ...item, ...{ children: undefined } })
33
+ map[item.value] = { ...item, ...{ children: undefined } }
36
34
  packageDictDataMap(map, item.children)
37
35
  })
38
36
  }
@@ -40,7 +38,9 @@ export default function useDictHooks(dictTypes: string[]) {
40
38
 
41
39
  const findDefaultValue = async (list: ISysDictDataCacheVo[], type: string) => {
42
40
  const find = getDefaultValue(list)
43
- find && dictStores.dictDefaultValueMap.set(type, find)
41
+ if (find) {
42
+ dictStores.dictDefaultValueMap[type] = find
43
+ }
44
44
  }
45
45
 
46
46
  const getDefaultValue = (list?: ISysDictDataCacheVo[]): ISysDictDataCacheVo | undefined => {
@@ -55,20 +55,24 @@ export default function useDictHooks(dictTypes: string[]) {
55
55
  }
56
56
 
57
57
  const getDictName = (value?: string, dictType?: string) => {
58
- return dictStores.dictDataMap.get(dictType!)?.get(value!)?.label || value
58
+ if (dictStores.dictDataMap[dictType!]) {
59
+ return dictStores.dictDataMap[dictType!][value!]?.label || value
60
+ }
61
+ return value
59
62
  }
60
63
 
61
64
  const getDictData = (value: string, dictType: string) => {
62
- return dictStores.dictDataMap.get(dictType)?.get(value)
65
+ return dictStores.dictDataMap[dictType!][value!]
63
66
  }
64
67
 
65
- getDict(dictTypes).then(() => {})
68
+ getDict(dictTypes).then(() => {
69
+ })
66
70
 
67
71
  return {
68
72
  dictMap: dictStores.dictMap,
69
73
  dictDefaultValueMap: dictStores.dictDefaultValueMap,
70
74
  getDict,
71
75
  getDictName,
72
- getDictData,
76
+ getDictData
73
77
  }
74
78
  }
@@ -7,11 +7,18 @@ export interface dictMapType {
7
7
  [key: string]: ISysDictDataCacheVo[]
8
8
  }
9
9
 
10
+ export interface dictDataMapVoType {
11
+ [key: string]: ISysDictDataCacheVo
12
+ }
13
+
14
+ export interface dictDataMapType {
15
+ [key: string]: { [key: string]: ISysDictDataCacheVo }
16
+ }
17
+
10
18
  export const dictStore = defineStore('dictStore', () => {
11
19
  const dictMap = ref<dictMapType>({})
12
- const dictDataMap = ref<Map<string, Map<string, ISysDictDataCacheVo>>>(new Map())
13
- const dictDefaultValueMap = ref<Map<string, ISysDictDataCacheVo>>(new Map())
14
-
20
+ const dictDataMap = ref<dictDataMapType>({})
21
+ const dictDefaultValueMap = ref<dictDataMapVoType>({})
15
22
  return {
16
23
  dictMap,
17
24
  dictDataMap,