135 lines
3.9 KiB
JavaScript
135 lines
3.9 KiB
JavaScript
// 手机端抽屉基础控件事件绑定,替代浮动按钮、关闭按钮与名单 tab 的内联事件。
|
|
|
|
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?.();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 绑定手机端抽屉基础控件事件。
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
export function bindMobileDrawerControls() {
|
|
if (mobileDrawerEventsBound || typeof document === "undefined") {
|
|
return;
|
|
}
|
|
|
|
mobileDrawerEventsBound = true;
|
|
document.addEventListener("click", (event) => {
|
|
if (!(event.target instanceof Element)) {
|
|
return;
|
|
}
|
|
|
|
const drawerTrigger = event.target.closest("[data-mobile-drawer-open]");
|
|
if (drawerTrigger) {
|
|
event.preventDefault();
|
|
window.openMobileDrawer?.(drawerTrigger.dataset.mobileDrawerOpen);
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest("[data-mobile-drawer-close]")) {
|
|
event.preventDefault();
|
|
window.closeMobileDrawer?.();
|
|
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();
|
|
window.switchMobileTab?.(tabTrigger.dataset.mobileDrawerTab);
|
|
}
|
|
});
|
|
|
|
document.addEventListener("change", (event) => {
|
|
if (!(event.target instanceof HTMLSelectElement) || event.target.id !== "mob-user-sort-select") {
|
|
return;
|
|
}
|
|
|
|
window.renderMobileUserList?.();
|
|
});
|
|
|
|
document.addEventListener("input", (event) => {
|
|
if (!(event.target instanceof HTMLInputElement) || event.target.id !== "mob-user-search-input") {
|
|
return;
|
|
}
|
|
|
|
window.scheduleRenderMobileUserList?.();
|
|
});
|
|
}
|