chore: 切换 mock api 服务
This commit is contained in:
12
src/App.vue
12
src/App.vue
@@ -38,18 +38,6 @@ ElNotification({
|
||||
position: "bottom-right",
|
||||
offset: 150
|
||||
})
|
||||
ElNotification({
|
||||
title: "服务挂了",
|
||||
type: "error",
|
||||
message: h(
|
||||
"a",
|
||||
{ style: "color: teal", target: "_blank", href: "https://github.com/un-pany/v3-admin-vite/issues/92" },
|
||||
"近期 API 服务不太稳定,请等我更换服务(可以加交流群第一时间获取进度),如果急需登录可以点击这里自己模拟一下数据"
|
||||
),
|
||||
duration: 0,
|
||||
position: "bottom-right",
|
||||
offset: 300
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -4,6 +4,12 @@ import { ElMessage } from "element-plus"
|
||||
import { get, merge } from "lodash-es"
|
||||
import { getToken } from "./cache/cookies"
|
||||
|
||||
/** 退出登录并强制刷新页面(会重定向到登录页) */
|
||||
function logout() {
|
||||
useUserStoreHook().logout()
|
||||
location.reload()
|
||||
}
|
||||
|
||||
/** 创建请求实例 */
|
||||
function createService() {
|
||||
// 创建一个 axios 实例命名为 service
|
||||
@@ -33,6 +39,9 @@ function createService() {
|
||||
case 0:
|
||||
// 本系统采用 code === 0 来表示没有业务错误
|
||||
return apiData
|
||||
case 401:
|
||||
// Token 过期时
|
||||
return logout()
|
||||
default:
|
||||
// 不是正确的 code
|
||||
ElMessage.error(apiData.message || "Error")
|
||||
@@ -47,9 +56,8 @@ function createService() {
|
||||
error.message = "请求错误"
|
||||
break
|
||||
case 401:
|
||||
// Token 过期时,直接退出登录并强制刷新页面(会重定向到登录页)
|
||||
useUserStoreHook().logout()
|
||||
location.reload()
|
||||
// Token 过期时
|
||||
logout()
|
||||
break
|
||||
case 403:
|
||||
error.message = "拒绝访问"
|
||||
|
||||
Reference in New Issue
Block a user