Browse Source

fix(lock-screen): fix lock-screen can skip on new window

修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
无木 3 years ago
parent
commit
d7b84c7874
3 changed files with 16 additions and 7 deletions
  1. 1 0
      CHANGELOG.zh_CN.md
  2. 2 2
      src/store/modules/lock.ts
  3. 13 5
      src/utils/cache/persistent.ts

+ 1 - 0
CHANGELOG.zh_CN.md

@@ -11,6 +11,7 @@
 - **SvgIcon** 修复图标样式问题
 - **Table** 修复为 table 提供 rowSelection.onChange 时,无法手动变更 table 的选中项的问题
 - **Icon** 修复 SvgIcon 缺少部分样式的问题
+- **LockScreen** 修复锁屏功能可以通过刷新页面或复制 URL 打开新的浏览器标签来跳过锁定状态的问题
 
 ## 2.5.2(2021-06-27)
 

+ 2 - 2
src/store/modules/lock.ts

@@ -23,10 +23,10 @@ export const useLockStore = defineStore({
   actions: {
     setLockInfo(info: LockInfo) {
       this.lockInfo = Object.assign({}, this.lockInfo, info);
-      Persistent.setLocal(LOCK_INFO_KEY, this.lockInfo);
+      Persistent.setLocal(LOCK_INFO_KEY, this.lockInfo, true);
     },
     resetLockInfo() {
-      Persistent.removeLocal(LOCK_INFO_KEY);
+      Persistent.removeLocal(LOCK_INFO_KEY, true);
       this.lockInfo = null;
     },
     // Unlock

+ 13 - 5
src/utils/cache/persistent.ts

@@ -57,12 +57,14 @@ export class Persistent {
     immediate && ls.set(APP_LOCAL_CACHE_KEY, localMemory.getCache);
   }
 
-  static removeLocal(key: LocalKeys): void {
+  static removeLocal(key: LocalKeys, immediate = false): void {
     localMemory.remove(key);
+    immediate && ls.set(APP_LOCAL_CACHE_KEY, localMemory.getCache);
   }
 
-  static clearLocal(): void {
+  static clearLocal(immediate = false): void {
     localMemory.clear();
+    immediate && ls.clear();
   }
 
   static getSession<T>(key: SessionKeys) {
@@ -74,16 +76,22 @@ export class Persistent {
     immediate && ss.set(APP_SESSION_CACHE_KEY, sessionMemory.getCache);
   }
 
-  static removeSession(key: SessionKeys): void {
+  static removeSession(key: SessionKeys, immediate = false): void {
     sessionMemory.remove(key);
+    immediate && ss.set(APP_SESSION_CACHE_KEY, sessionMemory.getCache);
   }
-  static clearSession(): void {
+  static clearSession(immediate = false): void {
     sessionMemory.clear();
+    immediate && ss.clear();
   }
 
-  static clearAll() {
+  static clearAll(immediate = false) {
     sessionMemory.clear();
     localMemory.clear();
+    if (immediate) {
+      ls.clear();
+      ss.clear();
+    }
   }
 }