feat: lock dialog and disable close actions during image upload to prevent orphan files and state errors

This commit is contained in:
DXC
2026-03-13 09:23:35 +08:00
parent 96122ed671
commit 9b290506da
4 changed files with 42 additions and 11 deletions

View File

@ -275,7 +275,9 @@
width="min(1000px, 95vw)"
top="5vh"
destroy-on-close
:close-on-click-modal="false"
:close-on-click-modal="!isUploading"
:close-on-press-escape="!isUploading"
:show-close="!isUploading"
class="stylish-dialog compact-layout"
>
<div class="dialog-scroll-container">
@ -562,8 +564,8 @@
<template #footer>
<div class="dialog-footer">
<el-button @click="visible = false" size="large">取消</el-button>
<el-button type="primary" :loading="submitting" @click="submitForm" size="large" class="confirm-btn">
<el-button @click="visible = false" size="large" :disabled="isUploading">取消</el-button>
<el-button type="primary" :loading="submitting || isUploading" @click="submitForm" size="large" class="confirm-btn">
{{ dialogStatus === 'create' ? '提交并打印' : '保存修改' }}
</el-button>
</div>
@ -666,6 +668,10 @@ const dialogStatus = ref<'create' | 'update'>('create')
const tableData = ref([])
const total = ref(0)
const formRef = ref()
// 上传锁定状态
const isUploading = ref(false)
const queryParams = reactive({ page: 1, pageSize: 50, keyword: '', searchField: 'all', sku: '', category: '', material_type: '', statuses: ['在库', '借库'], company: '', orderByColumn: '', isAsc: '', advancedFilters: [] })
const categoryOptions = ref<string[]>([])
const typeOptions = ref<string[]>([])
@ -1269,12 +1275,14 @@ const beforeAvatarUpload = (rawFile: any) => {
const customUpload = async (options: any, targetField: 'arrival_photo' | 'quality_report_link') => {
const { file, onSuccess, onError } = options
const formData = new FormData(); formData.append('file', file)
isUploading.value = true
try {
const res: any = await uploadFile(formData)
if (res.code === 200) {
const newUrl = res.data.url; form[targetField].push(newUrl); ElMessage.success('上传成功'); onSuccess(res)
} else { ElMessage.error(res.msg || '上传失败'); onError(new Error(res.msg)) }
} catch (e) { ElMessage.error('网络错误'); onError(e) }
finally { isUploading.value = false }
}
const handleRemoveImage = async (uploadFile: any, targetField: 'arrival_photo' | 'quality_report_link') => {
try {