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
| export const useDictStore = defineStore('dict', () => {
| const dict = ref<Map<string, DictDataOption[]>>(new Map());
|
| /**
| * 获取字典
| * @param _key 字典key
| */
| const getDict = (_key: string): DictDataOption[] | null => {
| if (!_key) {
| return null;
| }
| return dict.value.get(_key) || null;
| };
|
| /**
| * 设置字典
| * @param _key 字典key
| * @param _value 字典value
| */
| const setDict = (_key: string, _value: DictDataOption[]) => {
| if (!_key) {
| return false;
| }
| try {
| dict.value.set(_key, _value);
| return true;
| } catch (e) {
| console.error('Error in setDict:', e);
| return false;
| }
| };
|
| /**
| * 删除字典
| * @param _key
| */
| const removeDict = (_key: string): boolean => {
| if (!_key) {
| return false;
| }
| try {
| return dict.value.delete(_key);
| } catch (e) {
| console.error('Error in removeDict:', e);
| return false;
| }
| };
|
| /**
| * 清空字典
| */
| const cleanDict = (): void => {
| dict.value.clear();
| };
|
| return {
| dict,
| getDict,
| setDict,
| removeDict,
| cleanDict
| };
| });
|
| export default useDictStore;
|
|