parent
d15e2207c2
commit
7a3d386e4f
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 缓存工具类
|
||||
*/
|
||||
class Cache {
|
||||
/**
|
||||
* 本地缓存类
|
||||
*/
|
||||
local = {
|
||||
set(key, value) {
|
||||
window.localStorage.setItem(key, JSON.stringify(value));
|
||||
},
|
||||
get(key) {
|
||||
const value = window.localStorage.getItem(key);
|
||||
if (value) {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch (error) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
remove(key) {
|
||||
window.localStorage.removeItem(key);
|
||||
},
|
||||
clear() {
|
||||
window.localStorage.clear();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 会话缓存类
|
||||
*/
|
||||
session = {
|
||||
set(key, value) {
|
||||
window.sessionStorage.setItem(key, JSON.stringify(value));
|
||||
},
|
||||
get(key) {
|
||||
const value = window.sessionStorage.getItem(key);
|
||||
if (value) {
|
||||
try {
|
||||
return JSON.parse(value);
|
||||
} catch (error) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
remove(key) {
|
||||
window.sessionStorage.removeItem(key);
|
||||
},
|
||||
clear() {
|
||||
window.sessionStorage.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default new Cache();
|
@ -0,0 +1,10 @@
|
||||
import router from "@/router";
|
||||
import cache from "@/plugins/cache.js";
|
||||
/**
|
||||
* 处理如 新增-修改-详情页面设置菜单选中高亮项
|
||||
* @param {*} path
|
||||
*/
|
||||
export function setActiveMenu(path) {
|
||||
const currentPath = path ? path : router.currentRoute.value.path;
|
||||
cache.local.set("activeMenu", currentPath);
|
||||
}
|
Loading…
Reference in new issue