eight
2024-10-23 83bc7f6d33934f56fd1df80c7e8975e7c887d606
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { defineStore } from 'pinia'
import { store } from '../index'
// @ts-ignore
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache('sessionStorage')
import {CheckTypeApi} from "@/api/ecg/checktype";
 
export interface CheckTypeSimpleVO {
  value: number
  name: string
}
export interface CheckTypeState {
  checkTypeMap: Map<number, string>
  isSetCheckType: boolean
}
 
export const useCheckTypeStore = defineStore('checktype ', {
  state: (): CheckTypeState => ({
    checkTypeMap: new Map<number, string>(),
    isSetCheckType: false
  }),
  getters: {
    getCheckTypeMap(): Recordable {
      const checkTypeMap = wsCache.get(CACHE_KEY.CHECKTYPE_CACHE)
      if (checkTypeMap) {
        this.checkTypeMap = checkTypeMap
      }
      return this.checkTypeMap
    },
    getIsSetCheckType(): boolean {
      return this.isSetCheckType
    }
  },
  actions: {
    async setCheckTypeMap() {
      const checkTypeMap = wsCache.get(CACHE_KEY.CHECKTYPE_CACHE)
      if (checkTypeMap) {
        this.checkTypeMap = checkTypeMap
        this.isSetCheckType = true
      } else {
        const res = await CheckTypeApi.getSimpleCheckTypeList()
        // 设置数据
        const checkTypeMap = new Map<number, string>()
        res.forEach((simpleVO: CheckTypeSimpleVO) => {
          // 获得 dictType 层级
          const enumValueObj = checkTypeMap[simpleVO.value]
          if (!enumValueObj) {
            checkTypeMap[simpleVO.value] = simpleVO.name
          }
        })
        this.checkTypeMap = checkTypeMap
        this.isSetCheckType = true
        wsCache.set(CACHE_KEY.CHECKTYPE_CACHE, checkTypeMap, { exp: 60 }) // 60 秒 过期
      }
    },
    getCheckTypeName(type: number) {
      if (!this.isSetCheckType) {
        this.setcheckTypeMap()
      }
      return this.checkTypeMap[type]
    },
    getCheckTypeOptions() {
      if (!this.isSetCheckType) {
        this.setcheckTypeMap()
      }
      return Object.keys(this.checkTypeMap).map((key) => {
        return {
          value: key,
          label: this.checkTypeMap[key]
        }
      });
    },
    async resetCheckTypeInfo() {
      wsCache.delete(CACHE_KEY.CHECKTYPE_CACHE)
      const res = await CheckTypeApi.getSimpleCheckTypeList()
      // 设置数据
      const checkTypeMap = new Map<number, string>()
      res.forEach((simpleVO: CheckTypeSimpleVO) => {
        // 获得 dictType 层级
        const enumValueObj = checkTypeMap[simpleVO.value]
        if (!enumValueObj) {
          checkTypeMap[simpleVO.value] = simpleVO.name
        }
      })
      this.checkTypeMap = checkTypeMap
      this.isSetCheckType = true
      wsCache.set(CACHE_KEY.CHECKTYPE_CACHE, checkTypeMap, { exp: 60 }) // 60 秒 过期
    }
  }
})
 
export const useCheckTypeStoreWithOut = () => {
  return useCheckTypeStore(store)
}