refactor: ♻️ 上传图片增加参数是否远程删除

上传图片增加参数是否同步删除服务端文件
This commit is contained in:
Theo
2025-01-15 17:04:14 +08:00
parent 3413d3fcbe
commit 80aae1902d
2 changed files with 28 additions and 2 deletions

View File

@@ -144,6 +144,14 @@ const props = defineProps({
type: Array<string>, type: Array<string>,
default: () => [], default: () => [],
}, },
/**
* 是否同步删除
*/
isSyncDelete: {
type: Boolean,
default: true,
},
/** /**
* 自定义样式 * 自定义样式
*/ */
@@ -235,7 +243,19 @@ const handleError = (error: any) => {
*/ */
function handleRemove(path: string) { function handleRemove(path: string) {
if (path) { 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); valFileList.value = valFileList.value.filter((x) => x !== path);
// 删除成功回调 // 删除成功回调
if (props.limit === 1) { if (props.limit === 1) {
@@ -245,7 +265,7 @@ function handleRemove(path: string) {
emit("update:modelValue", valFileList.value); emit("update:modelValue", valFileList.value);
emit("change", valFileList.value); emit("change", valFileList.value);
} }
}); }
} }
} }

View File

@@ -112,6 +112,12 @@ const imageUploadArgData = [
default: "[]", default: "[]",
desc: "支持的文件类型,默认支持所有图片格式,eg:['png','jpg','jpeg','gif']", desc: "支持的文件类型,默认支持所有图片格式,eg:['png','jpg','jpeg','gif']",
}, },
{
argsName: "isSyncDelete",
type: "Boolean",
default: "true",
desc: "是否同步删除服务端文件(默认是,如果为否,则只会删除当前上传的图片,已经上传到服务端到图片不会删除)",
},
{ {
argsName: "style", argsName: "style",
type: "Object", type: "Object",