修改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);
});
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;
}
};

View File

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