From 22d729c16960f6acd15e7bf88b9b99f0407906d8 Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 19 Feb 2020 12:12:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9loading=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/common/ajax.js | 70 +++++++++---------- .../components/settings/Workspace.vue | 8 +-- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/frontend/src/common/ajax.js b/frontend/src/common/ajax.js index 4ebb7bfae8..41d11dbfc1 100644 --- a/frontend/src/common/ajax.js +++ b/frontend/src/common/ajax.js @@ -32,66 +32,64 @@ export default { return Promise.reject(error); }); + function then(success, response, result) { + if (!response.data) { + success(response); + } + if (response.data.success) { + success(response.data); + } else { + window.console.warn(response.data); + Message.warning(response.data.message); + } + result.loading = false; + } + + function exception(error, result) { + result.loading = false; + window.console.error(error.response || error.message); + Message.error({message: error.message, showClose: true}); + } + Vue.prototype.$get = function (url, success) { + let result = {loading: true}; if (!success) { return axios.get(url); } else { axios.get(url).then(response => { - if (!response.data) { - return success(response); - } - if (response.data.success) { - return success(response.data); - } else { - window.console.warn(response.data); - Message.warning(response.data.message); - } + then(success, response, result); }).catch(error => { - window.console.error(error.response || error.message); - Message.error({message: error.message, showClose: true}); - }) + exception(error, result); + }); + return result; } }; Vue.prototype.$post = function (url, data, success) { + let result = {loading: true}; if (!success) { return axios.post(url, data); } else { axios.post(url, data).then(response => { - if (!response.data) { - return success(response); - } - if (response.data.success) { - return success(response.data); - } else { - window.console.warn(response.data); - Message.warning(response.data.message); - } + then(success, response, result); }).catch(error => { - window.console.error(error.response || error.message); - Message.error({message: error.message, showClose: true}); - }) + exception(error, result); + }); + return result; } }; Vue.prototype.$request = function (axiosRequestConfig, success) { + let result = {loading: true}; if (!success) { return axios.request(axiosRequestConfig); } else { axios.request(axiosRequestConfig).then(response => { - if (!response.data) { - return success(response); - } - if (response.data.success) { - return success(response.data); - } else { - window.console.warn(response.data); - Message.warning(response.data.message); - } + then(success, response, result); }).catch(error => { - window.console.error(error.response || error.message); - Message.error({message: error.message, showClose: true}); - }) + exception(error, result); + }); + return result; } }; diff --git a/frontend/src/performance/components/settings/Workspace.vue b/frontend/src/performance/components/settings/Workspace.vue index a6f89babf4..a225bcc526 100644 --- a/frontend/src/performance/components/settings/Workspace.vue +++ b/frontend/src/performance/components/settings/Workspace.vue @@ -1,6 +1,6 @@