上次图片回答完成

master
jiangjunjie 2 weeks ago
parent b16c90187c
commit 29bd59345a
  1. 13
      src/components/chat-new.vue
  2. 5
      src/components/footer-bar-input.vue
  3. 11
      src/components/history-content.vue
  4. 5
      src/components/upload-image.vue
  5. 36
      src/store/app.js

@ -28,12 +28,15 @@ function isImageMessage(item) {
const msgType = String(raw.msgType || '') const msgType = String(raw.msgType || '')
const fromFlag = String(raw.fromFlag || '') const fromFlag = String(raw.fromFlag || '')
const isProtocolImage = const isProtocolImage =
(reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') ||
(reqAndResType === '08' && msgType === '02') (reqAndResType === '08' && msgType === '02')
const isTextAnswer = Boolean(raw.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage
return item?.message?.[0]?.type === 'image' || return !isTextAnswer && (
isProtocolImage || item?.message?.[0]?.type === 'image' ||
Boolean((item?.imageUrl || item?.imageKey || options.imageUrl || options.imageKey || raw.imgUrl || raw.imgKey || raw.fileKey) && !raw.msgText) isProtocolImage ||
Boolean((item?.imageUrl || item?.imageKey || options.imageUrl || options.imageKey || raw.imgUrl || raw.imgKey || raw.fileKey) && !raw.msgText)
)
} }
function getItemImage(item) { function getItemImage(item) {
@ -43,7 +46,7 @@ function getItemImage(item) {
const msgType = String(raw.msgType || '') const msgType = String(raw.msgType || '')
const fromFlag = String(raw.fromFlag || '') const fromFlag = String(raw.fromFlag || '')
const imageMessage = const imageMessage =
(reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') ||
(reqAndResType === '08' && msgType === '02') (reqAndResType === '08' && msgType === '02')
const directImage = [item?.imageUrl, options.imageUrl, raw.imgUrl] const directImage = [item?.imageUrl, options.imageUrl, raw.imgUrl]
.map((value) => String(value || '')) .map((value) => String(value || ''))

@ -506,6 +506,11 @@ function handleImageSent(payload) {
imageKey: payload.imageKey, imageKey: payload.imageKey,
uploadStatus: 'success', 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 addFlag.value = true
imageBoxShow.value = false imageBoxShow.value = false
scrollTopBody() scrollTopBody()

@ -91,10 +91,15 @@ function isImageMessage(item) {
const reqAndResType = String(item?.reqAndResType || '') const reqAndResType = String(item?.reqAndResType || '')
const msgType = String(item?.msgType || '') const msgType = String(item?.msgType || '')
const fromFlag = String(item?.fromFlag || '') 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 ( return (
(reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || !isTextAnswer && (
(reqAndResType === '08' && msgType === '02') || isProtocolImage ||
Boolean(item?.imgUrl || item?.imgKey || item?.fileKey || item?.imageUrl) Boolean(item?.imgUrl || item?.imgKey || item?.fileKey || item?.imageUrl)
)
) )
} }

@ -12,7 +12,7 @@
import { ref, inject, unref } from 'vue' import { ref, inject, unref } from 'vue'
import { showToast } from 'vant' import { showToast } from 'vant'
import { compressImage } from '@/utils/CompressImage' import { compressImage } from '@/utils/CompressImage'
import { upLoadImgHttp } from '@/utils/https' import { uploadConversationImage } from '@/utils/conversationApi'
const emit = defineEmits(['image-selected', 'image-sent', 'image-failed']) 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('msgSource', String(unref(manualService) || '1'))
formData.append('timestamp', String(Date.now())) formData.append('timestamp', String(Date.now()))
const response = await upLoadImgHttp('upload/image', formData) const response = await uploadConversationImage(formData)
if (isBusinessFailure(response)) { if (isBusinessFailure(response)) {
throw new Error(response?.msg || '图片发送失败') throw new Error(response?.msg || '图片发送失败')
} }
@ -125,6 +125,7 @@ async function handleFileChange(event) {
localId, localId,
imageUrl: data?.imgUrl || data?.url || previewUrl, imageUrl: data?.imgUrl || data?.url || previewUrl,
imageKey: data?.imgKey || data?.fileKey || data?.key || '', imageKey: data?.imgKey || data?.fileKey || data?.key || '',
responseData: data,
response, response,
}) })
} catch (error) { } catch (error) {

@ -378,24 +378,27 @@ export const useAppStore = defineStore('app', () => {
const reqAndResType = String(payload.reqAndResType || '') const reqAndResType = String(payload.reqAndResType || '')
const msgType = String(payload.msgType || '') const msgType = String(payload.msgType || '')
const fromFlag = String(payload.fromFlag || '') 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.imgUrl || payload.imgKey || payload.fileKey ||
(payload.imageUrl && !payload.msgText), (payload.imageUrl && !payload.msgText),
) )
const isProtocolImage =
(reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) ||
(reqAndResType === '08' && msgType === '02')
const isImageMessage = const isImageMessage =
payload.message?.[0]?.type === 'image' || !isTextAnswer && (
isProtocolImage || payload.message?.[0]?.type === 'image' ||
hasExplicitImageField isProtocolImage ||
hasExplicitImageField
)
if (!isImageMessage) { if (!isImageMessage) {
return payload.imageUrl || options.imageUrl || '' return payload.imageUrl || options.imageUrl || ''
} }
// liics may return an image URL/key in any of these fields. For the // liics may return an image URL/key in any of these fields. For a
// legacy reqAndResType=2 response, msgText is the image key. // user upload record (fromFlag=1, reqAndResType=2), msgText is the key.
return ( return (
payload.imageUrl || payload.imageUrl ||
payload.imgUrl || payload.imgUrl ||
@ -415,10 +418,11 @@ export const useAppStore = defineStore('app', () => {
const msgType = String(payload.msgType || '') const msgType = String(payload.msgType || '')
const fromFlag = String(payload.fromFlag || '') const fromFlag = String(payload.fromFlag || '')
const isProtocolImage = const isProtocolImage =
(reqAndResType === '2' && (fromFlag === '1' || msgType === '02')) || (reqAndResType === '2' && fromFlag === '1' && msgType !== '01') ||
(reqAndResType === '08' && msgType === '02') (reqAndResType === '08' && msgType === '02')
const isTextAnswer = Boolean(payload.msgText) && (msgType === '01' || fromFlag !== '1') && !isProtocolImage
return Boolean( return Boolean(
imageUrl && ( !isTextAnswer && imageUrl && (
payload.message?.[0]?.type === 'image' || payload.message?.[0]?.type === 'image' ||
isProtocolImage || isProtocolImage ||
payload.imgUrl || payload.imgUrl ||
@ -643,9 +647,13 @@ export const useAppStore = defineStore('app', () => {
// 消息列表 // 消息列表
function setChatList(payload) { function setChatList(payload) {
const normalizedItem = utils.normalizeMessage(payload) const payloadList = Array.isArray(payload) ? payload : [payload]
chatList.value.push(normalizedItem) payloadList.forEach((item) => {
pushConversationMessage(normalizedItem, 'bot') if (!item) return
const normalizedItem = utils.normalizeMessage(item)
chatList.value.push(normalizedItem)
pushConversationMessage(normalizedItem, 'bot')
})
} }
function delChatList(index) { function delChatList(index) {

Loading…
Cancel
Save