Parcourir la source

课件管理批量下载修改

zjq il y a 1 mois
Parent
commit
48716bc3fe
2 fichiers modifiés avec 4 ajouts et 12 suppressions
  1. 2 2
      src/api/courseware/index.ts
  2. 2 10
      src/views/courseware/index/index.vue

+ 2 - 2
src/api/courseware/index.ts

@@ -65,9 +65,9 @@ export const getCoursewareDetail = (Id: string) => {
 export const fileDownloadBatch = (params: object) => {
     return request({
         url: `/file/downloadfile_batch`,
-        method: 'get',
+        method: 'post',
         responseType: 'blob',
-        params,
+        data: params,
         baseURL: import.meta.env.VITE_API_UPLOAD_URL,
     },{
         reduce_data_format:false

+ 2 - 10
src/views/courseware/index/index.vue

@@ -134,7 +134,7 @@ import { formatDate } from '@/utils/formatTime';
 import { Splitpanes, Pane } from 'splitpanes';
 import 'splitpanes/dist/splitpanes.css';
 import Other from '@/utils/other';
-import { downloadFileByStream } from '@/utils/tools';
+import { downloadFileByStream, downloadZip } from '@/utils/tools';
 import { VxeUI } from 'vxe-pc-ui';
 import { VTreeSearch } from '@wsfe/vue-tree';
 import {deleteCourseware, getCoursewareData, fileDownloadBatch} from '@/api/courseware/index';
@@ -259,15 +259,7 @@ const onBatchDownload = () => {
 				Ids: ids,
 			}).then((res: any) => {
 				console.log(res);
-				let blob: Blob = new Blob([res.data], { type: res.data.type }); // 创建blob 设置blob文件类型 data 设置为后端返回的文件(例如mp3,jpeg) type:这里设置后端返回的类型 为 mp3
-				let down: HTMLAnchorElement = document.createElement('a'); // 创建A标签
-				let href: string = window.URL.createObjectURL(blob); // 创建下载的链接
-				down.href = href; // 下载地址
-				down.download = formatDate(new Date(), 'YYYYmmddHHMMSS')// 下载文件名
-				document.body.appendChild(down);
-				down.click(); // 模拟点击A标签
-				document.body.removeChild(down); // 下载完成移除元素
-				window.URL.revokeObjectURL(href); // 释放blob对象
+				downloadZip(res);
 			});
 		})
 		.catch(() => {});