迁移聊天室滚屏状态入口
This commit is contained in:
@@ -249,7 +249,7 @@ export {
|
|||||||
updateRedPacketClaimsUI,
|
updateRedPacketClaimsUI,
|
||||||
} from "./chat-room/red-packet-panel.js";
|
} from "./chat-room/red-packet-panel.js";
|
||||||
export { createMessageQueue } from "./chat-room/message-queue.js";
|
export { createMessageQueue } from "./chat-room/message-queue.js";
|
||||||
export { isExpiredChatImageMessage, localClearScreen } from "./chat-room/message-utils.js";
|
export { isExpiredChatImageMessage, localClearScreen, syncAutoScrollControls, toggleAutoScroll } from "./chat-room/message-utils.js";
|
||||||
|
|
||||||
import { escapeHtml, escapeHtmlWithLineBreaks, normalizeSafeChatUrl } from "./chat-room/html.js";
|
import { escapeHtml, escapeHtmlWithLineBreaks, normalizeSafeChatUrl } from "./chat-room/html.js";
|
||||||
import { bindAppointmentAnnouncementControls, showAppointmentBanner } from "./chat-room/appointment-announcement.js";
|
import { bindAppointmentAnnouncementControls, showAppointmentBanner } from "./chat-room/appointment-announcement.js";
|
||||||
@@ -442,7 +442,7 @@ import {
|
|||||||
updateRedPacketClaimsUI,
|
updateRedPacketClaimsUI,
|
||||||
} from "./chat-room/red-packet-panel.js";
|
} from "./chat-room/red-packet-panel.js";
|
||||||
import { createMessageQueue } from "./chat-room/message-queue.js";
|
import { createMessageQueue } from "./chat-room/message-queue.js";
|
||||||
import { isExpiredChatImageMessage, localClearScreen } from "./chat-room/message-utils.js";
|
import { isExpiredChatImageMessage, localClearScreen, syncAutoScrollControls, toggleAutoScroll } from "./chat-room/message-utils.js";
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
// 保留聚合入口,给新迁移模块、测试和仍在 Blade 内的存量脚本统一读取工具。
|
// 保留聚合入口,给新迁移模块、测试和仍在 Blade 内的存量脚本统一读取工具。
|
||||||
@@ -670,6 +670,8 @@ if (typeof window !== "undefined") {
|
|||||||
createMessageQueue,
|
createMessageQueue,
|
||||||
isExpiredChatImageMessage,
|
isExpiredChatImageMessage,
|
||||||
localClearScreen,
|
localClearScreen,
|
||||||
|
syncAutoScrollControls,
|
||||||
|
toggleAutoScroll,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 直接挂载只服务暂未迁移的 Blade 调用点;新代码优先通过模块导入或 ChatRoomTools 复用。
|
// 直接挂载只服务暂未迁移的 Blade 调用点;新代码优先通过模块导入或 ChatRoomTools 复用。
|
||||||
@@ -678,6 +680,7 @@ if (typeof window !== "undefined") {
|
|||||||
window.isExpiredChatImageMessage = isExpiredChatImageMessage;
|
window.isExpiredChatImageMessage = isExpiredChatImageMessage;
|
||||||
window.localClearScreen = localClearScreen;
|
window.localClearScreen = localClearScreen;
|
||||||
window.normalizeSafeChatUrl = normalizeSafeChatUrl;
|
window.normalizeSafeChatUrl = normalizeSafeChatUrl;
|
||||||
|
window.syncAutoScrollControls = syncAutoScrollControls;
|
||||||
window.openChatImageLightbox = openChatImageLightbox;
|
window.openChatImageLightbox = openChatImageLightbox;
|
||||||
window.closeFriendPanel = closeFriendPanel;
|
window.closeFriendPanel = closeFriendPanel;
|
||||||
window.friendSearch = friendSearch;
|
window.friendSearch = friendSearch;
|
||||||
|
|||||||
@@ -78,3 +78,42 @@ export function localClearScreen(roomId = window.chatContext?.roomId, maxMessage
|
|||||||
publicPane.scrollTop = publicPane.scrollHeight;
|
publicPane.scrollTop = publicPane.scrollHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步自动滚屏复选框与状态文字。
|
||||||
|
*
|
||||||
|
* @param {boolean} enabled 是否开启自动滚屏
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export function syncAutoScrollControls(enabled) {
|
||||||
|
const checkbox = document.getElementById("auto_scroll");
|
||||||
|
const status = document.getElementById("scroll-status");
|
||||||
|
|
||||||
|
if (checkbox) {
|
||||||
|
checkbox.checked = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
status.textContent = enabled ? "开" : "关";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换自动滚屏状态。
|
||||||
|
* 真实状态仍由 Blade 大脚本闭包保存,这里通过 getter/setter 桥接,避免 Vite 模块持有第二份状态。
|
||||||
|
*
|
||||||
|
* @param {() => boolean} getCurrent 读取当前状态
|
||||||
|
* @param {(enabled:boolean) => void} setCurrent 写回当前状态
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function toggleAutoScroll(getCurrent, setCurrent) {
|
||||||
|
const nextEnabled = !Boolean(typeof getCurrent === "function" ? getCurrent() : true);
|
||||||
|
|
||||||
|
if (typeof setCurrent === "function") {
|
||||||
|
setCurrent(nextEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncAutoScrollControls(nextEnabled);
|
||||||
|
|
||||||
|
return nextEnabled;
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,10 @@
|
|||||||
let autoScroll = true;
|
let autoScroll = true;
|
||||||
// 给已迁移到 Vite 的模块只读判断自动滚动状态,避免直接依赖 Blade 脚本作用域。
|
// 给已迁移到 Vite 的模块只读判断自动滚动状态,避免直接依赖 Blade 脚本作用域。
|
||||||
window.isChatAutoScrollEnabled = () => autoScroll;
|
window.isChatAutoScrollEnabled = () => autoScroll;
|
||||||
|
// 给 Vite 模块显式写回自动滚屏状态,避免模块和 Blade 闭包各自维护一份状态。
|
||||||
|
window.setChatAutoScrollEnabled = (enabled) => {
|
||||||
|
autoScroll = Boolean(enabled);
|
||||||
|
};
|
||||||
let userBadgeRotationTick = 0;
|
let userBadgeRotationTick = 0;
|
||||||
let userListRenderTimer = null;
|
let userListRenderTimer = null;
|
||||||
let _maxMsgId = 0; // 记录当前收到的最大消息 ID
|
let _maxMsgId = 0; // 记录当前收到的最大消息 ID
|
||||||
@@ -1757,7 +1761,7 @@
|
|||||||
const autoScrollEl = document.getElementById('auto_scroll');
|
const autoScrollEl = document.getElementById('auto_scroll');
|
||||||
if (autoScrollEl) {
|
if (autoScrollEl) {
|
||||||
autoScrollEl.addEventListener('change', function() {
|
autoScrollEl.addEventListener('change', function() {
|
||||||
autoScroll = this.checked;
|
window.setChatAutoScrollEnabled(this.checked);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3648,6 +3652,14 @@
|
|||||||
|
|
||||||
// ── 滚屏开关 ─────────────────────────────────────
|
// ── 滚屏开关 ─────────────────────────────────────
|
||||||
function toggleAutoScroll() {
|
function toggleAutoScroll() {
|
||||||
|
if (window.ChatRoomTools?.toggleAutoScroll) {
|
||||||
|
window.ChatRoomTools.toggleAutoScroll(
|
||||||
|
() => autoScroll,
|
||||||
|
(enabled) => window.setChatAutoScrollEnabled(enabled)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
autoScroll = !autoScroll;
|
autoScroll = !autoScroll;
|
||||||
const cb = document.getElementById('auto_scroll');
|
const cb = document.getElementById('auto_scroll');
|
||||||
if (cb) cb.checked = autoScroll;
|
if (cb) cb.checked = autoScroll;
|
||||||
|
|||||||
Reference in New Issue
Block a user