feat: insert welcome message only when history records exist
This commit is contained in:
parent
b58f046d00
commit
fc46be8385
@ -579,6 +579,20 @@ const getHistoryMessages = async (page: number = 1) => {
|
|||||||
if (historyMessages.length > 0) {
|
if (historyMessages.length > 0) {
|
||||||
messages.value = historyMessages
|
messages.value = historyMessages
|
||||||
console.log('第一页历史记录已加载,总共', historyMessages.length, '条消息')
|
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 {
|
} else {
|
||||||
// 如果没有历史记录,清空消息列表
|
// 如果没有历史记录,清空消息列表
|
||||||
console.log('没有历史记录')
|
console.log('没有历史记录')
|
||||||
@ -1257,25 +1271,9 @@ onLoad(async (op) => {
|
|||||||
quickQuestionsData.value = await getQuickQuestions()
|
quickQuestionsData.value = await getQuickQuestions()
|
||||||
console.log('页面加载时已获取开场白按钮数据:', quickQuestionsData.value.length)
|
console.log('页面加载时已获取开场白按钮数据:', quickQuestionsData.value.length)
|
||||||
|
|
||||||
// 获取历史记录
|
// 获取历史记录(如果有历史记录,会在接口返回成功后自动在最前方插入开场白)
|
||||||
getHistoryMessages(1)
|
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){
|
if(op?.message){
|
||||||
handleQuickAction(op as QuickAction)
|
handleQuickAction(op as QuickAction)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user