fix: remove duplicate welcome message insertion
This commit is contained in:
parent
a47be2c3f6
commit
8d811437e1
@ -575,52 +575,30 @@ const getHistoryMessages = async (page: number = 1) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (page === 1) {
|
if (page === 1) {
|
||||||
// 第一页直接替换消息(如果有历史记录)
|
// 第一页直接替换消息
|
||||||
if (historyMessages.length > 0) {
|
if (historyMessages.length > 0) {
|
||||||
messages.value = historyMessages
|
messages.value = historyMessages
|
||||||
console.log('第一页历史记录已加载,总共', historyMessages.length, '条消息')
|
console.log('第一页历史记录已加载,总共', historyMessages.length, '条消息')
|
||||||
|
|
||||||
// 在有历史记录的情况下,在历史数据后面push一条新的开场白信息
|
|
||||||
nextTick(() => {
|
|
||||||
if (quickQuestionsData.value.length > 0) {
|
|
||||||
const welcomeMessage: Message = {
|
|
||||||
role: 'ai',
|
|
||||||
content: '您好!我是物业客服,有什么可以帮助您的吗?',
|
|
||||||
quickQuestions: quickQuestionsData.value,
|
|
||||||
created_at: new Date().toISOString()
|
|
||||||
}
|
|
||||||
messages.value.push(welcomeMessage)
|
|
||||||
console.log('[Customer] 在有历史记录时,在历史数据后面push新开场白消息')
|
|
||||||
scrollToBottom()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
// 如果没有历史记录,清空消息列表
|
// 如果没有历史记录,清空消息列表
|
||||||
console.log('没有历史记录')
|
console.log('没有历史记录')
|
||||||
messages.value = []
|
messages.value = []
|
||||||
|
}
|
||||||
|
|
||||||
// 没有历史记录时,也展示一条开场白信息
|
// 获取历史记录成功后,不管有没有历史数据,都在历史记录后面push一条新开场白信息
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
if (quickQuestionsData.value.length > 0) {
|
if (quickQuestionsData.value.length > 0) {
|
||||||
const welcomeMessage: Message = {
|
const welcomeMessage: Message = {
|
||||||
role: 'ai',
|
role: 'ai',
|
||||||
content: '您好!我是物业客服,有什么可以帮助您的吗?',
|
content: '您好!我是物业客服,有什么可以帮助您的吗?',
|
||||||
quickQuestions: quickQuestionsData.value,
|
quickQuestions: quickQuestionsData.value,
|
||||||
created_at: new Date().toISOString()
|
created_at: new Date().toISOString()
|
||||||
}
|
|
||||||
messages.value.push(welcomeMessage)
|
|
||||||
console.log('[Customer] 没有历史记录时,展示开场白消息')
|
|
||||||
scrollToBottom()
|
|
||||||
}
|
}
|
||||||
})
|
messages.value.push(welcomeMessage)
|
||||||
}
|
console.log('[Customer] 获取历史记录成功后,在历史记录后面push新开场白消息')
|
||||||
|
scrollToBottom()
|
||||||
// 检查是否应该展示开场白(第一次进入或全部加载完成)
|
}
|
||||||
// 第一页如果hasMore为false,说明是最后一页,需要展示开场白
|
})
|
||||||
const isFirstPageLastPage = !hasMore.value
|
|
||||||
if (checkShouldShowQuickQuestions(isFirstPageLastPage)) {
|
|
||||||
addQuickQuestionsToFirstAIMessage(isFirstPageLastPage)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 加载更多,使用unshift插入到前面
|
// 加载更多,使用unshift插入到前面
|
||||||
if (historyMessages.length > 0) {
|
if (historyMessages.length > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user