style: 💄 字典状态管理代码格式化

This commit is contained in:
Ray.Hao
2025-03-31 14:46:16 +08:00
parent 486e5a038c
commit cdfe1e581e

View File

@@ -4,8 +4,10 @@ import DictAPI, { type DictItemOption } from "@/api/system/dict.api";
export const useDictStore = defineStore("dict", () => {
// 字典数据缓存
const dictCache = useStorage<Record<string, DictItemOption[]>>("dict_cache", {});
// 请求队列(防止重复请求)
const requestQueue: Record<string, Promise<void>> = {};
/**
* 缓存字典数据
* @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,