修复登录账号没有任何权限时跳转到403页面错误
This commit is contained in:
parent
331997e1e9
commit
61ef48d446
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
|
|
@ -44,7 +44,7 @@ router.beforeEach(async (to, from, next) => {
|
||||||
const routeName = findFirstValidRoute(routes)
|
const routeName = findFirstValidRoute(routes)
|
||||||
// 没有有效路由跳转到403页面
|
// 没有有效路由跳转到403页面
|
||||||
if (!routeName) {
|
if (!routeName) {
|
||||||
await userStore.logout()
|
clearAuthInfo()
|
||||||
next(PageEnum.ERROR_403)
|
next(PageEnum.ERROR_403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ const useUserStore = defineStore({
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
|
resetState() {
|
||||||
|
this.token = ''
|
||||||
|
this.userInfo = {}
|
||||||
|
this.perms = []
|
||||||
|
},
|
||||||
login(playload: any) {
|
login(playload: any) {
|
||||||
const { account, password } = playload
|
const { account, password } = playload
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export function getToken() {
|
||||||
export function clearAuthInfo() {
|
export function clearAuthInfo() {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const tabsStore = useTabsStore()
|
const tabsStore = useTabsStore()
|
||||||
userStore.$reset()
|
userStore.resetState()
|
||||||
tabsStore.$reset()
|
tabsStore.$reset()
|
||||||
cache.remove(TOKEN_KEY)
|
cache.remove(TOKEN_KEY)
|
||||||
resetRouter()
|
resetRouter()
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,9 @@ export class Axios {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.code == AxiosError.ECONNABORTED || err.code == AxiosError.ERR_NETWORK) {
|
if (err.code == AxiosError.ECONNABORTED || err.code == AxiosError.ERR_NETWORK) {
|
||||||
setTimeout(() => {
|
return new Promise((resolve) => setTimeout(resolve, 500)).then(() =>
|
||||||
console.log(err)
|
|
||||||
this.retryRequest(err)
|
this.retryRequest(err)
|
||||||
}, 500)
|
)
|
||||||
}
|
}
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
}
|
}
|
||||||
|
|
@ -103,17 +102,17 @@ export class Axios {
|
||||||
retryRequest(error: AxiosError) {
|
retryRequest(error: AxiosError) {
|
||||||
const config = error.config
|
const config = error.config
|
||||||
const { retryCount, isOpenRetry } = config.requestOptions
|
const { retryCount, isOpenRetry } = config.requestOptions
|
||||||
if (!isOpenRetry && config.method?.toUpperCase() == RequestMethodsEnum.POST) {
|
if (!isOpenRetry || config.method?.toUpperCase() == RequestMethodsEnum.POST) {
|
||||||
return
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
config.retryCount = config.retryCount ?? 0
|
config.retryCount = config.retryCount ?? 0
|
||||||
|
|
||||||
if (config.retryCount >= retryCount) {
|
if (config.retryCount >= retryCount) {
|
||||||
return
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
config.retryCount++
|
config.retryCount++
|
||||||
|
|
||||||
this.axiosInstance.request(config)
|
return this.axiosInstance.request(config)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description get请求
|
* @description get请求
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="error404">
|
<div class="error404">
|
||||||
<error
|
<error code="403" title="您的账号权限不足,请联系管理员添加权限!" :show-btn="false">
|
||||||
code="403"
|
<template #content>
|
||||||
title="您的账号权限不足,请联系管理员添加权限!"
|
<div class="flex justify-center">
|
||||||
:show-btn="false"
|
<img class="w-[150px] h-[150px]" src="@/assets/images/no_perms.png" alt="" />
|
||||||
></error>
|
</div>
|
||||||
|
</template>
|
||||||
|
</error>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="error">
|
<div class="error">
|
||||||
<div>
|
<div>
|
||||||
|
<slot name="content">
|
||||||
<div class="error-code">{{ code }}</div>
|
<div class="error-code">{{ code }}</div>
|
||||||
<div class="lg lighter mt-7 mb-7">{{ title }}</div>
|
</slot>
|
||||||
|
<div class="text-lg text-tx-secondary mt-7 mb-7">{{ title }}</div>
|
||||||
<el-button v-if="showBtn" type="primary" @click="router.go(-1)">
|
<el-button v-if="showBtn" type="primary" @click="router.go(-1)">
|
||||||
{{ second }} 秒后返回上一页
|
{{ second }} 秒后返回上一页
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue