eight
2024-11-29 d9020ea85395682af5621a6de6bf073d9ee5d086
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
  displayBarcode: []
  notes: string
}
export interface CheckTypeState {
  checkTypeMap: Map<number, CheckTypeSimpleVO>
  isSetCheckType: boolean
}
 
export const useCheckTypeStore = defineStore('checktype ', {
  state: (): CheckTypeState => ({
    checkTypeMap: new Map<number, CheckTypeSimpleVO>(),
    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, CheckTypeSimpleVO>()
        res.forEach((simpleVO: CheckTypeSimpleVO) => {
          // 获得 dictType 层级
          const enumValueObj = checkTypeMap[simpleVO.value]
          if (!enumValueObj) {
            checkTypeMap[simpleVO.value] = simpleVO
          }
        })
        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].name
    },
    getCheckTypeOptions() {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return Object.keys(this.checkTypeMap).map((key) => {
        return {
          value: parseInt(key, 10),
          label: this.checkTypeMap[key].name
        }
      });
    },
    getCheckTypeDispBarCode(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type].displayBarcode
    },
    getCheckTypeNotes(type: number) {
      if (!this.isSetCheckType) {
        this.setCheckTypeMap()
      }
      return this.checkTypeMap[type].notes
    },
    async resetCheckTypeInfo() {
      wsCache.delete(CACHE_KEY.CHECKTYPE_CACHE)
      const res = await CheckTypeApi.getSimpleCheckTypeList()
      // 设置数据
      const checkTypeMap = new Map<number, CheckTypeSimpleVO>()
      res.forEach((simpleVO: CheckTypeSimpleVO) => {
        // 获得 dictType 层级
        const enumValueObj = checkTypeMap[simpleVO.value]
        if (!enumValueObj) {
          checkTypeMap[simpleVO.value] = simpleVO
        }
      })
      this.checkTypeMap = checkTypeMap
      this.isSetCheckType = true
      wsCache.set(CACHE_KEY.CHECKTYPE_CACHE, checkTypeMap, { exp: 60 }) // 60 秒 过期
    }
  }
})
 
export const useCheckTypeStoreWithOut = () => {
  return useCheckTypeStore(store)
}