From 6652b5edde278e9a8d31640473ff0e3e4a261268 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周六, 03 5月 2025 17:41:12 +0800
Subject: [PATCH] 22
---
HIAWms/web/src/utils/storage.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/HIAWms/web/src/utils/storage.ts b/HIAWms/web/src/utils/storage.ts
new file mode 100644
index 0000000..c626ed4
--- /dev/null
+++ b/HIAWms/web/src/utils/storage.ts
@@ -0,0 +1,60 @@
+/**
+ * window.localStorage 娴忚鍣ㄦ案涔呯紦瀛�
+ * @method set 璁剧疆姘镐箙缂撳瓨
+ * @method get 鑾峰彇姘镐箙缂撳瓨
+ * @method remove 绉婚櫎姘镐箙缂撳瓨
+ * @method clear 绉婚櫎鍏ㄩ儴姘镐箙缂撳瓨
+ */
+const Local = {
+ // 璁剧疆姘镐箙缂撳瓨
+ set(key: string, val: any) {
+ window.localStorage.setItem(key, JSON.stringify(val))
+ },
+ // 鑾峰彇姘镐箙缂撳瓨
+ get(key: string) {
+ const value: null | string = window.localStorage.getItem(key) || null
+ if (!value) return null
+ return JSON.parse(value)
+ },
+ // 绉婚櫎姘镐箙缂撳瓨
+ remove(key: string) {
+ window.localStorage.removeItem(key)
+ },
+ // 绉婚櫎鍏ㄩ儴姘镐箙缂撳瓨
+ clear() {
+ window.localStorage.clear()
+ },
+}
+
+/**
+ * window.sessionStorage 娴忚鍣ㄤ复鏃剁紦瀛�
+ * @method set 璁剧疆涓存椂缂撳瓨
+ * @method get 鑾峰彇涓存椂缂撳瓨
+ * @method remove 绉婚櫎涓存椂缂撳瓨
+ * @method clear 绉婚櫎鍏ㄩ儴涓存椂缂撳瓨
+ */
+const Session = {
+ // 璁剧疆涓存椂缂撳瓨
+ set(key: string, val: any) {
+ window.sessionStorage.setItem(key, JSON.stringify(val))
+ },
+ // 鑾峰彇涓存椂缂撳瓨
+ get(key: string) {
+ const value: null | string = window.sessionStorage.getItem(key)
+ if (!value) return null
+ return JSON.parse(value)
+ },
+ // 绉婚櫎涓存椂缂撳瓨
+ remove(key: string) {
+ window.sessionStorage.removeItem(key)
+ },
+ // 绉婚櫎鍏ㄩ儴涓存椂缂撳瓨
+ clear() {
+ window.sessionStorage.clear()
+ },
+}
+
+export {
+ Local,
+ Session
+}
\ No newline at end of file
--
Gitblit v1.9.3