广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-02 80ff784bf60637cd348ae665fc907f7b1e527dd8
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
import { ref } from 'vue';
import { defineStore } from 'pinia';
import { $t } from '@/locales';
import { SetupStoreId } from '@/enum';
 
export const useDictStore = defineStore(SetupStoreId.Dict, () => {
  const dictData = ref<{ [key: string]: Api.System.DictData[] }>({});
 
  const getDict = (key: string) => {
    return dictData.value[key]?.map(item => ({
      ...item,
      dictLabel: item.dictLabel?.startsWith(`dict.${item.dictType}.`)
        ? $t(item.dictLabel as App.I18n.I18nKey)
        : item.dictLabel
    }));
  };
 
  const setDict = (key: string, dict: Api.System.DictData[]) => {
    dictData.value[key] = dict;
  };
 
  const removeDict = (key: string) => {
    if (key in dictData.value) {
      // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
      delete dictData.value[key];
    }
  };
 
  const cleanDict = () => {
    dictData.value = {};
  };
 
  return {
    dictData,
    getDict,
    setDict,
    removeDict,
    cleanDict
  };
});
 
export default useDictStore;