fix: AI客服回复内容格式化(换行+加粗+列表)

This commit is contained in:
2026-10-12 17:12:16 +08:00
parent 6a3e44b247
commit f3a1b01a10
8 changed files with 6528 additions and 222 deletions
+14 -5
View File
@@ -25,7 +25,7 @@
<view v-for="(msg, i) in messages" :key="i" :id="'msg' + i"
:class="['msg-item', msg.role === 'user' ? 'right' : 'left']">
<view v-if="msg.role !== 'user'" class="avatar">🤖</view>
<view class="bubble" v-html="msg.content"></view>
<view class="bubble" v-html="formatContent(msg.content)"></view>
</view>
<!-- 加载中 -->
@@ -61,6 +61,14 @@ export default {
this.msgListHeight = sys.windowHeight - 88 - 56;
},
methods: {
formatContent(text) {
if (!text) return '';
let html = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
html = html.replace(/^[\-\•]\s+(.+)$/gm, '<div style="padding-left:12px;">• $1</div>');
html = html.replace(/^(\d+)\.\s+(.+)$/gm, '<div style="padding-left:12px;">$1. $2</div>');
html = html.replace(/\n/g, '<br>');
return html;
},
quickSend(text) {
this.inputText = text;
this.send();
@@ -74,10 +82,11 @@ export default {
this.scrollToBottom();
try {
const res = await this.vk.callFunction({
url: 'client/ai/pub/chat',
data: { message: msg, conversation_id: this.conversationId }
});
const res = await this.vk.callFunction({
url: 'client/ai/pub/chat',
data: { message: msg, bot_id: '7680345813062680618' }
});
if (res.data.conversation_id) this.conversationId = res.data.conversation_id;
this.messages.push({ role: 'assistant', content: res.data.answer });
} catch (e) {