104 lines
3.6 KiB
JavaScript
104 lines
3.6 KiB
JavaScript
// 婚姻状态弹窗基础事件绑定,替代 toolbar 婚姻区域内联 onclick。
|
|
|
|
let marriageStatusEventsBound = false;
|
|
|
|
/**
|
|
* 调用婚姻系统存量全局函数。
|
|
*
|
|
* @param {string} functionName 全局函数名
|
|
* @param {...unknown} args 参数
|
|
* @returns {void}
|
|
*/
|
|
function callMarriageGlobal(functionName, ...args) {
|
|
// 婚姻状态业务仍在 Blade 内维护,当前模块只负责按钮事件和旧函数桥接。
|
|
if (typeof window[functionName] === "function") {
|
|
window[functionName](...args);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从分页文本解析当前页码。
|
|
*
|
|
* @returns {number}
|
|
*/
|
|
function resolveCurrentMarriedPage() {
|
|
const pageInfo = document.getElementById("married-page-info")?.textContent || "1 / 1";
|
|
const currentPage = Number.parseInt(pageInfo.split("/")[0]?.trim() || "1", 10);
|
|
|
|
return Number.isInteger(currentPage) && currentPage > 0 ? currentPage : 1;
|
|
}
|
|
|
|
/**
|
|
* 绑定婚姻弹窗 tab、分页、用户名片和状态操作按钮事件。
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
export function bindMarriageStatusControls() {
|
|
if (marriageStatusEventsBound || typeof document === "undefined") {
|
|
return;
|
|
}
|
|
|
|
marriageStatusEventsBound = true;
|
|
document.addEventListener("click", (event) => {
|
|
if (!(event.target instanceof Element)) {
|
|
return;
|
|
}
|
|
|
|
// 弹窗 tab 与分页内容由存量脚本渲染,事件统一通过 data-* 分发。
|
|
const tabButton = event.target.closest("[data-marriage-tab]");
|
|
if (tabButton) {
|
|
event.preventDefault();
|
|
callMarriageGlobal("switchMarriageTab", tabButton.getAttribute("data-marriage-tab") || "");
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest("[data-marriage-modal-close]")) {
|
|
event.preventDefault();
|
|
callMarriageGlobal("closeMarriageStatusModal");
|
|
return;
|
|
}
|
|
|
|
const pageButton = event.target.closest("[data-marriage-page-delta]");
|
|
if (pageButton) {
|
|
event.preventDefault();
|
|
|
|
// 分页状态仍由存量脚本维护,这里从页面文本推导目标页。
|
|
const delta = Number.parseInt(pageButton.getAttribute("data-marriage-page-delta") || "0", 10);
|
|
callMarriageGlobal("fetchMarriedList", resolveCurrentMarriedPage() + delta);
|
|
return;
|
|
}
|
|
|
|
const userCard = event.target.closest("[data-marriage-user-card]");
|
|
if (userCard) {
|
|
event.preventDefault();
|
|
callMarriageGlobal("openUserCard", userCard.getAttribute("data-marriage-user-card") || "");
|
|
return;
|
|
}
|
|
|
|
const actionButton = event.target.closest("[data-marriage-action]");
|
|
if (actionButton) {
|
|
event.preventDefault();
|
|
|
|
// 接受/拒绝沿用原 marriageAction,按钮可声明完成后关闭弹窗。
|
|
const marriageId = actionButton.getAttribute("data-marriage-id") || "";
|
|
const action = actionButton.getAttribute("data-marriage-action") || "";
|
|
callMarriageGlobal("marriageAction", marriageId, action);
|
|
|
|
// 部分操作按钮声明完成后立即关闭弹窗,这是按钮级行为约定。
|
|
if (actionButton.getAttribute("data-marriage-close-after-action") === "1") {
|
|
callMarriageGlobal("closeMarriageStatusModal");
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
const divorceButton = event.target.closest("[data-marriage-divorce]");
|
|
if (!divorceButton) {
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
callMarriageGlobal("tryDivorce", divorceButton.getAttribute("data-marriage-divorce") || "");
|
|
});
|
|
}
|