refactor: 代码重构优化(VueUse使用)

Former-commit-id: f33b8d352dd9e9b2a706c94cdd7afa150ac12931
This commit is contained in:
haoxr
2023-03-01 00:47:39 +08:00
parent 1e6e202ce6
commit 599624e944
16 changed files with 164 additions and 194 deletions

View File

@@ -1,53 +0,0 @@
/**
* window.localStorage 浏览器永久缓存
*/
export const localStorage = {
// 设置永久缓存
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() {
window.localStorage.clear();
}
};
// 侧边栏状态(显示/隐藏)
const SidebarStatusKey = 'sidebarStatus';
export function getSidebarStatus() {
return localStorage.get(SidebarStatusKey);
}
export function setSidebarStatus(sidebarStatus: string) {
localStorage.set(SidebarStatusKey, sidebarStatus);
}
// 布局大小
const SizeKey = 'size';
export function getSize() {
return localStorage.get(SizeKey);
}
export function setSize(size: string) {
localStorage.set(SizeKey, size);
}
// 语言
const LanguageKey = 'language';
export function getLanguage() {
return localStorage.get(LanguageKey);
}
export function setLanguage(language: string) {
localStorage.set(LanguageKey, language);
}

View File

@@ -1,6 +1,4 @@
import axios, { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { ElMessage, ElMessageBox } from 'element-plus';
import { getToken } from '@/utils/auth';
import { useUserStoreHook } from '@/store/modules/user';
// 创建 axios 实例
@@ -20,7 +18,7 @@ service.interceptors.request.use(
}
const user = useUserStoreHook();
if (user.token) {
config.headers.Authorization = getToken();
config.headers.Authorization = localStorage.getItem('accessToken');
}
return config;
},