人效管理-绩效管理-绩效填报-任务行下载压缩包

dev-scheduling
ysn 1 month ago
parent fc087603f0
commit c9b1081643
  1. 66
      src/views/personnelEfficiencyManagement/performanceManagement/dataReporting.vue

@ -126,6 +126,8 @@ import {
downloadBsEfficiencyTaskTemplate, downloadBsEfficiencyTaskTemplate,
} from '@/api/performanceManagement/dataReporting'; } from '@/api/performanceManagement/dataReporting';
import { downloadXls, downloadFile, downloadFileBlob } from '@/utils/util'; import { downloadXls, downloadFile, downloadFileBlob } from '@/utils/util';
import { saveAs } from 'file-saver';
import JSZip from 'jszip';
export default { export default {
components: { reportingPerf, prefDetail, batchAddContent }, components: { reportingPerf, prefDetail, batchAddContent },
data() { data() {
@ -334,35 +336,63 @@ export default {
this.currentRow = row; this.currentRow = row;
this.showExamine = true; this.showExamine = true;
}, },
// // ZIP
async downloadTask(row) { async downloadTask(row) {
const zip = new JSZip();
const promises = []; // Promise
if (row.parentId == 0) { if (row.parentId == 0) {
if (!row.subTasks || row.subTasks.length === 0) { if (!row.subTasks || row.subTasks.length === 0) {
this.$message.warning('暂无可下载文件!'); this.$message.warning('暂无可下载文件!');
return; return;
} }
// 2
const completedTasks = row.subTasks.filter(task => task.status === 2); const completedTasks = row.subTasks.filter(task => task.status === 2);
if (completedTasks.length === 0) { if (completedTasks.length === 0) {
this.$message.warning('暂无可下载文件!'); this.$message.warning('暂无可下载文件!');
return; return;
} }
// try {
downloadBsEfficiencyTaskTemplate() // 1.
.then(res => { const templateRes = await downloadBsEfficiencyTaskTemplate();
downloadXls(res.data, `${row.yearMonth}绩效填报模板.xlsx`); zip.file(`${row.yearMonth}绩效填报模板.xlsx`, templateRes.data);
// 2 // 2.
const completedTasks = row.subTasks.filter(task => task.status === 2); completedTasks.forEach(task => {
completedTasks.forEach(task => { if (task.attachLink) {
if (task.attachLink) { const promise = fetch(task.attachLink)
downloadFileBlob(task.attachLink, task.taskName + '.xlsx'); .then(res => res.blob())
} .then(blob => {
}); zip.file(`${task.taskName}.xlsx`, blob);
}) });
.catch(error => { promises.push(promise);
console.error('下载模板失败:', error); }
this.$message.error('下载失败,请检查网络或稍后重试');
}); });
// zip
await Promise.all(promises);
const content = await zip.generateAsync({ type: 'blob' });
saveAs(content, `${row.yearMonth}绩效填报文件包.zip`);
this.$message.success('打包下载成功');
} catch (error) {
console.error('打包下载失败:', error);
this.$message.error('打包下载失败,请稍后重试');
}
} else { } else {
// zip
// if (!row.attachLink) {
// this.$message.warning('');
// return;
// }
// try {
// const res = await fetch(row.attachLink);
// const blob = await res.blob();
// zip.file(`${row.taskName}.xlsx`, blob);
// const content = await zip.generateAsync({ type: 'blob' });
// saveAs(content, `${row.taskName}.zip`);
// this.$message.success('');
// } catch (error) {
// console.error(':', error);
// this.$message.error('');
// }
if (row.attachLink == '') { if (row.attachLink == '') {
this.$message.warning('暂无可下载文件!'); this.$message.warning('暂无可下载文件!');
return; return;
@ -477,13 +507,13 @@ export default {
.then(res => { .then(res => {
if (res.data.code === 200) { if (res.data.code === 200) {
// //
const processTasks = (tasks) => { const processTasks = tasks => {
return tasks.map(task => { return tasks.map(task => {
if (task.subTasks && task.subTasks.length > 0) { if (task.subTasks && task.subTasks.length > 0) {
// //
task.subTasks = task.subTasks.map(subTask => ({ task.subTasks = task.subTasks.map(subTask => ({
...subTask, ...subTask,
parentStatus: task.status // parentStatus: task.status, //
})); }));
// //
processTasks(task.subTasks); processTasks(task.subTasks);

Loading…
Cancel
Save