2026-06-04 19:06:36 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* window.localStorage
|
|
|
|
|
|
* @method set 设置
|
|
|
|
|
|
* @method get 获取
|
|
|
|
|
|
* @method remove 移除
|
2026-07-20 09:33:10 +08:00
|
|
|
|
* @method clear 移除全部(保留表格列配置、Pinia DevTools 设置)
|
2026-06-04 19:06:36 +08:00
|
|
|
|
*/
|
2026-07-20 09:33:10 +08:00
|
|
|
|
const LOCAL_STORAGE_PRESERVE_KEYS = [
|
|
|
|
|
|
'VXE_CUSTOM_STORE',
|
|
|
|
|
|
'__VUE_DEVTOOLS_NEXT_PLUGIN_SETTINGS__dev.esm.pinia__'
|
|
|
|
|
|
]
|
|
|
|
|
|
|
2026-06-04 19:06:36 +08:00
|
|
|
|
export const Local = {
|
|
|
|
|
|
set(key: string, val: any) {
|
|
|
|
|
|
window.localStorage.setItem(key, JSON.stringify(val))
|
|
|
|
|
|
},
|
|
|
|
|
|
get(key: string) {
|
|
|
|
|
|
const json: any = window.localStorage.getItem(key)
|
|
|
|
|
|
return JSON.parse(json)
|
|
|
|
|
|
},
|
|
|
|
|
|
remove(key: string) {
|
|
|
|
|
|
window.localStorage.removeItem(key)
|
|
|
|
|
|
},
|
|
|
|
|
|
clear() {
|
2026-07-20 09:33:10 +08:00
|
|
|
|
const preserved: Record<string, string> = {}
|
|
|
|
|
|
for (const key of LOCAL_STORAGE_PRESERVE_KEYS) {
|
|
|
|
|
|
const value = window.localStorage.getItem(key)
|
|
|
|
|
|
if (value !== null) preserved[key] = value
|
|
|
|
|
|
}
|
2026-06-04 19:06:36 +08:00
|
|
|
|
window.localStorage.clear()
|
2026-07-20 09:33:10 +08:00
|
|
|
|
for (const [key, value] of Object.entries(preserved)) {
|
|
|
|
|
|
window.localStorage.setItem(key, value)
|
|
|
|
|
|
}
|
2026-06-04 19:06:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* window.sessionStorage
|
|
|
|
|
|
* @method set 设置会话缓存
|
|
|
|
|
|
* @method get 获取会话缓存
|
|
|
|
|
|
* @method remove 移除会话缓存
|
|
|
|
|
|
* @method clear 移除全部会话缓存
|
|
|
|
|
|
*/
|
|
|
|
|
|
const DEFAULT_THEME_NAME = '电能质量监测系统'
|
|
|
|
|
|
|
|
|
|
|
|
export function getStoredTheme(): { name?: string; logoUrl?: string; [key: string]: any } {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const raw = window.localStorage.getItem('getTheme')
|
|
|
|
|
|
return raw ? JSON.parse(raw) : {}
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
return {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getStoredThemeName(): string {
|
|
|
|
|
|
return getStoredTheme().name || DEFAULT_THEME_NAME
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const Session = {
|
|
|
|
|
|
set(key: string, val: any) {
|
|
|
|
|
|
window.sessionStorage.setItem(key, JSON.stringify(val))
|
|
|
|
|
|
},
|
|
|
|
|
|
get(key: string) {
|
|
|
|
|
|
const json: any = window.sessionStorage.getItem(key)
|
|
|
|
|
|
return JSON.parse(json)
|
|
|
|
|
|
},
|
|
|
|
|
|
remove(key: string) {
|
|
|
|
|
|
window.sessionStorage.removeItem(key)
|
|
|
|
|
|
},
|
|
|
|
|
|
clear() {
|
|
|
|
|
|
window.sessionStorage.clear()
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|