迁移婚姻弹窗基础按钮事件绑定

This commit is contained in:
2026-04-25 08:10:23 +08:00
parent 1a750f2fe7
commit 3773cf905b
3 changed files with 118 additions and 14 deletions
+4
View File
@@ -8,6 +8,7 @@ export { bindChatImageUploadControl } from "./chat-room/image-upload.js";
export { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
export { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js";
export { bindMobileDrawerControls } from "./chat-room/mobile-drawer.js";
export { bindMarriageStatusControls } from "./chat-room/marriage-status.js";
export { bindToolbarControls } from "./chat-room/toolbar.js";
export { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
export { bindAdminMenuControls } from "./chat-room/admin-menu.js";
@@ -56,6 +57,7 @@ import { bindChatImageUploadControl } from "./chat-room/image-upload.js";
import { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
import { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js";
import { bindMobileDrawerControls } from "./chat-room/mobile-drawer.js";
import { bindMarriageStatusControls } from "./chat-room/marriage-status.js";
import { bindToolbarControls } from "./chat-room/toolbar.js";
import { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
import { bindAdminMenuControls } from "./chat-room/admin-menu.js";
@@ -123,6 +125,7 @@ if (typeof window !== "undefined") {
submitBaccaratLossCoverEvent,
bindBankControls,
bindFishingControls,
bindMarriageStatusControls,
bindProfileControls,
bindShopControls,
bindVipControls,
@@ -175,6 +178,7 @@ if (typeof window !== "undefined") {
bindBaccaratLossCoverAdminControls();
bindBankControls();
bindFishingControls();
bindMarriageStatusControls();
bindProfileControls();
bindShopControls();
bindVipControls();
+100
View File
@@ -0,0 +1,100 @@
// 婚姻状态弹窗基础事件绑定,替代 toolbar 婚姻区域内联 onclick。
let marriageStatusEventsBound = false;
/**
* 调用婚姻系统存量全局函数。
*
* @param {string} functionName 全局函数名
* @param {...unknown} args 参数
* @returns {void}
*/
function callMarriageGlobal(functionName, ...args) {
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;
}
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") || "");
});
}