refactor: ♻️ 字典缓存加载方式修改为按需加载,添加字典实时更新通知

This commit is contained in:
ray
2025-04-27 18:30:24 +08:00
parent 6a245e9d26
commit 7a04eea075
10 changed files with 606 additions and 10043 deletions

View File

@@ -1,7 +1,5 @@
const TOKEN_KEY = "app-token";
const USER_INFO_KEY = "user-info";
const DICT_KEY = "dict";
import { type DictData } from "@/api/system/dict";
// 设置 token
export function setToken(token: string) {
@@ -33,24 +31,10 @@ export function clearUserInfo() {
uni.removeStorageSync(USER_INFO_KEY);
}
// 设置字典缓存
export function setDictCache(dict: Record<string, DictData[]>) {
uni.setStorageSync(DICT_KEY, dict);
}
// 获取字典缓存
export function getDictCache(): Record<string, DictData[]> {
return uni.getStorageSync(DICT_KEY) || {};
}
// 清除字典缓存
export function clearDictCache() {
uni.removeStorageSync(DICT_KEY);
}
// 清除所有缓存信息
export function clearAll() {
clearToken();
clearUserInfo();
clearDictCache();
// 清除字典缓存
uni.removeStorageSync("dict_cache");
}