上次图片回答完成

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 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 || ''))

@ -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()

@ -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)
)
)
}

@ -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) {

@ -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) {

Loading…
Cancel
Save