Просмотр исходного кода

附件列表新增批量下载功能

cfort 1 год назад
Родитель
Сommit
1a3a27dc5e

+ 14 - 0
src/api/platform/file/attachment.js

@@ -110,6 +110,19 @@ export function download (params) {
         params: params
     })
 }
+/**
+ * 打包下载文件
+ * @param {*} params
+ */
+export function downloadZip (params) {
+    return request({
+        url: SYSTEM_URL() + '/file/downloadZip',
+        method: 'get',
+        isLoading: true,
+        responseType: 'arraybuffer',
+        params: params
+    })
+}
 /**
  * 根据文件id获取文件流
  * @param {*} params
@@ -196,3 +209,4 @@ export function snapshoot (params) {
         params: params
     })
 }
+

+ 28 - 2
src/business/platform/file/utils/index.js

@@ -1,9 +1,9 @@
-import { download } from '@/api/platform/file/attachment'
+import { download, downloadZip } from '@/api/platform/file/attachment'
 import Utils from '@/utils/util'
 import ActionUtils from '@/utils/action'
 import { Loading } from 'element-ui'
 
-export function downloadFile (file) {
+export const downloadFile = (file) => {
     const loadingInstance = Loading.service({
         lock: true,
         text: '下载中..'
@@ -23,3 +23,29 @@ export function downloadFile (file) {
         loadingInstance.close()
     })
 }
+
+export const downloadFileByZip = (ids) => {
+    const loadingInstance = Loading.service({
+        lock: true,
+        text: '下载中..'
+    })
+    downloadZip({
+        attachmentIds: ids
+    }).then(response => {
+        loadingInstance.close()
+        if (!response) {
+            return
+        }
+        ActionUtils.exportFile(
+            response.data,
+            '批量下载文件.zip'
+        )
+    }).catch(() => {
+        loadingInstance.close()
+    })
+}
+
+export default {
+    downloadFile,
+    downloadFileByZip
+}

+ 11 - 1
src/views/platform/file/attachment/list.vue

@@ -57,7 +57,7 @@
 
 <script>
 import { queryPageList, deleteFile } from '@/api/platform/file/attachment'
-import { downloadFile } from '@/business/platform/file/utils'
+import { downloadFile, downloadFileByZip } from '@/business/platform/file/utils'
 import ActionUtils from '@/utils/action'
 import FixHeight from '@/mixins/height'
 import IbpsUploader from '@/business/platform/file/uploader'
@@ -125,6 +125,11 @@ export default {
                         label: '上传',
                         icon: 'ibps-icon-upload'
                     },
+                    {
+                        key: 'downloadZip',
+                        label: '批量下载',
+                        icon: 'ibps-icon-download'
+                    },
                     {
                         key: 'remove'
                     }
@@ -295,6 +300,11 @@ export default {
                 case 'download': // 下载
                     this.handleDownload(data)
                     break
+                case 'downloadZip': // 批量下载
+                    ActionUtils.selectedMultiRecord(selection).then((id) => {
+                        downloadFileByZip(id)
+                    })
+                    break
                 case 'remove': // 删除
                     ActionUtils.removeRecord(selection).then((ids) => {
                         this.handleRemove(ids)