u
This commit is contained in:
1 parent
f9eaacf02a
commit
69eda8b8ad
27 files changed
+2797
-616
No files matched your search
@@ -27,8 +27,15 @@ import {
|
||||
getAliyunFileBlob,
|
||||
getFileExtension,
|
||||
uploadFile,
|
||||
buildPublicUrl,
|
||||
} from "@/utils/file";
|
||||
import { loadDataApi, saveObjectKeysApi, deleteFileApi } from "@/request/api";
|
||||
import {
|
||||
loadDataApi,
|
||||
insertFileApi,
|
||||
saveObjectApi,
|
||||
deleteFileApi,
|
||||
uploadCommonFileApi,
|
||||
} from "@/request/api";
|
||||
|
||||
const props = defineProps({
|
||||
father: {
|
||||
@@ -158,7 +165,7 @@ async function handleConfirmUpdate() {
|
||||
];
|
||||
|
||||
try {
|
||||
const response = await saveObjectKeysApi(requestData);
|
||||
const response = await saveObjectApi(requestData);
|
||||
|
||||
if (response.success) {
|
||||
ElMessage.success("文件名更新成功");
|
||||
@@ -239,8 +246,15 @@ async function loadFiles() {
|
||||
const res = await loadDataApi("bf_file", searchCondition, "mx_xh");
|
||||
|
||||
if (res.success) {
|
||||
fileList.value = res.data;
|
||||
oldFileList.value = JSON.parse(JSON.stringify(res.data));
|
||||
let datas = res.data.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
mx_mapfilename: buildPublicUrl(item.mx_mapfilename),
|
||||
};
|
||||
});
|
||||
|
||||
fileList.value = datas;
|
||||
oldFileList.value = JSON.parse(JSON.stringify(datas));
|
||||
loading.value = false;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -588,45 +602,69 @@ async function deleteFiles(files) {
|
||||
});
|
||||
}
|
||||
|
||||
// 保存
|
||||
// 保存
|
||||
async function handleSave() {
|
||||
loading.value = true;
|
||||
loadingTip.value = "正在保存中 . . .";
|
||||
|
||||
const { insertdata, updatedata, deletedata, hasChanges } = compareAndClassifyData(
|
||||
fileList.value,
|
||||
oldFileList.value,
|
||||
"subid",
|
||||
["_content", "_status", "checked"],
|
||||
);
|
||||
try {
|
||||
const { insertdata, updatedata, deletedata, hasChanges } = compareAndClassifyData(
|
||||
fileList.value,
|
||||
oldFileList.value,
|
||||
"subid",
|
||||
["_content", "_status", "checked"],
|
||||
);
|
||||
|
||||
// 处理新增的文件
|
||||
for (const item of insertdata) {
|
||||
try {
|
||||
await uploadFile(
|
||||
item._content,
|
||||
item.mx_filename,
|
||||
item.mx_fileext,
|
||||
item.mx_filesize,
|
||||
item.mx_xh,
|
||||
props.moduleId,
|
||||
props.father,
|
||||
);
|
||||
console.log(`文件 ${item.mx_filename} 上传成功`);
|
||||
item._status = "";
|
||||
} catch (error) {
|
||||
console.error(`文件 ${item.mx_filename} 上传失败:`, error);
|
||||
ElMessage.error(`文件 ${item.mx_filename} 上传失败,请重试`);
|
||||
// 没有变化直接结束
|
||||
if (!hasChanges) {
|
||||
ElMessage.info("没有数据变更");
|
||||
return;
|
||||
}
|
||||
|
||||
const mxXh =
|
||||
fileList.value.length > 0 ? Math.max(...fileList.value.map((item) => item.mx_xh ?? 0)) : 2;
|
||||
|
||||
// 处理新增
|
||||
for (const item of insertdata) {
|
||||
try {
|
||||
const uploadRes = await uploadCommonFileApi(item.mx_mapfilename, {
|
||||
fileName: item.mx_filename,
|
||||
});
|
||||
|
||||
if (!uploadRes.success) {
|
||||
throw new Error("上传失败");
|
||||
}
|
||||
|
||||
const insertRes = await insertFileApi({
|
||||
father: props.father,
|
||||
mx_xh: mxXh + 1,
|
||||
mx_filename: item.mx_filename,
|
||||
mx_filesize: item.mx_filesize,
|
||||
mx_fileext: item.mx_fileext,
|
||||
mx_mapfilename: uploadRes.data.path,
|
||||
mx_moduleid: props.moduleId,
|
||||
mx_cate_id: props.cateId,
|
||||
});
|
||||
|
||||
if (!insertRes.success) {
|
||||
throw new Error("入库失败");
|
||||
}
|
||||
|
||||
console.log(`文件 ${item.mx_filename} 上传成功`);
|
||||
item._status = "";
|
||||
} catch (error) {
|
||||
console.error(`文件 ${item.mx_filename} 处理失败:`, error);
|
||||
ElMessage.error(`文件 ${item.mx_filename} 上传失败,请重试`);
|
||||
}
|
||||
}
|
||||
|
||||
ElMessage.success("保存成功");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
ElMessage.success("上传成功");
|
||||
|
||||
loading.value = false;
|
||||
|
||||
loadFiles();
|
||||
}
|
||||
|
||||
async function handleDownloadZip() {
|
||||
if (checkedFiles.value.length < 2) {
|
||||
ElMessage.warning("打包文件数量不得少于2");
|
||||
|
||||
Reference in new issue
Block a user