feat: insert welcome message only when history records exist

This commit is contained in:
Your Name 2026-04-01 14:45:57 +08:00
parent b58f046d00
commit fc46be8385

View File

@ -579,6 +579,20 @@ const getHistoryMessages = async (page: number = 1) => {
if (historyMessages.length > 0) {
messages.value = historyMessages
console.log('第一页历史记录已加载,总共', historyMessages.length, '条消息')
//
nextTick(() => {
if (quickQuestionsData.value.length > 0) {
const welcomeMessage: Message = {
role: 'ai',
content: '您好!我是物业客服,有什么可以帮助您的吗?',
quickQuestions: quickQuestionsData.value,
created_at: new Date().toISOString()
}
messages.value.unshift(welcomeMessage)
console.log('[Customer] 在有历史记录时,在最前方插入新开场白消息')
}
})
} else {
//
console.log('没有历史记录')
@ -1257,25 +1271,9 @@ onLoad(async (op) => {
quickQuestionsData.value = await getQuickQuestions()
console.log('页面加载时已获取开场白按钮数据:', quickQuestionsData.value.length)
//
//
getHistoryMessages(1)
//
if (quickQuestionsData.value.length > 0) {
const welcomeMessage: Message = {
role: 'ai',
content: '您好!我是物业客服,有什么可以帮助您的吗?',
quickQuestions: quickQuestionsData.value,
created_at: new Date().toISOString()
}
//
nextTick(() => {
messages.value.unshift(welcomeMessage)
console.log('[Customer] 每次进入页面都在最前方插入新开场白消息')
scrollToBottom()
})
}
if(op?.message){
handleQuickAction(op as QuickAction)
}