2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: ensureStore supports page-state.js by holding or executing the ensure store 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-20 16:02:57 +08:00
|
|
|
function ensureStore() {
|
|
|
|
|
const app = getApp()
|
|
|
|
|
app.globalData.pageDirtyFlags = app.globalData.pageDirtyFlags || {}
|
|
|
|
|
return app.globalData.pageDirtyFlags
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: markDirty supports page-state.js by holding or executing the mark dirty 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-20 16:02:57 +08:00
|
|
|
function markDirty(key) {
|
|
|
|
|
if (!key) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const store = ensureStore()
|
|
|
|
|
store[key] = true
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: consumeDirty supports page-state.js by holding or executing the consume dirty 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-20 16:02:57 +08:00
|
|
|
function consumeDirty(key) {
|
|
|
|
|
if (!key) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
const store = ensureStore()
|
|
|
|
|
const value = Boolean(store[key])
|
|
|
|
|
delete store[key]
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
markDirty,
|
|
|
|
|
consumeDirty
|
|
|
|
|
}
|