|
@@ -1,7 +1,7 @@
|
|
|
import axios from 'axios'
|
|
|
-import { Notification, MessageBox, Message } from 'element-ui'
|
|
|
+import {Message, MessageBox, Notification} from 'element-ui'
|
|
|
import store from '@/store'
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
+import {getToken} from '@/utils/auth'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
@@ -10,7 +10,7 @@ const service = axios.create({
|
|
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
|
baseURL: process.env.VUE_APP_BASE_API,
|
|
|
// 超时
|
|
|
- timeout: 10000
|
|
|
+ timeout: 20000
|
|
|
})
|
|
|
// request拦截器
|
|
|
service.interceptors.request.use(config => {
|
|
@@ -25,7 +25,7 @@ service.interceptors.request.use(config => {
|
|
|
for (const propName of Object.keys(config.params)) {
|
|
|
const value = config.params[propName];
|
|
|
var part = encodeURIComponent(propName) + "=";
|
|
|
- if (value !== null && typeof(value) !== "undefined") {
|
|
|
+ if (value !== null && typeof (value) !== "undefined") {
|
|
|
if (typeof value === 'object') {
|
|
|
for (const key of Object.keys(value)) {
|
|
|
let params = propName + '[' + key + ']';
|
|
@@ -43,8 +43,8 @@ service.interceptors.request.use(config => {
|
|
|
}
|
|
|
return config
|
|
|
}, error => {
|
|
|
- console.log(error)
|
|
|
- Promise.reject(error)
|
|
|
+ console.log(error)
|
|
|
+ Promise.reject(error)
|
|
|
})
|
|
|
|
|
|
// 响应拦截器
|
|
@@ -63,7 +63,8 @@ service.interceptors.response.use(res => {
|
|
|
store.dispatch('LogOut').then(() => {
|
|
|
location.href = '/index';
|
|
|
})
|
|
|
- }).catch(() => {});
|
|
|
+ }).catch(() => {
|
|
|
+ });
|
|
|
} else if (code === 500) {
|
|
|
Message({
|
|
|
message: msg,
|
|
@@ -81,14 +82,12 @@ service.interceptors.response.use(res => {
|
|
|
},
|
|
|
error => {
|
|
|
console.log('err' + error)
|
|
|
- let { message } = error;
|
|
|
+ let {message} = error;
|
|
|
if (message == "Network Error") {
|
|
|
message = "后端接口连接异常";
|
|
|
- }
|
|
|
- else if (message.includes("timeout")) {
|
|
|
+ } else if (message.includes("timeout")) {
|
|
|
message = "系统接口请求超时";
|
|
|
- }
|
|
|
- else if (message.includes("Request failed with status code")) {
|
|
|
+ } else if (message.includes("Request failed with status code")) {
|
|
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
|
}
|
|
|
Message({
|