迁移会员中心基础按钮事件绑定
This commit is contained in:
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user