You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.0 KiB
51 lines
1.0 KiB
let loadingCount = 0;
|
|
let timer = null; // 避免多次loading
|
|
let loadingTimer = null;
|
|
let custom = false;
|
|
|
|
// 开启loading
|
|
export const showLoading = () => {
|
|
return
|
|
// 设置加载动画区域
|
|
if (loadingCount === 0 && !timer) {
|
|
// TODO locale
|
|
if (custom) {
|
|
app.$emit("showLoading");
|
|
} else {
|
|
uni.showLoading({ title: '加载中...' })
|
|
}
|
|
// if (loadingTimer) clearTimeout(loadingTimer);
|
|
// // 3秒超时 关闭loading
|
|
// loadingTimer = setTimeout(() => {
|
|
// hideLoading()
|
|
// }, 3000)
|
|
}
|
|
if (timer) clearTimeout(timer);
|
|
loadingCount++;
|
|
};
|
|
|
|
// 隐藏loading
|
|
export const hideLoading = () => {
|
|
return
|
|
if (loadingCount <= 0) return;
|
|
loadingCount--;
|
|
if (loadingCount === 0) {
|
|
timer = setTimeout(() => {
|
|
// TODO locale
|
|
if (custom) {
|
|
app.$emit("hideLoading");
|
|
} else {
|
|
uni.hideLoading()
|
|
}
|
|
|
|
timer = null;
|
|
}, 500);
|
|
}
|
|
};
|
|
|
|
// 清空loading
|
|
export const clearLoading = () => {
|
|
loadingCount = 0;
|
|
uni.hideLoading()
|
|
};
|
|
|
|
|