From 69a8e92ffa57855ebc77f2954d44392e1c586b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=BF=94=E5=AE=87-=E6=97=85=E7=AE=A1=E5=AE=B6?= <153298343@qq.com> Date: Tue, 6 Sep 2022 08:51:42 +0800 Subject: [PATCH] up --- src/api/user.js | 3 ++- src/utils/request.js | 27 +++++++++++++++---------- src/views/login/index.vue | 42 ++++++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index ba40eb1..9cef11e 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -13,7 +13,8 @@ export function loginOss(data) { return request({ url: '/api/admin/auth/oss-login', method: 'post', - data + data, + noloading: true }) } diff --git a/src/utils/request.js b/src/utils/request.js index b215a34..ab2f96d 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -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, diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 3f37148..ae6d3a4 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,5 +1,5 @@