迁移竖向工具条按钮事件绑定
This commit is contained in:
@@ -7,6 +7,7 @@ export { bindChatImageUploadControl } from "./chat-room/image-upload.js";
|
||||
export { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
|
||||
export { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js";
|
||||
export { bindMobileDrawerControls } from "./chat-room/mobile-drawer.js";
|
||||
export { bindToolbarControls } from "./chat-room/toolbar.js";
|
||||
export { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
|
||||
export {
|
||||
BLOCKABLE_SYSTEM_SENDERS,
|
||||
@@ -40,6 +41,7 @@ import { bindChatImageUploadControl } from "./chat-room/image-upload.js";
|
||||
import { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
|
||||
import { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js";
|
||||
import { bindMobileDrawerControls } from "./chat-room/mobile-drawer.js";
|
||||
import { bindToolbarControls } from "./chat-room/toolbar.js";
|
||||
import { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
|
||||
import {
|
||||
BLOCKABLE_SYSTEM_SENDERS,
|
||||
@@ -80,6 +82,7 @@ if (typeof window !== "undefined") {
|
||||
loadFriends,
|
||||
openFriendPanel,
|
||||
bindMobileDrawerControls,
|
||||
bindToolbarControls,
|
||||
bindWelcomeMenuControls,
|
||||
CHAT_FONT_SIZE_STORAGE_KEY,
|
||||
restoreChatFontSize,
|
||||
@@ -118,6 +121,7 @@ if (typeof window !== "undefined") {
|
||||
bindChatFontSizeControl();
|
||||
bindChatImageUploadControl();
|
||||
bindFriendPanelControls();
|
||||
bindToolbarControls();
|
||||
bindChatRightPanelControls();
|
||||
bindMobileDrawerControls();
|
||||
bindWelcomeMenuControls();
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// 聊天室竖向工具条事件绑定,替代顶部工具按钮内联 onclick。
|
||||
|
||||
let toolbarEventsBound = false;
|
||||
|
||||
/**
|
||||
* 执行竖向工具条动作。
|
||||
*
|
||||
* @param {string} action 工具条动作
|
||||
* @returns {void}
|
||||
*/
|
||||
function runToolbarAction(action) {
|
||||
// 工具条只做入口分发,具体业务仍由原有全局函数负责。
|
||||
const actions = {
|
||||
shop: () => window.openShopModal?.(),
|
||||
vip: () => window.openVipModal?.(),
|
||||
"save-exp": () => window.saveExp?.(),
|
||||
game: () => window.openGameHall?.(),
|
||||
earn: () => window.dispatchEvent(new CustomEvent("open-earn-panel")),
|
||||
bank: () => window.openBankModal?.(),
|
||||
marriage: () => window.openMarriageStatusModal?.(),
|
||||
friend: () => window.openFriendPanel?.(),
|
||||
avatar: () => window.openAvatarPicker?.(),
|
||||
settings: () => window.openSettingsModal?.(),
|
||||
};
|
||||
|
||||
actions[action]?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认并执行离开聊天室动作。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function confirmToolbarLeaveRoom() {
|
||||
// 离开房间保留二次确认,避免误点竖向工具条直接退出。
|
||||
window.chatDialog
|
||||
?.confirm("确定要离开聊天室吗?", "离开聊天室")
|
||||
.then((ok) => {
|
||||
if (ok) {
|
||||
window.leaveRoom?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定竖向工具条按钮事件。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindToolbarControls() {
|
||||
if (toolbarEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
toolbarEventsBound = true;
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionButton = event.target.closest("[data-toolbar-action]");
|
||||
if (actionButton) {
|
||||
event.preventDefault();
|
||||
|
||||
const action = actionButton.getAttribute("data-toolbar-action") || "";
|
||||
if (action === "leave") {
|
||||
confirmToolbarLeaveRoom();
|
||||
return;
|
||||
}
|
||||
|
||||
runToolbarAction(action);
|
||||
return;
|
||||
}
|
||||
|
||||
const urlButton = event.target.closest("[data-toolbar-url]");
|
||||
if (!urlButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// 后端路由保留在 Blade data 属性中,Vite 模块不硬编码 Laravel URL。
|
||||
const url = urlButton.getAttribute("data-toolbar-url");
|
||||
if (url) {
|
||||
window.open(url, "_blank");
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user