From ee1004043ac065f44ef313e8dded616e5838f95c Mon Sep 17 00:00:00 2001
From: zhangchen <1652267879@qq.com>
Date: 星期六, 06 九月 2025 16:35:35 +0800
Subject: [PATCH] ID2040-重连次数
---
src/utils/storage.ts | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/src/utils/storage.ts b/src/utils/storage.ts
index d6d1eef..385f99d 100644
--- a/src/utils/storage.ts
+++ b/src/utils/storage.ts
@@ -30,4 +30,33 @@
window.localStorage.clear();
},
};
-
\ No newline at end of file
+ /**
+ * window.sessionStorage 浏览器临时缓存
+ * @method set 设置临时缓存
+ * @method get 获取临时缓存
+ * @method remove 移除临时缓存
+ * @method clear 移除全部临时缓存
+ */
+export const Session = {
+ // 设置临时缓存
+ set<T>(key: string, val: T) {
+ if (key === 'token') return Cookies.set(key, val);
+ window.sessionStorage.setItem(Local.setKey(key), JSON.stringify(val));
+ },
+ // 获取临时缓存
+ get(key: string) {
+ if (key === 'token') return Cookies.get(key);
+ let json = <string>window.sessionStorage.getItem(Local.setKey(key));
+ return JSON.parse(json);
+ },
+ // 移除临时缓存
+ remove(key: string) {
+ if (key === 'token') return Cookies.remove(key);
+ window.sessionStorage.removeItem(Local.setKey(key));
+ },
+ // 移除全部临时缓存
+ clear() {
+ Cookies.remove('token');
+ window.sessionStorage.clear();
+ },
+};
\ No newline at end of file
--
Gitblit v1.8.0