From dcab19a7652e3966af725341d46a463a1a1b22e0 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Thu, 12 Jan 2023 18:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=B7=E6=B1=82=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E5=99=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xim/web/filters/token/TokenFilter.java | 37 +++++++++++++++++ .../AdminSys/src/main/webapp/WEB-INF/web.xml | 14 ++++++- .../web/admin_system/src/router/index.js | 11 ++++- .../src/utils/api/info/account.js | 11 +++-- .../web/admin_system/src/utils/api/request.js | 40 +++++++++++++++++-- .../admin_system/src/views/info/StaffInfo.vue | 23 +++++++++++ 6 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java create mode 100644 企业级管理系统/web/admin_system/src/views/info/StaffInfo.vue diff --git a/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java new file mode 100644 index 0000000..020115e --- /dev/null +++ b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java @@ -0,0 +1,37 @@ +/* + * @Author: Kane + * @Date: 2023-01-12 15:01:22 + * @LastEditors: Kane + * @LastEditTime: 2023-01-12 15:15:59 + * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java + * @Description: 用于检查token的过滤器 + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ +package com.cpic.xim.web.filters.token; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@SuppressWarnings( "unused") +public class TokenFilter implements Filter +{ + @Override + public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain ) + throws ServletException, IOException + { + HttpServletRequest request = (HttpServletRequest) req; + HttpServletResponse response = (HttpServletResponse) resp; + + String URI = request.getRequestURI(); + + chain.doFilter( request, response ); + } +} + diff --git a/企业级管理系统/java/AdminSys/src/main/webapp/WEB-INF/web.xml b/企业级管理系统/java/AdminSys/src/main/webapp/WEB-INF/web.xml index b4a35be..b4a50e9 100644 --- a/企业级管理系统/java/AdminSys/src/main/webapp/WEB-INF/web.xml +++ b/企业级管理系统/java/AdminSys/src/main/webapp/WEB-INF/web.xml @@ -1,4 +1,7 @@ - + Archetype Created Web Application @@ -24,6 +27,15 @@ *.do + + token-filter + com.cpic.xim.web.filters.token.TokenFilter + + + token-filter + *.do + + config_file_location diff --git a/企业级管理系统/web/admin_system/src/router/index.js b/企业级管理系统/web/admin_system/src/router/index.js index 76e543e..70f3d3c 100644 --- a/企业级管理系统/web/admin_system/src/router/index.js +++ b/企业级管理系统/web/admin_system/src/router/index.js @@ -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", diff --git a/企业级管理系统/web/admin_system/src/utils/api/info/account.js b/企业级管理系统/web/admin_system/src/utils/api/info/account.js index 07d34e5..a3d5ddd 100644 --- a/企业级管理系统/web/admin_system/src/utils/api/info/account.js +++ b/企业级管理系统/web/admin_system/src/utils/api/info/account.js @@ -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) diff --git a/企业级管理系统/web/admin_system/src/utils/api/request.js b/企业级管理系统/web/admin_system/src/utils/api/request.js index 29225bd..aabbbdd 100644 --- a/企业级管理系统/web/admin_system/src/utils/api/request.js +++ b/企业级管理系统/web/admin_system/src/utils/api/request.js @@ -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); } ); diff --git a/企业级管理系统/web/admin_system/src/views/info/StaffInfo.vue b/企业级管理系统/web/admin_system/src/views/info/StaffInfo.vue new file mode 100644 index 0000000..879e0f7 --- /dev/null +++ b/企业级管理系统/web/admin_system/src/views/info/StaffInfo.vue @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file