feat: 长文本在详情页面中的消息流式输出
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<text class="font-size-12 font-400 font-color-600">正在生成</text>
|
||||
<DotLoading />
|
||||
</view>
|
||||
<view v-if="isOverflow && finish" class="flex flex-row flex-items-center mt-8" @click="lookDetailAction">
|
||||
<view v-if="isOverflow" class="flex flex-row flex-items-center mt-8" @click="lookDetailAction">
|
||||
<text class="font-size-12 font-400 theme-color-500 mr-4">查看详情</text>
|
||||
<uni-icons class="icon-active" type="right" size="14" color="opacity"></uni-icons>
|
||||
</view>
|
||||
@@ -27,10 +27,11 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { defineProps, computed, ref, watch } from "vue";
|
||||
import { defineProps, computed, ref, watch, onBeforeUnmount } from "vue";
|
||||
|
||||
import ChatMarkdown from "../../chat/ChatMarkdown/index.vue";
|
||||
import DotLoading from "../../loading/DotLoading.vue";
|
||||
import StreamManager from '@/utils/StreamManager.js';
|
||||
|
||||
const isOverflow = ref(false)
|
||||
|
||||
@@ -93,9 +94,37 @@ watch(
|
||||
|
||||
const lookDetailAction = () => {
|
||||
const message = props.text ? String(props.text) : "";
|
||||
uni.navigateTo({
|
||||
url: `/pages/long-answer/index?message=${encodeURIComponent(message)}`,
|
||||
// 使用 StreamManager 以 streamId 转发当前及后续流式更新,详情页通过 streamId 订阅
|
||||
const streamId = `stream_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;
|
||||
StreamManager.openStream(streamId, message, !!props.finish);
|
||||
|
||||
// 将当前组件后续 props.text/props.finish 的更新转发到 StreamManager
|
||||
const stopForward = watch(
|
||||
() => props.text,
|
||||
(v) => {
|
||||
StreamManager.updateStream(streamId, v ? String(v) : "", !!props.finish);
|
||||
}
|
||||
);
|
||||
const stopFinishWatcher = watch(
|
||||
() => props.finish,
|
||||
(f) => {
|
||||
StreamManager.updateStream(streamId, props.text ? String(props.text) : "", !!f);
|
||||
if (f) {
|
||||
stopForward();
|
||||
stopFinishWatcher();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 清理:组件卸载时停止转发(若仍存在)
|
||||
onBeforeUnmount(() => {
|
||||
try {
|
||||
stopForward && stopForward();
|
||||
stopFinishWatcher && stopFinishWatcher();
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
uni.navigateTo({ url: `/pages/long-answer/index?streamId=${encodeURIComponent(streamId)}` });
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user