69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
// 会员中心基础按钮事件绑定,替代 toolbar VIP 区域内联 onclick。
|
|
|
|
let vipControlEventsBound = false;
|
|
|
|
/**
|
|
* 调用会员中心存量全局函数。
|
|
*
|
|
* @param {string} functionName 全局函数名
|
|
* @param {...unknown} args 参数
|
|
* @returns {void}
|
|
*/
|
|
function callVipGlobal(functionName, ...args) {
|
|
// VIP 业务函数暂留在 Blade 内,当前模块只统一按钮事件与旧函数调用边界。
|
|
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;
|
|
}
|
|
|
|
// VIP 内容由接口动态渲染,tab 和购买按钮通过 data-* 代理避免重复绑定。
|
|
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");
|
|
}
|
|
});
|
|
}
|