新增商品团购

This commit is contained in:
gyq
2025-12-18 11:19:28 +08:00
parent a7763ef903
commit e72188a3f2
15 changed files with 1833 additions and 80 deletions

View File

@@ -62,13 +62,15 @@ const props = defineProps({
},
});
// 定义Emits
const emit = defineEmits(['upDataEvent', 'uploadAllSuccess']);
// 定义Emits:新增 uploadStart 事件触发开始上传用于父级loading
const emit = defineEmits(['upDataEvent', 'uploadAllSuccess', 'uploadStart']);
// 响应式数据
const previewVisible = ref(false);
const previewImageIndex = ref(0);
const progress = ref(0);
// 新增:跟踪是否已触发开始上传(避免重复触发)
const isUploadStarted = ref(false);
// 修复defineModel 类型定义
const modelValue = defineModel<string[]>("modelValue", {
type: Array as PropType<string[]>,
@@ -94,6 +96,10 @@ function handleRemove(imageUrl: string) {
}
fileList.value.splice(index, 1);
}
// 若删除后无上传中的文件,重置开始上传状态
if (uploadingFiles.value.size === 0) {
isUploadStarted.value = false;
}
}
/**
@@ -113,6 +119,11 @@ function handleFileChange(file: UploadUserFile, files: UploadUserFile[]) {
status: 'pending',
file
});
// 新增:触发开始上传事件(仅第一次上传时触发,避免重复)
if (!isUploadStarted.value) {
isUploadStarted.value = true;
emit('uploadStart'); // 通知父级开始上传开启loading
}
emit('upDataEvent', true); // 开始上传触发loading
}
// 同步fileList避免重复
@@ -244,6 +255,9 @@ function checkAllUploadCompleted() {
emit('uploadAllSuccess', modelValue.value); // 触发全部完成事件
emit('upDataEvent', false); // 结束loading
// 新增:重置开始上传状态(下次上传可重新触发)
isUploadStarted.value = false;
// 重置上传状态跟踪(关键:避免多次触发)
uploadingFiles.value.clear();
}