Commit d38ff6670a37478b31447f8058e786c4b044e218

Authored by 无木
1 parent e5f37885

fix(lock-screen): ensure lock info is saved

确保打开多个窗口锁屏时,其它窗口不会误覆盖锁屏状态
Showing 1 changed file with 6 additions and 5 deletions
src/utils/cache/persistent.ts
@@ -16,7 +16,7 @@ import { @@ -16,7 +16,7 @@ import {
16 } from '/@/enums/cacheEnum'; 16 } from '/@/enums/cacheEnum';
17 import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting'; 17 import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
18 import { toRaw } from 'vue'; 18 import { toRaw } from 'vue';
19 -import { pick } from 'lodash-es'; 19 +import { pick, omit } from 'lodash-es';
20 20
21 interface BasicStore { 21 interface BasicStore {
22 [TOKEN_KEY]: string | number | null | undefined; 22 [TOKEN_KEY]: string | number | null | undefined;
@@ -98,13 +98,14 @@ export class Persistent { @@ -98,13 +98,14 @@ export class Persistent {
98 98
99 window.addEventListener('beforeunload', function () { 99 window.addEventListener('beforeunload', function () {
100 // TOKEN_KEY 在登录或注销时已经写入到storage了,此处为了解决同时打开多个窗口时token不同步的问题 100 // TOKEN_KEY 在登录或注销时已经写入到storage了,此处为了解决同时打开多个窗口时token不同步的问题
  101 + // LOCK_INFO_KEY 在锁屏和解锁时写入,此处也不应修改
101 ls.set(APP_LOCAL_CACHE_KEY, { 102 ls.set(APP_LOCAL_CACHE_KEY, {
102 - ...localMemory.getCache,  
103 - ...pick(ls.get(APP_LOCAL_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY]), 103 + ...omit(localMemory.getCache, LOCK_INFO_KEY),
  104 + ...pick(ls.get(APP_LOCAL_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY, LOCK_INFO_KEY]),
104 }); 105 });
105 ss.set(APP_SESSION_CACHE_KEY, { 106 ss.set(APP_SESSION_CACHE_KEY, {
106 - ...sessionMemory.getCache,  
107 - ...pick(sessionMemory.getCache, [TOKEN_KEY, USER_INFO_KEY]), 107 + ...omit(sessionMemory.getCache, LOCK_INFO_KEY),
  108 + ...pick(ss.get(APP_SESSION_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY, LOCK_INFO_KEY]),
108 }); 109 });
109 }); 110 });
110 111