功能:新增微信小程序界面
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
let activeLoadingCount = 0
|
||||
|
||||
function showLoading(options) {
|
||||
const config = options || {}
|
||||
activeLoadingCount += 1
|
||||
|
||||
if (activeLoadingCount > 1) {
|
||||
return
|
||||
}
|
||||
|
||||
wx.showLoading({
|
||||
title: config.title || '\u52a0\u8f7d\u4e2d',
|
||||
mask: config.mask !== false
|
||||
})
|
||||
}
|
||||
|
||||
function hideLoading() {
|
||||
activeLoadingCount = Math.max(0, activeLoadingCount - 1)
|
||||
|
||||
if (activeLoadingCount > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
wx.hideLoading({
|
||||
fail() {}
|
||||
})
|
||||
}
|
||||
|
||||
function resetLoading() {
|
||||
activeLoadingCount = 0
|
||||
wx.hideLoading({
|
||||
fail() {}
|
||||
})
|
||||
}
|
||||
|
||||
function runWithLoading(task, options) {
|
||||
showLoading(options)
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => task())
|
||||
.finally(() => {
|
||||
hideLoading()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
showLoading,
|
||||
hideLoading,
|
||||
resetLoading,
|
||||
runWithLoading
|
||||
}
|
||||
Reference in New Issue
Block a user