committed by
trae-solo-agent
co-authored by
Kimi-K3.1-Pro noreply@moonshot.cn
parent
1181d598b4
commit
df96cb3b07
+22
-6
@@ -8,9 +8,9 @@ Page({
|
||||
isTyping: false,
|
||||
scrollToMessage: '',
|
||||
quickQuestions: [
|
||||
'陪诊服务的流程是什么?',
|
||||
'如何预约陪诊服务?',
|
||||
'陪诊服务收费标准?'
|
||||
{ id: '陪诊服务的流程是什么?', text: '陪诊服务的流程是什么?' },
|
||||
{ id: '如何预约陪诊服务?', text: '如何预约陪诊服务?' },
|
||||
{ id: '陪诊服务收费标准?', text: '陪诊服务收费标准?' }
|
||||
]
|
||||
},
|
||||
|
||||
@@ -46,13 +46,27 @@ Page({
|
||||
try {
|
||||
const res = await API.resource.getAiQuickQuestions()
|
||||
if (res.code === 0) {
|
||||
this.setData({ quickQuestions: res.data.aiquick_questions })
|
||||
this.setData({
|
||||
quickQuestions: this.createQuestionItems(res.data.aiquick_questions)
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取陪诊服务问题失败', err)
|
||||
}
|
||||
},
|
||||
|
||||
// 问题文本即稳定键;重复问题只保留一项,避免服务端清单造成重复 key。
|
||||
createQuestionItems(questions) {
|
||||
const seen = new Set()
|
||||
return (Array.isArray(questions) ? questions : []).reduce((list, item) => {
|
||||
const text = typeof item === 'string' ? item : item?.text
|
||||
if (!text || seen.has(text)) return list
|
||||
seen.add(text)
|
||||
list.push({ id: text, text })
|
||||
return list
|
||||
}, [])
|
||||
},
|
||||
|
||||
initSocketListeners() {
|
||||
const socket = getApp().initChatSocket()
|
||||
|
||||
@@ -190,6 +204,9 @@ Page({
|
||||
.filter(item => item && ['ai', 'user', 'system'].includes(item.type))
|
||||
.map((item) => {
|
||||
const message = { ...item }
|
||||
if (message.contentType === 'questions') {
|
||||
message.content = this.createQuestionItems(message.content)
|
||||
}
|
||||
if (!message.id || usedIds.has(message.id)) {
|
||||
message.id = this.createMessageId()
|
||||
}
|
||||
@@ -248,7 +265,7 @@ Page({
|
||||
id: this.createMessageId(),
|
||||
type: 'ai',
|
||||
contentType: 'questions',
|
||||
content: questions,
|
||||
content: this.createQuestionItems(questions.map(item => item.text)),
|
||||
time: this.formatTime(new Date())
|
||||
}
|
||||
|
||||
@@ -324,7 +341,6 @@ Page({
|
||||
content,
|
||||
id: requestId,
|
||||
token,
|
||||
appId: app.globalData.appId,
|
||||
ts: new Date().toISOString()
|
||||
})
|
||||
return true
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
<view
|
||||
class="quick-item"
|
||||
wx:for="{{quickQuestions}}"
|
||||
wx:key="index"
|
||||
wx:key="id"
|
||||
bindtap="onQuickQuestionTap"
|
||||
data-question="{{item}}"
|
||||
data-question="{{item.text}}"
|
||||
>
|
||||
<text>{{item}}</text>
|
||||
<text>{{item.text}}</text>
|
||||
<t-icon name="chevron-right" size="26rpx" color="#9B4508" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -74,11 +74,11 @@
|
||||
class="quick-item"
|
||||
wx:for="{{item.content}}"
|
||||
wx:for-item="question"
|
||||
wx:key="*this"
|
||||
wx:key="id"
|
||||
bindtap="onQuickQuestionTap"
|
||||
data-question="{{question}}"
|
||||
data-question="{{question.text}}"
|
||||
>
|
||||
<text>{{question}}</text>
|
||||
<text>{{question.text}}</text>
|
||||
<t-icon name="chevron-right" size="26rpx" color="#9B4508" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user