瀏覽代碼

附件批量下载补齐

laiguoran 3 年之前
父節點
當前提交
1caf69e51c
共有 2 個文件被更改,包括 37 次插入15 次删除
  1. 35 15
      app/public/js/sr_detail.js
  2. 2 0
      config/web.js

+ 35 - 15
app/public/js/sr_detail.js

@@ -83,6 +83,8 @@ function getAllList(currPageNum = 1) {
     $('#currentPage').text(total === 0 ? 0 : currPageNum);
     // 当前页附件内容
     const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
+    currPageFileData = currPageAttData;
+    console.log(currPageFileData);
     let html = '';
     for(const att of currPageAttData) {
         html += `<tr>
@@ -142,7 +144,7 @@ function getHintMsg () {
     }
 }
 
-
+let currPageFileData = [];
 $(document).ready(() => {
     let detail, searchLedger;
     // 界面布局
@@ -1221,20 +1223,38 @@ $(document).ready(() => {
             }
             toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
             $(this).attr('disabled', "true")
-            const btn = $(this)
-            postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
-              toastr.clear()
-              toastr.success('压缩文件成功')
-              btn.removeAttr('disabled')
-              const href = window.URL.createObjectURL(result)
-              $('#zipDown').attr('href', href);
-              $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
-              $("#zipDown")[0].click();
-            }, () => {
-              btn.removeAttr('disabled')
-              toastr.clear()
-              toastr.error('批量下载失败')
-            });
+            const btn = $(this);
+
+            const fileArr = [];
+            for (const id of fileIds) {
+                const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
+                fileArr.push({
+                    url: fileInfo.orginpath, //文件的oss存储路径 (必填)
+                    name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
+                    foldPath: '' // (可选, 文件在压缩包中的存储路径)
+                });
+            }
+            const packageName = `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`;
+            try {
+                zipOss.downloadFromAliOss(fileArr, packageName, btn);
+            } catch (e) {
+                btn.removeAttr('disabled');
+                toastr.clear();
+                toastr.error('批量下载失败');
+            }
+            // postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
+            //   toastr.clear()
+            //   toastr.success('压缩文件成功')
+            //   btn.removeAttr('disabled')
+            //   const href = window.URL.createObjectURL(result)
+            //   $('#zipDown').attr('href', href);
+            //   $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
+            //   $("#zipDown")[0].click();
+            // }, () => {
+            //   btn.removeAttr('disabled')
+            //   toastr.clear()
+            //   toastr.error('批量下载失败')
+            // });
         }
     });
 

+ 2 - 0
config/web.js

@@ -571,6 +571,7 @@ const JsFiles = {
                 files: [
                     '/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js',
                     '/public/js/decimal.min.js',
+                    '/public/js/axios/axios.min.js', '/public/js/js-xlsx/jszip.min.js', '/public/js/file-saver/FileSaver.min.js',
                 ],
                 mergeFiles: [
                     '/public/js/component/menu.js',
@@ -581,6 +582,7 @@ const JsFiles = {
                     '/public/js/shares/sjs_setting.js',
                     '/public/js/zh_calc.js',
                     '/public/js/path_tree.js',
+                    '/public/js/zip_oss.js',
                     '/public/js/stage_im.js',
                     '/public/js/sr_detail.js',
                 ],