|
@@ -2,21 +2,25 @@ import axios from 'axios'
|
|
|
import { MessageBox, Message } from 'element-ui'
|
|
|
import store from '@/store'
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
-
|
|
|
-//获取当前url
|
|
|
-
|
|
|
-var aa = process.env.VUE_APP_BASE_API
|
|
|
-//获取当前url
|
|
|
-
|
|
|
-if(aa.indexOf('/')==0 && aa.length==1){
|
|
|
- aa= window.location.protocol + "//"+window.location.host+aa
|
|
|
-}
|
|
|
- const service = axios.create({
|
|
|
- baseURL: aa, // url = base url + request url
|
|
|
- withCredentials: true, // send cookies when cross-domain requests
|
|
|
- timeout: 60000 ,// request timeout
|
|
|
- })
|
|
|
-// request interceptor
|
|
|
+
|
|
|
+//获取当前url
|
|
|
+const DoMainString = document.querySelector("html").getAttribute("domain");
|
|
|
+var URL = process.env.VUE_APP_BASE_API
|
|
|
+if (DoMainString) {
|
|
|
+ URL = DoMainString
|
|
|
+}
|
|
|
+console.log(URL,'===========URL')
|
|
|
+
|
|
|
+if(URL.indexOf('/')==0 && URL.length==1){
|
|
|
+ URL= window.location.protocol + "//"+window.location.host+aa
|
|
|
+}
|
|
|
+
|
|
|
+const service = axios.create({
|
|
|
+ baseURL: URL, // url = base url + request url
|
|
|
+ withCredentials: true, // send cookies when cross-domain requests
|
|
|
+ timeout: 60000 ,// request timeout
|
|
|
+})
|
|
|
+// request interceptor
|
|
|
service.interceptors.request.use(
|
|
|
config => {
|
|
|
// do something before request is sent
|
|
@@ -35,7 +39,7 @@ service.interceptors.request.use(
|
|
|
} else {
|
|
|
config.headers['token'] = getToken()
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
return config
|
|
|
},
|
|
|
error => {
|
|
@@ -97,30 +101,30 @@ service.interceptors.response.use(
|
|
|
}
|
|
|
},
|
|
|
error => {
|
|
|
- console.log('err' + error) // for debug
|
|
|
- let config = error.config
|
|
|
- if (!config) {
|
|
|
- Message({ message: error.message, type: 'error', duration: 5 * 1000 })
|
|
|
- return Promise.reject(error)
|
|
|
- }
|
|
|
- console.log('config==>', config) // for debug
|
|
|
- console.log('config.__retryCount==>', config.__retryCount) // for debug
|
|
|
- // 设置请求超时次数
|
|
|
- config.__retryCount = config.__retryCount || 0
|
|
|
- if (config.__retryCount >= 3) {
|
|
|
- // Message({ message:error.message, type: 'error', duration: 5 * 1000 })
|
|
|
- Message({ message:'请求超时', type: 'error', duration: 5 * 1000 })
|
|
|
- // Message.error((error && error.data && error.data.msg) || '请求超时')
|
|
|
- return Promise.reject(error)
|
|
|
- }
|
|
|
- config.__retryCount += 1
|
|
|
- let backoff = new Promise((resolve) => {
|
|
|
- setTimeout(() => {
|
|
|
- resolve()
|
|
|
- }, config.retryDelay || 1000)
|
|
|
- })
|
|
|
- return backoff.then(() => {
|
|
|
- return service(config)
|
|
|
+ console.log('err' + error) // for debug
|
|
|
+ let config = error.config
|
|
|
+ if (!config) {
|
|
|
+ Message({ message: error.message, type: 'error', duration: 5 * 1000 })
|
|
|
+ return Promise.reject(error)
|
|
|
+ }
|
|
|
+ console.log('config==>', config) // for debug
|
|
|
+ console.log('config.__retryCount==>', config.__retryCount) // for debug
|
|
|
+ // 设置请求超时次数
|
|
|
+ config.__retryCount = config.__retryCount || 0
|
|
|
+ if (config.__retryCount >= 3) {
|
|
|
+ // Message({ message:error.message, type: 'error', duration: 5 * 1000 })
|
|
|
+ Message({ message:'请求超时', type: 'error', duration: 5 * 1000 })
|
|
|
+ // Message.error((error && error.data && error.data.msg) || '请求超时')
|
|
|
+ return Promise.reject(error)
|
|
|
+ }
|
|
|
+ config.__retryCount += 1
|
|
|
+ let backoff = new Promise((resolve) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ resolve()
|
|
|
+ }, config.retryDelay || 1000)
|
|
|
+ })
|
|
|
+ return backoff.then(() => {
|
|
|
+ return service(config)
|
|
|
})
|
|
|
// Message({
|
|
|
// message: error.message,
|