60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
|
|
// 聊天室管理菜单事件绑定,替代 input-bar 中的管理类内联 onclick。
|
||
|
|
|
||
|
|
let adminMenuEventsBound = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 绑定管理菜单、管理动作与全屏特效选择事件。
|
||
|
|
*
|
||
|
|
* @returns {void}
|
||
|
|
*/
|
||
|
|
export function bindAdminMenuControls() {
|
||
|
|
if (adminMenuEventsBound || typeof document === "undefined") {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
adminMenuEventsBound = true;
|
||
|
|
document.addEventListener("click", (event) => {
|
||
|
|
if (!(event.target instanceof Element)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const menuToggle = event.target.closest("[data-chat-admin-menu-toggle]");
|
||
|
|
if (menuToggle) {
|
||
|
|
event.preventDefault();
|
||
|
|
window.toggleAdminMenu?.(event);
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const adminAction = event.target.closest("[data-chat-admin-action]");
|
||
|
|
if (adminAction) {
|
||
|
|
event.preventDefault();
|
||
|
|
|
||
|
|
// 管理菜单只负责入口分发,权限校验和实际动作仍由后端与原有全局函数负责。
|
||
|
|
const action = adminAction.getAttribute("data-chat-admin-action") || "";
|
||
|
|
if (action && typeof window.runAdminAction === "function") {
|
||
|
|
window.runAdminAction(action);
|
||
|
|
}
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const effectButton = event.target.closest("[data-chat-admin-effect]");
|
||
|
|
if (effectButton) {
|
||
|
|
event.preventDefault();
|
||
|
|
|
||
|
|
// 特效按钮只触发管理员发起请求,实际播放仍由 chat:effect 广播和 EffectManager 处理。
|
||
|
|
const effect = effectButton.getAttribute("data-chat-admin-effect") || "";
|
||
|
|
if (effect && typeof window.selectEffect === "function") {
|
||
|
|
window.selectEffect(effect);
|
||
|
|
}
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (event.target.closest("[data-chat-admin-menu]")) {
|
||
|
|
event.stopPropagation();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|