You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
76 lines
2.0 KiB
//vxvdvdsvsdvvds3
|
|
import router from "@/router";
|
|
import axios from "axios";
|
|
// import Promise from 'promise'
|
|
import { yztoken } from "@/utlis/istoken";
|
|
import mm from "@/utlis/mm";
|
|
import { Message } from "element-ui";
|
|
|
|
const instance = axios.create({
|
|
baseURL: mm.apiurl,
|
|
timeout: 5000,
|
|
});
|
|
|
|
//请求拦截
|
|
instance.interceptors.request.use(
|
|
async function (config) {
|
|
// console.log('old token:',localStorage.getItem("token"))
|
|
console.log('old expires_in',localStorage.getItem("expires_in"))
|
|
await yztoken();
|
|
|
|
let token = localStorage.getItem("token");
|
|
|
|
let tokentype = localStorage.getItem("tokentype");
|
|
config.headers["Access-Control-Allow-Origin"] = "*";
|
|
// config.headers.ContentType = 'application/x-www-form-urlencoded'
|
|
config.headers.Authorization = `${tokentype} ${token}`;
|
|
return config;
|
|
},
|
|
function (err) {
|
|
console.log("666");
|
|
return Promise.reject(err);
|
|
}
|
|
);
|
|
|
|
//响应拦截
|
|
instance.interceptors.response.use(
|
|
(res) => {
|
|
console.log(res);
|
|
if (res.data.Code == -1) {
|
|
Message.error(res.data.Message);
|
|
}
|
|
return res.data;
|
|
},
|
|
(err) => {
|
|
// console.log(err);
|
|
// if (response.data.code == -1) {
|
|
// router.push({ path: '/login' })
|
|
// // this.$router.push({path:'/login'})
|
|
// // this.$message.success('状态失效')
|
|
// Message.error('状态失效请重新登录')
|
|
// console.log('token失效返回登录');
|
|
// }
|
|
// console.log(err);
|
|
return Promise.reject(err);
|
|
}
|
|
// function (response) {
|
|
// console.log(response,10010)
|
|
// const {data} = response
|
|
// if (data.status == 401) {
|
|
|
|
// window.location.href = '#/login'
|
|
// this.$message.error('状态失效');
|
|
// }
|
|
// return data
|
|
// },
|
|
// function (err) {
|
|
// if (err.response.status === 401) {
|
|
// window.location.href = '#/login'
|
|
// this.$router.push({ path: '/login' })
|
|
// this.$message.error('登录失效请重新登录');
|
|
// }
|
|
// return err
|
|
// }
|
|
);
|
|
|
|
export default instance;
|