协会整改

This commit is contained in:
2026-10-20 20:50:11 +08:00
parent 24f6b50304
commit d8ac0a7aa4
11 changed files with 661 additions and 586 deletions
@@ -34,6 +34,67 @@ const clone = (val) => {
return JSON.parse(JSON.stringify(val))
}
// H5 页面按需注册弹框同步回调;全站只保留一个 popstate 监听,弹框按后进先出关闭。
const mobilePopupHistory = {
owner: null,
token: null,
stack: [],
pending: null,
register(sync) {
this.owner = sync
this.token = String(Date.now()) + Math.random()
this.stack = []
return this
},
open(key) {
if (!this.owner || this.pending || this.stack.includes(key)) return
this.stack.push(key)
window.history.pushState(Object.assign({}, window.history.state, {
mobilePopupDepth: this.stack.length,
mobilePopupOwner: this.token
}), '', window.location.href)
this.owner(key, true)
},
// 返回 Promise,关闭确认框后再提交,避免回退尚未完成便清理父级弹框。
close() {
if (this.pending) return this.pending.promise
if (!this.stack.length) return Promise.resolve()
return this.back(1)
},
back(count) {
let complete
const promise = new Promise(resolve => { complete = resolve })
this.pending = {promise, complete}
window.history.go(-count)
return promise
},
clear() {
if (this.pending) return this.pending.promise.then(() => this.clear())
return this.stack.length ? this.back(this.stack.length) : Promise.resolve()
},
unregister(sync) {
if (this.owner !== sync) return
this.owner = null
this.stack = []
},
onPop(event) {
if (!this.owner) return
const depth = event.state && event.state.mobilePopupOwner === this.token
? event.state.mobilePopupDepth : 0
// 弹框回退由本管理器消费,避免 PJAX 同时将其识别为业务页面切换。
if (this.stack.length > depth || this.pending) event.stopImmediatePropagation()
while (this.stack.length > depth) {
this.owner(this.stack.pop(), false)
}
if (this.pending) {
const complete = this.pending.complete
this.pending = null
complete()
}
}
}
window.addEventListener('popstate', event => mobilePopupHistory.onPop(event), true)
const toChinesNum = (num) => {
let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
let unit = ["", "十", "百", "千", "万"];