迁移手机抽屉工具按钮事件绑定

This commit is contained in:
2026-04-25 03:55:57 +08:00
parent 04ee32e4d5
commit 0310798675
2 changed files with 94 additions and 17 deletions
+78
View File
@@ -2,6 +2,56 @@
let mobileDrawerEventsBound = false;
/**
* 执行手机抽屉工具入口动作。
*
* @param {string} action 工具动作
* @returns {void}
*/
function runMobileToolAction(action) {
// 抽屉工具只负责分发到现有全局函数,业务实现仍留在原模块中。
const actions = {
"daily-sign-in": () => window.quickDailySignIn?.(),
shop: () => window.openShopModal?.(),
vip: () => window.openVipModal?.(),
"save-exp": () => window.saveExp?.(),
game: () => window.openGameHall?.(),
bank: () => window.openBankModal?.(),
marriage: () => window.openMarriageStatusModal?.(),
friend: () => window.openFriendPanel?.(),
avatar: () => window.openAvatarPicker?.(),
settings: () => {
if (typeof window.openSettingsModal === "function") {
window.openSettingsModal();
return;
}
const settingsModal = document.getElementById("settings-modal");
if (settingsModal) {
settingsModal.style.display = "flex";
}
},
};
actions[action]?.();
}
/**
* 确认并执行手机端离开房间动作。
*
* @returns {void}
*/
function confirmMobileLeaveRoom() {
// 离开房间需要保留二次确认,避免手机误触直接退出。
window.chatDialog
?.confirm("确定要离开聊天室吗?", "离开聊天室")
.then((ok) => {
if (ok) {
window.leaveRoom?.();
}
});
}
/**
* 绑定手机端抽屉基础控件事件。
*
@@ -31,6 +81,34 @@ export function bindMobileDrawerControls() {
return;
}
const toolAction = event.target.closest("[data-mobile-tool-action]");
if (toolAction) {
event.preventDefault();
window.closeMobileDrawer?.();
const action = toolAction.getAttribute("data-mobile-tool-action") || "";
if (action === "leave") {
confirmMobileLeaveRoom();
return;
}
runMobileToolAction(action);
return;
}
const toolUrl = event.target.closest("[data-mobile-tool-url]");
if (toolUrl) {
event.preventDefault();
window.closeMobileDrawer?.();
const url = toolUrl.getAttribute("data-mobile-tool-url");
if (url) {
window.open(url, "_blank");
}
return;
}
const tabTrigger = event.target.closest("[data-mobile-drawer-tab]");
if (tabTrigger) {
event.preventDefault();