迁移聊天室菜单显示逻辑

This commit is contained in:
2026-04-25 19:33:06 +08:00
parent aecabde44c
commit 7fc40eba32
3 changed files with 164 additions and 43 deletions
+15
View File
@@ -214,14 +214,19 @@ export {
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
closeDailyStatusEditor,
closeFeatureMenu,
isSoundMuted,
loadBlockedSystemSenders,
normalizeChatPreferences,
normalizeDailyStatus,
openDailyStatusEditor,
parseDailyStatusExpiry,
persistBlockedSystemSenders,
setSoundMuted,
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
} from "./chat-room/preferences-status.js";
export { bindChatRightPanelControls } from "./chat-room/right-panel.js";
export {
@@ -400,14 +405,19 @@ import {
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
closeDailyStatusEditor,
closeFeatureMenu,
isSoundMuted,
loadBlockedSystemSenders,
normalizeChatPreferences,
normalizeDailyStatus,
openDailyStatusEditor,
parseDailyStatusExpiry,
persistBlockedSystemSenders,
setSoundMuted,
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
} from "./chat-room/preferences-status.js";
import { bindChatRightPanelControls } from "./chat-room/right-panel.js";
import {
@@ -622,14 +632,19 @@ if (typeof window !== "undefined") {
CHAT_SOUND_MUTED_STORAGE_KEY,
bindBlockMenuControls,
bindSoundMuteControl,
closeDailyStatusEditor,
closeFeatureMenu,
isSoundMuted,
loadBlockedSystemSenders,
normalizeChatPreferences,
normalizeDailyStatus,
openDailyStatusEditor,
parseDailyStatusExpiry,
persistBlockedSystemSenders,
setSoundMuted,
shouldMigrateLocalChatPreferences,
toggleBlockMenu,
toggleFeatureMenu,
bindChatRightPanelControls,
bindRoomStatusControls,
normalizeRoomStatus,
@@ -171,6 +171,117 @@ export function bindSoundMuteControl(onChange) {
});
}
/**
* 设置浮层显示状态。
*
* @param {string} elementId 元素 ID
* @param {boolean} visible 是否显示
* @returns {HTMLElement|null}
*/
function setPanelVisible(elementId, visible) {
const panel = document.getElementById(elementId);
if (panel) {
panel.style.display = visible ? "block" : "none";
}
return panel;
}
/**
* 关闭一组会互斥显示的聊天室浮层。
*
* @param {string[]} panelIds 浮层 ID 列表
* @returns {void}
*/
function closePanels(panelIds) {
panelIds.forEach((panelId) => setPanelVisible(panelId, false));
}
/**
* 关闭功能快捷菜单。
*
* @returns {void}
*/
export function closeFeatureMenu() {
setPanelVisible("feature-menu", false);
}
/**
* 切换功能快捷菜单显示状态,并关闭其他互斥浮层。
*
* @param {Event|null} event 点击事件
* @param {() => void} beforeToggle 切换前同步回调
* @returns {void}
*/
export function toggleFeatureMenu(event = null, beforeToggle = undefined) {
event?.stopPropagation?.();
const menu = document.getElementById("feature-menu");
if (!menu) {
return;
}
closePanels(["welcome-menu", "admin-menu", "block-menu", "daily-status-editor-overlay"]);
if (typeof beforeToggle === "function") {
beforeToggle();
}
menu.style.display = menu.style.display === "none" ? "block" : "none";
}
/**
* 打开每日状态编辑器。
*
* @param {() => void} beforeOpen 打开前同步回调
* @returns {void}
*/
export function openDailyStatusEditor(beforeOpen = undefined) {
closeFeatureMenu();
if (typeof beforeOpen === "function") {
beforeOpen();
}
setPanelVisible("daily-status-editor-overlay", true);
}
/**
* 关闭每日状态编辑器。
*
* @returns {void}
*/
export function closeDailyStatusEditor() {
setPanelVisible("daily-status-editor-overlay", false);
}
/**
* 切换系统播报屏蔽菜单显示状态,并关闭其他互斥浮层。
*
* @param {Event|null} event 点击事件
* @param {() => void} beforeToggle 切换前同步回调
* @returns {void}
*/
export function toggleBlockMenu(event = null, beforeToggle = undefined) {
event?.stopPropagation?.();
const menu = document.getElementById("block-menu");
if (!menu) {
return;
}
closePanels(["welcome-menu", "admin-menu", "feature-menu", "daily-status-editor-overlay"]);
if (typeof beforeToggle === "function") {
beforeToggle();
}
menu.style.display = menu.style.display === "none" ? "block" : "none";
}
/**
* 绑定功能菜单、每日状态编辑与系统播报屏蔽的统一事件代理。
*