u
This commit is contained in:
1 parent
b7f50f3ccb
commit
11bcef03e1
8 files changed
+437
-537
No files matched your search
@@ -8,7 +8,11 @@ import {
|
||||
} from "@/request/api";
|
||||
import { getAlignByFormat, formatValueByFormat } from "@/utils/columns";
|
||||
import { updateViewTableColumns } from "@/utils/columns";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { downloadZip } from "@/utils/file";
|
||||
import { formatToDate } from "@/utils/time";
|
||||
import { ElLoading, ElMessage } from "element-plus";
|
||||
import { saveAs } from "file-saver";
|
||||
import JSZip from "jszip";
|
||||
|
||||
const tableRef = ref();
|
||||
|
||||
@@ -49,7 +53,9 @@ const viewName = "v_container";
|
||||
const showPreview = ref(false);
|
||||
const previewIndex = ref(-1);
|
||||
const previewImageList = computed(() => {
|
||||
return tableData.value.map((item) => item.b_container_img).filter((img) => img);
|
||||
return tableData.value
|
||||
.map((item) => item.b_container_img)
|
||||
.filter((img) => img);
|
||||
});
|
||||
|
||||
const currentRow = ref({});
|
||||
@@ -172,38 +178,53 @@ async function deleteRows(rows = []) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保 deleteIds 数组中的值是数字,防止 SQL 注入
|
||||
const safeDeleteIds = deleteIds.map((id) => Number(id));
|
||||
|
||||
// 使用安全的 SQL 查询
|
||||
const fileRes = await loadDataApi("bf_file", `father IN (${safeDeleteIds.join(",")})`, "", [
|
||||
"subid",
|
||||
]);
|
||||
|
||||
if (!fileRes.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const file of fileRes.data) {
|
||||
await deleteFileApi(file.subid);
|
||||
}
|
||||
|
||||
const requestData = [
|
||||
{
|
||||
tableName: "b_container",
|
||||
keyField: "b_id",
|
||||
inserts: [],
|
||||
updates: [],
|
||||
deletes: deleteIds.map((id) => ({ b_id: id })),
|
||||
},
|
||||
];
|
||||
|
||||
await saveObjectApi(requestData).then((res) => {
|
||||
if (res.success) {
|
||||
ElMessage.success("删除成功");
|
||||
loadTableDatas();
|
||||
}
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: "正在删除中...",
|
||||
});
|
||||
|
||||
try {
|
||||
// 确保 deleteIds 数组中的值是数字,防止 SQL 注入
|
||||
const safeDeleteIds = deleteIds.map((id) => Number(id));
|
||||
|
||||
// 使用安全的 SQL 查询
|
||||
const fileRes = await loadDataApi(
|
||||
"bf_file",
|
||||
`father IN (${safeDeleteIds.join(",")})`,
|
||||
"",
|
||||
["subid"],
|
||||
);
|
||||
|
||||
if (!fileRes.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const file of fileRes.data) {
|
||||
await deleteFileApi(file.subid);
|
||||
}
|
||||
|
||||
const requestData = [
|
||||
{
|
||||
tableName: "b_container",
|
||||
keyField: "b_id",
|
||||
inserts: [],
|
||||
updates: [],
|
||||
deletes: deleteIds.map((id) => ({ b_id: id })),
|
||||
},
|
||||
];
|
||||
|
||||
await saveObjectApi(requestData).then((res) => {
|
||||
if (res.success) {
|
||||
ElMessage.success("删除成功");
|
||||
loadTableDatas();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
ElMessage.error("删除失败");
|
||||
console.log(err);
|
||||
} finally {
|
||||
loading.close();
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
@@ -241,9 +262,167 @@ function handleFileShow(data) {
|
||||
showFile.value = true;
|
||||
}
|
||||
|
||||
function handleDownloadOne(data) {
|
||||
console.log(data);
|
||||
// 获取
|
||||
async function handleDownloadOne(data) {
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: "正在下载并打包文件,请稍候...",
|
||||
});
|
||||
|
||||
try {
|
||||
const fileRes = await loadDataApi(
|
||||
"bf_file",
|
||||
`father = '${data.b_id}'`,
|
||||
"mx_xh asc",
|
||||
);
|
||||
|
||||
if (!fileRes.success) {
|
||||
ElMessage.error("获取附件失败");
|
||||
return;
|
||||
}
|
||||
|
||||
const downloadFiles = fileRes.data.map((item, index) => ({
|
||||
mx_filename: buildFileName(
|
||||
data.b_container_no,
|
||||
index + 1,
|
||||
item.mx_filename,
|
||||
),
|
||||
mx_mapfilename: item.mx_mapfilename,
|
||||
}));
|
||||
|
||||
await downloadZip(
|
||||
downloadFiles,
|
||||
`${data.b_container_no}_${formatToDate(data.b_inputdatetime)}`,
|
||||
);
|
||||
|
||||
ElMessage.success("下载完成");
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
ElMessage.error("下载失败");
|
||||
} finally {
|
||||
loading.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function runWithLimit(tasks, limit = 3) {
|
||||
const results = [];
|
||||
const executing = [];
|
||||
|
||||
for (const task of tasks) {
|
||||
const p = task().then((res) => {
|
||||
executing.splice(executing.indexOf(p), 1);
|
||||
return res;
|
||||
});
|
||||
|
||||
results.push(p);
|
||||
executing.push(p);
|
||||
|
||||
if (executing.length >= limit) {
|
||||
await Promise.race(executing);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(results);
|
||||
}
|
||||
|
||||
async function handleDownloadBatch() {
|
||||
const $table = tableRef.value;
|
||||
if (!$table) return;
|
||||
|
||||
const records = $table.getCheckboxRecords();
|
||||
|
||||
if (records.length === 0) {
|
||||
ElMessage.warning("请选择需要下载的数据");
|
||||
return;
|
||||
}
|
||||
|
||||
const loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: "正在下载并打包文件,请稍候...",
|
||||
});
|
||||
|
||||
const zip = new JSZip();
|
||||
|
||||
try {
|
||||
let total = 0;
|
||||
let finished = 0;
|
||||
|
||||
// 👉 先统计总文件数(用于进度)
|
||||
for (const item of records) {
|
||||
const fileRes = await loadDataApi(
|
||||
"bf_file",
|
||||
`father = '${item.b_id}'`,
|
||||
"",
|
||||
);
|
||||
if (fileRes.success) {
|
||||
total += (fileRes.data || []).length;
|
||||
}
|
||||
}
|
||||
|
||||
// 👉 正式处理
|
||||
for (const item of records) {
|
||||
const folderName = `${item.b_container_no}_${formatToDate(
|
||||
item.b_inputdatetime,
|
||||
)}`;
|
||||
|
||||
const folder = zip.folder(folderName);
|
||||
|
||||
const fileRes = await loadDataApi(
|
||||
"bf_file",
|
||||
`father = '${item.b_id}'`,
|
||||
"mx_xh asc",
|
||||
);
|
||||
|
||||
if (!fileRes.success) {
|
||||
ElMessage.error("获取附件失败");
|
||||
continue;
|
||||
}
|
||||
|
||||
const files = fileRes.data || [];
|
||||
|
||||
const tasks = files.map((file, index) => async () => {
|
||||
const fileUrl = file.mx_mapfilename;
|
||||
|
||||
try {
|
||||
const res = await fetch(fileUrl);
|
||||
const blob = await res.blob();
|
||||
|
||||
const fileName =
|
||||
buildFileName(item.b_container_no, index + 1, file.mx_filename) ||
|
||||
"未命名文件";
|
||||
|
||||
folder.file(fileName, blob);
|
||||
} catch (e) {
|
||||
ElMessage.error(item.b_container_no + "箱号部分图片下载失败");
|
||||
console.error("下载失败:", fileUrl);
|
||||
} finally {
|
||||
finished++;
|
||||
loading.setText(`正在下载 ${finished}/${total} 个文件...`);
|
||||
}
|
||||
});
|
||||
|
||||
// 控制并发数
|
||||
await runWithLimit(tasks, 3);
|
||||
}
|
||||
|
||||
// 👉 生成 zip
|
||||
loading.setText("正在生成压缩包...");
|
||||
const content = await zip.generateAsync({ type: "blob" });
|
||||
|
||||
saveAs(content, "批量下载.zip");
|
||||
|
||||
ElMessage.success("下载完成");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
ElMessage.error("打包失败");
|
||||
} finally {
|
||||
loading.close();
|
||||
}
|
||||
}
|
||||
|
||||
function buildFileName(containerNo, index, fileName) {
|
||||
const formattedIndex = String(index).padStart(2, "0");
|
||||
|
||||
return `${containerNo}_${formattedIndex}.${fileName.split(".").pop()}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -299,7 +478,7 @@ function handleDownloadOne(data) {
|
||||
<div class="g3-content">
|
||||
<div class="content-top">
|
||||
<div>
|
||||
<el-button type="primary">
|
||||
<el-button type="primary" @click="handleDownloadBatch">
|
||||
<el-icon class="el-icon--left">
|
||||
<G3Icon icon="lucide:cloud-download" />
|
||||
</el-icon>
|
||||
@@ -368,7 +547,14 @@ function handleDownloadOne(data) {
|
||||
}"
|
||||
height="100%"
|
||||
>
|
||||
<vxe-column field="seq" type="seq" width="50" align="center" title=" " fixed="left" />
|
||||
<vxe-column
|
||||
field="seq"
|
||||
type="seq"
|
||||
width="50"
|
||||
align="center"
|
||||
title=" "
|
||||
fixed="left"
|
||||
/>
|
||||
<vxe-column type="checkbox" width="50" align="center" fixed="left" />
|
||||
<vxe-column
|
||||
v-for="column in columns"
|
||||
@@ -389,7 +575,12 @@ function handleDownloadOne(data) {
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ formatValueByFormat(row[column.col_FieldName], column.col_DisplayFormat) }}
|
||||
{{
|
||||
formatValueByFormat(
|
||||
row[column.col_FieldName],
|
||||
column.col_DisplayFormat,
|
||||
)
|
||||
}}
|
||||
</template>
|
||||
</template>
|
||||
</vxe-column>
|
||||
|
||||
Reference in new issue
Block a user