微调
This commit is contained in:
@@ -42,7 +42,7 @@ class RequestHttp {
|
|||||||
config.loading ?? (config.loading = true)
|
config.loading ?? (config.loading = true)
|
||||||
config.loading && showFullScreenLoading()
|
config.loading && showFullScreenLoading()
|
||||||
if (config.headers && typeof config.headers.set === 'function') {
|
if (config.headers && typeof config.headers.set === 'function') {
|
||||||
config.headers.set('x-access-token', userStore.token)
|
config.headers.set('Authorization', 'Bearer '+userStore.token)
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
@@ -63,6 +63,7 @@ class RequestHttp {
|
|||||||
// 登陆失效
|
// 登陆失效
|
||||||
if (data.code == ResultEnum.OVERDUE) {
|
if (data.code == ResultEnum.OVERDUE) {
|
||||||
userStore.setToken('')
|
userStore.setToken('')
|
||||||
|
userStore.setUserInfo({name: ''})
|
||||||
router.replace(LOGIN_URL)
|
router.replace(LOGIN_URL)
|
||||||
ElMessage.error(data.message)
|
ElMessage.error(data.message)
|
||||||
return Promise.reject(data)
|
return Promise.reject(data)
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ export namespace Login {
|
|||||||
}
|
}
|
||||||
export interface ResLogin {
|
export interface ResLogin {
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
userInfo:{
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export interface ResAuthButtons {
|
export interface ResAuthButtons {
|
||||||
[key: string]: string[];
|
[key: string]: string[];
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ import ThemeSetting from "./components/ThemeSetting.vue";
|
|||||||
import Message from "./components/Message.vue";
|
import Message from "./components/Message.vue";
|
||||||
import Fullscreen from "./components/Fullscreen.vue";
|
import Fullscreen from "./components/Fullscreen.vue";
|
||||||
import { useAuthStore } from "@/stores/modules/auth";
|
import { useAuthStore } from "@/stores/modules/auth";
|
||||||
|
import {useDictStore} from "@/stores/modules/dict";
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const dictStore = useDictStore();
|
||||||
const username = computed(() => userStore.userInfo.name);
|
const username = computed(() => userStore.userInfo.name);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
@@ -64,6 +66,8 @@ const logout = () => {
|
|||||||
await logoutApi();
|
await logoutApi();
|
||||||
// 2.清除 Token
|
// 2.清除 Token
|
||||||
userStore.setToken("");
|
userStore.setToken("");
|
||||||
|
userStore.setUserInfo({name: ""});
|
||||||
|
dictStore.setDictData([]);
|
||||||
// 3.重定向到登陆页
|
// 3.重定向到登陆页
|
||||||
router.replace(LOGIN_URL);
|
router.replace(LOGIN_URL);
|
||||||
ElMessage.success("退出登录成功!");
|
ElMessage.success("退出登录成功!");
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ export const useDictStore = defineStore({
|
|||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
|
setDictData(data: Dict[]) {
|
||||||
|
this.dictData = data
|
||||||
|
},
|
||||||
// 获取字典数据数组,如果为空则返回空数组
|
// 获取字典数据数组,如果为空则返回空数组
|
||||||
getDictData(code: string) {
|
getDictData(code: string) {
|
||||||
if (!this.dictData.length) {
|
if (!this.dictData.length) {
|
||||||
|
|||||||
@@ -67,15 +67,13 @@ import { initDynamicRouter } from '@/routers/modules/dynamicRouter'
|
|||||||
import { CircleClose, UserFilled } from '@element-plus/icons-vue'
|
import { CircleClose, UserFilled } from '@element-plus/icons-vue'
|
||||||
import { useAuthStore } from '@/stores/modules/auth'
|
import { useAuthStore } from '@/stores/modules/auth'
|
||||||
import type { ElForm } from 'element-plus'
|
import type { ElForm } from 'element-plus'
|
||||||
import md5 from 'md5'
|
import {useDictStore} from "@/stores/modules/dict";
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const tabsStore = useTabsStore()
|
const tabsStore = useTabsStore()
|
||||||
const keepAliveStore = useKeepAliveStore()
|
const keepAliveStore = useKeepAliveStore()
|
||||||
import { useDictStore } from '@/stores/modules/dict'
|
|
||||||
import { onMounted } from 'vue'
|
|
||||||
|
|
||||||
const dictStore = useDictStore()
|
const dictStore = useDictStore()
|
||||||
|
|
||||||
@@ -103,9 +101,10 @@ const login = (formEl: FormInstance | undefined) => {
|
|||||||
// 1.执行登录接口
|
// 1.执行登录接口
|
||||||
const { data } = await loginApi({
|
const { data } = await loginApi({
|
||||||
...loginForm,
|
...loginForm,
|
||||||
password: md5(loginForm.password),
|
password: loginForm.password,
|
||||||
})
|
})
|
||||||
userStore.setToken(data.accessToken)
|
userStore.setToken(data.accessToken)
|
||||||
|
userStore.setUserInfo(data.userInfo)
|
||||||
const response = await getDictList()
|
const response = await getDictList()
|
||||||
const dictData = response.data as unknown as Dict[]
|
const dictData = response.data as unknown as Dict[]
|
||||||
await dictStore.initDictData(dictData)
|
await dictStore.initDictData(dictData)
|
||||||
|
|||||||
Reference in New Issue
Block a user