mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2025-12-02 16:59:01 +08:00
!1 merge 2.x into 2.x
refactor: 重构认证过期处理逻辑,消除代码重复 Created-by: u013737132 Commit-by: Ray.Hao Merged-by: zclzone Description: refactor: 重构认证过期处理逻辑,消除代码重复 See merge request: zclzone/vue-naive-admin!1
This commit is contained in:
commit
5663f58b6e
@ -10,45 +10,34 @@
|
|||||||
import { useAuthStore } from '@/store'
|
import { useAuthStore } from '@/store'
|
||||||
|
|
||||||
let isConfirming = false
|
let isConfirming = false
|
||||||
|
|
||||||
|
function handleAuthExpired(content, needTip) {
|
||||||
|
if (isConfirming || !needTip)
|
||||||
|
return
|
||||||
|
isConfirming = true
|
||||||
|
$dialog.confirm({
|
||||||
|
title: '提示',
|
||||||
|
type: 'info',
|
||||||
|
content,
|
||||||
|
confirm() {
|
||||||
|
useAuthStore().logout()
|
||||||
|
window.$message?.success('已退出登录')
|
||||||
|
isConfirming = false
|
||||||
|
},
|
||||||
|
cancel() {
|
||||||
|
isConfirming = false
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveResError(code, message, needTip = true) {
|
export function resolveResError(code, message, needTip = true) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 401:
|
case 401:
|
||||||
if (isConfirming || !needTip)
|
return handleAuthExpired('登录已过期,是否重新登录?', needTip)
|
||||||
return
|
|
||||||
isConfirming = true
|
|
||||||
$dialog.confirm({
|
|
||||||
title: '提示',
|
|
||||||
type: 'info',
|
|
||||||
content: '登录已过期,是否重新登录?',
|
|
||||||
confirm() {
|
|
||||||
useAuthStore().logout()
|
|
||||||
window.$message?.success('已退出登录')
|
|
||||||
isConfirming = false
|
|
||||||
},
|
|
||||||
cancel() {
|
|
||||||
isConfirming = false
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
case 11007:
|
case 11007:
|
||||||
case 11008:
|
case 11008:
|
||||||
if (isConfirming || !needTip)
|
return handleAuthExpired(`${message},是否重新登录?`, needTip)
|
||||||
return
|
|
||||||
isConfirming = true
|
|
||||||
$dialog.confirm({
|
|
||||||
title: '提示',
|
|
||||||
type: 'info',
|
|
||||||
content: `${message},是否重新登录?`,
|
|
||||||
confirm() {
|
|
||||||
useAuthStore().logout()
|
|
||||||
window.$message?.success('已退出登录')
|
|
||||||
isConfirming = false
|
|
||||||
},
|
|
||||||
cancel() {
|
|
||||||
isConfirming = false
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return false
|
|
||||||
case 403:
|
case 403:
|
||||||
message = '请求被拒绝'
|
message = '请求被拒绝'
|
||||||
break
|
break
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user