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