|
@@ -1,16 +1,19 @@
|
|
|
import axios from 'axios'
|
|
|
-import { Notification, MessageBox, Message } from 'element-ui'
|
|
|
+import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
|
|
import store from '@/store'
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
|
+
|
|
|
+let loadingInstance = undefined;
|
|
|
+
|
|
|
// 创建axios实例
|
|
|
const service = axios.create({
|
|
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
|
|
baseURL: process.env.VUE_APP_BASE_API,
|
|
|
// 超时
|
|
|
- timeout: 36000 * 1000
|
|
|
+ timeout: 10000
|
|
|
})
|
|
|
// request拦截器
|
|
|
service.interceptors.request.use(config => {
|
|
@@ -41,6 +44,12 @@ service.interceptors.request.use(config => {
|
|
|
config.params = {};
|
|
|
config.url = url;
|
|
|
}
|
|
|
+ if (config["loading"]) {
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.close();
|
|
|
+ }
|
|
|
+ loadingInstance = Loading.service({ lock: true, target: config["loading"], text: "处理中...", spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' })
|
|
|
+ }
|
|
|
return config
|
|
|
}, error => {
|
|
|
console.log(error)
|
|
@@ -49,6 +58,9 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(res => {
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.close();
|
|
|
+ }
|
|
|
// 未设置状态码则默认成功状态
|
|
|
const code = res.data.code || 200;
|
|
|
// 获取错误信息
|
|
@@ -80,6 +92,9 @@ service.interceptors.response.use(res => {
|
|
|
}
|
|
|
},
|
|
|
error => {
|
|
|
+ if (loadingInstance) {
|
|
|
+ loadingInstance.close();
|
|
|
+ }
|
|
|
console.log('err' + error)
|
|
|
let { message } = error;
|
|
|
if (message == "Network Error") {
|