From 80aae1902daeea0ba1fd751b367a8d2f6eb583dd Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Wed, 15 Jan 2025 17:04:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E8=BF=9C=E7=A8=8B=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上传图片增加参数是否同步删除服务端文件 --- src/components/Upload/ImageUpload.vue | 24 ++++++++++++++++++++++-- src/views/demo/upload.vue | 6 ++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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",