feat: 卡片调整

This commit is contained in:
2026-06-05 15:19:32 +08:00
parent 9d7a75a307
commit c59342c22c

View File

@@ -7,8 +7,12 @@
<view v-if="title" class="flex flex-row flex-items-start flex-justify-start mb-4"> <view v-if="title" class="flex flex-row flex-items-start flex-justify-start mb-4">
<text class="font-size-16 font-600 text-color-900"> {{ title }}</text> <text class="font-size-16 font-600 text-color-900"> {{ title }}</text>
</view> </view>
<!-- 文字内容最多显示2行 --> <!-- 文字内容根据数据模式限制预览行数 -->
<view v-if="processedContent" class="answer-content font-size-12 font-color-600"> <view
v-if="processedContent"
class="answer-content font-size-12 font-color-600"
:style="answerContentStyle"
>
<ChatMarkdown :text="processedContent" :fontColor="'#94A3B8'" /> <ChatMarkdown :text="processedContent" :fontColor="'#94A3B8'" />
</view> </view>
<!-- 超过2行时显示...提示 --> <!-- 超过2行时显示...提示 -->
@@ -76,10 +80,26 @@ const shouldRenderCard = computed(() => {
return hasStructuredLongTextData.value || !!previewContent.value || !props.finish; return hasStructuredLongTextData.value || !!previewContent.value || !props.finish;
}); });
// 处理文本内容:按行截断以保证预览最多显示两行(更贴近视觉行数) // 处理文本内容:按行截断以保证预览最多显示指定行数(更贴近视觉行数)
// 点击“查看详情”会跳转到完整页面(不受预览截断影响)。 // 点击“查看详情”会跳转到完整页面(不受预览截断影响)。
const PREVIEW_LINES = 2; const STRUCTURED_PREVIEW_LINES = 2;
const PREVIEW_CHAR_LIMIT = 40; // 作为备用,当没有换行但过长时也会截断 const STRUCTURED_PREVIEW_CHAR_LIMIT = 40;
const STRUCTURED_PREVIEW_MAX_HEIGHT = "62px";
const PLAIN_PREVIEW_LINES = 4;
const PLAIN_PREVIEW_CHAR_LIMIT = 100;
const PLAIN_PREVIEW_MAX_HEIGHT = "100px";
const previewLines = computed(() => {
return hasStructuredLongTextData.value ? STRUCTURED_PREVIEW_LINES : PLAIN_PREVIEW_LINES;
});
const previewCharLimit = computed(() => {
return hasStructuredLongTextData.value ? STRUCTURED_PREVIEW_CHAR_LIMIT : PLAIN_PREVIEW_CHAR_LIMIT;
});
const answerContentStyle = computed(() => {
const maxHeight = hasStructuredLongTextData.value
? STRUCTURED_PREVIEW_MAX_HEIGHT
: PLAIN_PREVIEW_MAX_HEIGHT;
return `-webkit-line-clamp: ${previewLines.value}; max-height: ${maxHeight};`;
});
const processedContent = computed(() => { const processedContent = computed(() => {
const content = previewContent.value ? String(previewContent.value) : ""; const content = previewContent.value ? String(previewContent.value) : "";
if (!content) return ""; if (!content) return "";
@@ -87,14 +107,14 @@ const processedContent = computed(() => {
// 按行分割(保留空行) // 按行分割(保留空行)
const lines = content.split(/\r?\n/); const lines = content.split(/\r?\n/);
// 如果行数超过限制,截取前 PREVIEW_LINES 行并添加省略号 // 如果行数超过限制,截取前指定行数并添加省略号
if (lines.length > PREVIEW_LINES) { if (lines.length > previewLines.value) {
return lines.slice(0, PREVIEW_LINES).join("\n") + "..."; return lines.slice(0, previewLines.value).join("\n") + "...";
} }
// 若虽然行数不超过,但总长度仍然很长,做字符级截断作为兜底 // 若虽然行数不超过,但总长度仍然很长,做字符级截断作为兜底
if (content.length > PREVIEW_CHAR_LIMIT) { if (content.length > previewCharLimit.value) {
return content.slice(0, PREVIEW_CHAR_LIMIT) + "..."; return content.slice(0, previewCharLimit.value) + "...";
} }
return content; return content;
@@ -105,8 +125,8 @@ const isOverflow = computed(() => {
const lines = contentStr.split(/\r?\n/); const lines = contentStr.split(/\r?\n/);
return ( return (
(hasStructuredLongTextData.value && hasLongTextExtraSections(props.longTextData)) || (hasStructuredLongTextData.value && hasLongTextExtraSections(props.longTextData)) ||
lines.length > PREVIEW_LINES || lines.length > previewLines.value ||
contentStr.length > PREVIEW_CHAR_LIMIT contentStr.length > previewCharLimit.value
); );
}); });
@@ -186,12 +206,10 @@ const lookDetailAction = () => {
<style scoped lang="scss"> <style scoped lang="scss">
.answer-content { .answer-content {
display: -webkit-box; display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
line-height: 16px; line-height: 16px;
max-height: 62px;
} }
.long-answer-tag { .long-answer-tag {
display: inline-flex; display: inline-flex;