调整请求拦截器。

This commit is contained in:
2023-01-12 18:16:45 +08:00
parent d995251d7b
commit dcab19a765
6 changed files with 127 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-12-14 15:12:46
* @LastEditors: Kane
* @LastEditTime: 2023-01-11 10:28:24
* @LastEditTime: 2023-01-12 14:52:09
* @FilePath: \admin_system\src\router\index.js
* @Description: 定义应用路由配置
*
@@ -62,6 +62,15 @@ const routes = [
icon: "edit",
},
children: [
{
path: "/staffInfo",
name: "StaffInfo",
meta: {
title: "人员信息",
icon: "edit",
},
component: () => import("../views/info/StaffInfo.vue"),
},
{
path: "/newsIndex",
name: "NewsIndex",

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-12-22 09:10:20
* @LastEditors: Kane
* @LastEditTime: 2023-01-11 17:02:15
* @LastEditTime: 2023-01-12 17:47:36
* @FilePath: \admin_system\src\utils\api\info\account.js
* @Description:
*
@@ -13,11 +13,13 @@ import { API_URL } from "@/utils/api/config"; //所有API的地址
import router from "../../../router/index";
import store from "../../../store/index";
/**
* 登录请求函数
* @param {*} userInfo
* @returns 返回promise对象
*/
export function Login(userInfo)
{
//debugger;
console.log(API_URL.URL_LOGIN);
return instance.request(
{
method: "post",
@@ -27,6 +29,7 @@ export function Login(userInfo)
);
}
export function Logout()
{
// if (this.$store && this.$store.state.app)

View File

@@ -2,14 +2,16 @@
* @Author: Kane
* @Date: 2022-12-22 17:18:10
* @LastEditors: Kane
* @LastEditTime: 2023-01-11 14:58:44
* @LastEditTime: 2023-01-12 17:47:39
* @FilePath: \admin_system\src\utils\api\request.js
* @Description:
* @Description: 配置axios拦截器
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
import axios from "axios";
import store from "../../store/index";
import { ElMessageBox } from "element-plus";
import router from "@/router";
const service = axios.create(
{
@@ -18,7 +20,10 @@ const service = axios.create(
}
);
//加上请求拦截器
/**
* 加上请求拦截器
*/
service.interceptors.request.use(
function (config)
{
@@ -47,13 +52,42 @@ service.interceptors.request.use(
}
);
//响应拦截器
service.interceptors.response.use(
function (response)
{
//200
if (response.status === 200)
{
console.log("响应拦截器,响应代码", response.status);
}
//401用户token失效跳转到
if (response.state === 401)
{
ElMessageBox.confirm(
"用户登录超时,请重新登录",
"警告",
{
confirmButtonText: "是",
cancelButtonText: "否",
type: "warning",
},
).then(() =>
{
router.replace("/login");
}).catch(() =>
{
router.replace("/login");
});
}
return response;
},
function (error)
{
console.log("响应拦截器,异常信息:", error);
return Promise.reject(error);
}
);

View File

@@ -0,0 +1,23 @@
<!--
* @Author: Kane
* @Date: 2023-01-12 14:43:46
* @LastEditors: Kane
* @LastEditTime: 2023-01-12 14:43:48
* @FilePath: \admin_system\src\views\info\StaffInfo.vue
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<template>
<div>员工信息查询</div>
</template>
<script>
export default {
name: "staff-info",
};
</script>
<style scoped>
</style>