Files

72 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 18:45:41 +08:00
/**
* Purpose: activeLoadingCount supports loading.js by holding or executing the active loading count page or API role.
* Usage: import, call, read, or update this let from the owning page/module while preserving the surrounding loading and permission flow.
*/
let activeLoadingCount = 0
2026-05-23 18:45:41 +08:00
/**
* Purpose: showLoading supports loading.js by holding or executing the show loading page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function showLoading(options) {
const config = options || {}
activeLoadingCount += 1
if (activeLoadingCount > 1) {
return
}
wx.showLoading({
title: config.title || '加载中',
mask: config.mask !== false
})
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: hideLoading supports loading.js by holding or executing the hide loading page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function hideLoading() {
activeLoadingCount = Math.max(0, activeLoadingCount - 1)
if (activeLoadingCount > 0) {
return
}
wx.hideLoading({
fail() {}
})
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: resetLoading supports loading.js by holding or executing the reset loading page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function resetLoading() {
activeLoadingCount = 0
wx.hideLoading({
fail() {}
})
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: runWithLoading supports loading.js by holding or executing the run with loading page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function runWithLoading(task, options) {
showLoading(options)
return Promise.resolve()
.then(() => task())
.finally(() => {
hideLoading()
})
}
module.exports = {
showLoading,
hideLoading,
resetLoading,
runWithLoading
}