@ditari/store 5.0.6 → 5.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/modules/useDicStore.cjs +55 -9
- package/dist/cjs/modules/useDicStore.cjs.map +1 -1
- package/dist/esm/modules/useDicStore.mjs +55 -9
- package/dist/esm/modules/useDicStore.mjs.map +1 -1
- package/dist/types/modules/useDicStore.d.ts +36 -6
- package/dist/types/modules/useDicStore.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/modules/useDictStore.cjs +0 -4
- package/dist/cjs/modules/useDictStore.cjs.map +0 -1
- package/dist/esm/modules/useDictStore.mjs +0 -2
- package/dist/esm/modules/useDictStore.mjs.map +0 -1
- package/dist/types/modules/useDictStore.d.ts +0 -1
- package/dist/types/modules/useDictStore.d.ts.map +0 -1
|
@@ -8,8 +8,10 @@ var types = require('../types.cjs');
|
|
|
8
8
|
"use strict";
|
|
9
9
|
const useDicStore = pinia.defineStore(types.DATA_DICTIONARY_ID, {
|
|
10
10
|
state: () => ({
|
|
11
|
-
|
|
11
|
+
dataDic: {},
|
|
12
12
|
// 初始化为空对象
|
|
13
|
+
cacheDuration: 5 * 60 * 1e3
|
|
14
|
+
// 缓存有效期:5分钟(单位:毫秒)
|
|
13
15
|
}),
|
|
14
16
|
getters: {
|
|
15
17
|
/**
|
|
@@ -18,7 +20,19 @@ const useDicStore = pinia.defineStore(types.DATA_DICTIONARY_ID, {
|
|
|
18
20
|
*/
|
|
19
21
|
getDicByKey: (state) => {
|
|
20
22
|
return (key) => {
|
|
21
|
-
|
|
23
|
+
var _a;
|
|
24
|
+
return ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* 返回value匹配到的整个对象
|
|
29
|
+
* @param state
|
|
30
|
+
*/
|
|
31
|
+
getDicObjByValue: (state) => {
|
|
32
|
+
return (key, value) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
35
|
+
return rs.find((item) => item.value === value) || {};
|
|
22
36
|
};
|
|
23
37
|
},
|
|
24
38
|
/**
|
|
@@ -27,8 +41,11 @@ const useDicStore = pinia.defineStore(types.DATA_DICTIONARY_ID, {
|
|
|
27
41
|
*/
|
|
28
42
|
getDicTextByValue: (state) => {
|
|
29
43
|
return (key, value) => {
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
var _a;
|
|
45
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
46
|
+
return rs.filter(
|
|
47
|
+
(item) => item.value === value
|
|
48
|
+
).map((item) => item.label).join("");
|
|
32
49
|
};
|
|
33
50
|
},
|
|
34
51
|
/**
|
|
@@ -37,18 +54,47 @@ const useDicStore = pinia.defineStore(types.DATA_DICTIONARY_ID, {
|
|
|
37
54
|
*/
|
|
38
55
|
getDicValueByText: (state) => {
|
|
39
56
|
return (key, text) => {
|
|
40
|
-
|
|
41
|
-
|
|
57
|
+
var _a;
|
|
58
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
59
|
+
return rs.filter(
|
|
60
|
+
(item) => item.label === text
|
|
61
|
+
).map((item) => item.value).join("");
|
|
42
62
|
};
|
|
43
63
|
}
|
|
44
64
|
},
|
|
45
65
|
actions: {
|
|
66
|
+
// 检查缓存是否过期
|
|
67
|
+
isCacheExpired(name) {
|
|
68
|
+
if (this.cacheDuration === 0) return false;
|
|
69
|
+
const cache = this.dataDic[name];
|
|
70
|
+
if (!cache) return true;
|
|
71
|
+
const now = Date.now();
|
|
72
|
+
return now - cache.timestamp > this.cacheDuration;
|
|
73
|
+
},
|
|
46
74
|
/**
|
|
47
|
-
*
|
|
75
|
+
* 动态读取下拉字典的时候使用
|
|
76
|
+
* 根据key保存字典数据
|
|
77
|
+
* @param key key
|
|
48
78
|
* @param data 字典数据
|
|
49
79
|
*/
|
|
50
|
-
|
|
51
|
-
this.
|
|
80
|
+
saveDicByKey(key, data) {
|
|
81
|
+
this.dataDic[key] = {
|
|
82
|
+
value: data,
|
|
83
|
+
timestamp: Date.now()
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* 一次性存入数据字典的时候使用
|
|
88
|
+
* 数据格式: {key1:[{value:'',label:''}],key2:[{value:'',label:''}]}
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
saveAll(data) {
|
|
92
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
93
|
+
this.dataDic[key] = {
|
|
94
|
+
value,
|
|
95
|
+
timestamp: 1314521
|
|
96
|
+
};
|
|
97
|
+
});
|
|
52
98
|
}
|
|
53
99
|
},
|
|
54
100
|
persist: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDicStore.cjs","sources":["../../../src/modules/useDicStore.ts"],"sourcesContent":["import { defineStore } from \"pinia\";\r\n\r\nimport { DATA_DICTIONARY_ID } from \"../types\";\r\n\r\n// 定义字典项的类型\r\nexport interface DictionaryItem {\r\n value: string; // 字典项的值\r\n label: string; // 字典项的显示文本\r\n}\r\n\r\n// 定义字典列表的类型\r\nexport interface
|
|
1
|
+
{"version":3,"file":"useDicStore.cjs","sources":["../../../src/modules/useDicStore.ts"],"sourcesContent":["import { defineStore } from \"pinia\";\r\n\r\nimport { DATA_DICTIONARY_ID } from \"../types\";\r\n\r\n// 定义字典项的类型\r\nexport interface DictionaryItem {\r\n value: string; // 字典项的值\r\n label: string; // 字典项的显示文本\r\n}\r\n\r\n// 定义字典列表的类型\r\nexport interface Dictionary {\r\n [key: string]: {\r\n value: DictionaryItem[]; // 数组字典\r\n timestamp: number; // 数据缓存时间戳\r\n };\r\n}\r\n\r\n/**\r\n * {key:[]}\r\n */\r\nexport interface DictionaryList {\r\n [key: string]: DictionaryItem[]; // 数组字典\r\n}\r\n\r\n// 定义 Store 的状态类型\r\nexport interface DataDictionaryState {\r\n dataDic: Dictionary; // 使用 DictionaryList 替换 any\r\n cacheDuration: number; //如果 cacheDuration等于0,不用发送请求更新数据\r\n}\r\n\r\nconst useDicStore = defineStore(DATA_DICTIONARY_ID, {\r\n state: (): DataDictionaryState => ({\r\n dataDic: {}, // 初始化为空对象\r\n cacheDuration: 5 * 60 * 1000 // 缓存有效期:5分钟(单位:毫秒)\r\n }),\r\n getters: {\r\n /**\r\n * 根据 key 获取字典列表\r\n * @param state\r\n */\r\n getDicByKey: state => {\r\n return (key: string): DictionaryItem[] => {\r\n return state.dataDic[key]?.value || [];\r\n };\r\n },\r\n \r\n /**\r\n * 返回value匹配到的整个对象\r\n * @param state\r\n */\r\n getDicObjByValue: state => {\r\n return (\r\n key: string,\r\n value: never\r\n ): DictionaryItem => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return (\r\n rs.find(item => item.value === value) ||\r\n ({} as DictionaryItem)\r\n );\r\n };\r\n },\r\n\r\n /**\r\n * 根据字典名称和字典的 value 获取对应的中文\r\n * @param state\r\n */\r\n getDicTextByValue: state => {\r\n return (key: string, value: string): string => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return rs\r\n .filter(\r\n (item: DictionaryItem) => item.value === value\r\n )\r\n .map((item: DictionaryItem) => item.label)\r\n .join(\"\");\r\n };\r\n },\r\n\r\n /**\r\n * 根据文字匹配对应的 value\r\n * @param state\r\n */\r\n getDicValueByText: state => {\r\n return (key: string, text: string): string => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return rs\r\n .filter(\r\n (item: DictionaryItem) => item.label === text\r\n )\r\n .map((item: DictionaryItem) => item.value)\r\n .join(\"\");\r\n };\r\n }\r\n },\r\n actions: {\r\n // 检查缓存是否过期\r\n isCacheExpired(name: string): boolean {\r\n // 缓存时间为0,说明不用检查时间来进行触发请求\r\n if (this.cacheDuration === 0) return false;\r\n const cache = this.dataDic[name];\r\n if (!cache) return true; // 视为过期\r\n const now = Date.now();\r\n return now - cache.timestamp > this.cacheDuration; // 超过有效期\r\n },\r\n /**\r\n * 动态读取下拉字典的时候使用\r\n * 根据key保存字典数据\r\n * @param key key\r\n * @param data 字典数据\r\n */\r\n saveDicByKey(key: string, data: never) {\r\n this.dataDic[key] = {\r\n value: data,\r\n timestamp: Date.now()\r\n };\r\n },\r\n /**\r\n * 一次性存入数据字典的时候使用\r\n * 数据格式: {key1:[{value:'',label:''}],key2:[{value:'',label:''}]}\r\n *\r\n */\r\n saveAll(data: DictionaryList) {\r\n Object.entries(data).forEach(([key, value]) => {\r\n this.dataDic[key] = {\r\n value,\r\n timestamp: 1314521\r\n };\r\n });\r\n }\r\n },\r\n persist: true\r\n});\r\n\r\nexport default useDicStore;\r\n"],"names":["defineStore","DATA_DICTIONARY_ID"],"mappings":";;;;;;;;AA+BM,MAAA,WAAA,GAAcA,kBAAYC,wBAAoB,EAAA;AAAA,EAClD,OAAO,OAA4B;AAAA,IACjC,SAAS,EAAC;AAAA;AAAA,IACV,aAAA,EAAe,IAAI,EAAK,GAAA;AAAA;AAAA,GAC1B,CAAA;AAAA,EACA,OAAS,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKP,aAAa,CAAS,KAAA,KAAA;AACpB,MAAA,OAAO,CAAC,GAAkC,KAAA;AA1ChD,QAAA,IAAA,EAAA;AA2CQ,QAAA,OAAA,CAAA,CAAO,WAAM,OAAQ,CAAA,GAAG,CAAjB,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAoB,UAAS,EAAC;AAAA,OACvC;AAAA,KACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,kBAAkB,CAAS,KAAA,KAAA;AACzB,MAAO,OAAA,CACL,KACA,KACmB,KAAA;AAvD3B,QAAA,IAAA,EAAA;AAwDQ,QAAA,MAAM,OAAK,EAAM,GAAA,KAAA,CAAA,OAAA,CAAQ,GAAG,CAAjB,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAoB,UAAS,EAAC;AACzC,QAAA,OACE,GAA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AAC/B,MAAI,IAAA,CAAC,OAAc,OAAA,IAAA;AACnB,MAAM,MAAA,GAAA,GAAM,KAAK,GAAI,EAAA;AACrB,MAAO,OAAA,GAAA,GAAM,KAAM,CAAA,SAAA,GAAY,IAAK,CAAA,aAAA;AAAA,KACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAA,CAAa,KAAa,IAAa,EAAA;AACrC,MAAK,IAAA,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA;AAAA,QAClB,KAAO,EAAA,IAAA;AAAA,QACP,SAAA,EAAW,KAAK,GAAI;AAAA,OACtB;AAAA,KACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,QAAQ,IAAsB,EAAA;AAC5B,MAAO,MAAA,CAAA,OAAA,CAAQ,IAAI,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAA,EAAK,KAAK,CAAM,KAAA;AAC7C,QAAK,IAAA,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA;AAAA,UAClB,KAAA;AAAA,UACA,SAAW,EAAA;AAAA,SACb;AAAA,OACD,CAAA;AAAA;AACH,GACF;AAAA,EACA,OAAS,EAAA;AACX,CAAC;;;;"}
|
|
@@ -4,8 +4,10 @@ import { DATA_DICTIONARY_ID } from '../types.mjs';
|
|
|
4
4
|
"use strict";
|
|
5
5
|
const useDicStore = defineStore(DATA_DICTIONARY_ID, {
|
|
6
6
|
state: () => ({
|
|
7
|
-
|
|
7
|
+
dataDic: {},
|
|
8
8
|
// 初始化为空对象
|
|
9
|
+
cacheDuration: 5 * 60 * 1e3
|
|
10
|
+
// 缓存有效期:5分钟(单位:毫秒)
|
|
9
11
|
}),
|
|
10
12
|
getters: {
|
|
11
13
|
/**
|
|
@@ -14,7 +16,19 @@ const useDicStore = defineStore(DATA_DICTIONARY_ID, {
|
|
|
14
16
|
*/
|
|
15
17
|
getDicByKey: (state) => {
|
|
16
18
|
return (key) => {
|
|
17
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
return ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* 返回value匹配到的整个对象
|
|
25
|
+
* @param state
|
|
26
|
+
*/
|
|
27
|
+
getDicObjByValue: (state) => {
|
|
28
|
+
return (key, value) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
31
|
+
return rs.find((item) => item.value === value) || {};
|
|
18
32
|
};
|
|
19
33
|
},
|
|
20
34
|
/**
|
|
@@ -23,8 +37,11 @@ const useDicStore = defineStore(DATA_DICTIONARY_ID, {
|
|
|
23
37
|
*/
|
|
24
38
|
getDicTextByValue: (state) => {
|
|
25
39
|
return (key, value) => {
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
var _a;
|
|
41
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
42
|
+
return rs.filter(
|
|
43
|
+
(item) => item.value === value
|
|
44
|
+
).map((item) => item.label).join("");
|
|
28
45
|
};
|
|
29
46
|
},
|
|
30
47
|
/**
|
|
@@ -33,18 +50,47 @@ const useDicStore = defineStore(DATA_DICTIONARY_ID, {
|
|
|
33
50
|
*/
|
|
34
51
|
getDicValueByText: (state) => {
|
|
35
52
|
return (key, text) => {
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
const rs = ((_a = state.dataDic[key]) == null ? void 0 : _a.value) || [];
|
|
55
|
+
return rs.filter(
|
|
56
|
+
(item) => item.label === text
|
|
57
|
+
).map((item) => item.value).join("");
|
|
38
58
|
};
|
|
39
59
|
}
|
|
40
60
|
},
|
|
41
61
|
actions: {
|
|
62
|
+
// 检查缓存是否过期
|
|
63
|
+
isCacheExpired(name) {
|
|
64
|
+
if (this.cacheDuration === 0) return false;
|
|
65
|
+
const cache = this.dataDic[name];
|
|
66
|
+
if (!cache) return true;
|
|
67
|
+
const now = Date.now();
|
|
68
|
+
return now - cache.timestamp > this.cacheDuration;
|
|
69
|
+
},
|
|
42
70
|
/**
|
|
43
|
-
*
|
|
71
|
+
* 动态读取下拉字典的时候使用
|
|
72
|
+
* 根据key保存字典数据
|
|
73
|
+
* @param key key
|
|
44
74
|
* @param data 字典数据
|
|
45
75
|
*/
|
|
46
|
-
|
|
47
|
-
this.
|
|
76
|
+
saveDicByKey(key, data) {
|
|
77
|
+
this.dataDic[key] = {
|
|
78
|
+
value: data,
|
|
79
|
+
timestamp: Date.now()
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* 一次性存入数据字典的时候使用
|
|
84
|
+
* 数据格式: {key1:[{value:'',label:''}],key2:[{value:'',label:''}]}
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
saveAll(data) {
|
|
88
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
89
|
+
this.dataDic[key] = {
|
|
90
|
+
value,
|
|
91
|
+
timestamp: 1314521
|
|
92
|
+
};
|
|
93
|
+
});
|
|
48
94
|
}
|
|
49
95
|
},
|
|
50
96
|
persist: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDicStore.mjs","sources":["../../../src/modules/useDicStore.ts"],"sourcesContent":["import { defineStore } from \"pinia\";\r\n\r\nimport { DATA_DICTIONARY_ID } from \"../types\";\r\n\r\n// 定义字典项的类型\r\nexport interface DictionaryItem {\r\n value: string; // 字典项的值\r\n label: string; // 字典项的显示文本\r\n}\r\n\r\n// 定义字典列表的类型\r\nexport interface
|
|
1
|
+
{"version":3,"file":"useDicStore.mjs","sources":["../../../src/modules/useDicStore.ts"],"sourcesContent":["import { defineStore } from \"pinia\";\r\n\r\nimport { DATA_DICTIONARY_ID } from \"../types\";\r\n\r\n// 定义字典项的类型\r\nexport interface DictionaryItem {\r\n value: string; // 字典项的值\r\n label: string; // 字典项的显示文本\r\n}\r\n\r\n// 定义字典列表的类型\r\nexport interface Dictionary {\r\n [key: string]: {\r\n value: DictionaryItem[]; // 数组字典\r\n timestamp: number; // 数据缓存时间戳\r\n };\r\n}\r\n\r\n/**\r\n * {key:[]}\r\n */\r\nexport interface DictionaryList {\r\n [key: string]: DictionaryItem[]; // 数组字典\r\n}\r\n\r\n// 定义 Store 的状态类型\r\nexport interface DataDictionaryState {\r\n dataDic: Dictionary; // 使用 DictionaryList 替换 any\r\n cacheDuration: number; //如果 cacheDuration等于0,不用发送请求更新数据\r\n}\r\n\r\nconst useDicStore = defineStore(DATA_DICTIONARY_ID, {\r\n state: (): DataDictionaryState => ({\r\n dataDic: {}, // 初始化为空对象\r\n cacheDuration: 5 * 60 * 1000 // 缓存有效期:5分钟(单位:毫秒)\r\n }),\r\n getters: {\r\n /**\r\n * 根据 key 获取字典列表\r\n * @param state\r\n */\r\n getDicByKey: state => {\r\n return (key: string): DictionaryItem[] => {\r\n return state.dataDic[key]?.value || [];\r\n };\r\n },\r\n \r\n /**\r\n * 返回value匹配到的整个对象\r\n * @param state\r\n */\r\n getDicObjByValue: state => {\r\n return (\r\n key: string,\r\n value: never\r\n ): DictionaryItem => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return (\r\n rs.find(item => item.value === value) ||\r\n ({} as DictionaryItem)\r\n );\r\n };\r\n },\r\n\r\n /**\r\n * 根据字典名称和字典的 value 获取对应的中文\r\n * @param state\r\n */\r\n getDicTextByValue: state => {\r\n return (key: string, value: string): string => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return rs\r\n .filter(\r\n (item: DictionaryItem) => item.value === value\r\n )\r\n .map((item: DictionaryItem) => item.label)\r\n .join(\"\");\r\n };\r\n },\r\n\r\n /**\r\n * 根据文字匹配对应的 value\r\n * @param state\r\n */\r\n getDicValueByText: state => {\r\n return (key: string, text: string): string => {\r\n const rs = state.dataDic[key]?.value || [];\r\n return rs\r\n .filter(\r\n (item: DictionaryItem) => item.label === text\r\n )\r\n .map((item: DictionaryItem) => item.value)\r\n .join(\"\");\r\n };\r\n }\r\n },\r\n actions: {\r\n // 检查缓存是否过期\r\n isCacheExpired(name: string): boolean {\r\n // 缓存时间为0,说明不用检查时间来进行触发请求\r\n if (this.cacheDuration === 0) return false;\r\n const cache = this.dataDic[name];\r\n if (!cache) return true; // 视为过期\r\n const now = Date.now();\r\n return now - cache.timestamp > this.cacheDuration; // 超过有效期\r\n },\r\n /**\r\n * 动态读取下拉字典的时候使用\r\n * 根据key保存字典数据\r\n * @param key key\r\n * @param data 字典数据\r\n */\r\n saveDicByKey(key: string, data: never) {\r\n this.dataDic[key] = {\r\n value: data,\r\n timestamp: Date.now()\r\n };\r\n },\r\n /**\r\n * 一次性存入数据字典的时候使用\r\n * 数据格式: {key1:[{value:'',label:''}],key2:[{value:'',label:''}]}\r\n *\r\n */\r\n saveAll(data: DictionaryList) {\r\n Object.entries(data).forEach(([key, value]) => {\r\n this.dataDic[key] = {\r\n value,\r\n timestamp: 1314521\r\n };\r\n });\r\n }\r\n },\r\n persist: true\r\n});\r\n\r\nexport default useDicStore;\r\n"],"names":[],"mappings":";;;;AA+BM,MAAA,WAAA,GAAc,YAAY,kBAAoB,EAAA;AAAA,EAClD,OAAO,OAA4B;AAAA,IACjC,SAAS,EAAC;AAAA;AAAA,IACV,aAAA,EAAe,IAAI,EAAK,GAAA;AAAA;AAAA,GAC1B,CAAA;AAAA,EACA,OAAS,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKP,aAAa,CAAS,KAAA,KAAA;AACpB,MAAA,OAAO,CAAC,GAAkC,KAAA;AA1ChD,QAAA,IAAA,EAAA;AA2CQ,QAAA,OAAA,CAAA,CAAO,WAAM,OAAQ,CAAA,GAAG,CAAjB,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAoB,UAAS,EAAC;AAAA,OACvC;AAAA,KACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,kBAAkB,CAAS,KAAA,KAAA;AACzB,MAAO,OAAA,CACL,KACA,KACmB,KAAA;AAvD3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AAA;AAAA;AAAA,IAEP,eAAe,IAAuB,EAAA;AAEpC,MAAI,IAAA,IAAA,CAAK,aAAkB,KAAA,CAAA,EAAU,OAAA,KAAA;AACrC,MAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,IAAI,CAAA;AAC/B,MAAI,IAAA,CAAC,OAAc,OAAA,IAAA;AACnB,MAAM,MAAA,GAAA,GAAM,KAAK,GAAI,EAAA;AACrB,MAAO,OAAA,GAAA,GAAM,KAAM,CAAA,SAAA,GAAY,IAAK,CAAA,aAAA;AAAA,KACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAA,CAAa,KAAa,IAAa,EAAA;AACrC,MAAK,IAAA,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA;AAAA,QAClB,KAAO,EAAA,IAAA;AAAA,QACP,SAAA,EAAW,KAAK,GAAI;AAAA,OACtB;AAAA,KACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,QAAQ,IAAsB,EAAA;AAC5B,MAAO,MAAA,CAAA,OAAA,CAAQ,IAAI,CAAE,CAAA,OAAA,CAAQ,CAAC,CAAC,GAAA,EAAK,KAAK,CAAM,KAAA;AAC7C,QAAK,IAAA,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA;AAAA,UAClB,KAAA;AAAA,UACA,SAAW,EAAA;AAAA,SACb;AAAA,OACD,CAAA;AAAA;AACH,GACF;AAAA,EACA,OAAS,EAAA;AACX,CAAC;;;;"}
|
|
@@ -2,11 +2,21 @@ export interface DictionaryItem {
|
|
|
2
2
|
value: string;
|
|
3
3
|
label: string;
|
|
4
4
|
}
|
|
5
|
+
export interface Dictionary {
|
|
6
|
+
[key: string]: {
|
|
7
|
+
value: DictionaryItem[];
|
|
8
|
+
timestamp: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* {key:[]}
|
|
13
|
+
*/
|
|
5
14
|
export interface DictionaryList {
|
|
6
15
|
[key: string]: DictionaryItem[];
|
|
7
16
|
}
|
|
8
17
|
export interface DataDictionaryState {
|
|
9
|
-
|
|
18
|
+
dataDic: Dictionary;
|
|
19
|
+
cacheDuration: number;
|
|
10
20
|
}
|
|
11
21
|
declare const useDicStore: import("pinia").StoreDefinition<"_STORE_DATA_DICTIONARY_ID", DataDictionaryState, {
|
|
12
22
|
/**
|
|
@@ -14,28 +24,48 @@ declare const useDicStore: import("pinia").StoreDefinition<"_STORE_DATA_DICTIONA
|
|
|
14
24
|
* @param state
|
|
15
25
|
*/
|
|
16
26
|
getDicByKey: (state: {
|
|
17
|
-
|
|
27
|
+
dataDic: Dictionary;
|
|
28
|
+
cacheDuration: number;
|
|
18
29
|
} & import("pinia").PiniaCustomStateProperties<DataDictionaryState>) => (key: string) => DictionaryItem[];
|
|
30
|
+
/**
|
|
31
|
+
* 返回value匹配到的整个对象
|
|
32
|
+
* @param state
|
|
33
|
+
*/
|
|
34
|
+
getDicObjByValue: (state: {
|
|
35
|
+
dataDic: Dictionary;
|
|
36
|
+
cacheDuration: number;
|
|
37
|
+
} & import("pinia").PiniaCustomStateProperties<DataDictionaryState>) => (key: string, value: never) => DictionaryItem;
|
|
19
38
|
/**
|
|
20
39
|
* 根据字典名称和字典的 value 获取对应的中文
|
|
21
40
|
* @param state
|
|
22
41
|
*/
|
|
23
42
|
getDicTextByValue: (state: {
|
|
24
|
-
|
|
43
|
+
dataDic: Dictionary;
|
|
44
|
+
cacheDuration: number;
|
|
25
45
|
} & import("pinia").PiniaCustomStateProperties<DataDictionaryState>) => (key: string, value: string) => string;
|
|
26
46
|
/**
|
|
27
47
|
* 根据文字匹配对应的 value
|
|
28
48
|
* @param state
|
|
29
49
|
*/
|
|
30
50
|
getDicValueByText: (state: {
|
|
31
|
-
|
|
51
|
+
dataDic: Dictionary;
|
|
52
|
+
cacheDuration: number;
|
|
32
53
|
} & import("pinia").PiniaCustomStateProperties<DataDictionaryState>) => (key: string, text: string) => string;
|
|
33
54
|
}, {
|
|
55
|
+
isCacheExpired(name: string): boolean;
|
|
34
56
|
/**
|
|
35
|
-
*
|
|
57
|
+
* 动态读取下拉字典的时候使用
|
|
58
|
+
* 根据key保存字典数据
|
|
59
|
+
* @param key key
|
|
36
60
|
* @param data 字典数据
|
|
37
61
|
*/
|
|
38
|
-
|
|
62
|
+
saveDicByKey(key: string, data: never): void;
|
|
63
|
+
/**
|
|
64
|
+
* 一次性存入数据字典的时候使用
|
|
65
|
+
* 数据格式: {key1:[{value:'',label:''}],key2:[{value:'',label:''}]}
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
saveAll(data: DictionaryList): void;
|
|
39
69
|
}>;
|
|
40
70
|
export default useDicStore;
|
|
41
71
|
//# sourceMappingURL=useDicStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDicStore.d.ts","sourceRoot":"","sources":["../../../src/modules/useDicStore.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,EAAE,CAAC;CACjC;AAGD,MAAM,WAAW,mBAAmB;IAClC,
|
|
1
|
+
{"version":3,"file":"useDicStore.d.ts","sourceRoot":"","sources":["../../../src/modules/useDicStore.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,EAAE,CAAC;CACjC;AAGD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,UAAU,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,QAAA,MAAM,WAAW;IAMb;;;OAGG;;iBAbI,UAAU;uBACJ,MAAM;kFAcJ,MAAM,KAAG,cAAc,EAAE;IAKxC;;;OAGG;;iBAvBI,UAAU;uBACJ,MAAM;kFAyBV,MAAM,SACJ,KAAK,KACX,cAAc;IASnB;;;OAGG;;iBAxCI,UAAU;uBACJ,MAAM;kFAyCJ,MAAM,SAAS,MAAM,KAAG,MAAM;IAW7C;;;OAGG;;iBAxDI,UAAU;uBACJ,MAAM;kFAyDJ,MAAM,QAAQ,MAAM,KAAG,MAAM;;yBAavB,MAAM,GAAG,OAAO;IAQrC;;;;;OAKG;sBACe,MAAM,QAAQ,KAAK;IAMrC;;;;OAIG;kBACW,cAAc;EAU9B,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictStore.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictStore.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=useDictStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDictStore.d.ts","sourceRoot":"","sources":["../../../src/modules/useDictStore.ts"],"names":[],"mappings":""}
|