mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-02-02 19:08:40 +08:00
perf: improve persistent logic
This commit is contained in:
parent
11d3f395ca
commit
f57eb944ed
2
.env
2
.env
@ -5,4 +5,4 @@ VITE_PORT = 3100
|
||||
VITE_GLOB_APP_TITLE = Vben Admin
|
||||
|
||||
# spa shortname
|
||||
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin_2x
|
||||
VITE_GLOB_APP_SHORT_NAME = vue_vben_admin
|
||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
id: release_tag
|
||||
uses: yyx990803/release-tag@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.OPER_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
body: |
|
||||
|
2
.vscode/extensions.json
vendored
2
.vscode/extensions.json
vendored
@ -5,7 +5,7 @@
|
||||
"stylelint.vscode-stylelint",
|
||||
"esbenp.prettier-vscode",
|
||||
"mrmlnc.vscode-less",
|
||||
"antfu.i18n-ally",
|
||||
"lokalise.i18n-ally",
|
||||
"antfu.iconify",
|
||||
"mikestead.dotenv",
|
||||
"heybourn.headwind"
|
||||
|
10
package.json
10
package.json
@ -26,7 +26,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@iconify/iconify": "^2.0.0-rc.6",
|
||||
"@vueuse/core": "^4.2.2",
|
||||
"@vueuse/core": "^4.3.0",
|
||||
"@zxcvbn-ts/core": "^0.2.0",
|
||||
"ant-design-vue": "2.0.0",
|
||||
"apexcharts": "^3.25.0",
|
||||
@ -41,7 +41,7 @@
|
||||
"sortablejs": "^1.13.0",
|
||||
"vditor": "^3.8.1",
|
||||
"vue": "3.0.5",
|
||||
"vue-i18n": "9.0.0-rc.8",
|
||||
"vue-i18n": "^9.0.0",
|
||||
"vue-router": "^4.0.4",
|
||||
"vue-types": "^3.0.2",
|
||||
"vuex": "^4.0.0",
|
||||
@ -68,7 +68,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "^4.15.2",
|
||||
"@typescript-eslint/parser": "^4.15.2",
|
||||
"@vitejs/plugin-legacy": "^1.3.1",
|
||||
"@vitejs/plugin-vue": "^1.1.4",
|
||||
"@vitejs/plugin-vue": "^1.1.5",
|
||||
"@vitejs/plugin-vue-jsx": "^1.1.2",
|
||||
"@vue/compiler-sfc": "3.0.5",
|
||||
"autoprefixer": "^10.2.4",
|
||||
@ -97,7 +97,7 @@
|
||||
"stylelint-order": "^4.1.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"typescript": "4.1.5",
|
||||
"vite": "2.0.3",
|
||||
"vite": "2.0.4",
|
||||
"vite-plugin-compression": "^0.2.2",
|
||||
"vite-plugin-html": "^2.0.2",
|
||||
"vite-plugin-imagemin": "^0.2.8",
|
||||
@ -106,7 +106,7 @@
|
||||
"vite-plugin-pwa": "^0.5.5",
|
||||
"vite-plugin-style-import": "^0.7.5",
|
||||
"vite-plugin-theme": "^0.4.8",
|
||||
"vite-plugin-windicss": "0.5.3",
|
||||
"vite-plugin-windicss": "0.5.4",
|
||||
"vue-eslint-parser": "^7.5.0",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
// token key
|
||||
export const TOKEN_KEY = 'TOKEN';
|
||||
export const TOKEN_KEY = 'TOKEN__';
|
||||
|
||||
// user info key
|
||||
export const USER_INFO_KEY = 'USER__INFO__';
|
||||
@ -19,6 +19,12 @@ export const BASE_LOCAL_CACHE_KEY = 'LOCAL__CACHE__KEY__';
|
||||
// base global session key
|
||||
export const BASE_SESSION_CACHE_KEY = 'SESSION__CACHE__KEY__';
|
||||
|
||||
// base global local key
|
||||
export const APP_LOCAL_CACHE_KEY = 'LOCAL__CACHE__KEY__';
|
||||
|
||||
// base global session key
|
||||
export const APP_SESSION_CACHE_KEY = 'SESSION__CACHE__KEY__';
|
||||
|
||||
export enum CacheTypeEnum {
|
||||
SESSION,
|
||||
LOCAL,
|
||||
|
@ -7,7 +7,7 @@ import type { ProjectConfig } from '/#/config';
|
||||
import { PROJ_CFG_KEY } from '/@/enums/cacheEnum';
|
||||
|
||||
import projectSetting from '/@/settings/projectSetting';
|
||||
import { getLocal } from '/@/utils/cache/persistent';
|
||||
import { Persistent } from '/@/utils/cache/persistent';
|
||||
import { updateHeaderBgColor, updateSidebarBgColor } from '/@/logics/theme/updateBackground';
|
||||
import { updateColorWeak } from '/@/logics/theme/updateColorWeak';
|
||||
import { updateGrayMode } from '/@/logics/theme/updateGrayMode';
|
||||
@ -19,7 +19,7 @@ import { primaryColor } from '../../build/config/themeConfig';
|
||||
|
||||
// Initial project configuration
|
||||
export function initAppConfigStore() {
|
||||
let projCfg: ProjectConfig = getLocal(PROJ_CFG_KEY) as ProjectConfig;
|
||||
let projCfg: ProjectConfig = Persistent.getLocal(PROJ_CFG_KEY) as ProjectConfig;
|
||||
projCfg = deepMerge(projectSetting, projCfg || {});
|
||||
try {
|
||||
const {
|
||||
|
@ -4,6 +4,7 @@ export default {
|
||||
|
||||
// app theme preset color
|
||||
export const APP_PRESET_COLOR_LIST: string[] = [
|
||||
'#0960bd',
|
||||
'#0084f4',
|
||||
'#009688',
|
||||
'#536dfe',
|
||||
|
@ -6,7 +6,7 @@ import store from '/@/store';
|
||||
import { PROJ_CFG_KEY } from '/@/enums/cacheEnum';
|
||||
|
||||
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
|
||||
import { setLocal, getLocal, clearSession, clearLocal } from '/@/utils/cache/persistent';
|
||||
import { Persistent } from '/@/utils/cache/persistent';
|
||||
import { deepMerge } from '/@/utils';
|
||||
|
||||
import { resetRouter } from '/@/router';
|
||||
@ -29,7 +29,7 @@ export default class App extends VuexModule {
|
||||
private pageLoadingState = false;
|
||||
|
||||
// project config
|
||||
private projectConfigState: ProjectConfig | null = getLocal(PROJ_CFG_KEY);
|
||||
private projectConfigState: ProjectConfig | null = Persistent.getLocal(PROJ_CFG_KEY);
|
||||
|
||||
// set main overflow hidden
|
||||
private lockMainScrollState = false;
|
||||
@ -59,14 +59,13 @@ export default class App extends VuexModule {
|
||||
@Mutation
|
||||
commitProjectConfigState(proCfg: DeepPartial<ProjectConfig>): void {
|
||||
this.projectConfigState = deepMerge(this.projectConfigState || {}, proCfg);
|
||||
setLocal(PROJ_CFG_KEY, this.projectConfigState);
|
||||
Persistent.setLocal(PROJ_CFG_KEY, this.projectConfigState);
|
||||
}
|
||||
|
||||
@Action
|
||||
async resumeAllState() {
|
||||
resetRouter();
|
||||
clearSession();
|
||||
clearLocal();
|
||||
Persistent.clearAll();
|
||||
|
||||
permissionStore.commitResetState();
|
||||
tabStore.commitResetState();
|
||||
|
@ -4,7 +4,7 @@ import store from '/@/store';
|
||||
import { LOCK_INFO_KEY } from '/@/enums/cacheEnum';
|
||||
|
||||
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
|
||||
import { setLocal, getLocal, removeLocal } from '/@/utils/cache/persistent';
|
||||
import { Persistent } from '/@/utils/cache/persistent';
|
||||
|
||||
import { userStore } from './user';
|
||||
|
||||
@ -18,7 +18,7 @@ hotModuleUnregisterModule(NAME);
|
||||
@Module({ dynamic: true, namespaced: true, store, name: NAME })
|
||||
class Lock extends VuexModule {
|
||||
// lock info
|
||||
private lockInfoState: LockInfo | null = getLocal(LOCK_INFO_KEY);
|
||||
private lockInfoState: LockInfo | null = Persistent.getLocal(LOCK_INFO_KEY);
|
||||
|
||||
get getLockInfo(): LockInfo {
|
||||
return this.lockInfoState || ({} as LockInfo);
|
||||
@ -27,12 +27,12 @@ class Lock extends VuexModule {
|
||||
@Mutation
|
||||
commitLockInfoState(info: LockInfo): void {
|
||||
this.lockInfoState = Object.assign({}, this.lockInfoState, info);
|
||||
setLocal(LOCK_INFO_KEY, this.lockInfoState);
|
||||
Persistent.setLocal(LOCK_INFO_KEY, this.lockInfoState);
|
||||
}
|
||||
|
||||
@Mutation
|
||||
resetLockInfo(): void {
|
||||
removeLocal(LOCK_INFO_KEY);
|
||||
Persistent.removeLocal(LOCK_INFO_KEY);
|
||||
this.lockInfoState = null;
|
||||
}
|
||||
|
||||
|
@ -18,30 +18,23 @@ import router from '/@/router';
|
||||
|
||||
import { loginApi, getUserInfoById } from '/@/api/sys/user';
|
||||
|
||||
import { setLocal, getLocal, getSession, setSession } from '/@/utils/cache/persistent';
|
||||
import { useProjectSetting } from '/@/hooks/setting';
|
||||
import { Persistent, BasicKeys } from '/@/utils/cache/persistent';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
import { ErrorMessageMode } from '/@/utils/http/axios/types';
|
||||
import projectSetting from '/@/settings/projectSetting';
|
||||
|
||||
export type UserInfo = Omit<GetUserInfoByUserIdModel, 'roles'>;
|
||||
|
||||
const NAME = 'user';
|
||||
hotModuleUnregisterModule(NAME);
|
||||
|
||||
const { permissionCacheType } = useProjectSetting();
|
||||
|
||||
function getCache<T>(key: string) {
|
||||
const fn = permissionCacheType === CacheTypeEnum.LOCAL ? getLocal : getSession;
|
||||
function getCache<T>(key: BasicKeys) {
|
||||
const { permissionCacheType } = projectSetting;
|
||||
const fn =
|
||||
permissionCacheType === CacheTypeEnum.LOCAL ? Persistent.getLocal : Persistent.getSession;
|
||||
return fn(key) as T;
|
||||
}
|
||||
|
||||
function setCache(USER_INFO_KEY: string, info: any) {
|
||||
if (!info) return;
|
||||
setLocal(USER_INFO_KEY, info, true);
|
||||
// TODO
|
||||
setSession(USER_INFO_KEY, info, true);
|
||||
}
|
||||
|
||||
@Module({ namespaced: true, name: NAME, dynamic: true, store })
|
||||
class User extends VuexModule {
|
||||
// user info
|
||||
@ -75,19 +68,19 @@ class User extends VuexModule {
|
||||
@Mutation
|
||||
commitUserInfoState(info: UserInfo): void {
|
||||
this.userInfoState = info;
|
||||
setCache(USER_INFO_KEY, info);
|
||||
Persistent.setLocal(USER_INFO_KEY, info);
|
||||
}
|
||||
|
||||
@Mutation
|
||||
commitRoleListState(roleList: RoleEnum[]): void {
|
||||
this.roleListState = roleList;
|
||||
setCache(ROLES_KEY, roleList);
|
||||
Persistent.setLocal(ROLES_KEY, roleList);
|
||||
}
|
||||
|
||||
@Mutation
|
||||
commitTokenState(info: string): void {
|
||||
this.tokenState = info;
|
||||
setCache(TOKEN_KEY, info);
|
||||
Persistent.setLocal(TOKEN_KEY, info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
22
src/utils/cache/index.ts
vendored
22
src/utils/cache/index.ts
vendored
@ -1,22 +1,32 @@
|
||||
import { getStorageShortName } from '/@/utils/env';
|
||||
import { createStorage as create } from './storageCache';
|
||||
import { createStorage as create, CreateStorageParams } from './storageCache';
|
||||
import { enableStorageEncryption } from '/@/settings/encryptionSetting';
|
||||
import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
|
||||
|
||||
const createOptions = (storage = sessionStorage) => {
|
||||
export type Options = Partial<CreateStorageParams>;
|
||||
|
||||
const createOptions = (storage: Storage, options: Options = {}): Options => {
|
||||
return {
|
||||
// No encryption in debug mode
|
||||
hasEncrypt: enableStorageEncryption,
|
||||
storage,
|
||||
prefixKey: getStorageShortName(),
|
||||
timeout: DEFAULT_CACHE_TIME,
|
||||
|
||||
...options,
|
||||
};
|
||||
};
|
||||
|
||||
export const WebStorage = create(createOptions());
|
||||
export const WebStorage = create(createOptions(sessionStorage));
|
||||
|
||||
export const createStorage = (storage: Storage = sessionStorage) => {
|
||||
return create(createOptions(storage))!;
|
||||
export const createStorage = (storage: Storage = sessionStorage, options: Options = {}) => {
|
||||
return create(createOptions(storage, options));
|
||||
};
|
||||
|
||||
export const createPersistentStorage = (
|
||||
storage: Storage = sessionStorage,
|
||||
options: Options = {}
|
||||
) => {
|
||||
return createStorage(storage, { ...options, timeout: DEFAULT_CACHE_TIME });
|
||||
};
|
||||
|
||||
export default WebStorage;
|
||||
|
98
src/utils/cache/memory.ts
vendored
Normal file
98
src/utils/cache/memory.ts
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
export interface Cache<V = any> {
|
||||
value?: V;
|
||||
timeoutId?: ReturnType<typeof setTimeout>;
|
||||
time?: number;
|
||||
alive?: number;
|
||||
}
|
||||
|
||||
const NOT_ALIVE = 0;
|
||||
|
||||
export class Memory<T = any, V = any> {
|
||||
private cache: { [key in keyof T]?: Cache<V> } = {};
|
||||
private alive: number;
|
||||
|
||||
constructor(alive = NOT_ALIVE) {
|
||||
// Unit second
|
||||
this.alive = alive * 1000;
|
||||
}
|
||||
|
||||
get getCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
setCache(cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
// get<K extends keyof T>(key: K) {
|
||||
// const item = this.getItem(key);
|
||||
// const time = item?.time;
|
||||
// if (!isNullOrUnDef(time) && time < new Date().getTime()) {
|
||||
// this.remove(key);
|
||||
// }
|
||||
// return item?.value ?? undefined;
|
||||
// }
|
||||
|
||||
get<K extends keyof T>(key: K) {
|
||||
return this.cache[key];
|
||||
}
|
||||
|
||||
set<K extends keyof T>(key: K, value: V, expires?: number) {
|
||||
let item = this.get(key);
|
||||
|
||||
if (!expires || (expires as number) <= 0) {
|
||||
expires = this.alive;
|
||||
}
|
||||
if (item) {
|
||||
if (item.timeoutId) {
|
||||
clearTimeout(item.timeoutId);
|
||||
item.timeoutId = undefined;
|
||||
}
|
||||
item.value = value;
|
||||
} else {
|
||||
item = { value, alive: expires };
|
||||
this.cache[key] = item;
|
||||
}
|
||||
|
||||
if (!expires) {
|
||||
return value;
|
||||
}
|
||||
item.time = new Date().getTime() + this.alive * 1000;
|
||||
item.timeoutId = setTimeout(() => {
|
||||
this.remove(key);
|
||||
}, expires);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
remove<K extends keyof T>(key: K) {
|
||||
const item = this.get(key);
|
||||
Reflect.deleteProperty(this.cache, key);
|
||||
if (item) {
|
||||
clearTimeout(item.timeoutId!);
|
||||
return item.value;
|
||||
}
|
||||
}
|
||||
|
||||
resetCache(cache: { [K in keyof T]: Cache }) {
|
||||
Object.keys(cache).forEach((key) => {
|
||||
const k = (key as any) as keyof T;
|
||||
const item = cache[k];
|
||||
if (item && item.time) {
|
||||
const now = new Date().getTime();
|
||||
const expire = now + item.time * 1000;
|
||||
if (expire > now) {
|
||||
this.set(k, item.value, expire);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
clear() {
|
||||
Object.keys(this.cache).forEach((key) => {
|
||||
const item = this.cache[key];
|
||||
item.timeoutId && clearTimeout(item.timeoutId);
|
||||
});
|
||||
this.cache = {};
|
||||
}
|
||||
}
|
203
src/utils/cache/persistent.ts
vendored
203
src/utils/cache/persistent.ts
vendored
@ -1,130 +1,109 @@
|
||||
import { createStorage } from '/@/utils/cache';
|
||||
import { createPersistentStorage } from '/@/utils/cache';
|
||||
import { Memory } from './memory';
|
||||
import {
|
||||
TOKEN_KEY,
|
||||
USER_INFO_KEY,
|
||||
ROLES_KEY,
|
||||
LOCK_INFO_KEY,
|
||||
PROJ_CFG_KEY,
|
||||
APP_LOCAL_CACHE_KEY,
|
||||
APP_SESSION_CACHE_KEY,
|
||||
} from '/@/enums/cacheEnum';
|
||||
import { DEFAULT_CACHE_TIME } from '/@/settings/encryptionSetting';
|
||||
import { toRaw } from 'vue';
|
||||
|
||||
import { BASE_LOCAL_CACHE_KEY, BASE_SESSION_CACHE_KEY } from '/@/enums/cacheEnum';
|
||||
|
||||
const ls = createStorage(localStorage);
|
||||
const ss = createStorage();
|
||||
|
||||
interface CacheStore {
|
||||
local: Recordable;
|
||||
session: Recordable;
|
||||
interface BasicStore {
|
||||
[TOKEN_KEY]: string | number | null | undefined;
|
||||
[USER_INFO_KEY]: Recordable;
|
||||
[ROLES_KEY]: Recordable;
|
||||
[LOCK_INFO_KEY]: Recordable;
|
||||
[PROJ_CFG_KEY]: Recordable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Persistent cache
|
||||
*/
|
||||
const cacheStore: CacheStore = {
|
||||
// localstorage cache
|
||||
local: {},
|
||||
// sessionstorage cache
|
||||
session: {},
|
||||
};
|
||||
type LocalStore = BasicStore;
|
||||
|
||||
function initCache() {
|
||||
cacheStore.local = ls.get(BASE_LOCAL_CACHE_KEY) || {};
|
||||
cacheStore.session = ss.get(BASE_SESSION_CACHE_KEY) || {};
|
||||
type SessionStore = BasicStore;
|
||||
|
||||
export type BasicKeys = keyof BasicStore;
|
||||
type LocalKeys = keyof LocalStore;
|
||||
type SessionKeys = keyof SessionStore;
|
||||
|
||||
const ls = createPersistentStorage(localStorage);
|
||||
const ss = createPersistentStorage(sessionStorage);
|
||||
|
||||
const localMemory = new Memory(DEFAULT_CACHE_TIME);
|
||||
const sessionMemory = new Memory(DEFAULT_CACHE_TIME);
|
||||
|
||||
function initMemory() {
|
||||
const localCache = ls.get(APP_LOCAL_CACHE_KEY);
|
||||
const sessionCache = ls.get(APP_SESSION_CACHE_KEY);
|
||||
localCache && localMemory.resetCache(localCache);
|
||||
sessionCache && sessionMemory.resetCache(sessionCache);
|
||||
}
|
||||
initMemory();
|
||||
export class Persistent {
|
||||
static getLocal<T>(key: LocalKeys) {
|
||||
return localMemory.get(key)?.value as Nullable<T>;
|
||||
}
|
||||
|
||||
initCache();
|
||||
static setLocal(key: LocalKeys, value: LocalStore[LocalKeys], immediate = false): void {
|
||||
localMemory.set(key, toRaw(value));
|
||||
immediate && ls.set(APP_LOCAL_CACHE_KEY, localMemory.getCache);
|
||||
}
|
||||
|
||||
export function setLocal(key: string, value: any, immediate = false) {
|
||||
const local = ls.get(BASE_LOCAL_CACHE_KEY)?.[BASE_LOCAL_CACHE_KEY] || {};
|
||||
static removeLocal(key: LocalKeys): void {
|
||||
localMemory.remove(key);
|
||||
}
|
||||
|
||||
cacheStore.local[BASE_LOCAL_CACHE_KEY] =
|
||||
{ ...local, ...cacheStore.local[BASE_LOCAL_CACHE_KEY] } || {};
|
||||
cacheStore.local[BASE_LOCAL_CACHE_KEY][key] = value;
|
||||
static clearLocal(): void {
|
||||
localMemory.clear();
|
||||
}
|
||||
|
||||
if (immediate) {
|
||||
ls.set(BASE_LOCAL_CACHE_KEY, cacheStore.local);
|
||||
static getSession<T>(key: SessionKeys) {
|
||||
return sessionMemory.get(key)?.value as Nullable<T>;
|
||||
}
|
||||
|
||||
static setSession(key: SessionKeys, value: SessionStore[SessionKeys], immediate = false): void {
|
||||
sessionMemory.set(key, toRaw(value));
|
||||
immediate && ss.set(APP_SESSION_CACHE_KEY, localMemory);
|
||||
}
|
||||
|
||||
static removeSession(key: SessionKeys): void {
|
||||
sessionMemory.remove(key);
|
||||
}
|
||||
static clearSession(): void {
|
||||
sessionMemory.clear();
|
||||
}
|
||||
|
||||
static clearAll() {
|
||||
sessionMemory.clear();
|
||||
localMemory.clear();
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocal<T>(key: string): T | null {
|
||||
try {
|
||||
return cacheStore.local[BASE_LOCAL_CACHE_KEY][key];
|
||||
} catch (error) {
|
||||
return null;
|
||||
window.addEventListener('beforeunload', function () {
|
||||
ls.set(APP_LOCAL_CACHE_KEY, localMemory.getCache);
|
||||
ss.set(APP_SESSION_CACHE_KEY, sessionMemory.getCache);
|
||||
});
|
||||
|
||||
function storageChange(e: any) {
|
||||
const { key, newValue, oldValue } = e;
|
||||
|
||||
if (!key) {
|
||||
Persistent.clearAll();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function removeLocal(key: string) {
|
||||
if (cacheStore.local[BASE_LOCAL_CACHE_KEY]) {
|
||||
Reflect.deleteProperty(cacheStore.local[BASE_LOCAL_CACHE_KEY], key);
|
||||
}
|
||||
}
|
||||
|
||||
export function clearLocal(immediate = false) {
|
||||
cacheStore.local = {};
|
||||
immediate && ls.remove(BASE_LOCAL_CACHE_KEY);
|
||||
}
|
||||
|
||||
export function setSession(key: string, value: any, immediate = false) {
|
||||
const session = ss.get(BASE_SESSION_CACHE_KEY)?.[BASE_SESSION_CACHE_KEY] || {};
|
||||
|
||||
cacheStore.session[BASE_SESSION_CACHE_KEY] =
|
||||
{ ...session, ...cacheStore.session[BASE_SESSION_CACHE_KEY] } || {};
|
||||
|
||||
cacheStore.session[BASE_SESSION_CACHE_KEY][key] = value;
|
||||
|
||||
if (immediate) {
|
||||
ss.set(BASE_SESSION_CACHE_KEY, cacheStore.session);
|
||||
}
|
||||
}
|
||||
|
||||
export function removeSession(key: string) {
|
||||
if (cacheStore.session[BASE_SESSION_CACHE_KEY]) {
|
||||
Reflect.deleteProperty(cacheStore.session[BASE_SESSION_CACHE_KEY], key);
|
||||
}
|
||||
}
|
||||
|
||||
export function getSession<T>(key: string): T | null {
|
||||
try {
|
||||
return cacheStore.session[BASE_SESSION_CACHE_KEY][key];
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function clearSession(immediate = false) {
|
||||
cacheStore.session = {};
|
||||
immediate && ss.remove(BASE_SESSION_CACHE_KEY);
|
||||
}
|
||||
|
||||
export function clearAll() {
|
||||
clearLocal();
|
||||
clearSession();
|
||||
}
|
||||
|
||||
export function persistentCache() {
|
||||
const localCache = cacheStore.local;
|
||||
const sessionCache = cacheStore.session;
|
||||
ls.set(BASE_LOCAL_CACHE_KEY, localCache);
|
||||
ss.set(BASE_SESSION_CACHE_KEY, sessionCache);
|
||||
}
|
||||
|
||||
(() => {
|
||||
// /** Write to local before closing window */
|
||||
window.addEventListener('beforeunload', () => {
|
||||
persistentCache();
|
||||
});
|
||||
|
||||
function storageChange(e: any) {
|
||||
const { key, newValue, oldValue } = e;
|
||||
|
||||
if (!key) {
|
||||
clearAll();
|
||||
return;
|
||||
if (!!newValue && !!oldValue) {
|
||||
if (APP_LOCAL_CACHE_KEY === key) {
|
||||
Persistent.clearLocal();
|
||||
}
|
||||
|
||||
if (!!newValue && !!oldValue) {
|
||||
if (BASE_LOCAL_CACHE_KEY === key) {
|
||||
clearLocal();
|
||||
}
|
||||
if (BASE_SESSION_CACHE_KEY === key) {
|
||||
clearSession();
|
||||
}
|
||||
if (APP_SESSION_CACHE_KEY === key) {
|
||||
Persistent.clearSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('storage', storageChange);
|
||||
})();
|
||||
window.addEventListener('storage', storageChange);
|
||||
|
||||
export default {};
|
||||
|
129
yarn.lock
129
yarn.lock
@ -1123,43 +1123,43 @@
|
||||
resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.308.tgz#162210182c14af4eb217f19e1a1707b787aca2aa"
|
||||
integrity sha512-zoVnvr5A1tpuTCzuw5EvRcWYV5rcmWLGLhEzg9+SuRAXWyT2st0ShF8hYbeHzm+MJHhJWodHVfsTu2DkshMX2g==
|
||||
|
||||
"@intlify/core-base@9.0.0-rc.8":
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/@intlify/core-base/-/core-base-9.0.0-rc.8.tgz#674b88c313cbe471bb66f52dd0907106b01e1c38"
|
||||
integrity sha512-Nwj2GTZN7gOiN7uGgAeaaJAho/UamkXTheMrdjLrj7FPjE3d1oiSeB3fBgobJxzpyBRjhmjUmpPCEs1afokSxQ==
|
||||
"@intlify/core-base@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@intlify/core-base/-/core-base-9.0.0.tgz#3de223b8532c535d022e5be58f7d56a26d2fb12f"
|
||||
integrity sha512-dxqakT94EV2bFshG3LENQUPWX9yJFCga1BOwJ6mz7J8LnAYVB9Kxw7NRyE2ybN31USW2IUTQH6WWR1yDbCiefQ==
|
||||
dependencies:
|
||||
"@intlify/message-compiler" "9.0.0-rc.8"
|
||||
"@intlify/message-resolver" "9.0.0-rc.8"
|
||||
"@intlify/runtime" "9.0.0-rc.8"
|
||||
"@intlify/shared" "9.0.0-rc.8"
|
||||
"@intlify/message-compiler" "9.0.0"
|
||||
"@intlify/message-resolver" "9.0.0"
|
||||
"@intlify/runtime" "9.0.0"
|
||||
"@intlify/shared" "9.0.0"
|
||||
|
||||
"@intlify/message-compiler@9.0.0-rc.8":
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/@intlify/message-compiler/-/message-compiler-9.0.0-rc.8.tgz#b2c291b728858aa6fa57b6329a806c1accc8450b"
|
||||
integrity sha512-vtKk5z7ovenLUXMGHVUyS+snEYrTpHT4o6bQyjPeEL3BoXcVyHlLKIHXNJ6QzlHVQN8aN1bWyj3rMf9ZKEZF3A==
|
||||
"@intlify/message-compiler@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@intlify/message-compiler/-/message-compiler-9.0.0.tgz#8a1079f8aebcde33057ce769817691ce27ad3e0d"
|
||||
integrity sha512-3oiLj+8z6koRYJwknazjilBsrqnJEAJywr/t39MYVy2yPmwOI1+NDfdDwM9U3ioA2RvsQEUICqW8gmjq1YIElw==
|
||||
dependencies:
|
||||
"@intlify/message-resolver" "9.0.0-rc.8"
|
||||
"@intlify/shared" "9.0.0-rc.8"
|
||||
"@intlify/message-resolver" "9.0.0"
|
||||
"@intlify/shared" "9.0.0"
|
||||
source-map "0.6.1"
|
||||
|
||||
"@intlify/message-resolver@9.0.0-rc.8":
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/@intlify/message-resolver/-/message-resolver-9.0.0-rc.8.tgz#09382e6390298d6786cc53c483d4240e4654ec17"
|
||||
integrity sha512-8Qqh23yN3sM/hIZKIgJ1S6a9mNm1LVeUxkjhHdfyGV84P6G3Q9bgwCSenX1BKuUrVUJfK45FUkg87BZnUd2Qpg==
|
||||
"@intlify/message-resolver@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@intlify/message-resolver/-/message-resolver-9.0.0.tgz#0077ec24606b6486d238bdef9044e27729f4782c"
|
||||
integrity sha512-LVK4cwu1l33yvBy0UQkEdXm6pZUcbbiparobruJXz+U8jRTmYHBprN59j59YKXEKcV43cHfzNveaQIm84bgxvQ==
|
||||
|
||||
"@intlify/runtime@9.0.0-rc.8":
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/@intlify/runtime/-/runtime-9.0.0-rc.8.tgz#be5d1c776bba2678b51c3c0492d4676a910921ca"
|
||||
integrity sha512-ZK0eZwZQ6wb3nxUPc+WYSebnswSSt/lRJotmaVdcmS+tT9/FFz6PJ9pO0nNFV/cGn0uEGW92buldCiNVKA5aHg==
|
||||
"@intlify/runtime@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@intlify/runtime/-/runtime-9.0.0.tgz#bf9415ff90c746a9be38a5c32f71cbbe9848eee8"
|
||||
integrity sha512-UqCKduZezb5/qA+XPRfHVvXoLmhnQ8iKMyCh0Lg3ZwjW2vOMep/AgZU3T9cgESe67r4buPYHs7nOBSHbTdjNxg==
|
||||
dependencies:
|
||||
"@intlify/message-compiler" "9.0.0-rc.8"
|
||||
"@intlify/message-resolver" "9.0.0-rc.8"
|
||||
"@intlify/shared" "9.0.0-rc.8"
|
||||
"@intlify/message-compiler" "9.0.0"
|
||||
"@intlify/message-resolver" "9.0.0"
|
||||
"@intlify/shared" "9.0.0"
|
||||
|
||||
"@intlify/shared@9.0.0-rc.8":
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/@intlify/shared/-/shared-9.0.0-rc.8.tgz#0b1b387a3237d4ae95496e8ae60cec267625f55d"
|
||||
integrity sha512-HH05+lD4A9q6F0VLbGY5eZmmCbfaBMuCSSQXmrGgegtsRVu7WFiUMQLNsouN1UtHabOJC9PQarxKwfTzdHyN6Q==
|
||||
"@intlify/shared@9.0.0":
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/@intlify/shared/-/shared-9.0.0.tgz#d85b3b5f9033f377c5cf2202cf2459aa49948f36"
|
||||
integrity sha512-0r4v7dnY8g/Jfx2swUWy2GyfH/WvIpWvkU4OIupvxDTWiE8RhcpbOCVvqpVh/xGi0proHQ/r2Dhc0QSItUsfDQ==
|
||||
|
||||
"@ls-lint/ls-lint@^1.9.2":
|
||||
version "1.9.2"
|
||||
@ -1595,10 +1595,10 @@
|
||||
"@vue/babel-plugin-jsx" "^1.0.3"
|
||||
hash-sum "^2.0.0"
|
||||
|
||||
"@vitejs/plugin-vue@^1.1.4":
|
||||
version "1.1.4"
|
||||
resolved "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.1.4.tgz#1dd388519b75439b7733601b55238ca691864796"
|
||||
integrity sha512-cUDILd++9jdhdjpuhgJofQqOabOKe+kTWTE2HQY2PBHEUO2fgwTurLE0cJg9UcIo1x4lHfsp+59S9TBCHgTZkw==
|
||||
"@vitejs/plugin-vue@^1.1.5":
|
||||
version "1.1.5"
|
||||
resolved "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-1.1.5.tgz#fa1e8e5e049c35e213672e33f73fe81706ad5dbe"
|
||||
integrity sha512-4DV8VPYo8/OR1YsnK39QN16xhKENt2XvcmJxqfRtyz75kvbjBYh1zTSHLp7XsXqv4R2I+fOZlbEBvxosMYLcPA==
|
||||
|
||||
"@vue/babel-helper-vue-transform-on@^1.0.2":
|
||||
version "1.0.2"
|
||||
@ -1703,25 +1703,25 @@
|
||||
resolved "https://registry.npmjs.org/@vue/shared/-/shared-3.0.5.tgz#c131d88bd6713cc4d93b3bb1372edb1983225ff0"
|
||||
integrity sha512-gYsNoGkWejBxNO6SNRjOh/xKeZ0H0V+TFzaPzODfBjkAIb0aQgBuixC1brandC/CDJy1wYPwSoYrXpvul7m6yw==
|
||||
|
||||
"@vueuse/core@^4.2.2":
|
||||
version "4.2.2"
|
||||
resolved "https://registry.npmjs.org/@vueuse/core/-/core-4.2.2.tgz#ecbba4ba05e0360e9c9079b32e149fac803a1020"
|
||||
integrity sha512-NMU3Vr4eBiNrPzCoUH5ptNj+DETg85Vtww0OJjaQEXobDTH28gzbLJseqCh4m3NYR92C5qlXRnzhSvWOoR/uLg==
|
||||
"@vueuse/core@^4.3.0":
|
||||
version "4.3.0"
|
||||
resolved "https://registry.npmjs.org/@vueuse/core/-/core-4.3.0.tgz#409d1c8fc0b7fffcf5b5388dfc487762bb936b0c"
|
||||
integrity sha512-PQ3r6wZDCN3pY+UBB5NLQdRfwiasd8MmWppuzpvNE2Sr8T48gmWXDWw3GG4EHMXnuz5EBfQG+U+1TjSaGaK6/w==
|
||||
dependencies:
|
||||
"@vueuse/shared" "4.2.2"
|
||||
"@vueuse/shared" "4.3.0"
|
||||
vue-demi latest
|
||||
|
||||
"@vueuse/shared@4.2.2":
|
||||
version "4.2.2"
|
||||
resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-4.2.2.tgz#e52ee278b929f028117c0ca1792b24df462bff80"
|
||||
integrity sha512-yudh4jt0SxaW0i3j2iumI8GTloA8aUpLwGaBw9Xv2rQCdZvOZpXpvpGEz8EsMK793ySs+d5S4/opItlxuzjtSg==
|
||||
"@vueuse/shared@4.3.0":
|
||||
version "4.3.0"
|
||||
resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-4.3.0.tgz#82e05dc2941642814ac6fcbb5f9076c38c052968"
|
||||
integrity sha512-udc1ADIYwizTK/iSfjZQj6+QDFM099oHuX0Sj/yv0NgE9eSODcesV4zO7PtvmJanzw43hCdvtdGBz8miyRkHCQ==
|
||||
dependencies:
|
||||
vue-demi latest
|
||||
|
||||
"@windicss/plugin-utils@0.5.3":
|
||||
version "0.5.3"
|
||||
resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.5.3.tgz#5302864cb2f94dd3d71bb5af958dab6ce3f74dab"
|
||||
integrity sha512-BXNvMSRmi1TyM8j3EnF/li9HViJPN4EPeGKTiIDWemxrfkRNlgN+Gmv31CFtZwnjiAlXRO58B6LIqVTSVYaTfQ==
|
||||
"@windicss/plugin-utils@0.5.4":
|
||||
version "0.5.4"
|
||||
resolved "https://registry.npmjs.org/@windicss/plugin-utils/-/plugin-utils-0.5.4.tgz#69476a9d1fee92046695766bf7fbfe48e48809a7"
|
||||
integrity sha512-zxpHdTsVZl7TF8A3uAymJCqMRlG83dMRAXf//fXonluoLDSJCuGBJyxN3NdkAyNZZR1L1DvoUUtkZLYOba+ElQ==
|
||||
dependencies:
|
||||
esbuild "^0.8.52"
|
||||
esbuild-register "^2.0.0"
|
||||
@ -3601,11 +3601,6 @@ esbuild-register@^2.0.0:
|
||||
source-map-support "^0.5.19"
|
||||
strip-json-comments "^3.1.1"
|
||||
|
||||
esbuild@^0.8.47:
|
||||
version "0.8.51"
|
||||
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.8.51.tgz#1a59f1fee34892f143b7009081f9b4901a564b93"
|
||||
integrity sha512-MVIom8fgL1+B6iGqWtrG7QJ1gqd64BycxounlsX1kR/IcIITaSlTo7gghKpg4a+bnxkpo0dwcikuvk4MVSA9ww==
|
||||
|
||||
esbuild@^0.8.48:
|
||||
version "0.8.48"
|
||||
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.8.48.tgz#a57e4dde84ec56da1c6ecaefee97e9da6c5b00b5"
|
||||
@ -8973,20 +8968,20 @@ vite-plugin-theme@^0.4.8:
|
||||
es-module-lexer "^0.3.26"
|
||||
tinycolor2 "^1.4.2"
|
||||
|
||||
vite-plugin-windicss@0.5.3:
|
||||
version "0.5.3"
|
||||
resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.5.3.tgz#7929b5fbaed7f0530cbe79947e7bc9e4f471b683"
|
||||
integrity sha512-hVfj0QjgxBch4j5M6BfMj9Dsm7iKioP9uQUvs00RGkuUdG+Gc0PQcT9SuLrcZJjUE/2Tp9+J44BEbOYxjesqlA==
|
||||
vite-plugin-windicss@0.5.4:
|
||||
version "0.5.4"
|
||||
resolved "https://registry.npmjs.org/vite-plugin-windicss/-/vite-plugin-windicss-0.5.4.tgz#35764e91536d596ac2c9266c3e16c546915d8b3e"
|
||||
integrity sha512-iPLoqfpZdnRIY1AzweumpdE8ILQQnyhywZwJDqFpj8SZ3h43e5tfQFnJb5nS6FLccOsBcCV9JFugD2w6pGyfqg==
|
||||
dependencies:
|
||||
"@windicss/plugin-utils" "0.5.3"
|
||||
"@windicss/plugin-utils" "0.5.4"
|
||||
windicss "^2.2.0"
|
||||
|
||||
vite@2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.npmjs.org/vite/-/vite-2.0.3.tgz#ea0329295d4da9341e670036e5e7f0bfa30ae2cf"
|
||||
integrity sha512-4CUm3FVUHyTSSSK6vHWkj3SVkP+GGNNzwYcFsHOjjc8xQ3BPjJa1JDDmFlYxpxR29ANa+7RWptYPoyHyJ29Nhw==
|
||||
vite@2.0.4:
|
||||
version "2.0.4"
|
||||
resolved "https://registry.npmjs.org/vite/-/vite-2.0.4.tgz#063532a4139b59a067297d8ebb5960d450907a09"
|
||||
integrity sha512-+PP89D7AKXFE4gps8c5+4eP5yXTh5qCogjdYX7iSsIxbLZAa26JoGSq6OLk0qdb/fqDh7gtJqGiLbG2V6NvkKQ==
|
||||
dependencies:
|
||||
esbuild "^0.8.47"
|
||||
esbuild "^0.8.52"
|
||||
postcss "^8.2.1"
|
||||
resolve "^1.19.0"
|
||||
rollup "^2.38.5"
|
||||
@ -9010,13 +9005,13 @@ vue-eslint-parser@^7.5.0:
|
||||
esquery "^1.4.0"
|
||||
lodash "^4.17.15"
|
||||
|
||||
vue-i18n@9.0.0-rc.8:
|
||||
version "9.0.0-rc.8"
|
||||
resolved "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.0.0-rc.8.tgz#36d022516cf2527ce02eecf9de116b978e163da3"
|
||||
integrity sha512-WQC9q0UG1lbk+naBBoVTrJjHPZfHP6Pid35Ek9AkCxUcXolW1pXUCQg1gIMF8I0obxLd/fSx9GuOWrB/aaU3aQ==
|
||||
vue-i18n@^9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.0.0.tgz#a04c41d5ed3d5a068e923517bfaa0abcbc84e174"
|
||||
integrity sha512-iks0eJDv/4cK/7tl/ooMUroNVVIGOK4kKS1PIHmPQk7QjT/sDfFM84vjPKgpARbw0GjJsOiADL43jufNfs9e9A==
|
||||
dependencies:
|
||||
"@intlify/core-base" "9.0.0-rc.8"
|
||||
"@intlify/shared" "9.0.0-rc.8"
|
||||
"@intlify/core-base" "9.0.0"
|
||||
"@intlify/shared" "9.0.0"
|
||||
"@vue/devtools-api" "^6.0.0-beta.5"
|
||||
|
||||
vue-router@^4.0.4:
|
||||
|
Loading…
Reference in New Issue
Block a user