Files
fe-manage/src/api/config.js

64 lines
1.9 KiB
JavaScript

/*
* @Author: lixg lixg@dongwu-inc.com
* @Date: 2022-11-21 14:32:52
* @LastEditors: lixg lixg@dongwu-inc.com
* @LastEditTime: 2022-11-23 09:59:26
* @FilePath: /fe-manage/src/api/config.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import axios from "axios";
// const Qs = require("qs");
// axios.defaults.headers.post["Content-Type"] =
// "application/x-www-form-urlencoded";
axios.defaults.withCredentials = true;
const http = axios.create({
baseURL: "/manageApi",
timeout: 1000 * 5,
// headers: { "Content-Type": "multipart/form-data" },
headers: { "Content-Type": "application/json" },
});
http.interceptors.request.use(
(config) => {
const token = localStorage.getItem("token");
if (token) {
// config.headers.token = token;
config.headers.token = token; //测试1111
} else {
console.log("当前请求页面无token,请执行操作!!!");
// 此处测试默认配置token
config.headers.token = "123456";
// config.headers.token = "eyJ0eXBlIjoidG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC91LmJvZS5jb20iLCJpYXQiOjE2NjkyODg3MzIsImV4cCI6MTY2OTI5NTkzMiwiR2l2ZW5OYW1lIjoiYm9ldSIsInVzZXJJZCI6IjZCMDQ5RkFGLUMzMTQtN0NDRi0wRDI4LTBEMjNGNEM0MjUzMSIsInVJZCI6Ijk2NTM0MjAyNzQ5NzYwNzE2OCIsInBlcm1pc3Npb24iOiIifQ==.af724ca2f4c530868cf923daa2e1a4a3733ee97430b830039ace513d628dfb42";
}
return config;
},
(err) => {
console.log("登陆前拦截", err);
return Promise.reject(err);
}
);
http.interceptors.response.use(
(response) => {
const {
data: { code, msg },
} = response;
if (code === 0 || code === 200) {
return response;
} else {
console.log("api %o", msg);
}
return response;
},
function (error) {
console.log("api error %o", error);
return Promise.reject(error);
}
);
export default http;