From 7b11aa99606966e3957b633b717459a0eec681fe Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Mon, 27 Nov 2023 13:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=9B=E4=BA=8B=E6=88=90=E7=BB=A9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=97=E8=A1=A8=E5=AF=BC=E5=87=BA=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E5=8C=85=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 30 +++++++++++-- package.json | 1 + src/libs/zip.js | 56 ++++++++++++++++++++++++ src/setting.js | 2 +- src/utils/api.js | 1 + src/views/match/manage/matchArchList.vue | 52 +++++++++++----------- 6 files changed, 111 insertions(+), 31 deletions(-) create mode 100644 src/libs/zip.js diff --git a/package-lock.json b/package-lock.json index ff377a6..7c41ee1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7139,6 +7139,11 @@ "resolved": "https://registry.npmjs.org/image-conversion/-/image-conversion-2.1.1.tgz", "integrity": "sha512-hnMOmP7q2jxA+52FZ+wHNhg3fdFRlgfngsQH2JQHEQkafY7tj/8F15e6Rv/RxDegc872jvyaRHwMbkTZK1Cjbg==" }, + "immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" + }, "import-cwd": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-2.1.0.tgz", @@ -7753,6 +7758,17 @@ "resolved": "https://registry.npmjs.org/jstoxml/-/jstoxml-2.2.9.tgz", "integrity": "sha512-OYWlK0j+roh+eyaMROlNbS5cd5R25Y+IUpdl7cNdB8HNrkgwQzIS7L9MegxOiWNBj9dQhA/yAxiMwCC5mwNoBw==" }, + "jszip": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", + "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "requires": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "setimmediate": "^1.0.5" + } + }, "killable": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz", @@ -7792,6 +7808,14 @@ "invert-kv": "^2.0.0" } }, + "lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "requires": { + "immediate": "~3.0.5" + } + }, "liftoff": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-2.5.0.tgz", @@ -9241,8 +9265,7 @@ "pako": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.10.tgz", - "integrity": "sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==", - "dev": true + "integrity": "sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==" }, "parallel-transform": { "version": "1.2.0", @@ -11448,8 +11471,7 @@ "setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=", - "dev": true + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" }, "setprototypeof": { "version": "1.1.1", diff --git a/package.json b/package.json index 9928b76..9b96004 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "file-saver": "^2.0.5", "image-conversion": "^2.1.1", "js-cookie": "^3.0.1", + "jszip": "^3.10.1", "mavon-editor": "^2.10.4", "postcss-px2rem": "^0.3.0", "px2rem-loader": "^0.1.9", diff --git a/src/libs/zip.js b/src/libs/zip.js new file mode 100644 index 0000000..14f57d7 --- /dev/null +++ b/src/libs/zip.js @@ -0,0 +1,56 @@ +// 导出压缩包 +import JSZip from 'jszip' +import FileSaver from 'file-saver' + +//文件以流的形式获取(参数url为文件链接地址) +const getImgArrayBuffer = url => { + return new Promise((resolve, reject) => { + //通过请求获取文件blob格式 + let xmlhttp = new XMLHttpRequest(); + xmlhttp.open('GET', url, true); + xmlhttp.responseType = 'blob' + xmlhttp.onload = function () { + if (xmlhttp.status == 200) { + resolve(xmlhttp.response); + } else { + reject(xmlhttp.response); + } + }; + xmlhttp.send(); + }); +} + +/** + * @param {String} zipName 压缩包名字 + * @param {Array} files 需要压缩的文件数组 + * @param {Function | undefined} callback 回调 + */ +export default function (zipName, files, callback) { + var zip = new JSZip(); + var promises = []; + let cache = {}; + for (let item of files) { + // item.filePath为文件链接地址 + // item.fileName为文件名称 + if(item.filePath) { + const promise = getImgArrayBuffer(item.filePath).then((data) => { + // 下载文件, 并存成ArrayBuffer对象(blob) + zip.file(item.fileName, data, { binary: true }); // 逐个添加文件 + cache[item.fileName] = data; + }); + promises.push(promise); + } else { + // 地址不存在时提示 + console.log(`附件${item.fileName}地址错误,下载失败`); + } + } + Promise.all(promises).then(() => { + zip.generateAsync({ type: "blob" }).then((content) => { + // 生成二进制流 + FileSaver.saveAs(content, zipName); // 利用file-saver保存文件 zipName: 自定义文件名 + callback && callback() + }); + }).catch((res) => { + console.log("文件压缩失败"); + }); +} diff --git a/src/setting.js b/src/setting.js index b8ddb3a..28506aa 100644 --- a/src/setting.js +++ b/src/setting.js @@ -13,7 +13,7 @@ if (isDev) { sandPath = `http://${location.hostname}:9520` host = 'http://121.37.12.51/' // host = 'https://huorantech.cn/' - // host = 'http://192.168.31.217:9000/'// 榕 + host = 'http://192.168.31.217:9000/'// 榕 // host = 'http://192.168.31.51:9000/'// 赓 } else if (isPro) { jumpPath = 'https://www.huorantech.cn/judgmentPoint/' diff --git a/src/utils/api.js b/src/utils/api.js index e08336e..bff10a7 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -414,6 +414,7 @@ export default { frontOfficeCompetitionRanking: `competition/competition/rank/frontOfficeCompetitionRanking`, cCompetitionStageFileList: `competition/cCompetitionStageFile/listByEntity`, derive: `${host}competition/cCompetitionStageFile/deriveAll`, + allExperimentalResultsAreDerived: `${host}competition/competition/performance/allExperimentalResultsAreDerived`, gradeImport: `https://www.occupationlab.com/template/赛事成绩导入模板.xlsx`, rankImportTeam: `https://www.occupationlab.com/template/赛事排名导入模板(团队赛).xlsx`, rankImportPerson: `https://www.occupationlab.com/template/赛事排名导入模板(个人赛).xlsx`, diff --git a/src/views/match/manage/matchArchList.vue b/src/views/match/manage/matchArchList.vue index e3e37f2..f376d40 100644 --- a/src/views/match/manage/matchArchList.vue +++ b/src/views/match/manage/matchArchList.vue @@ -263,6 +263,7 @@ import Setting from "@/setting"; import util from "@/libs/util"; import * as echarts from "echarts"; import axios from 'axios'; +import Zip from '@/libs/zip' export default { data () { return { @@ -369,40 +370,39 @@ export default { }, // 导出(有勾选:就导勾选中的;没有勾选:就导全部) exportData () { - let { list } = this - // 有勾选,就带上勾选的id + // 有选择数据,则导出已选择的,否则导出全部 if (this.multipleSelection.length) { - list = this.multipleSelection + axios.post(this.api.exportExperimentalResultsInBatch, this.multipleSelection, { + headers: this.headers, + responseType: 'blob' + }).then((res) => { + util.downloadFileDirect(`赛事成绩.xls`, new Blob([res.data])) + }).catch(res => { }) + } else if (this.list.length) { + axios.post(this.api.allExperimentalResultsAreDerived, { + pageNum: 1, + pageSize: 10000, + competitionId: this.id, + isNakadai: 1, + stageId: this.stageId, + }, { + headers: this.headers, + responseType: 'blob' + }).then((res) => { + util.downloadFileDirect(`赛事成绩.xls`, new Blob([res.data])) + }).catch(res => { }) } - axios.post(this.api.exportExperimentalResultsInBatch, list, { - headers: this.headers, - responseType: 'blob' - }).then((res) => { - util.downloadFileDirect(`赛事成绩.xls`, new Blob([res.data])) - }).catch(res => { }) }, // 导出(有勾选:就导勾选中的;没有勾选:就导全部) exportData1 () { - // 有勾选,就带上勾选的id - let ids + this.loading = true + let list = this.list1 if (this.multipleSelection1.length) { - ids = this.multipleSelection1.map(e => e.id) - } - const data = { - pageNum: 1, - pageSize: 1000, - competitionId: this.id, - stageId: this.stageId, + list = this.multipleSelection1 } - if (ids) data.ids = ids - this.loading = true - axios.post(this.api.derive, data, { - headers: this.headers, - responseType: 'blob' - }).then((res) => { - util.downloadFileDirect(`批量导出.zip`, new Blob([res.data])) + Zip('批量导出', list, () => { this.loading = false - }).catch(res => { }) + }) }, handleDelete (row) { // 删除 this.$confirm("确定要删除吗?", "提示", {