globalCacheStore.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * 用户存储全局一些 状态 和 类型的数据词典
  3. */
  4. import {defineStore} from "pinia";
  5. import {DictApi} from "/@/api/admin/Dict";
  6. /**
  7. * 数据词典的缓存编码
  8. * */
  9. const arr =
  10. ['componentStatus',
  11. 'componentType',
  12. 'componentStatusType',
  13. 'componentTypeListStatus',
  14. 'productionLogListStatus',
  15. 'groupLogoKeyKeyType',
  16. 'groupKeyGroupStatus',
  17. 'softwareType',
  18. 'equipmentType',
  19. 'softwarePackageStatus',
  20. 'oilEngineStatus'
  21. ]
  22. export const useGlobalCacheStore = defineStore('globalCacheStore', {
  23. state: () => ({
  24. globalStore:new Map
  25. }),
  26. actions: {
  27. /**获取所有字典缓存*/
  28. async requestGlobalStore () {
  29. const { data } = await new DictApi().getList(arr)
  30. Object.keys(data as object).forEach(key => {
  31. const newMap = data?.[key]?.reduce((map, obj) => {
  32. // @ts-ignore
  33. obj.color = obj.code.split("_")[1] ?? ''
  34. map.set(obj.value,{...obj})
  35. return map
  36. },new Map)
  37. this.globalStore.set(key,newMap)
  38. })
  39. },
  40. getGlobalStore(){
  41. return this.globalStore
  42. },
  43. }
  44. })