feat:优化回答消息的返回方式与交互样式调整
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<!-- 占位撑开 -->
|
||||
<view class="w-vw"></view>
|
||||
<view class="flex flex-col p-16 border-box">
|
||||
<view class="flex flex-row flex-items-start justify-center">
|
||||
<view class="flex flex-row flex-items-start flex-justify-start">
|
||||
<uni-icons class="icon-active" type="fire-filled" size="18" color="opacity" />
|
||||
<text class="font-size-16 font-500 text-color-900 ml-6">游玩划重点</text>
|
||||
</view>
|
||||
@@ -12,7 +12,7 @@
|
||||
<ChatMarkdown :key="textKey" :text="processedText" />
|
||||
</view>
|
||||
<!-- 超过3行时显示...提示 -->
|
||||
<view class="flex flex-row mt-8" v-if="isOverflow" @click="lookDetailAction">
|
||||
<view class="flex flex-row flex-items-center mt-8" v-if="isOverflow" @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>
|
||||
@@ -43,10 +43,28 @@ const props = defineProps({
|
||||
// 用于强制重新渲染的key
|
||||
const textKey = ref(0);
|
||||
|
||||
// 处理文本内容(纯计算,不应有副作用)
|
||||
// 处理文本内容:按行截断以保证预览最多显示三行(更贴近视觉行数)
|
||||
// 点击“查看详情”会跳转到完整页面(不受预览截断影响)。
|
||||
const PREVIEW_LINES = 3;
|
||||
const PREVIEW_CHAR_LIMIT = 100; // 作为备用,当没有换行但过长时也会截断
|
||||
const processedText = computed(() => {
|
||||
if (!props.text) return "";
|
||||
return String(props.text);
|
||||
const txt = props.text ? String(props.text) : "";
|
||||
if (!txt) return "";
|
||||
|
||||
// 按行分割(保留空行)
|
||||
const lines = txt.split(/\r?\n/);
|
||||
|
||||
// 如果行数超过限制,截取前 PREVIEW_LINES 行并添加省略号
|
||||
if (lines.length > PREVIEW_LINES) {
|
||||
return lines.slice(0, PREVIEW_LINES).join("\n") + "...";
|
||||
}
|
||||
|
||||
// 若虽然行数不超过,但总长度仍然很长,做字符级截断作为兜底
|
||||
if (txt.length > PREVIEW_CHAR_LIMIT) {
|
||||
return txt.slice(0, PREVIEW_CHAR_LIMIT) + "...";
|
||||
}
|
||||
|
||||
return txt;
|
||||
});
|
||||
|
||||
// 监听 text 变化:更新 textKey 并同步 isOverflow(合并为单一响应函数,避免冗余)
|
||||
@@ -54,7 +72,8 @@ watch(
|
||||
() => props.text,
|
||||
(newText, oldText) => {
|
||||
const textStr = newText ? String(newText) : "";
|
||||
isOverflow.value = textStr.length > 100;
|
||||
const lines = textStr.split(/\r?\n/);
|
||||
isOverflow.value = lines.length > PREVIEW_LINES || textStr.length > PREVIEW_CHAR_LIMIT;
|
||||
if (newText !== oldText) {
|
||||
textKey.value++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user