diff --git a/src/api/common.ts b/src/api/common.ts index 26ee593..b7a7172 100644 --- a/src/api/common.ts +++ b/src/api/common.ts @@ -36,7 +36,7 @@ export type TokenDTO = { }; export type CurrentLoginUserDTO = { - userInfo: any; + user: any; roleKey: string; permissions: Set; }; diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts index c07c52c..068d793 100644 --- a/src/utils/http/index.ts +++ b/src/utils/http/index.ts @@ -12,6 +12,7 @@ import { import { stringify } from "qs"; import NProgress from "../progress"; import { getToken, formatToken } from "@/utils/auth"; +import { message } from "../message"; const { VITE_APP_BASE_API } = import.meta.env; // 相关配置请参考:www.axios-js.com/zh-cn/docs/#axios-request-config-1 @@ -100,6 +101,9 @@ class PureHttp { const instance = PureHttp.axiosInstance; instance.interceptors.response.use( (response: PureHttpResponse) => { + if (response.data.code !== 0) { + message(response.data.msg, { type: "error" }); + } const $config = response.config; // 关闭进度条动画 NProgress.done(); @@ -147,7 +151,15 @@ class PureHttp { resolve(response); }) .catch(error => { - reject(error); + if (error.response.status >= 500) { + message("网络异常", { type: "error" }); + } + + if (error.response.status >= 400 && error.response.status < 500) { + message("请求接口不存在", { type: "error" }); + } + + reject(error.response.statusText); }); }); } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index e5986c1..50c5856 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -81,18 +81,16 @@ const onLogin = async (formEl: FormInstance | undefined) => { password: rsaEncrypt(ruleForm.password), captchaCode: ruleForm.captchaCode, captchaCodeKey: ruleForm.captchaCodeKey - }).then(res => { - if (res.code === 0) { - // 登录成功后 将token存储到sessionStorage中 - setTokenFromBackend(res.data); - // 获取后端路由 - initRouter().then(() => { - router.push(getTopMenu(true).path); - message("登录成功", { type: "success" }); - }); - if (isRememberMe.value) { - savePassword(ruleForm.password); - } + }).then(({ data }) => { + // 登录成功后 将token存储到sessionStorage中 + setTokenFromBackend(data); + // 获取后端路由 + initRouter().then(() => { + router.push(getTopMenu(true).path); + message("登录成功", { type: "success" }); + }); + if (isRememberMe.value) { + savePassword(ruleForm.password); } }); } else {