feat: 重构首页对话

This commit is contained in:
duanshuwen
2025-08-10 12:07:58 +08:00
parent 5174e75662
commit c231a72acb
9 changed files with 2104 additions and 636 deletions

View File

@@ -1,7 +1,10 @@
<template>
<view class="container">
<view class="chat-ai">
<ChatMarkdown :text="text"></ChatMarkdown>
<ChatMarkdown
:key="textKey"
:text="processedText"
></ChatMarkdown>
<slot name="content"></slot>
</view>
<slot name="footer"></slot>
@@ -9,15 +12,42 @@
</template>
<script setup>
import { defineProps } from "vue";
import { defineProps, computed, ref, watch } from "vue";
import ChatMarkdown from "./ChatMarkdown.vue";
defineProps({
const props = defineProps({
text: {
type: String,
default: ''
}
})
});
// 用于强制重新渲染的key
const textKey = ref(0);
// 处理文本内容
const processedText = computed(() => {
if (!props.text) {
return '';
}
// 确保文本是字符串类型
const textStr = String(props.text);
// 处理加载状态的文本
if (textStr.includes('加载中') || textStr.includes('...')) {
return textStr;
}
return textStr;
});
// 监听text变化强制重新渲染
watch(() => props.text, (newText, oldText) => {
if (newText !== oldText) {
textKey.value++;
}
}, { immediate: true });
</script>