|
@@ -1,14 +1,15 @@
|
|
import Vue from "vue";
|
|
import Vue from "vue";
|
|
|
|
+import { Notice } from "iview";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
import { loadProgressBar } from "./axiosProgress";
|
|
import { loadProgressBar } from "./axiosProgress";
|
|
import cachingGet from "./axiosCache";
|
|
import cachingGet from "./axiosCache";
|
|
-import router from "../router";
|
|
|
|
import { getKeyToken, removeKeyToken } from "../auth/auth";
|
|
import { getKeyToken, removeKeyToken } from "../auth/auth";
|
|
|
|
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
// Full config: https://github.com/axios/axios#request-config
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
+axios.defaults.headers.post["Access-Control-Allow-Origin"] = "*";
|
|
|
|
|
|
let config = {
|
|
let config = {
|
|
// baseURL: process.env.baseURL || process.env.apiUrl || ""
|
|
// baseURL: process.env.baseURL || process.env.apiUrl || ""
|
|
@@ -29,8 +30,8 @@ const _axiosCommonService = axios.create(config);
|
|
|
|
|
|
_axiosCommonService.interceptors.request.use(
|
|
_axiosCommonService.interceptors.request.use(
|
|
function(config) {
|
|
function(config) {
|
|
- if (config.url.includes("/login") === false) {
|
|
|
|
- let [wk_token, wk_key] = getKeyToken();
|
|
|
|
|
|
+ if (config.url.endsWith("Login") === false) {
|
|
|
|
+ const [wk_token, wk_key] = getKeyToken();
|
|
if (wk_token) {
|
|
if (wk_token) {
|
|
config.headers.common["token"] = wk_token;
|
|
config.headers.common["token"] = wk_token;
|
|
config.headers.common["key"] = wk_key;
|
|
config.headers.common["key"] = wk_key;
|
|
@@ -40,10 +41,8 @@ _axiosCommonService.interceptors.request.use(
|
|
},
|
|
},
|
|
function(error) {
|
|
function(error) {
|
|
// Do something with request error
|
|
// Do something with request error
|
|
- Vue.prototype.$notify({
|
|
|
|
- showClose: true,
|
|
|
|
- message: error,
|
|
|
|
- type: "error"
|
|
|
|
|
|
+ Notice.error({
|
|
|
|
+ title: error
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
@@ -58,10 +57,8 @@ _axiosCommonService.interceptors.response.use(
|
|
if (!error.response) {
|
|
if (!error.response) {
|
|
// "Network Error" 网络不通,直接返回
|
|
// "Network Error" 网络不通,直接返回
|
|
|
|
|
|
- Vue.prototype.$notify({
|
|
|
|
- showClose: true,
|
|
|
|
- message: "网络连接异常,请检查网络设置。",
|
|
|
|
- type: "error"
|
|
|
|
|
|
+ Notice.error({
|
|
|
|
+ title: "网络连接异常,请检查网络设置。"
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
@@ -70,19 +67,14 @@ _axiosCommonService.interceptors.response.use(
|
|
|
|
|
|
// 登录失效 跳转登录页面
|
|
// 登录失效 跳转登录页面
|
|
if (status == 403 || status == 401) {
|
|
if (status == 403 || status == 401) {
|
|
- Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
|
|
- confirmButtonText: "确定",
|
|
|
|
- callback: () => {
|
|
|
|
- removeKeyToken();
|
|
|
|
- router.push("/login/");
|
|
|
|
- }
|
|
|
|
|
|
+ Notice.warning({
|
|
|
|
+ title: "登录失效,请重新登录!"
|
|
});
|
|
});
|
|
|
|
+ removeKeyToken();
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
} else if (status == 405) {
|
|
} else if (status == 405) {
|
|
- Vue.prototype.$notify({
|
|
|
|
- showClose: true,
|
|
|
|
- message: "没有权限!",
|
|
|
|
- type: "error"
|
|
|
|
|
|
+ Notice.warning({
|
|
|
|
+ title: "没有权限!"
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
}
|
|
}
|
|
@@ -90,16 +82,14 @@ _axiosCommonService.interceptors.response.use(
|
|
if (status != 200) {
|
|
if (status != 200) {
|
|
const data = error.response.data;
|
|
const data = error.response.data;
|
|
if (data && data.desc) {
|
|
if (data && data.desc) {
|
|
- Vue.prototype.$notify({
|
|
|
|
- showClose: true,
|
|
|
|
- message: data.desc,
|
|
|
|
- type: "error"
|
|
|
|
|
|
+ Notice.error({
|
|
|
|
+ title: "服务器返回",
|
|
|
|
+ desc: data.desc
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- Vue.prototype.$notify({
|
|
|
|
- showClose: true,
|
|
|
|
- message: "未定义异常: " + JSON.stringify(data, 2),
|
|
|
|
- type: "error"
|
|
|
|
|
|
+ Notice.error({
|
|
|
|
+ title: "未定义异常: ",
|
|
|
|
+ desc: JSON.stringify(data, 2)
|
|
});
|
|
});
|
|
}
|
|
}
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|