From cdfe1e581e27c7662c13f2f5fccc708f8569db76 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Mon, 31 Mar 2025 14:46:16 +0800 Subject: [PATCH] =?UTF-8?q?style:=20:lipstick:=20=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/dict.store.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/store/modules/dict.store.ts b/src/store/modules/dict.store.ts index 0e1dea10..e053ed94 100644 --- a/src/store/modules/dict.store.ts +++ b/src/store/modules/dict.store.ts @@ -4,8 +4,10 @@ import DictAPI, { type DictItemOption } from "@/api/system/dict.api"; export const useDictStore = defineStore("dict", () => { // 字典数据缓存 const dictCache = useStorage>("dict_cache", {}); + // 请求队列(防止重复请求) const requestQueue: Record> = {}; + /** * 缓存字典数据 * @param dictCode 字典编码 @@ -14,6 +16,7 @@ export const useDictStore = defineStore("dict", () => { const cacheDictItems = (dictCode: string, data: DictItemOption[]) => { dictCache.value[dictCode] = data; }; + /** * 加载字典数据(如果缓存中没有则请求) * @param dictCode 字典编码 @@ -29,6 +32,7 @@ export const useDictStore = defineStore("dict", () => { } await requestQueue[dictCode]; }; + /** * 获取字典项列表 * @param dictCode 字典编码 @@ -37,12 +41,14 @@ export const useDictStore = defineStore("dict", () => { const getDictItems = (dictCode: string): DictItemOption[] => { return dictCache.value[dictCode] || []; }; + /** * 清空字典缓存 */ const clearDictCache = () => { dictCache.value = {}; }; + return { loadDictItems, getDictItems,