瀏覽代碼

中间计量,附件,图片、pdf、txt格式,提供预览功能

MaiXinRong 3 年之前
父節點
當前提交
75d1348bec
共有 3 個文件被更改,包括 21 次插入9 次删除
  1. 15 3
      app/public/js/stage.js
  2. 5 5
      app/service/stage_detail_att.js
  3. 1 1
      app/view/stage/modal.ejs

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

@@ -2781,11 +2781,12 @@ $(document).ready(() => {
             if (data.attachment) {
                 for (const att of data.attachment) {
                     const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked))
-                        ? '<a class="delete-att text-danger" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
+                        ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
                         : '';
+                    const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
+                    const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
                     html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
-                        '<td><a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a> ',
-                        delHtml, '</td></tr>');
+                        '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
                 }
             }
             $('#im-attList').html(html.join(''));
@@ -2856,6 +2857,17 @@ $(document).ready(() => {
                     self.makeAttTable(select);
                 });
             });
+            // 预览附件
+            $('body').on('click', '.preview-att', function () {
+                const uuid = $(this).attr('data-imid');
+                const file_id = $(this).attr('data-attid');
+
+                postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
+                    const { filepath } = result;
+                    $('#load-file').attr('href', filepath);
+                    $('#load-file')[0].click();
+                });
+            })
         }
         _initImTypeSetRela() {
             const self = this;

+ 5 - 5
app/service/stage_detail_att.js

@@ -56,12 +56,12 @@ module.exports = app => {
         }
 
         _analysisDetailAtt(data) {
-            if (data instanceof Array) {
-                for (const a of data) {
-                    a.attachment = a.attachment ? JSON.parse(a.attachment) : [];
+            const datas = data instanceof Array ? data : [data];
+            for (const a of datas) {
+                a.attachment = a.attachment ? JSON.parse(a.attachment) : [];
+                for (const aa of a.attachment) {
+                    if (this.ctx.helper.canPreview(aa.fileext)) aa.viewpath = aa.filepath.replace(/^app|\/app/, '');
                 }
-            } else {
-                data.attachment = data.attachment ? JSON.parse(data.attachment) : [];
             }
         }
 

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

@@ -608,7 +608,7 @@
                 <div class="modal-height-500" style="overflow:auto;">
                     <table class="table table-sm table-bordered" style="word-break:break-all; table-layout: fixed">
                         <thead>
-                        <tr><th width="240">文件名</th><th>上传人</th><th>上传时间</th><th width="40">操作</th></tr>
+                        <tr><th width="240">文件名</th><th>上传人</th><th>上传时间</th><th width="52">操作</th></tr>
                         </thead>
                         <tbody id="im-attList">
                         </tbody>