mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
fix: 智能助手与发布面板加载历史消息后滚到底部
This commit is contained in:
@@ -147,10 +147,33 @@ function stripLegacyToolMarkers(content: string) {
|
|||||||
.replace(/^\s+|\s+$/g, '');
|
.replace(/^\s+|\s+$/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 滚到消息区底部;多拍几次等 ChatItem 异步撑高后再定住 */
|
||||||
function scrollChatToBottom() {
|
function scrollChatToBottom() {
|
||||||
|
const run = () => {
|
||||||
|
const el = messagePaneRef.value;
|
||||||
|
if (!el) return;
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
};
|
||||||
|
void nextTick(() => {
|
||||||
|
run();
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
run();
|
||||||
|
window.setTimeout(run, 50);
|
||||||
|
window.setTimeout(run, 200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 历史消息加载后:短时监听高度变化,避免气泡异步渲染后仍停在顶部 */
|
||||||
|
function scrollChatToBottomAfterLoad() {
|
||||||
|
scrollChatToBottom();
|
||||||
const el = messagePaneRef.value;
|
const el = messagePaneRef.value;
|
||||||
if (!el) return;
|
if (!el || typeof ResizeObserver === 'undefined') return;
|
||||||
el.scrollTop = el.scrollHeight;
|
const ro = new ResizeObserver(() => {
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
});
|
||||||
|
ro.observe(el);
|
||||||
|
window.setTimeout(() => ro.disconnect(), 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultModelKey() {
|
function defaultModelKey() {
|
||||||
@@ -230,8 +253,6 @@ async function loadMessages(threadId: string) {
|
|||||||
messages.value = res.items || [];
|
messages.value = res.items || [];
|
||||||
streamingText.value = '';
|
streamingText.value = '';
|
||||||
syncSelectedFromSession();
|
syncSelectedFromSession();
|
||||||
await nextTick();
|
|
||||||
scrollChatToBottom();
|
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (seq === messagesLoadSeq && !sending.value) {
|
if (seq === messagesLoadSeq && !sending.value) {
|
||||||
message.error(e?.message || '加载消息失败');
|
message.error(e?.message || '加载消息失败');
|
||||||
@@ -239,6 +260,9 @@ async function loadMessages(threadId: string) {
|
|||||||
} finally {
|
} finally {
|
||||||
if (seq === messagesLoadSeq) {
|
if (seq === messagesLoadSeq) {
|
||||||
loadingMessages.value = false;
|
loadingMessages.value = false;
|
||||||
|
if (messages.value.length > 0) {
|
||||||
|
scrollChatToBottomAfterLoad();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-3
@@ -148,10 +148,33 @@ function syncSelectedFromSession() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 滚到消息区底部;多拍几次等 ChatItem 异步撑高后再定住 */
|
||||||
function scrollChatToBottom() {
|
function scrollChatToBottom() {
|
||||||
|
const run = () => {
|
||||||
|
const el = messagePaneRef.value;
|
||||||
|
if (!el) return;
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
};
|
||||||
|
void nextTick(() => {
|
||||||
|
run();
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
run();
|
||||||
|
window.setTimeout(run, 50);
|
||||||
|
window.setTimeout(run, 200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 历史消息加载后:短时监听高度变化,避免气泡异步渲染后仍停在顶部 */
|
||||||
|
function scrollChatToBottomAfterLoad() {
|
||||||
|
scrollChatToBottom();
|
||||||
const el = messagePaneRef.value;
|
const el = messagePaneRef.value;
|
||||||
if (!el) return;
|
if (!el || typeof ResizeObserver === 'undefined') return;
|
||||||
el.scrollTop = el.scrollHeight;
|
const ro = new ResizeObserver(() => {
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
});
|
||||||
|
ro.observe(el);
|
||||||
|
window.setTimeout(() => ro.disconnect(), 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadEnabledModels() {
|
async function loadEnabledModels() {
|
||||||
@@ -196,7 +219,12 @@ async function loadMessages(threadId: string) {
|
|||||||
if (seq !== messagesLoadSeq) return;
|
if (seq !== messagesLoadSeq) return;
|
||||||
message.error(e?.message || '加载消息失败');
|
message.error(e?.message || '加载消息失败');
|
||||||
} finally {
|
} finally {
|
||||||
if (seq === messagesLoadSeq) loadingMessages.value = false;
|
if (seq === messagesLoadSeq) {
|
||||||
|
loadingMessages.value = false;
|
||||||
|
if (messages.value.length > 0) {
|
||||||
|
scrollChatToBottomAfterLoad();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user