职工慰问:增加工会备案流程环节,慰问报销导出模板同步优化更新

This commit is contained in:
2026-09-18 14:57:24 +08:00
parent 4f8f23e632
commit 71ead6854a
8 changed files with 849 additions and 57 deletions
@@ -94,6 +94,110 @@
// toast多例模式
vant.Toast.allowMultiple()
// H5 统一弹框历史栈:仅接入的页面启用,捕获阶段消费弹框返回,防止 PJAX 重载页面。
window.h5PopupHistory = (() => {
let active = null
let serial = 0
let pending = null
let skippingClosedHistory = false
const sync = (closedKeys) => {
if (active) active.onChange(active.keys.slice(), closedKeys)
}
// 回退到指定层级,Promise 在 popstate 同步完成后结束,提交/跳转可安全等待。
const rewind = (depth) => {
if (pending) return pending.promise.then(() => rewind(depth))
if (!active || active.keys.length <= depth) return Promise.resolve()
let resolveBack
const promise = new Promise((resolve) => { resolveBack = resolve })
pending = { promise, resolve: resolveBack }
window.history.go(depth - active.keys.length)
return promise
}
window.addEventListener("popstate", (event) => {
// 清除前进进入的残留记录时,紧随其后的回退也不能触发 PJAX。
if (skippingClosedHistory) {
skippingClosedHistory = false
event.stopImmediatePropagation()
return
}
const mark = event.state && event.state.h5Popup
if ((!active || !active.keys.length) && !mark) return
// 只处理当前页面弹框记录;普通业务页面的返回继续由原 PJAX 处理。
event.stopImmediatePropagation()
if (mark && (!active || mark.owner !== active.id)) {
skippingClosedHistory = true
window.history.go(-mark.depth)
return
}
const depth = mark ? mark.depth : 0
if (depth > active.keys.length) {
// 已关闭的弹框历史不重新打开,前进到残留记录时退回业务页记录。
skippingClosedHistory = true
window.history.go(active.keys.length - depth)
return
}
const closedKeys = active.keys.slice(depth)
active.keys = active.keys.slice(0, depth)
const completed = pending
pending = null
sync(closedKeys)
if (completed) completed.resolve()
}, true)
return {
/** 注册页面同步回调,参数为仍打开的弹框 key 数组;返回页面专用操作句柄。 */
register(onChange) {
if (active) throw new Error("上一个页面的弹框历史尚未注销")
const owner = { id: Date.now() + "-" + (++serial), keys: [], onChange }
active = owner
return {
// key 是页面内唯一弹框名称;相同弹框重复打开不会重复压栈。
open(key) {
const open = () => {
if (active !== owner || owner.keys.includes(key)) return
owner.keys.push(key)
window.history.pushState({ h5Popup: { owner: owner.id, depth: owner.keys.length } }, "", window.location.href)
}
return pending ? pending.promise.then(open) : Promise.resolve(open())
},
// 关闭指定弹框及其上层弹框,返回 Promise<void>,保持后进先出。
close(key) {
if (active !== owner) return Promise.resolve()
const index = owner.keys.indexOf(key)
return index < 0 ? Promise.resolve() : rewind(index)
},
clear() {
return active === owner ? rewind(0) : Promise.resolve()
},
destroy() {
// 无弹框时同步注销,保证 PJAX 同次替换中下一个页面可以立即注册。
if (active === owner && !owner.keys.length && !pending) {
active = null
return Promise.resolve()
}
return this.clear().then(() => {
if (active === owner) active = null
})
}
}
},
hasOpen() { return !!(active && active.keys.length) },
back() { return active ? rewind(Math.max(0, active.keys.length - 1)) : Promise.resolve() },
clear() { return rewind(0) }
}
})()
// 带弹框离开页面时先回收历史,再交给原链接/PJAX,避免返回到已关闭的弹框。
document.addEventListener("click", (event) => {
const link = event.target.closest && event.target.closest("a[href]")
if (!link || !window.h5PopupHistory.hasOpen() || event.defaultPrevented ||
event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey ||
link.target === "_blank" || link.hasAttribute("download")) return
const href = link.getAttribute("href")
if (!href || href.startsWith("#") || href.startsWith("javascript:")) return
event.preventDefault()
event.stopImmediatePropagation()
window.h5PopupHistory.clear().then(() => link.click())
}, true)
//初始化pjax
;(function initPjax() {
if ($.support.pjax) {
@@ -136,6 +240,10 @@
})()
function pjaxReplace(url, data = null) {
if (window.h5PopupHistory.hasOpen()) {
window.h5PopupHistory.clear().then(() => pjaxReplace(url, data))
return
}
$.pjax({
url: url,
container: "#container",
@@ -159,6 +267,11 @@
}
function historyBack(func) {
// 弹框存在时只退一层;等待历史同步期间的重复点击不会穿透到业务页面。
if (window.h5PopupHistory.hasOpen()) {
window.h5PopupHistory.back()
return
}
if (window.history.length > 1) {
window.history.back()
} else {