mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2026-01-22 15:40:21 +08:00
init
This commit is contained in:
64
src/utils/http/helpers.js
Normal file
64
src/utils/http/helpers.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/**********************************
|
||||
* @FilePath: helpers.js
|
||||
* @Author: Ronnie Zhang
|
||||
* @LastEditor: Ronnie Zhang
|
||||
* @LastEditTime: 2023/12/04 22:46:22
|
||||
* @Email: zclzone@outlook.com
|
||||
* Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
|
||||
**********************************/
|
||||
|
||||
import { useAuthStore } from '@/store'
|
||||
|
||||
let isConfirming = false
|
||||
export function resolveResError(code, message) {
|
||||
switch (code) {
|
||||
case 401:
|
||||
if (isConfirming) 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 11008:
|
||||
if (isConfirming) 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:
|
||||
message = '请求被拒绝'
|
||||
break
|
||||
case 404:
|
||||
message = '请求资源或接口不存在'
|
||||
break
|
||||
case 500:
|
||||
message = '服务器发生异常'
|
||||
break
|
||||
default:
|
||||
message = message ?? `【${code}】: 未知异常!`
|
||||
break
|
||||
}
|
||||
return message
|
||||
}
|
||||
Reference in New Issue
Block a user