This commit is contained in:
2026-04-14 13:37:39 +08:00
parent c4dd44ae89
commit 2334588b26
11 changed files with 342 additions and 85 deletions
@@ -53,6 +53,11 @@ const prop = defineProps({
type: String,
default: "/api/files/upload",
},
/** 初始已有文件 [{ hash, name, ... }] */
initialFiles: {
type: Array,
default: () => [],
},
});
// 初始化 Dropzone
@@ -201,11 +206,43 @@ function return_files() {
return files;
}
// 加载初始已有文件(编辑场景)
function loadInitialFiles() {
if (!dropzoneInstance || !prop.initialFiles?.length) return;
prop.initialFiles.forEach((f) => {
// 构造 Dropzone 期望的 mock file 对象
const mockFile = {
name: f.Name || f.name || f.hash,
size: f.Size || f.size || 0,
type: f.Mime || f.mime || "image/jpeg",
status: Dropzone.SUCCESS,
accepted: true,
upload: { uuid: f.Hash || f.hash || f.Sha256 },
previewElement: null,
_removeLink: null,
};
// 通知 Dropzone "这是一个已存在的文件,不要上传"
dropzoneInstance.emit("addedfile", mockFile);
dropzoneInstance.emit("complete", mockFile);
dropzoneInstance.files.push(mockFile);
// 填充上传结果字段
const url = `/api/files/get/${f.Hash || f.hash || f.Sha256}`;
files.push({
uuid: f.Hash || f.hash || f.Sha256,
hash: f.Hash || f.hash || f.Sha256,
get_url: url,
download_url: `/api/files/download/${f.Hash || f.hash || f.Sha256}`,
file_name: f.Name || f.name || "",
file_size: f.Size || f.size || 0,
is_upload: true,
});
});
}
// 组件挂载时初始化
onMounted(() => {
initDropzone();
//console.log(lightbox)
loadInitialFiles();
});
// 组件卸载时销毁