Преглед изворни кода

#3754 C1159 课堂记录--以打包方式进行课堂记录统计表批量下载

XW пре 4 месеци
родитељ
комит
8866e6b668
1 измењених фајлова са 36 додато и 11 уклоњено
  1. 36 11
      TEAMModelOS/ClientApp/src/view/research-center/ResearchMgt.vue

+ 36 - 11
TEAMModelOS/ClientApp/src/view/research-center/ResearchMgt.vue

@@ -381,6 +381,8 @@
 	import excel from "@/utils/excel.js";
 	import domtoimage from "@/utils/dom_to_image";
 	import QRCode from "qrcodejs2";
+	import JsZip from 'jszip';
+	import FileSaver from 'file-saver';
 	export default {
 		components: {
 			BaseTypeMgmt,
@@ -1140,21 +1142,44 @@
 			},
 			/* 下载课例总表 */
 			downloadTableList() {
-				const downloadRes = async (row, url) => {
-					let response = await fetch(url); // 内容转变成blob地址
-					let blob = await response.blob(); // 创建隐藏的可下载链接
-					let objectUrl = window.URL.createObjectURL(blob);
-					let a = document.createElement("a");
-					a.href = objectUrl;
-					a.download = row.name + ".xlsx";
-					a.click();
-					a.remove();
-				};
+				const zip = new JsZip()
+				const cache = {}
+				const promiseArr = []
+				let data = []
+				this.batchDelArr.forEach(item => {
+					let repeatData = data.filter(file => file.name === item.name)
+					item.showName = `${item.name}${repeatData.length ? `(${repeatData.length})` : ''}`
+					data.push(item)
+				})
 				this.batchDelArr.forEach(item => {
 					let blobInfo = item.scope == "school" ? this.$store.state.user.schoolProfile : this.$store.state.user.userProfile;
 					let url = `${blobInfo.blob_uri}/records/${item.id}/IES/summary.xlsx?${blobInfo.blob_sas}`;
-					downloadRes(item, url)
+					const promise = this.fetchBlob(url).then(res => {
+						zip.file(item.showName + ".xlsx", res, {binary: true})
+						cache[item.showName] = url
+					})
+					promiseArr.push(promise)
+				})
+				Promise.all(promiseArr).then(res => {
+					zip.generateAsync({type: 'blob'}).then(content => {
+						FileSaver.saveAs(content, '课堂记录.zip')
+					}).catch(err => {
+						console.log('文件压缩失败——', err);
+					})
+				})
+			},
+			async fetchBlob(url) {
+				let response = await window.fetch(url, {
+					method: 'get',
+					body: null,
+					headers: {
+						Accept: 'application/json',
+						'Content-Type': 'application/json',
+						'X-Requested-With': 'XMLHttpRequest'
+					}
 				})
+				const blob = await response.blob()
+				return blob
 			},
 			/* 预览课例笔记 */
 			downloadNote(row) {