globalCacheStore.ts 991 B

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