Przeglądaj źródła

调整常量缓存

Signed-off-by: skywolf627 <skywolf627@qq.com>
skywolf627 2 lat temu
rodzic
commit
647c1a9be3
1 zmienionych plików z 25 dodań i 6 usunięć
  1. 25 6
      Web/src/stores/userInfo.ts

+ 25 - 6
Web/src/stores/userInfo.ts

@@ -17,12 +17,12 @@ export const useUserInfo = defineStore('userInfo', {
 		constList: [] as any,
 	}),
 	getters: {
-		// 获取系统常量列表
-		async getSysConstList(): Promise<any[]> {
-			var res = await getAPI(SysConstApi).apiSysConstListGet();
-			this.constList = res.data.result ?? [];
-			return this.constList;
-		},
+		// // 获取系统常量列表
+		// async getSysConstList(): Promise<any[]> {
+		// 	var res = await getAPI(SysConstApi).apiSysConstListGet();
+		// 	this.constList = res.data.result ?? [];
+		// 	return this.constList;
+		// },
 	},
 	actions: {
 		async setUserInfos() {
@@ -34,6 +34,16 @@ export const useUserInfo = defineStore('userInfo', {
 				this.userInfos = userInfos;
 			}
 		},
+        async setConstList() {
+			// 存储用户信息到浏览器缓存
+			if (Session.get('constList')) {
+				this.constList = Session.get('constList');
+			} else {
+				const constList = <any[]>await this.getSysConstList();
+				Session.set('constList', constList);
+				this.constList = constList;
+			}
+		},
 		// 获取当前用户信息
 		getApiUserInfo() {
 			return new Promise((resolve) => {
@@ -76,5 +86,14 @@ export const useUserInfo = defineStore('userInfo', {
 					});
 			});
 		},
+		getSysConstList() {
+			return new Promise((resolve) => {
+				getAPI(SysConstApi)
+					.apiSysConstListGet()
+					.then(async (res: any) => {
+						resolve(res.data.result ?? []);
+					});
+			});
+		},
 	},
 });