diff --git a/src/components/Upload/ImageUpload.vue b/src/components/Upload/ImageUpload.vue index b51f1198..495d398a 100644 --- a/src/components/Upload/ImageUpload.vue +++ b/src/components/Upload/ImageUpload.vue @@ -144,6 +144,14 @@ const props = defineProps({ type: Array, default: () => [], }, + + /** + * 是否同步删除 + */ + isSyncDelete: { + type: Boolean, + default: true, + }, /** * 自定义样式 */ @@ -235,7 +243,19 @@ const handleError = (error: any) => { */ function handleRemove(path: string) { if (path) { - FileAPI.deleteByPath(path).then(() => { + if (props.isSyncDelete) { + FileAPI.deleteByPath(path).then(() => { + valFileList.value = valFileList.value.filter((x) => x !== path); + // 删除成功回调 + if (props.limit === 1) { + emit("update:modelValue", ""); + emit("change", ""); + } else { + emit("update:modelValue", valFileList.value); + emit("change", valFileList.value); + } + }); + } else { valFileList.value = valFileList.value.filter((x) => x !== path); // 删除成功回调 if (props.limit === 1) { @@ -245,7 +265,7 @@ function handleRemove(path: string) { emit("update:modelValue", valFileList.value); emit("change", valFileList.value); } - }); + } } } diff --git a/src/views/demo/upload.vue b/src/views/demo/upload.vue index abb99eef..802cbf88 100644 --- a/src/views/demo/upload.vue +++ b/src/views/demo/upload.vue @@ -112,6 +112,12 @@ const imageUploadArgData = [ default: "[]", desc: "支持的文件类型,默认支持所有图片格式,eg:['png','jpg','jpeg','gif']", }, + { + argsName: "isSyncDelete", + type: "Boolean", + default: "true", + desc: "是否同步删除服务端文件(默认是,如果为否,则只会删除当前上传的图片,已经上传到服务端到图片不会删除)", + }, { argsName: "style", type: "Object",