Skip to content

Commit

Permalink
fix(lock-screen): ensure lock info is saved
Browse files Browse the repository at this point in the history
确保打开多个窗口锁屏时,其它窗口不会误覆盖锁屏状态
  • Loading branch information
mynetfan committed Jun 29, 2021
1 parent e5f3788 commit d38ff66
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils/cache/persistent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '/@/enums/cacheEnum';
import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
import { toRaw } from 'vue';
import { pick } from 'lodash-es';
import { pick, omit } from 'lodash-es';

interface BasicStore {
[TOKEN_KEY]: string | number | null | undefined;
Expand Down Expand Up @@ -98,13 +98,14 @@ export class Persistent {

window.addEventListener('beforeunload', function () {
// TOKEN_KEY 在登录或注销时已经写入到storage了,此处为了解决同时打开多个窗口时token不同步的问题
// LOCK_INFO_KEY 在锁屏和解锁时写入,此处也不应修改
ls.set(APP_LOCAL_CACHE_KEY, {
...localMemory.getCache,
...pick(ls.get(APP_LOCAL_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY]),
...omit(localMemory.getCache, LOCK_INFO_KEY),
...pick(ls.get(APP_LOCAL_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY, LOCK_INFO_KEY]),
});
ss.set(APP_SESSION_CACHE_KEY, {
...sessionMemory.getCache,
...pick(sessionMemory.getCache, [TOKEN_KEY, USER_INFO_KEY]),
...omit(sessionMemory.getCache, LOCK_INFO_KEY),
...pick(ss.get(APP_SESSION_CACHE_KEY), [TOKEN_KEY, USER_INFO_KEY, LOCK_INFO_KEY]),
});
});

Expand Down

0 comments on commit d38ff66

Please sign in to comment.