Skip to content

Commit 2c697e8

Browse files
authored
fix: Incomplete file upload resulted in Exception: 'file_id' error when answering (#4078)
1 parent d2c7167 commit 2c697e8

File tree

1 file changed

+15
-10
lines changed
  • ui/src/components/ai-chat/component/chat-input-operate

1 file changed

+15
-10
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
@TouchEnd="TouchEnd"
164164
:time="recorderTime"
165165
:start="recorderStatus === 'START'"
166-
:disabled="loading"
166+
:disabled="localLoading"
167167
/>
168168
<el-input
169169
v-else
@@ -199,7 +199,7 @@
199199
</span>
200200
<span class="flex align-center" v-else>
201201
<el-button
202-
:disabled="loading"
202+
:disabled="localLoading"
203203
text
204204
@click="startRecording"
205205
v-if="recorderStatus === 'STOP'"
@@ -252,7 +252,7 @@
252252
}}:{{ getAcceptList().replace(/\./g, '').replace(/,/g, '、').toUpperCase() }}
253253
</div>
254254
</template>
255-
<el-button text :disabled="checkMaxFilesLimit() || loading" class="mt-4">
255+
<el-button text :disabled="checkMaxFilesLimit() || localLoading" class="mt-4">
256256
<el-icon><Paperclip /></el-icon>
257257
</el-button>
258258
</el-tooltip>
@@ -268,11 +268,11 @@
268268
<el-button
269269
text
270270
class="sent-button"
271-
:disabled="isDisabledChat || loading"
271+
:disabled="isDisabledChat || localLoading"
272272
@click="sendChatHandle"
273273
>
274-
<img v-show="isDisabledChat || loading" src="@/assets/icon_send.svg" alt="" />
275-
<SendIcon v-show="!isDisabledChat && !loading" />
274+
<img v-show="isDisabledChat || localLoading" src="@/assets/icon_send.svg" alt="" />
275+
<SendIcon v-show="!isDisabledChat && !localLoading" />
276276
</el-button>
277277
</template>
278278
</div>
@@ -339,9 +339,13 @@ const chatId_context = computed({
339339
emit('update:chatId', v)
340340
}
341341
})
342+
const uploadLoading = computed(() => {
343+
return Object.values(filePromisionDict.value).length > 0
344+
})
345+
342346
const localLoading = computed({
343347
get: () => {
344-
return props.loading
348+
return props.loading || uploadLoading.value
345349
},
346350
set: (v) => {
347351
emit('update:loading', v)
@@ -393,7 +397,7 @@ const checkMaxFilesLimit = () => {
393397
uploadOtherList.value.length
394398
)
395399
}
396-
400+
const filePromisionDict: any = ref<any>({})
397401
const uploadFile = async (file: any, fileList: any) => {
398402
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
399403
// 单次上传文件数量限制
@@ -414,7 +418,7 @@ const uploadFile = async (file: any, fileList: any) => {
414418
fileList.splice(0, fileList.length)
415419
return
416420
}
417-
421+
filePromisionDict.value[file.uid] = false
418422
const formData = new FormData()
419423
formData.append('file', file.raw, file.name)
420424
//
@@ -454,6 +458,7 @@ const uploadFile = async (file: any, fileList: any) => {
454458
fileList.splice(0, fileList.length)
455459
file.url = response.data[0].url
456460
file.file_id = response.data[0].file_id
461+
delete filePromisionDict.value[file.uid]
457462
})
458463
}
459464
// 粘贴处理
@@ -798,7 +803,7 @@ function sendChatHandle(event?: any) {
798803
if (!event?.ctrlKey && !event?.shiftKey && !event?.altKey && !event?.metaKey) {
799804
// 如果没有按下组合键,则会阻止默认事件
800805
event?.preventDefault()
801-
if (!isDisabledChat.value && !props.loading && !event?.isComposing) {
806+
if (!isDisabledChat.value && !localLoading.value && !event?.isComposing) {
802807
if (
803808
inputValue.value.trim() ||
804809
uploadImageList.value.length > 0 ||

0 commit comments

Comments
 (0)