|
|
|
|
@ -14,18 +14,21 @@ let loading;
|
|
|
|
|
const service = axios.create({
|
|
|
|
|
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
|
|
|
|
// withCredentials: true, // send cookies when cross-domain requests
|
|
|
|
|
timeout: 50000 // request timeout
|
|
|
|
|
timeout: 500000 // request timeout
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// request interceptor
|
|
|
|
|
service.interceptors.request.use(
|
|
|
|
|
config => {
|
|
|
|
|
// do something before request is sent
|
|
|
|
|
loading = Loading.service({
|
|
|
|
|
lock: true,
|
|
|
|
|
background: "rgba(0,0,0,0.4)",
|
|
|
|
|
text: "正在加载中..."
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!config.noloading) {
|
|
|
|
|
// do something before request is sent
|
|
|
|
|
loading = Loading.service({
|
|
|
|
|
lock: true,
|
|
|
|
|
background: "rgba(0,0,0,0.4)",
|
|
|
|
|
text: "正在加载中..."
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (store.getters.token) {
|
|
|
|
|
// let each request carry token
|
|
|
|
|
// ['X-Token'] is a custom headers key
|
|
|
|
|
@ -56,11 +59,13 @@ service.interceptors.response.use(
|
|
|
|
|
* You can also judge the status by HTTP Status Code
|
|
|
|
|
*/
|
|
|
|
|
response => {
|
|
|
|
|
if (loading) {
|
|
|
|
|
loading.close()
|
|
|
|
|
}
|
|
|
|
|
const res = response.data
|
|
|
|
|
|
|
|
|
|
loading.close()
|
|
|
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
|
|
|
if (res.hasOwnProperty("errcode")) {
|
|
|
|
|
if (res.errcode) {
|
|
|
|
|
Message({
|
|
|
|
|
message: res.errmsg || 'Error',
|
|
|
|
|
type: 'error',
|
|
|
|
|
@ -87,7 +92,9 @@ service.interceptors.response.use(
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
loading.close()
|
|
|
|
|
if (loading) {
|
|
|
|
|
loading.close()
|
|
|
|
|
}
|
|
|
|
|
console.log('err' + error) // for debug
|
|
|
|
|
Message({
|
|
|
|
|
message: error.message,
|
|
|
|
|
|