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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
function showLoading(options) {
|
|
|
|
|
const config = options || {}
|
|
|
|
|
activeLoadingCount += 1
|
|
|
|
|
|
|
|
|
|
if (activeLoadingCount > 1) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: config.title || '\u52a0\u8f7d\u4e2d',
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
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.
|
|
|
|
|
*/
|
2026-04-01 15:18:35 +08:00
|
|
|
function runWithLoading(task, options) {
|
|
|
|
|
showLoading(options)
|
|
|
|
|
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
.then(() => task())
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoading()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
showLoading,
|
|
|
|
|
hideLoading,
|
|
|
|
|
resetLoading,
|
|
|
|
|
runWithLoading
|
|
|
|
|
}
|