From 29bd59345a456c515f3d20ab64e1e1a5d3202347 Mon Sep 17 00:00:00 2001 From: jiangjunjie Date: Sun, 20 Sep 2026 17:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E5=9B=BE=E7=89=87=E5=9B=9E?= =?UTF-8?q?=E7=AD=94=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat-new.vue | 13 +++++++---- src/components/footer-bar-input.vue | 5 ++++ src/components/history-content.vue | 11 ++++++--- src/components/upload-image.vue | 5 ++-- src/store/app.js | 36 ++++++++++++++++++----------- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/components/chat-new.vue b/src/components/chat-new.vue index b662864..ba0cc63 100644 --- a/src/components/chat-new.vue +++ b/src/components/chat-new.vue @@ -28,12 +28,15 @@ function isImageMessage(item) { const msgType = String(raw.msgType || '') const fromFlag = String(raw.fromFlag || '') const isProtocolImage = - (reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || + (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') || (reqAndResType === '08' && msgType === '02') + const isTextAnswer = Boolean(raw.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage - return item?.message?.[0]?.type === 'image' || - isProtocolImage || - Boolean((item?.imageUrl || item?.imageKey || options.imageUrl || options.imageKey || raw.imgUrl || raw.imgKey || raw.fileKey) && !raw.msgText) + return !isTextAnswer && ( + item?.message?.[0]?.type === 'image' || + isProtocolImage || + Boolean((item?.imageUrl || item?.imageKey || options.imageUrl || options.imageKey || raw.imgUrl || raw.imgKey || raw.fileKey) && !raw.msgText) + ) } function getItemImage(item) { @@ -43,7 +46,7 @@ function getItemImage(item) { const msgType = String(raw.msgType || '') const fromFlag = String(raw.fromFlag || '') const imageMessage = - (reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || + (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') || (reqAndResType === '08' && msgType === '02') const directImage = [item?.imageUrl, options.imageUrl, raw.imgUrl] .map((value) => String(value || '')) diff --git a/src/components/footer-bar-input.vue b/src/components/footer-bar-input.vue index c17bd5b..94a6bbe 100644 --- a/src/components/footer-bar-input.vue +++ b/src/components/footer-bar-input.vue @@ -506,6 +506,11 @@ function handleImageSent(payload) { imageKey: payload.imageKey, uploadStatus: 'success', }) + // liics upload/image returns the follow-up conversation record in res.data. + // Keep it in the chat list after updating the local image bubble. + if (payload.responseData) { + store?.setChatList?.(payload.responseData) + } addFlag.value = true imageBoxShow.value = false scrollTopBody() diff --git a/src/components/history-content.vue b/src/components/history-content.vue index 4f3f2ec..fc0638c 100644 --- a/src/components/history-content.vue +++ b/src/components/history-content.vue @@ -91,10 +91,15 @@ function isImageMessage(item) { const reqAndResType = String(item?.reqAndResType || '') const msgType = String(item?.msgType || '') const fromFlag = String(item?.fromFlag || '') + const isProtocolImage = + (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') || + (reqAndResType === '08' && msgType === '02') + const isTextAnswer = Boolean(item?.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage return ( - (reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || - (reqAndResType === '08' && msgType === '02') || - Boolean(item?.imgUrl || item?.imgKey || item?.fileKey || item?.imageUrl) + !isTextAnswer && ( + isProtocolImage || + Boolean(item?.imgUrl || item?.imgKey || item?.fileKey || item?.imageUrl) + ) ) } diff --git a/src/components/upload-image.vue b/src/components/upload-image.vue index 3a4f2be..418a2c4 100644 --- a/src/components/upload-image.vue +++ b/src/components/upload-image.vue @@ -12,7 +12,7 @@ import { ref, inject, unref } from 'vue' import { showToast } from 'vant' import { compressImage } from '@/utils/CompressImage' -import { upLoadImgHttp } from '@/utils/https' +import { uploadConversationImage } from '@/utils/conversationApi' const emit = defineEmits(['image-selected', 'image-sent', 'image-failed']) @@ -115,7 +115,7 @@ async function handleFileChange(event) { formData.append('msgSource', String(unref(manualService) || '1')) formData.append('timestamp', String(Date.now())) - const response = await upLoadImgHttp('upload/image', formData) + const response = await uploadConversationImage(formData) if (isBusinessFailure(response)) { throw new Error(response?.msg || '图片发送失败') } @@ -125,6 +125,7 @@ async function handleFileChange(event) { localId, imageUrl: data?.imgUrl || data?.url || previewUrl, imageKey: data?.imgKey || data?.fileKey || data?.key || '', + responseData: data, response, }) } catch (error) { diff --git a/src/store/app.js b/src/store/app.js index a258f0b..b9390d6 100644 --- a/src/store/app.js +++ b/src/store/app.js @@ -378,24 +378,27 @@ export const useAppStore = defineStore('app', () => { const reqAndResType = String(payload.reqAndResType || '') const msgType = String(payload.msgType || '') const fromFlag = String(payload.fromFlag || '') - const hasExplicitImageField = Boolean( + const isProtocolImage = + (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') || + (reqAndResType === '08' && msgType === '02') + const isTextAnswer = Boolean(payload.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage + const hasExplicitImageField = !isTextAnswer && Boolean( payload.imgUrl || payload.imgKey || payload.fileKey || (payload.imageUrl && !payload.msgText), ) - const isProtocolImage = - (reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || - (reqAndResType === '08' && msgType === '02') const isImageMessage = - payload.message?.[0]?.type === 'image' || - isProtocolImage || - hasExplicitImageField + !isTextAnswer && ( + payload.message?.[0]?.type === 'image' || + isProtocolImage || + hasExplicitImageField + ) if (!isImageMessage) { return payload.imageUrl || options.imageUrl || '' } - // liics may return an image URL/key in any of these fields. For the - // legacy reqAndResType=2 response, msgText is the image key. + // liics may return an image URL/key in any of these fields. For a + // user upload record (fromFlag=1, reqAndResType=2), msgText is the key. return ( payload.imageUrl || payload.imgUrl || @@ -415,10 +418,11 @@ export const useAppStore = defineStore('app', () => { const msgType = String(payload.msgType || '') const fromFlag = String(payload.fromFlag || '') const isProtocolImage = - (reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || + (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') || (reqAndResType === '08' && msgType === '02') + const isTextAnswer = Boolean(payload.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage return Boolean( - imageUrl && ( + !isTextAnswer && imageUrl && ( payload.message?.[0]?.type === 'image' || isProtocolImage || payload.imgUrl || @@ -643,9 +647,13 @@ export const useAppStore = defineStore('app', () => { // 消息列表 function setChatList(payload) { - const normalizedItem = utils.normalizeMessage(payload) - chatList.value.push(normalizedItem) - pushConversationMessage(normalizedItem, 'bot') + const payloadList = Array.isArray(payload) ? payload : [payload] + payloadList.forEach((item) => { + if (!item) return + const normalizedItem = utils.normalizeMessage(item) + chatList.value.push(normalizedItem) + pushConversationMessage(normalizedItem, 'bot') + }) } function delChatList(index) {