Commit 8bbed154 authored by 沈翠玲's avatar 沈翠玲

增加状态控制loading

parent 1aacffec
......@@ -1929,7 +1929,6 @@ export default {
const t = this;
this.tableData = [];
this.tableSelectData = []
console.log('sadada', t.vuex_workunit.workunitId)
this.$u.api
.getTaskList({
workunitId: t.vuex_workunit.workunitId,
......
......@@ -25,16 +25,15 @@ class Request {
options.params = options.params || {};
options.header = Object.assign({}, this.config.header, options.header);
options.method = options.method || this.config.method;
this.config.loadStatus = true
return new Promise((resolve, reject) => {
options.complete = (response) => {
// 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
// uni.hideLoading();
setTimeout(()=>{
uni.hideLoading();
}, 10)
// 清除定时器,如果请求回来了,就无需loading
clearTimeout(this.config.timer);
uni.hideLoading();
this.config.timer = null;
this.config.loadStatus = false
// 判断用户对拦截返回数据的要求,如果originalData为true,返回所有的数据(response)到拦截器,否则只返回response.data
if(this.config.originalData) {
// 判断是否存在拦截器
......@@ -84,10 +83,12 @@ class Request {
// 而没有清除前者的定时器,导致前者超时,一直显示loading
if(this.config.showLoading && !this.config.timer) {
this.config.timer = setTimeout(() => {
if (this.config.loadStatus) {
uni.showLoading({
title: this.config.loadingText,
mask: this.config.loadingMask
})
}
this.config.timer = null;
}, this.config.loadingTime);
}
......@@ -111,6 +112,7 @@ class Request {
// 此参数无需处理,因为5+和支付宝小程序不支持,默认为text即可
responseType: 'text',
showLoading: true, // 是否显示请求中的loading
loadStatus:false, // loading状态
loadingText: '请求中...',
loadingTime: 800, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
timer: null, // 定时器
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment