曹睿
2025-04-22 2fa9c764993b4a7ad51754d0e8587990f96f1529
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
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) {
  uni.setStorageSync(TOKEN_KEY, token);
}
 
// 获取 token
export function getToken(): string {
  return uni.getStorageSync(TOKEN_KEY) || "";
}
 
// 清除 token
export function clearToken() {
  uni.removeStorageSync(TOKEN_KEY);
}
 
// 设置用户信息
export function setUserInfo(userInfo: any) {
  uni.setStorageSync(USER_INFO_KEY, userInfo);
}
 
// 获取用户信息
export function getUserInfo(): any {
  return uni.getStorageSync(USER_INFO_KEY) || null;
}
 
// 清除用户信息
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();
}