Skip to content

Commit 43f36d6

Browse files
author
piexlmax
committed
修复了token错误无法退出的bug
修复了字段查询为空的bug
1 parent 9b4c358 commit 43f36d6

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

web/src/permission.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ let asyncRouterFlag = 0
77

88
const whiteList = ['Login', 'Init']
99

10-
const getRouter = async() => {
10+
const getRouter = async(userStore) => {
1111
const routerStore = useRouterStore()
12-
const userStore = useUserStore()
1312
await routerStore.SetAsyncRouter()
1413
await userStore.GetUserInfo()
1514
const asyncRouters = routerStore.asyncRouters
@@ -45,7 +44,7 @@ router.beforeEach(async(to, from, next) => {
4544
if (token) {
4645
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
4746
asyncRouterFlag++
48-
await getRouter()
47+
await getRouter(userStore)
4948
}
5049
next({ name: userStore.userInfo.authority.defaultRouter })
5150
} else {
@@ -57,7 +56,7 @@ router.beforeEach(async(to, from, next) => {
5756
// 添加flag防止多次获取动态路由和栈溢出
5857
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
5958
asyncRouterFlag++
60-
await getRouter()
59+
await getRouter(userStore)
6160
next({ ...to, replace: true })
6261
} else {
6362
if (to.matched.length) {

web/src/pinia/modules/dictionary.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { ref } from 'vue'
66
export const useDictionaryStore = defineStore('dictionary', () => {
77
const dictionaryMap = ref({})
88

9-
const setDictionaryMap = (dictionaryMap) => {
10-
dictionaryMap.value = { ...dictionaryMap.value, ...dictionaryMap }
9+
const setDictionaryMap = (dictionaryRes) => {
10+
dictionaryMap.value = { ...dictionaryMap.value, ...dictionaryRes }
1111
}
1212

1313
const getDictionary = async(type) => {
@@ -16,16 +16,16 @@ export const useDictionaryStore = defineStore('dictionary', () => {
1616
} else {
1717
const res = await findSysDictionary({ type })
1818
if (res.code === 0) {
19-
const dictionaryMap = {}
19+
const dictionaryRes = {}
2020
const dict = []
2121
res.data.resysDictionary.sysDictionaryDetails && res.data.resysDictionary.sysDictionaryDetails.forEach(item => {
2222
dict.push({
2323
label: item.label,
2424
value: item.value
2525
})
2626
})
27-
dictionaryMap[res.data.resysDictionary.type] = dict
28-
setDictionaryMap(dictionaryMap)
27+
dictionaryRes[res.data.resysDictionary.type] = dict
28+
setDictionaryMap(dictionaryRes)
2929
return dictionaryMap.value[type]
3030
}
3131
}

web/src/utils/request.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from 'axios' // 引入axios
22
import { ElMessage, ElMessageBox } from 'element-plus'
33
import { useUserStore } from '@/pinia/modules/user'
44
import { emitter } from '@/utils/bus.js'
5+
import router from '@/router/index'
56

67
const service = axios.create({
78
baseURL: import.meta.env.VITE_BASE_API,
@@ -57,9 +58,9 @@ service.interceptors.request.use(
5758
// http response 拦截器
5859
service.interceptors.response.use(
5960
response => {
61+
const userStore = useUserStore()
6062
closeLoading()
6163
if (response.headers['new-token']) {
62-
const userStore = useUserStore()
6364
userStore.setToken(response.headers['new-token'])
6465
}
6566
if (response.data.code === 0 || response.headers.success === 'true') {
@@ -74,8 +75,9 @@ service.interceptors.response.use(
7475
type: 'error'
7576
})
7677
if (response.data.data && response.data.data.reload) {
77-
const userStore = useUserStore()
78-
userStore.LoginOut()
78+
userStore.token = ''
79+
localStorage.clear()
80+
router.push({ name: 'Login', replace: true })
7981
}
8082
return response.data.msg ? response.data : response
8183
}
@@ -95,7 +97,9 @@ service.interceptors.response.use(
9597
})
9698
.then(() => {
9799
const userStore = useUserStore()
98-
userStore.LoginOut()
100+
userStore.token = ''
101+
localStorage.clear()
102+
router.push({ name: 'Login', replace: true })
99103
})
100104
break
101105
case 404:

0 commit comments

Comments
 (0)