maven
8 天以前 4cc27f93a1901e12eb12a198029911c483dd991f
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
import {ListAllData} from "@/api/system/dict/data"
 
const useDictStore = defineStore(
  'dict',
  {
    state: () => ({
      dict: []
    }),
    actions: {
      async initDict() {
        const response = await ListAllData()
        this.dict = response.data
      },
 
      // 根据字典类型获取字典
      getDictTypeList(_type) {
        if (_type == null || _type === "") {
          return null;
        }
        return this.dict.filter(item => item.type === _type);
      },
 
      getDictDataByTypeAndValue(_type,_value){
        if (_type == null || _value == null) {
          return {
            type:"",
            value:"",
            label:""
          };
        }
        return this.dict.find(item => item.type == _type && item.value == _value ) || null;
 
      },
 
      // 获取字典
      getDict(_key) {
        if (_key == null && _key == "") {
          return null
        }
        // console.log(this.dict)
        try {
          for (let i = 0; i < this.dict.length; i++) {
            if (this.dict[i].key == _key) {
              return this.dict[i].value
            }
          }
        } catch (e) {
          return null
        }
      },
      // 设置字典
      setDict(_key, value) {
        if (_key !== null && _key !== "") {
          this.dict.push({
            key: _key,
            value: value
          })
        }
      },
      // 删除字典
      removeDict(_key) {
        var bln = false
        try {
          for (let i = 0; i < this.dict.length; i++) {
            if (this.dict[i].key == _key) {
              this.dict.splice(i, 1)
              return true
            }
          }
        } catch (e) {
          bln = false
        }
        return bln
      },
      // 清空字典
      cleanDict() {
        this.dict = new Array()
      },
 
    }
  })
 
export default useDictStore