Browse Source

优化deepmate输出时带html的问题

lihuilin/feature-20251024095243-我的
wangyi 3 weeks ago
parent
commit
cfa23e2b9b
  1. 69
      pages/deepMate/deepMate.vue

69
pages/deepMate/deepMate.vue

@ -677,26 +677,48 @@ const simulateBotResponse = async (userMessage) => {
const typeWriter = () => { const typeWriter = () => {
if (index < responseText.length) { if (index < responseText.length) {
const ch = responseText.charAt(index);
let ch = responseText.charAt(index);
let charsToAdd = ch;
let newIndex = index + 1;
// HTML
if (ch === '<') {
//
let tagEndIndex = responseText.indexOf('>', index);
if (tagEndIndex !== -1) {
//
charsToAdd = responseText.substring(index, tagEndIndex + 1);
newIndex = tagEndIndex + 1;
}
}
const current = messages.value[botIndex]; const current = messages.value[botIndex];
// //
messages.value.splice(botIndex, 1, { messages.value.splice(botIndex, 1, {
...current, ...current,
content: current.content + ch,
content: current.content + charsToAdd,
isTyping: true, isTyping: true,
}); });
index++;
index = newIndex;
scrollToBottom(); scrollToBottom();
// //
const baseDelay = 5; // const baseDelay = 5; //
const slowPunct = /[。!?!?;;]/; // const slowPunct = /[。!?!?;;]/; //
const midPunct = /[,、,::]/; // const midPunct = /[,、,::]/; //
const delay = slowPunct.test(ch)
// 使
let delay;
if (charsToAdd.startsWith('<')) {
delay = 1; //
} else {
delay = slowPunct.test(ch)
? 220 ? 220
: midPunct.test(ch) : midPunct.test(ch)
? 120 ? 120
: baseDelay; : baseDelay;
}
setTimeout(typeWriter, delay); setTimeout(typeWriter, delay);
} else { } else {
// //
@ -786,22 +808,33 @@ const simulateBotResponse = async (userMessage) => {
const typeWriter = () => { const typeWriter = () => {
if (index < responseText.length) { if (index < responseText.length) {
const ch = responseText.charAt(index);
let ch = responseText.charAt(index);
let charsToAdd = ch;
let newIndex = index + 1;
let delay = baseDelay;
// HTML
if (ch === '<') {
//
let tagEndIndex = responseText.indexOf('>', index);
if (tagEndIndex !== -1) {
//
charsToAdd = responseText.substring(index, tagEndIndex + 1);
newIndex = tagEndIndex + 1;
delay = 1; //
}
}
const current = messages.value[botIndex]; const current = messages.value[botIndex];
// //
messages.value.splice(botIndex, 1, { messages.value.splice(botIndex, 1, {
...current, ...current,
content: current.content + ch,
content: current.content + charsToAdd,
isTyping: true, isTyping: true,
}); });
index++;
index = newIndex;
scrollToBottom(); scrollToBottom();
const delay = slowPunct.test(ch)
? 220
: midPunct.test(ch)
? 120
: baseDelay;
setTimeout(typeWriter, delay); setTimeout(typeWriter, delay);
} else { } else {
const current = messages.value[botIndex]; const current = messages.value[botIndex];
@ -1769,9 +1802,21 @@ async function itemClick(item) {
} }
.thinking-content { .thinking-content {
transition: transform 1s ease; /* 添加过渡效果 */
transform-origin: top center; /* 设置变换原点 */
padding: 20rpx 30rpx; padding: 20rpx 30rpx;
} }
@keyframes transform {
from {
transform: scaleY(0);
}
to {
transform: scaleY(1);
}
}
.thinking-item { .thinking-item {
display: flex; display: flex;
align-items: center; align-items: center;

Loading…
Cancel
Save