feat: 兼容老的长文本

This commit is contained in:
2026-06-05 15:01:15 +08:00
parent be175591cc
commit 9d7a75a307
3 changed files with 55 additions and 36 deletions

View File

@@ -8,25 +8,29 @@
<!-- 滚动区域 -->
<scroll-view class="flex-full overflow-hidden chat-scroll" scroll-y :scroll-into-view="scrollIntoViewId" scroll-with-animation @scroll="onScroll" @touchstart="onTouchStart" @touchend="onTouchEnd" @touchcancel="onTouchEnd">
<view class="flex flex-col pt-12 px-16 pb-24 border-box gap-8">
<view v-if="headerSections.title || headerSections.tag" class="long-answer-header">
<view v-if="headerSections.title" class="long-answer-title">
{{ headerSections.title.contentValue }}
<template v-if="hasStructuredLongTextData">
<view v-if="headerSections.title || headerSections.tag" class="long-answer-header">
<view v-if="headerSections.title" class="long-answer-title">
{{ headerSections.title.contentValue }}
</view>
<view v-if="headerSections.tag" class="long-answer-tag" :style="longAnswerTagStyle">
{{ headerSections.tag.contentValue }}
</view>
</view>
<view v-if="headerSections.tag" class="long-answer-tag" :style="longAnswerTagStyle">
{{ headerSections.tag.contentValue }}
</view>
</view>
<template v-for="section in contentSections" :key="section.contentKey">
<ParsedValueView
v-if="shouldUseParsedValueView(section)"
:field-key="section.contentKey"
:value="section.parsedValue !== null ? section.parsedValue : section.contentValue"
/>
<template v-for="section in contentSections" :key="section.contentKey">
<ParsedValueView
v-if="shouldUseParsedValueView(section)"
:field-key="section.contentKey"
:value="section.parsedValue !== null ? section.parsedValue : section.contentValue"
/>
<ChatMarkdown v-else :text="section.contentValue" />
<ChatMarkdown v-else :text="section.contentValue" />
</template>
</template>
<ChatMarkdown v-else-if="answerText" :text="answerText" />
<!-- 底部锚点必须存在 -->
<view id="bottom-anchor"></view>
</view>
@@ -64,6 +68,10 @@ const longAnswerTagStyle = computed(() => buildTagToneStyle(longAnswerTagColor.v
let unsubscribe = null;
const HIDDEN_DETAIL_SECTION_KEYS = [];
const hasStructuredLongTextData = computed(() => {
const values = longTextData.value?.values;
return !!(values && Object.keys(values).length > 0);
});
const shouldUseParsedValueView = (section) => {
return (
@@ -75,19 +83,14 @@ const shouldUseParsedValueView = (section) => {
};
const renderSections = computed(() => {
const data = longTextData.value;
if (data && data.values) {
return getLongTextSections(data)
.filter((section) => section.contentValue)
.map((section) => ({
...section,
fromLongTextData: true,
}));
}
if (!hasStructuredLongTextData.value) return [];
return answerText.value
? [{ contentKey: "content", contentValue: answerText.value }]
: [];
return getLongTextSections(longTextData.value)
.filter((section) => section.contentValue)
.map((section) => ({
...section,
fromLongTextData: true,
}));
});
const headerSections = computed(() => {

View File

@@ -74,15 +74,16 @@
"
>
<AnswerComponent
v-if="isLongTextCard(item.componentName)"
v-if="isLongTextCard(item.componentName) && (item.componentName === CompName.longTextCard)"
:content="item.componentMsg || ''"
:longTextData="item.longTextData"
:finish="item.finish"
/>
<!-- <LongTextGuideCardPreview
<LongTextGuideCardPreview
v-if="isLongTextCard(item.componentName) && (item.componentName !== CompName.longTextCard)"
:componentName="item.componentName"
/> -->
/>
<QuickBookingComponent
v-if="
@@ -798,6 +799,7 @@ const handleWebSocketMessage = (data) => {
messageId: currentSessionMessageId,
replyMessageId: data.replyMessageId || "",
componentName: "",
componentMsg: "",
longTextData: null,
finish: false,
};
@@ -820,6 +822,7 @@ const handleWebSocketMessage = (data) => {
messageId: currentSessionMessageId,
replyMessageId: data.replyMessageId || "",
componentName: "",
componentMsg: "",
longTextData: null,
finish: false,
};
@@ -1213,6 +1216,7 @@ const sendChat = async (message, isInstruct = false) => {
messageId: currentSessionMessageId,
replyMessageId: "",
componentName: "",
componentMsg: "",
longTextData: null,
finish: false,
};