|
|
@@ -63,7 +63,12 @@
|
|
|
<span v-if="artifacts.length" class="chat-context-bar__artifact-count">{{ artifacts.length }}</span>
|
|
|
</button>
|
|
|
</div>
|
|
|
- <div ref="messageContainerRef" class="message-area" :class="{ 'message-area--empty': !messages.length }">
|
|
|
+ <div
|
|
|
+ ref="messageContainerRef"
|
|
|
+ class="message-area"
|
|
|
+ :class="{ 'message-area--empty': !messages.length }"
|
|
|
+ @scroll="handleMessageScroll"
|
|
|
+ >
|
|
|
<template v-for="msg in messages" :key="String(msg.id)">
|
|
|
<div v-if="msg.role === 'user'" class="msg-row msg-row--user">
|
|
|
<div class="msg-block msg-block--user">
|
|
|
@@ -343,6 +348,16 @@
|
|
|
|
|
|
<div v-else class="msg-row msg-row--system">{{ msg.content }}</div>
|
|
|
</template>
|
|
|
+ <button
|
|
|
+ v-if="!stickToBottom"
|
|
|
+ type="button"
|
|
|
+ class="scroll-down-btn"
|
|
|
+ title="回到底部"
|
|
|
+ aria-label="回到底部"
|
|
|
+ @click="scrollToBottomSoon(true)"
|
|
|
+ >
|
|
|
+ <Icon icon="i-mdi:chevron-down" />
|
|
|
+ </button>
|
|
|
</div>
|
|
|
|
|
|
<!-- 底栏:输入区(对话前垂直居中,发出第一条消息后回到底部) -->
|
|
|
@@ -1408,6 +1423,10 @@
|
|
|
window.removeEventListener('resize', syncWorkbenchHeight);
|
|
|
workbenchResizeObserver?.disconnect();
|
|
|
workbenchResizeObserver = undefined;
|
|
|
+ if (scrollRaf) {
|
|
|
+ cancelAnimationFrame(scrollRaf);
|
|
|
+ scrollRaf = 0;
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// SSE 连接:fetch + x-token,手动 open;流结束 / 停止时 abort
|
|
|
@@ -1768,16 +1787,57 @@
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- /** 滚动到底部 */
|
|
|
- const scrollToBottom = () => {
|
|
|
- const el = messageContainerRef.value;
|
|
|
- if (el) {
|
|
|
+ /** 贴底跟随阈值(px):距底部不超过该值视为“在底部”,允许自动跟随 */
|
|
|
+ const SCROLL_BOTTOM_THRESHOLD = 80;
|
|
|
+ /** 是否贴底跟随:用户上滚离开底部即暂停自动滚动,滚回底部自动恢复 */
|
|
|
+ const stickToBottom = ref(true);
|
|
|
+ let scrollRaf = 0;
|
|
|
+
|
|
|
+ const isNearBottom = (el: HTMLElement) =>
|
|
|
+ el.scrollHeight - el.scrollTop - el.clientHeight <= SCROLL_BOTTOM_THRESHOLD;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 滚动到底部。流式输出高频触发,用 requestAnimationFrame 合并到每帧一次,避免反复重排导致闪烁。
|
|
|
+ * 默认仅在贴底状态(用户未上滚)时跟随;force=true 强制贴底并恢复跟随(发送消息 / 切换会话)。
|
|
|
+ */
|
|
|
+ const scrollToBottom = (force = false) => {
|
|
|
+ if (force) {
|
|
|
+ stickToBottom.value = true;
|
|
|
+ } else if (!stickToBottom.value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (scrollRaf) {
|
|
|
+ cancelAnimationFrame(scrollRaf);
|
|
|
+ }
|
|
|
+ scrollRaf = requestAnimationFrame(() => {
|
|
|
+ scrollRaf = 0;
|
|
|
+ const el = messageContainerRef.value;
|
|
|
+ if (!el || (!force && !stickToBottom.value)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
el.scrollTop = el.scrollHeight;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const scrollToBottomSoon = (force = false) => {
|
|
|
+ if (force) {
|
|
|
+ stickToBottom.value = true;
|
|
|
}
|
|
|
+ nextTick(() => scrollToBottom(force));
|
|
|
};
|
|
|
|
|
|
- const scrollToBottomSoon = () => {
|
|
|
- nextTick(scrollToBottom);
|
|
|
+ /** 用户滚动:离开底部则暂停跟随并取消待执行的自动滚动;滚回底部则恢复跟随 */
|
|
|
+ const handleMessageScroll = () => {
|
|
|
+ const el = messageContainerRef.value;
|
|
|
+ if (!el) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const near = isNearBottom(el);
|
|
|
+ stickToBottom.value = near;
|
|
|
+ if (!near && scrollRaf) {
|
|
|
+ cancelAnimationFrame(scrollRaf);
|
|
|
+ scrollRaf = 0;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
/** 关闭当前流并复位流式状态 */
|
|
|
@@ -2406,7 +2466,7 @@
|
|
|
});
|
|
|
// 最后一轮的重新生成可用性由后端预检决定(写操作轮次置灰)
|
|
|
void refreshRegenerateCheck();
|
|
|
- scrollToBottomSoon();
|
|
|
+ scrollToBottomSoon(true);
|
|
|
// 产物面板按会话隔离:切换会话时清空旧列表,面板打开则立即加载新会话产物
|
|
|
artifacts.value = [];
|
|
|
artifactError.value = '';
|
|
|
@@ -3214,7 +3274,7 @@
|
|
|
};
|
|
|
messages.value.push(assistant);
|
|
|
currentAssistantKey.value = tempId;
|
|
|
- scrollToBottomSoon();
|
|
|
+ scrollToBottomSoon(true);
|
|
|
|
|
|
streaming.value = true;
|
|
|
streamUrl.value = buildChatStreamUrl(sessionId, userMessageId);
|
|
|
@@ -3420,6 +3480,34 @@
|
|
|
padding: 20px;
|
|
|
}
|
|
|
|
|
|
+ /* 回到底部:用户上滚暂停跟随时出现,sticky 钉在消息区可视右下角 */
|
|
|
+ .scroll-down-btn {
|
|
|
+ position: sticky;
|
|
|
+ bottom: 8px;
|
|
|
+ z-index: 5;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ width: 36px;
|
|
|
+ height: 36px;
|
|
|
+ margin-left: auto;
|
|
|
+ margin-right: 8px;
|
|
|
+ border: 1px solid var(--el-border-color-light, #e4e7ed);
|
|
|
+ border-radius: 50%;
|
|
|
+ background: var(--el-bg-color, #fff);
|
|
|
+ box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
|
|
|
+ color: var(--el-text-color-secondary, #606266);
|
|
|
+ cursor: pointer;
|
|
|
+ transition:
|
|
|
+ background 0.15s,
|
|
|
+ color 0.15s;
|
|
|
+ }
|
|
|
+
|
|
|
+ .scroll-down-btn:hover {
|
|
|
+ background: var(--el-fill-color-light, #f5f7fa);
|
|
|
+ color: var(--el-color-primary, #409eff);
|
|
|
+ }
|
|
|
+
|
|
|
/* 对话前(无消息):隐藏历史区,让输入区浮到聊天区域中间;不再显示空态文案与插图 */
|
|
|
.message-area--empty {
|
|
|
display: none;
|