Files
chatroom/resources/js/chat-room/toolbar.js
T
pllx 62371a7c64 新增:聊天室反馈模态弹窗(仿留言弹窗样式)
点击工具栏「反馈」按钮弹出反馈弹窗,不再跳转新页面。

新建文件:
- feedback-modal.blade.php — 蓝白渐变标题栏、类型筛选Tabs、反馈卡片列表(展开详情/评论)、提交反馈表单、滚动懒加载
- feedback.js — AJAX加载/提交/点赞/评论/删除,滚动懒加载,乐观UI更新

修改文件:
- toolbar.blade.php — 反馈按钮 data-toolbar-url → data-toolbar-action
- toolbar.js — 添加 feedback 动作
- chat-room.js — 静态导入 feedback 模块
- frame.blade.php — 引入反馈弹窗
- routes/web.php — 新增 feedback.data 路由
- FeedbackController.php — 新增 data() 方法
2026-04-28 10:29:14 +08:00

106 lines
3.0 KiB
JavaScript

// 聊天室竖向工具条事件绑定,替代顶部工具按钮内联 onclick。
let toolbarEventsBound = false;
/**
* 执行竖向工具条动作。
*
* @param {string} action 工具条动作
* @returns {void}
*/
export 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?.(),
guestbook: () => window.openGuestbookModal?.(),
feedback: () => window.openFeedbackModal?.(),
};
actions[action]?.();
}
/**
* 执行功能菜单快捷入口,并在打开目标面板前关闭功能菜单。
*
* @param {string} action 快捷入口动作
* @returns {void}
*/
export function runFeatureShortcut(action) {
// 功能菜单和竖向工具条共享同一组业务入口,只额外关闭菜单浮层。
window.closeFeatureMenu?.();
runToolbarAction(action);
}
/**
* 确认并执行离开聊天室动作。
*
* @returns {void}
*/
function confirmToolbarLeaveRoom() {
// 离开房间保留二次确认,避免误点竖向工具条直接退出。
window.chatDialog
?.confirm("确定要离开聊天室吗?", "离开聊天室")
.then((ok) => {
if (ok) {
window.leaveRoom?.();
}
});
}
/**
* 绑定竖向工具条按钮事件。
*
* @returns {void}
*/
// ── 挂载到 window ──
window.runFeatureShortcut = runFeatureShortcut;
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");
}
});
}