feat: 生成照片的组件搭建

This commit is contained in:
2026-03-26 15:13:33 +08:00
parent e72531cfb7
commit ba655834b9
9 changed files with 102 additions and 15 deletions

View File

@@ -3,16 +3,16 @@
<!-- 占位撑开 -->
<view class="w-vw"></view>
<view class="flex flex-col p-16 border-box">
<view class="flex flex-row flex-items-center justify-center">
<view class="flex flex-row flex-items-start justify-center">
<uni-icons class="icon-active" type="fire-filled" size="18" color="opacity" />
<text class="font-size-16 font-500 text-color-900 ml-6">{{ title }}</text>
</view>
<!-- 文字内容最多显示3行 -->
<view class="answer-content font-size-12 font-color-600 mt-8">
<ChatMarkdown :text="answerText" />
<ChatMarkdown :key="textKey" :text="processedText" />
</view>
<!-- 超过3行时显示...提示 -->
<view class="fles flex-row mt-8" v-if="isOverflow" @click="lookDetailAction">
<view class="flex flex-row 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>
@@ -22,10 +22,11 @@
</template>
<script setup>
import { ref, defineProps } from 'vue'
import { defineProps, computed, ref, watch } from "vue";
import ChatMarkdown from "../../chat/ChatMarkdown/index.vue";
const isOverflow = ref(true)
const isOverflow = ref(false)
// 直接根据文字长度判断超过约100个字符认为会溢出约3行
const props = defineProps({
@@ -33,18 +34,38 @@ const props = defineProps({
type: String,
default: "",
},
answerText: {
text: {
type: String,
default: "",
}
});
// 简单判断12号字体3行约100个字符
isOverflow.value = props.answerText.length > 100
// 用于强制重新渲染的key
const textKey = ref(0);
const lookDetailAction = () => {
// 处理文本内容(纯计算,不应有副作用)
const processedText = computed(() => {
if (!props.text) return "";
return String(props.text);
});
// 监听 text 变化:更新 textKey 并同步 isOverflow合并为单一响应函数避免冗余
watch(
() => props.text,
(newText, oldText) => {
const textStr = newText ? String(newText) : "";
isOverflow.value = textStr.length > 100;
if (newText !== oldText) {
textKey.value++;
}
},
{ immediate: true }
);
const lookDetailAction = () => {
const message = props.text ? String(props.text) : "";
uni.navigateTo({
url: `/pages/long-answer/index?message=${props.answerText}`,
url: `/pages/long-answer/index?message=${encodeURIComponent(message)}`,
});
}