修改loading方法

This commit is contained in:
q4speed 2020-02-19 12:12:35 +08:00
parent a2c9277c61
commit 22d729c169
2 changed files with 38 additions and 40 deletions

View File

@ -32,66 +32,64 @@ export default {
return Promise.reject(error); 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) { Vue.prototype.$get = function (url, success) {
let result = {loading: true};
if (!success) { if (!success) {
return axios.get(url); return axios.get(url);
} else { } else {
axios.get(url).then(response => { axios.get(url).then(response => {
if (!response.data) { then(success, response, result);
return success(response);
}
if (response.data.success) {
return success(response.data);
} else {
window.console.warn(response.data);
Message.warning(response.data.message);
}
}).catch(error => { }).catch(error => {
window.console.error(error.response || error.message); exception(error, result);
Message.error({message: error.message, showClose: true}); });
}) return result;
} }
}; };
Vue.prototype.$post = function (url, data, success) { Vue.prototype.$post = function (url, data, success) {
let result = {loading: true};
if (!success) { if (!success) {
return axios.post(url, data); return axios.post(url, data);
} else { } else {
axios.post(url, data).then(response => { axios.post(url, data).then(response => {
if (!response.data) { then(success, response, result);
return success(response);
}
if (response.data.success) {
return success(response.data);
} else {
window.console.warn(response.data);
Message.warning(response.data.message);
}
}).catch(error => { }).catch(error => {
window.console.error(error.response || error.message); exception(error, result);
Message.error({message: error.message, showClose: true}); });
}) return result;
} }
}; };
Vue.prototype.$request = function (axiosRequestConfig, success) { Vue.prototype.$request = function (axiosRequestConfig, success) {
let result = {loading: true};
if (!success) { if (!success) {
return axios.request(axiosRequestConfig); return axios.request(axiosRequestConfig);
} else { } else {
axios.request(axiosRequestConfig).then(response => { axios.request(axiosRequestConfig).then(response => {
if (!response.data) { then(success, response, result);
return success(response);
}
if (response.data.success) {
return success(response.data);
} else {
window.console.warn(response.data);
Message.warning(response.data.message);
}
}).catch(error => { }).catch(error => {
window.console.error(error.response || error.message); exception(error, result);
Message.error({message: error.message, showClose: true}); });
}) return result;
} }
}; };

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<el-card> <el-card v-loading="result.loading">
<div slot="header"> <div slot="header">
<el-row type="flex" justify="space-between" align="middle"> <el-row type="flex" justify="space-between" align="middle">
<span class="title"> <span class="title">
@ -121,12 +121,11 @@
}, },
list() { list() {
let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize; let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize;
this.$post(url, {}, response => { this.result = this.$post(url, {}, response => {
let data = response.data; let data = response.data;
this.items = data.listObject; this.items = data.listObject;
this.total = data.itemCount; this.total = data.itemCount;
}) });
}, },
handleSizeChange(size) { handleSizeChange(size) {
this.pageSize = size; this.pageSize = size;
@ -139,6 +138,7 @@
}, },
data() { data() {
return { return {
result: {},
loading: false, loading: false,
createVisible: false, createVisible: false,
btnTips: "添加工作空间", btnTips: "添加工作空间",