|
|
|
|
@ -362,7 +362,7 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chatArr.value.push(message) |
|
|
|
|
appendChatArr(message) |
|
|
|
|
isChatLoading.value = messageType === 'user' |
|
|
|
|
return message |
|
|
|
|
} |
|
|
|
|
@ -535,19 +535,27 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function appendChatArr(messages) { |
|
|
|
|
const list = (Array.isArray(messages) ? messages : [messages]).filter(Boolean) |
|
|
|
|
if (!list.length) return |
|
|
|
|
// 始终换新数组引用,避免打包后视图不刷新
|
|
|
|
|
chatArr.value = chatArr.value.concat(list) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function pushConversationMessage(payload, fallbackType = 'bot') { |
|
|
|
|
const payloadList = Array.isArray(payload) ? payload : [payload] |
|
|
|
|
const appended = [] |
|
|
|
|
let lastMessage = null |
|
|
|
|
|
|
|
|
|
payloadList.forEach((item) => { |
|
|
|
|
const message = formatConversationMessage(item, fallbackType) |
|
|
|
|
if (!message) return |
|
|
|
|
|
|
|
|
|
chatArr.value.push(message) |
|
|
|
|
appended.push(message) |
|
|
|
|
isChatLoading.value = message.type === 'user' |
|
|
|
|
lastMessage = message |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
appendChatArr(appended) |
|
|
|
|
if (fallbackType === 'bot') isChatLoading.value = false |
|
|
|
|
return lastMessage |
|
|
|
|
} |
|
|
|
|
@ -588,7 +596,7 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chatArr.value.push(message) |
|
|
|
|
appendChatArr(message) |
|
|
|
|
// 与 addSendMessageList 保持一致:记录当前发送的消息并展示上传 loading
|
|
|
|
|
timestamp.value = messageTimestamp |
|
|
|
|
sendLoading.value = true |
|
|
|
|
@ -751,17 +759,18 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
|
|
|
|
|
// 兼容接口偶发包一层 data
|
|
|
|
|
const rawItem = |
|
|
|
|
typeof entry === 'object' && entry.data && !entry.msgText && !entry.answer |
|
|
|
|
typeof entry === 'object' && |
|
|
|
|
entry.data && |
|
|
|
|
typeof entry.data === 'object' && |
|
|
|
|
!entry.msgText && |
|
|
|
|
!entry.answer && |
|
|
|
|
entry.fromFlag === undefined |
|
|
|
|
? entry.data |
|
|
|
|
: entry |
|
|
|
|
|
|
|
|
|
const normalizedItem = |
|
|
|
|
typeof rawItem === 'object' |
|
|
|
|
? utils.normalizeMessage({ ...rawItem }) |
|
|
|
|
: { msgText: String(rawItem), fromFlag: '2', reqAndResType: '01', msgType: '01' } |
|
|
|
|
|
|
|
|
|
// 兜底:保证 bot 文本消息有可渲染字段,避免 format 后被丢弃
|
|
|
|
|
if (typeof normalizedItem === 'object') { |
|
|
|
|
let normalizedItem |
|
|
|
|
if (typeof rawItem === 'object') { |
|
|
|
|
normalizedItem = utils.normalizeMessage({ ...rawItem }) |
|
|
|
|
if (!normalizedItem.msgText) { |
|
|
|
|
normalizedItem.msgText = |
|
|
|
|
normalizedItem.answer || |
|
|
|
|
@ -770,24 +779,40 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
normalizedItem.text || |
|
|
|
|
'' |
|
|
|
|
} |
|
|
|
|
if (normalizedItem.fromFlag === undefined || normalizedItem.fromFlag === null || normalizedItem.fromFlag === '') { |
|
|
|
|
if ( |
|
|
|
|
normalizedItem.fromFlag === undefined || |
|
|
|
|
normalizedItem.fromFlag === null || |
|
|
|
|
normalizedItem.fromFlag === '' |
|
|
|
|
) { |
|
|
|
|
normalizedItem.fromFlag = '2' |
|
|
|
|
} |
|
|
|
|
if (!normalizedItem.reqAndResType) normalizedItem.reqAndResType = '01' |
|
|
|
|
if (!normalizedItem.msgType) normalizedItem.msgType = '01' |
|
|
|
|
if (!normalizedItem.timestamp) normalizedItem.timestamp = Date.now() |
|
|
|
|
} else { |
|
|
|
|
normalizedItem = { |
|
|
|
|
msgText: String(rawItem), |
|
|
|
|
fromFlag: '2', |
|
|
|
|
reqAndResType: '01', |
|
|
|
|
msgType: '01', |
|
|
|
|
timestamp: Date.now(), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chatList.value.push(normalizedItem) |
|
|
|
|
|
|
|
|
|
let message = formatConversationMessage(normalizedItem, 'bot') |
|
|
|
|
if (!message && normalizedItem?.msgText) { |
|
|
|
|
if (!message) { |
|
|
|
|
const fallbackText = getConversationMessageText(normalizedItem) |
|
|
|
|
if (!fallbackText && !getConversationImageSource(normalizedItem)) return |
|
|
|
|
message = formatConversationMessage( |
|
|
|
|
{ |
|
|
|
|
...normalizedItem, |
|
|
|
|
...(typeof normalizedItem === 'object' ? normalizedItem : {}), |
|
|
|
|
msgText: fallbackText || String(normalizedItem?.msgText || ''), |
|
|
|
|
fromFlag: '2', |
|
|
|
|
reqAndResType: '01', |
|
|
|
|
msgType: '01', |
|
|
|
|
reqAndResType: normalizedItem?.reqAndResType || '01', |
|
|
|
|
msgType: normalizedItem?.msgType || '01', |
|
|
|
|
timestamp: normalizedItem?.timestamp || Date.now(), |
|
|
|
|
}, |
|
|
|
|
'bot', |
|
|
|
|
) |
|
|
|
|
@ -796,8 +821,7 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (appended.length) { |
|
|
|
|
// 用新数组赋值,避免个别打包环境下 push 对视图更新不稳定
|
|
|
|
|
chatArr.value = chatArr.value.concat(appended) |
|
|
|
|
appendChatArr(appended) |
|
|
|
|
isChatLoading.value = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -813,8 +837,8 @@ export const useAppStore = defineStore('app', () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function delAllChatList() { |
|
|
|
|
chatList.value.splice(0, chatList.value.length) |
|
|
|
|
chatArr.value.splice(0, chatArr.value.length) |
|
|
|
|
chatList.value = [] |
|
|
|
|
chatArr.value = [] |
|
|
|
|
isChatLoading.value = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|