2 Commits c0315f1905 ... b368f83073

Author SHA1 Message Date
  hanzhen b368f83073 pdf单文件预览下载 3 years ago
  hanzhen 2aa63f8fdb pdf单文件预览下载 3 years ago
1 changed files with 64 additions and 10 deletions
  1. 64 10
      src/main/resources/static/page/archive/show.html

+ 64 - 10
src/main/resources/static/page/archive/show.html

@@ -18,7 +18,6 @@
         }
 
 
-
         #file_list li a {
             display: inline-block;
             width: 50%;
@@ -53,7 +52,10 @@
             /*padding-right: 200px;*/
             width: 400px;
         }
-       ul li a{ white-space:nowrap;}
+
+        ul li a {
+            white-space: nowrap;
+        }
     </style>
 </head>
 <body>
@@ -99,7 +101,7 @@
                         <th width="40px">备注:</th>
                         <td colspan="3" id="remarks"></td>
                     </tr>
-                    <tr>
+                    <tr id="uploadFileId">
                         <th width="40px">下载:</th>
                         <td colspan="3" id="uploadFile"></td>
                     </tr>
@@ -126,13 +128,17 @@
 <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
 <script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
 <script>
+    var dataList = [];
+    var $;
+    var urlAll=[]
     layui.use(['http', 'element', 'url'], function () {
         let http = layui.http,
-            $ = layui.$,
             url = layui.url,
             element = layui.element
         ;
+        $ = layui.$;
         let archive_id = url('id')['id']
+
         if (!archive_id) {
             layer.msg('加载错误')
             return;
@@ -147,7 +153,7 @@
         });
 
         let initFile = () => {
-            let html = ""
+            let html = '' // '<button onclick="batchDownload()">批量下载</button><br/>';
             http.get('archive/archiveFile/selectByArchiveId', {
                 archiveId: archive_id,
                 fileType: 0
@@ -164,20 +170,25 @@
                         $("#files").hide();
                         $("#pdf_yl").removeClass();
                         $("#pdf_yl").addClass("layui-col-md12");
-                        let uploadPdf = '<a style="text-align: right;" download="'+obj.fileName+'" href="'+'http://66.1.21.158:9091/' + obj.filePath +'/'+ obj.fileName+ '">预览</a>';
+                        let uploadPdf = '<a style="text-align: right;color:#9ef5f9;" download="' + obj.fileName + '" href="' + 'http://66.1.21.158:9091' + obj.filePath + obj.fileName + '">预览</a>';
                         $("#uploadFile").html(uploadPdf);
+                        dataList.push(obj);
+                    } else {
+                        $("#uploadFileId").attr("style", "display:none");
+                        //$("#uploadFileId").css("display", "none");
                     }
                     for (let i = 0; i < res.data.length; i++) {
                         let item = res.data[i]
+                        dataList.push(item);
                         let pef_src = 'http://66.1.21.158:8012/onlinePreview?officePreviewType=pdf&disabledownload=false&url=' + encodeURIComponent(Base64.encode('http://66.1.21.158:9091/' + item.filePath + '/' + item.fileName))
                         if (i == 0) {
                             html += '<li class="layui-bg-green">' +
                                 '<a title="' + (i + 1) + '、' + (item.jnml ? item.jnml : '档案文件') + '" pdf_src="' + pef_src + '">' + (i + 1) + '、' + (item.jnml ? item.jnml : '档案文件') + '</a>' +
-                                '<a style="text-align: right;"download="'+item.fileName+'" href="'+'http://66.1.21.158:9091/' + item.filePath +'/'+ item.fileName+ '">下载</a></li>'
+                                '<a style="text-align: right;"download="' + item.fileName + '" href="' + 'http://66.1.21.158:9091/' + item.filePath + '/' + item.fileName + '">下载</a></li>'
                             $("#pdf_show").prop('src', pef_src)
                         } else {
                             html += '<li><a title="' + (i + 1) + '、' + (item.jnml ? item.jnml : '档案文件') + '" pdf_src="' + pef_src + '">' + (i + 1) + '、' + (item.jnml ? item.jnml : '档案文件') + '</a>' +
-                                '<a style="text-align: right;" download="'+item.fileName+'" href="'+'http://66.1.21.158:9091/' + item.filePath +'/'+ item.fileName+ '">下载</a></li>'
+                                '<a style="text-align: right;" download="' + item.fileName + '" href="' + 'http://66.1.21.158:9091/' + item.filePath + '/' + item.fileName + '">下载</a></li>'
                         }
                     }
                     $("#file_list").append(html)
@@ -186,12 +197,10 @@
                 }
             })
         }
-
         let initData = () => {
             http.get('archive/archive/selectByPrimaryKeyText', {
                 id: archive_id
             }, false, res => {
-                console.log(1111111111111,res)
                 if (res.code == 200) {
                     $("#dh").text(res.data.dh ? res.data.dh : '无');
                     $("#tm").text(res.data.tm ? res.data.tm : '无');
@@ -229,6 +238,51 @@
             }
         });
     })
+
+    function downloadFile() {//下载文件方法
+        urlAll.forEach(url => {
+            const iframe = document.createElement("iframe");
+            iframe.style.display = "none";  // 防止影响页面
+            iframe.style.height = 0;  // 防止影响页面
+            iframe.src = url;
+            console.log(iframe)
+            document.body.appendChild(iframe);  // 这一行必须,iframe挂在到dom树上才会发请求
+            setTimeout(() => {
+                iframe.remove();
+            }, 5 * 60 * 1000);
+
+        })
+    }
+    function batchDownload() {
+        let dataFileList = this.dataList;
+        console.log(JSON.stringify(dataFileList))
+        for (var i = 0; i < dataFileList.length; i++){
+            var item = dataFileList[i];
+            // console.log(item)
+            // var fileName = item.fileName;
+           urlAll.push('http://66.1.21.158:9091' + dataFileList[i].filePath + dataFileList[i].fileName)
+
+            // console.log(url)
+            // var a = document.createElement('a');
+            // var e = document.createEvent('MouseEvents');
+            // e.initEvent('click', false, false);
+            // a.target="_blank";
+            // a.href = url;
+            // a.download = fileName
+            // a.dispatchEvent(e);
+
+
+        }
+        urlAll.forEach(url => {
+            let a = document.createElement('a') // 创建a标签
+            let e = document.createEvent('MouseEvents') // 创建鼠标事件对象
+            e.initEvent('click', false, false) // 初始化事件对象
+            a.target="_blank";
+            a.href = url // 设置下载地址
+            a.download = '' // 设置下载文件名
+            a.dispatchEvent(e)
+        })
+    }
 </script>
 </body>
 </html>