mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-10 11:26:45 +08:00
88 lines
3.5 KiB
JavaScript
88 lines
3.5 KiB
JavaScript
/*
|
|
* @Author: lixg lixg@dongwu-inc.com
|
|
* @Date: 2022-11-21 14:32:52
|
|
* @LastEditors: lixg lixg@dongwu-inc.com
|
|
* @LastEditTime: 2023-01-04 13:49:54
|
|
* @FilePath: /fe-manage/src/api/config.js
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
import { message } from "ant-design-vue";
|
|
import axios from "axios";
|
|
import router from "@/router";
|
|
import { REFRESH_TOKEN_API } from "@/api/ThirdApi";
|
|
import { boeRequest } from "@/api/request";
|
|
// import { getCookie } from '../api/method'
|
|
// const Qs = require("qs");
|
|
|
|
// axios.defaults.headers.post["Content-Type"] =
|
|
// "application/x-www-form-urlencoded";
|
|
axios.defaults.withCredentials = true;
|
|
const http = axios.create({
|
|
// baseURL: '/growth',
|
|
baseURL: process.env.VUE_APP_BASE_API_GROWTH,
|
|
timeout: 1000 * 15,
|
|
// headers: { "Content-Type": "multipart/form-data" },
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
|
|
http.interceptors.request.use(
|
|
(config) => {
|
|
// console.log("config", config);
|
|
// const token = localStorage.getItem("token");
|
|
// // const token = getCookie('token')
|
|
// // console.log('token', token)
|
|
// if (token) {
|
|
// config.headers.token = token; //测试1111
|
|
// } else {
|
|
// console.log("当前请求页面无token,请执行操作!!!");
|
|
|
|
// // 此处测试默认配置token
|
|
// config.headers.token =
|
|
// "eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NzAxNTMxMDMsImV4cCI6MTY3MDE2MDMwMywiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.c937b2d3a59cbab2136fdde55fd38f06bdff041212aab0fa6741bc4be41e28a7";
|
|
// // }
|
|
return config;
|
|
},
|
|
(err) => {
|
|
console.log("登陆前拦截", err);
|
|
return Promise.reject(err);
|
|
}
|
|
);
|
|
|
|
http.interceptors.response.use(
|
|
(response) => {
|
|
// console.log('response', response)
|
|
const {
|
|
data: { code, msg, show },
|
|
} = response;
|
|
if (code === 0 || code === 200) {
|
|
return response;
|
|
} else if (code === 1000) {
|
|
window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)
|
|
// TODO token过期后退出登录 清空当前用户标记 - 为了刷新页面使用
|
|
localStorage.removeItem('refreshPage')
|
|
return Promise.reject(response);
|
|
} else if (code === 1001) {
|
|
window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)
|
|
return Promise.reject(response);
|
|
} else {
|
|
message.error(msg)
|
|
}
|
|
// show ? message.error(msg):message.error('系统接口数据异常,请联系管理员');
|
|
console.log("api %o", msg);
|
|
return Promise.reject(response);
|
|
},
|
|
function (error) {
|
|
if (error.message == "timeout of 1ms exceeded") {
|
|
message.destroy();
|
|
message.error("请求超时");
|
|
}
|
|
console.log("api error %o", error);
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
export default http;
|
|
export function setHttpTimeout(newTimeout) {
|
|
http.defaults.timeout = newTimeout;
|
|
}
|