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

This commit is contained in:
2026-10-12 17:12:19 +08:00
parent ca7d179d1b
commit 5039968316
58 changed files with 3551 additions and 905 deletions
+12 -6
View File
@@ -21,7 +21,7 @@
</view>
<!-- 对话消息 -->
<view v-for="(msg, i) in messages" :key="i" :id="'msg' + i" :class="['msg-item', msg.role]">
<view class="bubble" v-html="msg.content"></view>
<view class="bubble" v-html="formatContent(msg.content)"></view>
</view>
<view v-if="loading" class="msg-item assistant" id="msg-loading">
<view class="bubble typing">思考中...</view>
@@ -50,6 +50,14 @@
};
},
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;
},
toggle() {
this.visible = !this.visible;
if (this.visible) {
@@ -73,12 +81,10 @@
try {
const res = await this.vk.callFunction({
url: 'client/ai/pub/chat',
data: {
message: msg,
conversation_id: this.conversationId
}
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',