Explorar o código

fix: 计量附件当前节点与所有附件切换时,批量下载功能出错

lanjianrong %!s(int64=4) %!d(string=hai) anos
pai
achega
4ea9a1f592
Modificáronse 3 ficheiros con 32 adicións e 21 borrados
  1. 7 5
      app/controller/stage_controller.js
  2. 24 15
      app/public/js/stage.js
  3. 1 1
      app/view/stage/index.ejs

+ 7 - 5
app/controller/stage_controller.js

@@ -1561,11 +1561,13 @@ module.exports = app => {
                     'Content-Disposition': disposition,
                     'Content-Length': size,
                 });
-                ctx.body = fs.createReadStream(path.join(this.app.baseDir, zipPath));
-                // ctx.body = fs.readFileSync(path.resolve(this.app.baseDir, zipPath));
-                if (fs.existsSync(path.resolve(this.app.baseDir, zipPath))) {
-                    fs.unlinkSync(path.resolve(this.app.baseDir, zipPath));
-                }
+                const readStream = fs.createReadStream(path.join(this.app.baseDir, zipPath));
+                ctx.body = readStream;
+                readStream.on('close', () => {
+                    if (fs.existsSync(path.resolve(this.app.baseDir, zipPath))) {
+                        fs.unlinkSync(path.resolve(this.app.baseDir, zipPath));
+                    }
+                });
             } catch (error) {
                 this.log(error);
             }

+ 24 - 15
app/public/js/stage.js

@@ -3209,8 +3209,10 @@ $(document).ready(() => {
         const tabPanel = $(this).attr('fujian-content');
         if (tabPanel !== 'syfujian') {
             $('#showPage').hide();
+            $('#bach-download').prop('type', 'curr');
         } else {
             $('#showPage').show();
+            $('#bach-download').prop('type', 'all')
         }
         $('#showAttachment').hide();
     });
@@ -3450,34 +3452,41 @@ $(document).ready(() => {
 
     // 批量下载
     $('#bach-download').click(function() {
-        const fileIds = []
-        $('.tab-pane.active.show .list-table .check-file:checked').each(function() {
-            const fileId = $(this).attr('file-id')
-            fileId && fileIds.push(fileId)
-        })
+        const fileIds = [];
+        const type = $(this).prop('type');
+        let node = ''
+        if (type === 'curr') {
+            node = '#nodelist-table .check-file:checked'
+        } else {
+            node = '#alllist-table .check-file:checked'
+        }
+        $(node).each(function() {
+            const fileId = $(this).attr('file-id');
+            fileId && fileIds.push(fileId);
+        });
 
         if (fileIds.length) {
-            const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`
-            $('#zipDown').attr('href', url)
-            $("#zipDown")[0].click()
+            const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
+            $('#zipDown').attr('href', url);
+            $("#zipDown")[0].click();
         }
     });
 
     // 监听附件check是否选中
     $('.list-table').on('click', '.check-file', function() {
-        const checkedList = $(this).parents('.list-table').children().find('input:checked')
-        const childs = $(this).parents('.list-table').children().length
-        const checkBox = $(this).parents('.list-table').parent().find('.check-all-file')
+        const checkedList = $(this).parents('.list-table').children().find('input:checked');
+        const childs = $(this).parents('.list-table').children().length;
+        const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
         if (checkedList.length === childs) {
-            checkBox.prop("checked", true)
+            checkBox.prop("checked", true);
         } else {
-            checkBox.prop("checked", false)
+            checkBox.prop("checked", false);
         }
     });
     $('.check-all-file').click(function() {
-        const isCheck = $(this).is(':checked')
+        const isCheck = $(this).is(':checked');
         $(this).parents('table').find('.list-table').each(function() {
-            $(this).find('input:checkbox').prop("checked", isCheck)
+            $(this).find('input:checkbox').prop("checked", isCheck);
         })
     });
 

+ 1 - 1
app/view/stage/index.ejs

@@ -267,7 +267,7 @@
                                     <a class="nav-link" data-toggle="tab" href="#syfujian" role="tab" fujian-content="syfujian">所有附件</a>
                                 </li>
                                 <li class="nav-item ml-auto pt-1">
-                                    <a href="javascript:void(0);" id="bach-download" class="btn btn-sm btn-primary mr-3">批量下载</a>
+                                    <a href="javascript:void(0);" id="bach-download" class="btn btn-sm btn-primary mr-3" type="curr">批量下载</a>
                                     <!--所有附件 翻页-->
                                     <span id="showPage" style="display: none"><a href="javascript:void(0);" class="page-select" content="pre"><i class="fa fa-chevron-left"></i></a> <span id="currentPage">1</span>/<span id="totalPage">10</span> <a href="javascript:void(0);" class="page-select" content="next"><i class="fa fa-chevron-right"></i></a></span>
                                     <a href="#upload" data-toggle="modal" data-target="#upload"  class="btn btn-sm btn-outline-primary ml-3">上传</a>