迁移会员中心基础按钮事件绑定

This commit is contained in:
2026-04-25 08:07:28 +08:00
parent 0526419dbc
commit 37e4c5d4c5
3 changed files with 77 additions and 7 deletions
+4
View File
@@ -22,6 +22,7 @@ export {
export { bindFishingControls } from "./chat-room/fishing.js";
export { bindProfileControls } from "./chat-room/profile-controls.js";
export { bindShopControls } from "./chat-room/shop-controls.js";
export { bindVipControls } from "./chat-room/vip-controls.js";
export {
BLOCKABLE_SYSTEM_SENDERS,
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
@@ -68,6 +69,7 @@ import {
import { bindFishingControls } from "./chat-room/fishing.js";
import { bindProfileControls } from "./chat-room/profile-controls.js";
import { bindShopControls } from "./chat-room/shop-controls.js";
import { bindVipControls } from "./chat-room/vip-controls.js";
import {
BLOCKABLE_SYSTEM_SENDERS,
BLOCKED_SYSTEM_SENDERS_STORAGE_KEY,
@@ -120,6 +122,7 @@ if (typeof window !== "undefined") {
bindFishingControls,
bindProfileControls,
bindShopControls,
bindVipControls,
CHAT_FONT_SIZE_STORAGE_KEY,
restoreChatFontSize,
closeChatImageLightbox,
@@ -170,6 +173,7 @@ if (typeof window !== "undefined") {
bindFishingControls();
bindProfileControls();
bindShopControls();
bindVipControls();
bindChatRightPanelControls();
bindMobileDrawerControls();
bindWelcomeMenuControls();
+66
View File
@@ -0,0 +1,66 @@
// 会员中心基础按钮事件绑定,替代 toolbar VIP 区域内联 onclick。
let vipControlEventsBound = false;
/**
* 调用会员中心存量全局函数。
*
* @param {string} functionName 全局函数名
* @param {...unknown} args 参数
* @returns {void}
*/
function callVipGlobal(functionName, ...args) {
if (typeof window[functionName] === "function") {
window[functionName](...args);
}
}
/**
* 绑定会员中心 tab、关闭、购买与个性化保存事件。
*
* @returns {void}
*/
export function bindVipControls() {
if (vipControlEventsBound || typeof document === "undefined") {
return;
}
vipControlEventsBound = true;
document.addEventListener("click", (event) => {
if (!(event.target instanceof Element)) {
return;
}
const tabButton = event.target.closest("[data-vip-tab]");
if (tabButton) {
event.preventDefault();
callVipGlobal("switchVipTab", tabButton.getAttribute("data-vip-tab") || "");
return;
}
if (event.target.closest("[data-vip-modal-close]")) {
event.preventDefault();
callVipGlobal("closeVipModal");
return;
}
const buyButton = event.target.closest("[data-vip-buy-level]");
if (buyButton) {
event.preventDefault();
// 购买按钮由 VIP 数据动态渲染,等级和支付渠道从 data 属性读取。
const levelId = Number.parseInt(buyButton.getAttribute("data-vip-buy-level") || "", 10);
const provider = buyButton.getAttribute("data-vip-buy-provider") || "alipay";
if (Number.isInteger(levelId)) {
callVipGlobal("buyVip", levelId, provider);
}
return;
}
if (event.target.closest("[data-vip-save-presence]")) {
event.preventDefault();
callVipGlobal("saveVipPresenceSettings");
}
});
}