diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index fca2819..ccbc1b6 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -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(); diff --git a/resources/js/chat-room/toolbar.js b/resources/js/chat-room/toolbar.js new file mode 100644 index 0000000..a08e3e4 --- /dev/null +++ b/resources/js/chat-room/toolbar.js @@ -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"); + } + }); +} diff --git a/resources/views/chat/partials/layout/toolbar.blade.php b/resources/views/chat/partials/layout/toolbar.blade.php index cc8088c..985f03f 100644 --- a/resources/views/chat/partials/layout/toolbar.blade.php +++ b/resources/views/chat/partials/layout/toolbar.blade.php @@ -15,31 +15,30 @@ {{-- ═══════════ 竖向工具条按钮 ═══════════ --}}
-
商店
-
会员
-
存点
-
娱乐
-
赚钱
-
银行
-
婚姻
-
好友
-
头像
-
设置 +
商店
+
会员
+
存点
+
娱乐
+
赚钱
+
银行
+
婚姻
+
好友
+
头像
+
设置
-
反馈
-
留言
-
规则
+
反馈
+
留言
+
规则
@if ($user->id === 1 || $user->activePosition()->exists()) -
管理
-
排行 +
管理
+
排行
@else -
排行 +
排行
@endif -
+
离开