提交 43f36d64 编写于 作者: P piexlmax

修复了token错误无法退出的bug

修复了字段查询为空的bug
上级 9b4c3581
......@@ -7,9 +7,8 @@ let asyncRouterFlag = 0
const whiteList = ['Login', 'Init']
const getRouter = async() => {
const getRouter = async(userStore) => {
const routerStore = useRouterStore()
const userStore = useUserStore()
await routerStore.SetAsyncRouter()
await userStore.GetUserInfo()
const asyncRouters = routerStore.asyncRouters
......@@ -45,7 +44,7 @@ router.beforeEach(async(to, from, next) => {
if (token) {
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
asyncRouterFlag++
await getRouter()
await getRouter(userStore)
}
next({ name: userStore.userInfo.authority.defaultRouter })
} else {
......@@ -57,7 +56,7 @@ router.beforeEach(async(to, from, next) => {
// 添加flag防止多次获取动态路由和栈溢出
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
asyncRouterFlag++
await getRouter()
await getRouter(userStore)
next({ ...to, replace: true })
} else {
if (to.matched.length) {
......
......@@ -6,8 +6,8 @@ import { ref } from 'vue'
export const useDictionaryStore = defineStore('dictionary', () => {
const dictionaryMap = ref({})
const setDictionaryMap = (dictionaryMap) => {
dictionaryMap.value = { ...dictionaryMap.value, ...dictionaryMap }
const setDictionaryMap = (dictionaryRes) => {
dictionaryMap.value = { ...dictionaryMap.value, ...dictionaryRes }
}
const getDictionary = async(type) => {
......@@ -16,7 +16,7 @@ export const useDictionaryStore = defineStore('dictionary', () => {
} else {
const res = await findSysDictionary({ type })
if (res.code === 0) {
const dictionaryMap = {}
const dictionaryRes = {}
const dict = []
res.data.resysDictionary.sysDictionaryDetails && res.data.resysDictionary.sysDictionaryDetails.forEach(item => {
dict.push({
......@@ -24,8 +24,8 @@ export const useDictionaryStore = defineStore('dictionary', () => {
value: item.value
})
})
dictionaryMap[res.data.resysDictionary.type] = dict
setDictionaryMap(dictionaryMap)
dictionaryRes[res.data.resysDictionary.type] = dict
setDictionaryMap(dictionaryRes)
return dictionaryMap.value[type]
}
}
......
......@@ -2,6 +2,7 @@ import axios from 'axios' // 引入axios
import { ElMessage, ElMessageBox } from 'element-plus'
import { useUserStore } from '@/pinia/modules/user'
import { emitter } from '@/utils/bus.js'
import router from '@/router/index'
const service = axios.create({
baseURL: import.meta.env.VITE_BASE_API,
......@@ -57,9 +58,9 @@ service.interceptors.request.use(
// http response 拦截器
service.interceptors.response.use(
response => {
const userStore = useUserStore()
closeLoading()
if (response.headers['new-token']) {
const userStore = useUserStore()
userStore.setToken(response.headers['new-token'])
}
if (response.data.code === 0 || response.headers.success === 'true') {
......@@ -74,8 +75,9 @@ service.interceptors.response.use(
type: 'error'
})
if (response.data.data && response.data.data.reload) {
const userStore = useUserStore()
userStore.LoginOut()
userStore.token = ''
localStorage.clear()
router.push({ name: 'Login', replace: true })
}
return response.data.msg ? response.data : response
}
......@@ -95,7 +97,9 @@ service.interceptors.response.use(
})
.then(() => {
const userStore = useUserStore()
userStore.LoginOut()
userStore.token = ''
localStorage.clear()
router.push({ name: 'Login', replace: true })
})
break
case 404:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册