feat: 饱和
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, nextTick,onUnmounted } from 'vue'
|
||||
import { ref, watch, nextTick, onUnmounted, onMounted } from 'vue'
|
||||
import { renderMarkdown } from '@/utils/markdown'
|
||||
|
||||
const props = defineProps({
|
||||
@@ -23,9 +23,17 @@ const internalContent = ref('')
|
||||
const renderedContent = ref('')
|
||||
|
||||
let debounceTimer = null
|
||||
// 页面可见性状态
|
||||
const isPageVisible = ref(true)
|
||||
|
||||
// 仅在流式时计算并追加增量
|
||||
function appendStreamingDelta(newFullContent) {
|
||||
// 页面不可见时,跳过更新避免重复片段
|
||||
if (!isPageVisible.value) {
|
||||
console.log('[ChatMessageRenderer] 页面不可见,跳过流式更新')
|
||||
return
|
||||
}
|
||||
|
||||
const prev = internalContent.value
|
||||
if (newFullContent.startsWith(prev)) {
|
||||
// 正常情况:新内容包含旧内容 → 只追加差值
|
||||
@@ -33,7 +41,7 @@ function appendStreamingDelta(newFullContent) {
|
||||
internalContent.value += delta
|
||||
} else {
|
||||
// 异常情况(如后端重发了不连续的内容),直接覆盖防止乱序
|
||||
console.warn('[PromptDisplay] Streaming content out of order, forcing replace')
|
||||
console.warn('[ChatMessageRenderer] Streaming content out of order, forcing replace')
|
||||
internalContent.value = newFullContent
|
||||
}
|
||||
}
|
||||
@@ -80,9 +88,35 @@ watch(() => props.isStreaming, (newVal, oldVal) => {
|
||||
}
|
||||
})
|
||||
|
||||
// 可选:组件卸载时清理定时器
|
||||
// 监听页面可见性变化,避免后台时累积重复片段
|
||||
function handleVisibilityChange() {
|
||||
const wasVisible = isPageVisible.value
|
||||
isPageVisible.value = !document.hidden
|
||||
|
||||
if (!wasVisible && isPageVisible.value) {
|
||||
// 页面从不可见变为可见:立即同步最新内容
|
||||
console.log('[ChatMessageRenderer] 页面重新可见,同步最新内容')
|
||||
// 使用外部传入的最新content进行同步,而不是累积的增量
|
||||
if (props.content) {
|
||||
internalContent.value = props.content
|
||||
updateRendered()
|
||||
}
|
||||
} else if (wasVisible && !isPageVisible.value) {
|
||||
console.log('[ChatMessageRenderer] 页面进入后台')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 初始状态
|
||||
handleVisibilityChange()
|
||||
// 添加监听器
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
if (debounceTimer) clearTimeout(debounceTimer)
|
||||
// 移除监听器
|
||||
document.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -514,7 +514,7 @@ const loadLastTask = async () => {
|
||||
|
||||
// 如果任务是成功状态,显示结果
|
||||
if (task.status === 'SUCCESS' && task.resultVideoUrl) {
|
||||
previewVideoUrl.value = task.resultVideoUrl
|
||||
previewVideoUrl.value = task.videoUrl
|
||||
currentTaskStatus.value = 'SUCCESS'
|
||||
message.success('已自动加载最近一次任务结果')
|
||||
} else if (task.status === 'PROCESSING') {
|
||||
|
||||
Reference in New Issue
Block a user