85 lines
2.6 KiB
JavaScript
85 lines
2.6 KiB
JavaScript
// 金币银行基础按钮事件绑定,替代 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);
|
|
});
|
|
}
|