|
|
@ -3,75 +3,84 @@ import router from "@/router"; |
|
|
import axios from "axios"; |
|
|
import axios from "axios"; |
|
|
// import Promise from 'promise'
|
|
|
// import Promise from 'promise'
|
|
|
import { yztoken } from "@/utlis/istoken"; |
|
|
import { yztoken } from "@/utlis/istoken"; |
|
|
import { Message } from "element-ui"; |
|
|
|
|
|
|
|
|
import { Message, Loading } from "element-ui"; |
|
|
|
|
|
|
|
|
const sysConfig = JSON.parse(window.sessionStorage.getItem('sysConfig')) |
|
|
const sysConfig = JSON.parse(window.sessionStorage.getItem('sysConfig')) |
|
|
|
|
|
|
|
|
const instance = axios.create({ |
|
|
const instance = axios.create({ |
|
|
baseURL: sysConfig.apiurl, |
|
|
|
|
|
//timeout: 500000,
|
|
|
|
|
|
withCredentials: true, // 允许跨域
|
|
|
|
|
|
|
|
|
baseURL: sysConfig.apiurl, |
|
|
|
|
|
//timeout: 500000,
|
|
|
|
|
|
withCredentials: true, // 允许跨域
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
//请求拦截
|
|
|
|
|
|
|
|
|
let loading = null |
|
|
|
|
|
//请求拦截
|
|
|
instance.interceptors.request.use( |
|
|
instance.interceptors.request.use( |
|
|
async function (config) { |
|
|
|
|
|
//console.log('old token:',window.sessionStorage.getItem("token"))
|
|
|
|
|
|
//console.log('old expires_in',window.sessionStorage.getItem("expires_in"))
|
|
|
|
|
|
await yztoken(); |
|
|
|
|
|
|
|
|
async function(config) { |
|
|
|
|
|
loading = Loading.service({ |
|
|
|
|
|
lock: true, |
|
|
|
|
|
text: "正在加载中,请稍后", |
|
|
|
|
|
spinner: "el-icon-loading", |
|
|
|
|
|
background: "rgba(0, 0, 0, 0)", |
|
|
|
|
|
customClass: "boxStyle" |
|
|
|
|
|
}); |
|
|
|
|
|
//console.log('old token:',window.sessionStorage.getItem("token"))
|
|
|
|
|
|
//console.log('old expires_in',window.sessionStorage.getItem("expires_in"))
|
|
|
|
|
|
await yztoken(); |
|
|
|
|
|
|
|
|
let token = window.sessionStorage.getItem("token"); |
|
|
|
|
|
|
|
|
let token = window.sessionStorage.getItem("token"); |
|
|
|
|
|
|
|
|
let tokentype = window.sessionStorage.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) { |
|
|
|
|
|
return Promise.reject(err); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let tokentype = window.sessionStorage.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) { |
|
|
|
|
|
return Promise.reject(err); |
|
|
|
|
|
} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
//响应拦截
|
|
|
//响应拦截
|
|
|
instance.interceptors.response.use( |
|
|
instance.interceptors.response.use( |
|
|
(res) => { |
|
|
|
|
|
// console.log(res);
|
|
|
|
|
|
if (res.data.code < 0) { |
|
|
|
|
|
Message.error({ showClose: true, message: res.data.message }); |
|
|
|
|
|
|
|
|
(res) => { |
|
|
|
|
|
loading.close(); |
|
|
|
|
|
// console.log(res);
|
|
|
|
|
|
if (res.data.code < 0) { |
|
|
|
|
|
Message.error({ showClose: true, message: res.data.message }); |
|
|
|
|
|
} |
|
|
|
|
|
return res.data; |
|
|
|
|
|
}, |
|
|
|
|
|
(err) => { |
|
|
|
|
|
// console.log(err);
|
|
|
|
|
|
// if (response.data.code == -1) {
|
|
|
|
|
|
// router.push({ path: '/login' })
|
|
|
|
|
|
// // this.$router.push({path:'/login'})
|
|
|
|
|
|
// // console.log('状态失效')
|
|
|
|
|
|
// Message.error('状态失效请重新登录')
|
|
|
|
|
|
// console.log('token失效返回登录');
|
|
|
|
|
|
// }
|
|
|
|
|
|
// console.log(err);
|
|
|
|
|
|
loading.close(); |
|
|
|
|
|
return Promise.reject(err); |
|
|
} |
|
|
} |
|
|
return res.data; |
|
|
|
|
|
}, |
|
|
|
|
|
(err) => { |
|
|
|
|
|
// console.log(err);
|
|
|
|
|
|
// if (response.data.code == -1) {
|
|
|
|
|
|
// router.push({ path: '/login' })
|
|
|
|
|
|
// // this.$router.push({path:'/login'})
|
|
|
|
|
|
// // console.log('状态失效')
|
|
|
|
|
|
// 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) {
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
|
export default instance; |