解决两个问题:
1、config.js中写错URL导致axios请求失败; 2、axios为CROS发送两次请求,第一次的method是options,在token过滤器中需要忽略。
This commit is contained in:
parent
72b935c4b3
commit
e676e98a6e
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-29 10:39:41
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-29 10:39:44
|
||||
* @FilePath: \requirement\src\main\java\com\cpic\xim\web\filters\cros\CrosFilter.java
|
||||
* @LastEditTime: 2023-02-04 17:12:05
|
||||
* @FilePath: /后端-需求/src/main/java/com/cpic/xim/web/filters/cros/CrosFilter.java
|
||||
* @Description: 过滤器,用于对CROS访问进行响应。允许任何来源的访问。
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -33,7 +33,7 @@ public class CrosFilter implements Filter
|
||||
response.setHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE" );
|
||||
response.setHeader( "Access-Control-Max-Age", "0" );
|
||||
response.setHeader( "Access-Control-Allow-Headers",
|
||||
"Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token" );
|
||||
"Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token,username" );
|
||||
response.setHeader( "Access-Control-Allow-Credentials", "true" );
|
||||
response.setHeader( "XDomainRequestAllowed", "1" );
|
||||
response.setHeader( "XDomainRequestAllowed", "1" );
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-29 10:50:49
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-29 10:55:27
|
||||
* @FilePath: \requirement\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java
|
||||
* @LastEditTime: 2023-02-04 18:05:18
|
||||
* @FilePath: /后端-需求/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -11,6 +11,7 @@
|
||||
package com.cpic.xim.web.filters.token;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
@ -19,9 +20,11 @@ import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@SuppressWarnings( "unused")
|
||||
@SuppressWarnings( "unused" )
|
||||
public class TokenFilter implements Filter
|
||||
{
|
||||
private static final String FILTE_METHODS = "POST,GET";
|
||||
|
||||
@Override
|
||||
public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )
|
||||
throws ServletException, IOException
|
||||
@ -29,8 +32,14 @@ public class TokenFilter implements Filter
|
||||
HttpServletRequest request = (HttpServletRequest) req;
|
||||
HttpServletResponse response = (HttpServletResponse) resp;
|
||||
|
||||
// 获取请求中的token字符串
|
||||
String token = request.getHeader( "Token" );
|
||||
String method = request.getMethod().toUpperCase();
|
||||
|
||||
// 只处理POST和GET
|
||||
if ( FILTE_METHODS.indexOf( method ) != -1 )
|
||||
{
|
||||
// 检查token
|
||||
String token = request.getHeader( "token" );
|
||||
}
|
||||
|
||||
chain.doFilter( request, response );
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
VUE_APP_API_URL_LOGIN = "http://222.76.244.118:11001/admin-system/account/p13_account_check"
|
||||
VUE_APP_API_URL_UPLOAD_FILE= "http://222.76.244.118:11001/admin-system/file/file-upload.do"
|
||||
VUE_APP_API_URL_REQUIREMENT_STATUS= "http://222.76.244.118:11001/requirement/query_requirement_status.do"
|
||||
VUE_APP_API_URL_REQUIREMENT_STATUS= "http://localhost:8080/requirement/query_requirement_status.do"
|
@ -2,14 +2,14 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-04 11:05:44
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-04 01:02:13
|
||||
* @FilePath: \IT工具综合平台\src\layout\Index.vue
|
||||
* @LastEditTime: 2023-02-04 16:35:20
|
||||
* @FilePath: /IT工具综合平台/src/layout/Index.vue
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
-->
|
||||
<template>
|
||||
<el-container id="layout-container" v-loading="pageVisible" element-loading-text="载入应用数据…">
|
||||
<el-container id="layout-container" v-loading="ui.ageVisible" element-loading-text="载入应用数据…">
|
||||
<el-header id="layout-header">
|
||||
<LayoutHeader />
|
||||
</el-header>
|
||||
@ -28,35 +28,57 @@
|
||||
import LayoutAside from "./components/Aside.vue";
|
||||
import LayoutHeader from "./components/Header.vue";
|
||||
import LayoutMain from "./components/Main.vue";
|
||||
import { useStore } from "vuex";
|
||||
import { onMounted, computed, reactive } from "vue";
|
||||
// import { query_requirement_status } from "@/utils/api/requirement/requirement.js";
|
||||
|
||||
export default {
|
||||
name: "layoutPage",
|
||||
setup()
|
||||
{
|
||||
const store = useStore();
|
||||
|
||||
const ui = reactive(
|
||||
{
|
||||
pageVisible: true,
|
||||
});
|
||||
|
||||
const asideWidth = computed(() =>
|
||||
{
|
||||
const collapse = store.state.app.asideBarCollapse;
|
||||
|
||||
return collapse === true ? "65px" : "180px";
|
||||
});
|
||||
|
||||
onMounted(() =>
|
||||
{
|
||||
|
||||
//加载数据
|
||||
// query_requirement_status()
|
||||
// .then((response) =>
|
||||
// {
|
||||
// // debugger;
|
||||
// const data = response.data;
|
||||
|
||||
// console.log(data);
|
||||
// })
|
||||
// .catch((error) =>
|
||||
// {
|
||||
// // debugger;
|
||||
// console.log(error);
|
||||
// });
|
||||
});
|
||||
|
||||
return {
|
||||
ui,
|
||||
asideWidth,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
LayoutAside,
|
||||
LayoutHeader,
|
||||
LayoutMain,
|
||||
},
|
||||
data()
|
||||
{
|
||||
return {
|
||||
pageVisible: true,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
asideWidth()
|
||||
{
|
||||
const collapse = this.$store.state.app.asideBarCollapse;
|
||||
|
||||
return collapse === true ? "65px" : "180px";
|
||||
},
|
||||
},
|
||||
mounted()
|
||||
{
|
||||
setTimeout(() =>
|
||||
{
|
||||
this.pageVisible = false;
|
||||
}, 3000);
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -2,18 +2,20 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-14 15:12:46
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-11 14:20:04
|
||||
* @FilePath: \admin_system\src\store\index.js
|
||||
* @LastEditTime: 2023-02-04 15:59:09
|
||||
* @FilePath: /IT工具综合平台/src/store/index.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
import { createStore } from 'vuex';
|
||||
import app from "./modules/app";
|
||||
import requirement from "./modules/requirement";
|
||||
|
||||
const store = createStore({
|
||||
modules: {
|
||||
app,
|
||||
requirement,
|
||||
}
|
||||
});
|
||||
|
||||
|
21
code/web/IT工具综合平台/src/store/modules/requirement.js
Normal file
21
code/web/IT工具综合平台/src/store/modules/requirement.js
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-02-04 15:55:16
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-04 16:00:54
|
||||
* @FilePath: /IT工具综合平台/src/store/modules/requirement.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
|
||||
const state = {
|
||||
status: {},
|
||||
status_update_time: new Date(),
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
};
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-23 11:10:23
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2022-12-23 11:11:58
|
||||
* @FilePath: \admin_system\src\utils\api\config.js
|
||||
* @LastEditTime: 2023-02-04 17:08:15
|
||||
* @FilePath: /IT工具综合平台/src/utils/api/config.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -11,4 +11,5 @@
|
||||
|
||||
export const API_URL = {
|
||||
URL_LOGIN: process.env.VUE_APP_API_URL_LOGIN,
|
||||
URL_QUERY_REQUIREMENT_STATUS: process.env.VUE_APP_API_URL_REQUIREMENT_STATUS,
|
||||
};
|
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-22 09:10:20
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-03 22:04:22
|
||||
* @FilePath: \IT工具综合平台\src\utils\api\info\account.js
|
||||
* @LastEditTime: 2023-02-04 15:45:51
|
||||
* @FilePath: /IT工具综合平台/src/utils/api/info/account.js
|
||||
* @Description: 登录登出相关的API。
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -11,7 +11,6 @@
|
||||
import instance from "@/utils/api/request";
|
||||
import { API_URL } from "@/utils/api/config"; //所有API的地址
|
||||
import router from "../../../router/index";
|
||||
import store from "../../../store/index";
|
||||
|
||||
/**
|
||||
* 登录请求函数
|
||||
@ -34,8 +33,6 @@ export function Login(userInfo)
|
||||
*/
|
||||
export function Logout()
|
||||
{
|
||||
console.log(store);
|
||||
|
||||
window.localStorage.removeItem("token");
|
||||
window.localStorage.removeItem("user_info");
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-22 17:18:10
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-12 17:47:39
|
||||
* @FilePath: \admin_system\src\utils\api\request.js
|
||||
* @LastEditTime: 2023-02-04 17:20:01
|
||||
* @FilePath: /IT工具综合平台/src/utils/api/request.js
|
||||
* @Description: 配置axios拦截器
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -16,7 +16,7 @@ import router from "@/router";
|
||||
const service = axios.create(
|
||||
{
|
||||
baseURL: "",
|
||||
timeout: 5000,
|
||||
// timeout: 5000,
|
||||
}
|
||||
);
|
||||
|
||||
@ -27,11 +27,13 @@ const service = axios.create(
|
||||
service.interceptors.request.use(
|
||||
function (config)
|
||||
{
|
||||
console.log(store);
|
||||
|
||||
//axios拦截器请求,在请求的header加上用户名和token
|
||||
if (store.state.app.userInfo)
|
||||
{
|
||||
//如果userInfo存在,则加上用户名和token
|
||||
const username = store.state.app.userInfo.user_info.p13uid;
|
||||
const username = store.state.app.userInfo.staff_info.p13uid;
|
||||
const token = store.state.app.userInfo.token;
|
||||
|
||||
config.headers["token"] = token;
|
||||
@ -48,6 +50,7 @@ service.interceptors.request.use(
|
||||
},
|
||||
function (error)
|
||||
{
|
||||
console.log("请求拦截器失败!");
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
24
code/web/IT工具综合平台/src/utils/api/requirement/requirement.js
Normal file
24
code/web/IT工具综合平台/src/utils/api/requirement/requirement.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @Author: Kane
|
||||
* @Date: 2023-02-04 15:48:00
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-04 17:11:07
|
||||
* @FilePath: /IT工具综合平台/src/utils/api/requirement/requirement.js
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
*/
|
||||
import instance from "@/utils/api/request";
|
||||
import { API_URL } from "@/utils/api/config";
|
||||
|
||||
function query_requirement_status()
|
||||
{
|
||||
return instance.request(
|
||||
{
|
||||
method: "post",
|
||||
url: API_URL.URL_QUERY_REQUIREMENT_STATUS,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export { query_requirement_status };
|
@ -3,8 +3,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2022-12-14 15:23:54
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-03 15:46:55
|
||||
* @FilePath: \IT工具综合平台\src\views\account\Login32.vue
|
||||
* @LastEditTime: 2023-02-04 16:55:12
|
||||
* @FilePath: /IT工具综合平台/src/views/account/Login.vue
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -43,8 +43,8 @@
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" class="el-button-block" @click="login" :disabled="submit_btn_disable"
|
||||
:loading="submit_btn_loading">
|
||||
<el-button type="primary" class="el-button-block" @click="login" :disabled="ui.submit_btn_disable"
|
||||
:loading="ui.submit_btn_loading">
|
||||
{{ ui.current_menu === "login" ? "登录" : "注册" }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
@ -183,6 +183,8 @@ export default {
|
||||
//将获取到的用户信息和token保存到vuex和localStorage
|
||||
const saveUserInfo = (userInfo) =>
|
||||
{
|
||||
console.log("保存用户信息");
|
||||
console.log("保存用户信息", store);
|
||||
//保存到vuex
|
||||
store.commit("app/SET_USERINFO", userInfo);
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-06 15:30:12
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-01 16:07:55
|
||||
* @FilePath: \IT工具综合平台\src\views\overview\Desktop.vue
|
||||
* @LastEditTime: 2023-02-04 16:56:36
|
||||
* @FilePath: /IT工具综合平台/src/views/overview/Desktop.vue
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
@ -60,33 +60,52 @@
|
||||
<el-col :span="10"></el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<el-button type="danger" @click="test_1">测试</el-button>
|
||||
<el-button type="danger" @click="testRequest">测试</el-button>
|
||||
</template>
|
||||
|
||||
<script >
|
||||
import { reactive, onBeforeMount } from "vue";
|
||||
import { query_requirement_status } from "@/utils/api/requirement/requirement.js";
|
||||
|
||||
export default {
|
||||
name: "DeskTop",
|
||||
data()
|
||||
setup()
|
||||
{
|
||||
let start_date = reactive(new Date());
|
||||
let end_date = reactive(new Date());
|
||||
|
||||
onBeforeMount(() =>
|
||||
{
|
||||
end_date = new Date(Date.now());
|
||||
start_date = new Date();
|
||||
|
||||
start_date.setMonth(end_date.getMonth() - 1);
|
||||
});
|
||||
|
||||
const testRequest = () =>
|
||||
{
|
||||
//加载数据;
|
||||
query_requirement_status()
|
||||
.then((response) =>
|
||||
{
|
||||
// debugger;
|
||||
const data = response.data;
|
||||
|
||||
console.log(data);
|
||||
})
|
||||
.catch((error) =>
|
||||
{
|
||||
// debugger;
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
start_date: null,
|
||||
end_date: null,
|
||||
start_date,
|
||||
end_date,
|
||||
testRequest,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
test_1()
|
||||
{
|
||||
this.deleteConfirm();
|
||||
},
|
||||
},
|
||||
created()
|
||||
{
|
||||
this.end_date = new Date(Date.now());
|
||||
this.start_date = new Date();
|
||||
|
||||
this.start_date.setMonth(this.end_date.getMonth() - 1);
|
||||
//this.start_date.setMonth();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -2,18 +2,8 @@
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-25 23:16:29
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-02-03 11:07:02
|
||||
* @FilePath: \IT工具综合平台\src\views\requirement\RequirementEditing.vue
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
-->
|
||||
<!--
|
||||
* @Author: Kane
|
||||
* @Date: 2023-01-25 23:13:47
|
||||
* @LastEditors: Kane
|
||||
* @LastEditTime: 2023-01-25 23:15:21
|
||||
* @FilePath: \admin_system\src\views\requirement\RequirementManager.vue
|
||||
* @LastEditTime: 2023-02-04 15:46:29
|
||||
* @FilePath: /IT工具综合平台/src/views/requirement/RequirementEditing.vue
|
||||
* @Description:
|
||||
*
|
||||
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||
|
Loading…
x
Reference in New Issue
Block a user