迁移银行弹窗基础按钮事件绑定
This commit is contained in:
@@ -19,6 +19,7 @@ export {
|
||||
openAdminBaccaratLossCoverModal,
|
||||
submitBaccaratLossCoverEvent,
|
||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||
export { bindBankControls } from "./chat-room/bank-controls.js";
|
||||
export { bindFishingControls } from "./chat-room/fishing.js";
|
||||
export { bindProfileControls } from "./chat-room/profile-controls.js";
|
||||
export { bindShopControls } from "./chat-room/shop-controls.js";
|
||||
@@ -66,6 +67,7 @@ import {
|
||||
openAdminBaccaratLossCoverModal,
|
||||
submitBaccaratLossCoverEvent,
|
||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||
import { bindBankControls } from "./chat-room/bank-controls.js";
|
||||
import { bindFishingControls } from "./chat-room/fishing.js";
|
||||
import { bindProfileControls } from "./chat-room/profile-controls.js";
|
||||
import { bindShopControls } from "./chat-room/shop-controls.js";
|
||||
@@ -119,6 +121,7 @@ if (typeof window !== "undefined") {
|
||||
loadAdminCurrentLossCoverEvent,
|
||||
openAdminBaccaratLossCoverModal,
|
||||
submitBaccaratLossCoverEvent,
|
||||
bindBankControls,
|
||||
bindFishingControls,
|
||||
bindProfileControls,
|
||||
bindShopControls,
|
||||
@@ -170,6 +173,7 @@ if (typeof window !== "undefined") {
|
||||
bindToolbarControls();
|
||||
bindAdminMenuControls();
|
||||
bindBaccaratLossCoverAdminControls();
|
||||
bindBankControls();
|
||||
bindFishingControls();
|
||||
bindProfileControls();
|
||||
bindShopControls();
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// 金币银行基础按钮事件绑定,替代 toolbar 银行区域内联 onclick。
|
||||
|
||||
let bankControlEventsBound = false;
|
||||
|
||||
/**
|
||||
* 调用银行存量全局函数。
|
||||
*
|
||||
* @param {string} functionName 全局函数名
|
||||
* @param {...unknown} args 参数
|
||||
* @returns {void}
|
||||
*/
|
||||
function callBankGlobal(functionName, ...args) {
|
||||
if (typeof window[functionName] === "function") {
|
||||
window[functionName](...args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从分页文本中解析当前页码。
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
function resolveCurrentRankPage() {
|
||||
const pageInfo = document.getElementById("bank-rank-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 bindBankControls() {
|
||||
if (bankControlEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
bankControlEventsBound = true;
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tabButton = event.target.closest("[data-bank-tab]");
|
||||
if (tabButton) {
|
||||
event.preventDefault();
|
||||
callBankGlobal("switchBankTab", tabButton.getAttribute("data-bank-tab") || "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest("[data-bank-modal-close]")) {
|
||||
event.preventDefault();
|
||||
callBankGlobal("closeBankModal");
|
||||
return;
|
||||
}
|
||||
|
||||
const actionButton = event.target.closest("[data-bank-action]");
|
||||
if (actionButton) {
|
||||
event.preventDefault();
|
||||
// 存取款共用原 bankAction,由 type 决定读取哪个输入框和提交哪个接口。
|
||||
callBankGlobal("bankAction", actionButton.getAttribute("data-bank-action") || "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.closest("[data-bank-rank-sort]")) {
|
||||
event.preventDefault();
|
||||
callBankGlobal("toggleBankRankSort");
|
||||
return;
|
||||
}
|
||||
|
||||
const pageButton = event.target.closest("[data-bank-rank-page-delta]");
|
||||
if (!pageButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// 分页状态仍由存量脚本维护,这里从显示文本推导目标页,避免依赖其闭包变量。
|
||||
const delta = Number.parseInt(pageButton.getAttribute("data-bank-rank-page-delta") || "0", 10);
|
||||
callBankGlobal("fetchBankRanking", resolveCurrentRankPage() + delta);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user