|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
//import Vue from 'vue'
|
|
|
|
|
import vm from "../main";
|
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
|
|
axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8";
|
|
|
|
|
const request = axios.create({
|
|
|
|
|
//baseURL: 'http://172.18.113.50:8080/zhapi',
|
|
|
|
|
//baseURL: 'http://172.18.113.13:8080/zhapi', // 孙强
|
|
|
|
@ -10,84 +10,85 @@ const request = axios.create({
|
|
|
|
|
//baseURL: 'http://192.168.0.188:8888/zhapi',
|
|
|
|
|
//baseURL: 'http://121.41.91.94:12002/zhapi',
|
|
|
|
|
//baseURL: `http://${window.location.host}/zhapi`,
|
|
|
|
|
baseURL: 'http://1.94.45.26:10006/zhapi',
|
|
|
|
|
baseURL: "http://1.94.45.26:10006/zhapi",
|
|
|
|
|
timeout: 50000,
|
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
|
})
|
|
|
|
|
headers: { "content-type": "application/json" },
|
|
|
|
|
});
|
|
|
|
|
//const vm = Vue.prototype
|
|
|
|
|
// request拦截器
|
|
|
|
|
request.interceptors.request.use(config => {
|
|
|
|
|
request.interceptors.request.use(
|
|
|
|
|
(config) => {
|
|
|
|
|
// 是否需要设置 token
|
|
|
|
|
const isToken = (config.headers || {}).isToken === false;
|
|
|
|
|
console.log("isToken:", isToken);
|
|
|
|
|
// 是否需要防止数据重复提交
|
|
|
|
|
|
|
|
|
|
// 是否需要设置 token
|
|
|
|
|
const isToken = (config.headers || {}).isToken === false
|
|
|
|
|
// 是否需要防止数据重复提交
|
|
|
|
|
if (getToken() && !isToken) {
|
|
|
|
|
config.headers["Authorization"] = "Bearer " + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
|
|
}
|
|
|
|
|
//防止重复提交
|
|
|
|
|
|
|
|
|
|
if (getToken() && !isToken) {
|
|
|
|
|
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
|
|
return config;
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
console.log(error);
|
|
|
|
|
Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
//防止重复提交
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return config
|
|
|
|
|
}, error => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
Promise.reject(error)
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// response 拦截器
|
|
|
|
|
// 可以在接口响应后统一处理结果
|
|
|
|
|
request.interceptors.response.use(
|
|
|
|
|
response => {
|
|
|
|
|
(response) => {
|
|
|
|
|
if (response.data) {
|
|
|
|
|
switch (response.data.code) {
|
|
|
|
|
case 200:
|
|
|
|
|
// 如果是返回的文件
|
|
|
|
|
if (response.config.responseType === 'blob') {
|
|
|
|
|
return response.data
|
|
|
|
|
if (response.config.responseType === "blob") {
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
// 兼容服务端返回的字符串数据
|
|
|
|
|
if (typeof response.data === 'string') {
|
|
|
|
|
response.data = response.data ? JSON.parse(response.data) : response.data
|
|
|
|
|
if (typeof response.data === "string") {
|
|
|
|
|
response.data = response.data
|
|
|
|
|
? JSON.parse(response.data)
|
|
|
|
|
: response.data;
|
|
|
|
|
}
|
|
|
|
|
return response.data
|
|
|
|
|
return response.data;
|
|
|
|
|
|
|
|
|
|
case 401:
|
|
|
|
|
if (vm.$route.name !== 'login') {
|
|
|
|
|
if (vm.$route.name !== "login") {
|
|
|
|
|
vm.$message.warning({
|
|
|
|
|
content: '身份认证信息已失效,请重新登录。',
|
|
|
|
|
content: "身份认证信息已失效,请重新登录。",
|
|
|
|
|
duration: 2,
|
|
|
|
|
onClose: () => {
|
|
|
|
|
vm.$router.push({ name: 'login' })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
vm.$router.push({ name: "login" });
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return Promise.reject()
|
|
|
|
|
return Promise.reject();
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
break;
|
|
|
|
|
case 403:
|
|
|
|
|
vm.$message.warning({
|
|
|
|
|
content: response.data.msg,
|
|
|
|
|
duration: 3
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
duration: 3,
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case 500:
|
|
|
|
|
// 如果是返回的文件
|
|
|
|
|
vm.$message.warning({
|
|
|
|
|
content: response.data.msg,
|
|
|
|
|
duration: 3
|
|
|
|
|
})
|
|
|
|
|
return response.data
|
|
|
|
|
|
|
|
|
|
duration: 3,
|
|
|
|
|
});
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
console.log('err' + error) // for debug
|
|
|
|
|
(error) => {
|
|
|
|
|
console.log("err" + error); // for debug
|
|
|
|
|
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export default request
|
|
|
|
|
export default request;
|
|
|
|
|