Browse Source

office文件预览接入kkfile

MaiXinRong 2 weeks atrás
parent
commit
0c312477bb

+ 1 - 1
app/controller/construction_controller.js

@@ -414,7 +414,7 @@ module.exports = app => {
                         fileData.filepath = `/sp/${ctx.subProject.id}/construction/${original_data.tid}/log/${original_data.log_id}/file/${fileData.id}/download`;
                     } else {
                         fileData.filepath = ctx.app.config.fujianOssPath + filepath;
-                        fileData.viewpath = ctx.app.config.fujianOssPath + filepath;
+                        fileData.viewpath = ctx.helper.getPreviewPath(fileData.fileext, ctx.app.config.fujianOssPath + filepath);
                     }
                     files.push(fileData);
                     ++index;

+ 1 - 3
app/controller/ledger_controller.js

@@ -113,10 +113,8 @@ module.exports = app => {
                     ctx.tender.data.valuation, ctx.tender.data.measure_type);
 
                     // 获取附件列表
-                const attData = await ctx.service.ledgerAtt.getDataByTenderId(ctx.tender.id);
+                const attData = await ctx.service.ledgerAtt.getLedgerViewData(ctx.tender.id);
                 for (const index in attData) {
-                    attData[index].in_time = moment(attData[index].in_time * 1000).format('YYYY-MM-DD');
-                    attData[index].orginpath = ctx.app.config.fujianOssPath + attData[index].filepath;
                     delete attData[index].filepath;
                 }
 

+ 1 - 1
app/controller/payment_controller.js

@@ -1069,7 +1069,7 @@ module.exports = app => {
                         fileData.filepath = `/sp/${ctx.subProject.id}/payment/${original_data.tender_id}/detail/${original_data.td_id}/file/${fileData.id}/download`;
                     } else {
                         fileData.filepath = ctx.app.config.fujianOssPath + filepath;
-                        fileData.viewpath = ctx.app.config.fujianOssPath + filepath;
+                        fileData.viewpath = ctx.helper.getPreviewPath(fileData.fileext, ctx.app.config.fujianOssPath + filepath);
                     }
                     files.push(fileData);
                     ++index;

+ 1 - 3
app/controller/stage_extra_controller.js

@@ -405,9 +405,7 @@ module.exports = app => {
                 });
                 for (const pf of bonus.proof_file) {
                     pf.username = (await ctx.service.projectAccount.getAccountInfoById(pf.uid)).name;
-                    if (ctx.helper.canPreview(pf.fileext)){
-                        pf.viewpath = pf.filepath.substr(3, pf.filepath.length - 3);
-                    }
+                    pf.viewpath = ctx.helper.getPreviewPath(pf.fileext, pf.filepath.substr(3, pf.filepath.length - 3));
                     delete pf.filepath;
                 }
                 ctx.body = {err: 0, msg: '', data: bonus.proof_file};

+ 7 - 0
app/extend/helper.js

@@ -27,6 +27,8 @@ const jwt = require('jsonwebtoken');
 const sign = require('../const/sign');
 const xml2js = require('xml2js');
 const qtySourceValueConst = require('../const/material').qty_source_value;
+const Base64 = require('js-base64').Base64;
+
 module.exports = {
     _,
 
@@ -1322,6 +1324,11 @@ module.exports = {
         const reg = /(.doc)|(.docx)|(.xls)|(.xlsx)|(.ppt)(.pptx)/i;
         return reg.test(ext);
     },
+    getPreviewPath(ext, filepath) {
+        return this.canPreviewKkfile(ext)
+            ? this.ctx.app.config.kkfileUrl + encodeURIComponent(Base64.encode(filepath))
+            : (this.canPreview(ext) ? filepath : '');
+    },
     fileExtStr(ext) {
         const ExtStr = [
             { text: '图片', ext: ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.cad', '.dwg',] },

+ 2 - 6
app/public/js/ledger.js

@@ -5487,12 +5487,8 @@ $(document).ready(function() {
               $('#showAttachment').attr('file-id', '');
           });
       } else if (content === 'view') {
-          const data = {id: fid};
-          postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
-              const { filepath } = result
-              $('#load-file').attr('href', filepath);
-              $('#load-file')[0].click();
-          });
+          const att = attData.find(item => item.id === parseInt(fid));
+          window.open(att.viewpath || att.orginpath);
       } else if (content === 'location') {
           const att = attData.find(item => item.id === parseInt(fid));
           if (Object.keys(att).length) {

+ 1 - 1
app/service/construction_att.js

@@ -58,8 +58,8 @@ module.exports = app => {
                     item.filepath = `/sp/${this.ctx.subProject.id}/construction/${item.tid}/log/${item.log_id}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/contract_att.js

@@ -33,8 +33,8 @@ module.exports = app => {
                     item.filepath = `/sp/${this.ctx.subProject.id}/contract${item.tid ? '/tender/' + item.tid : ''}/detail/${contractConst.typeMap[item.contract_type]}/${item.cid}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/contract_pay_att.js

@@ -33,8 +33,8 @@ module.exports = app => {
                     item.filepath = `/sp/${this.ctx.subProject.id}/contract${item.tid ? '/tender/' + item.tid : ''}/detail/${contractConst.typeMap[item.contract_type]}/${item.cid}/pay/${item.cpid}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 4
app/service/file.js

@@ -9,7 +9,6 @@
  */
 
 const path = require('path');
-const base64 = require('js-base64').Base64;
 
 module.exports = app => {
     class File extends app.BaseService {
@@ -31,10 +30,8 @@ module.exports = app => {
             const userId = this.ctx.session.sessionUser.accountId;
             const ossPath = this.ctx.app.config.fujianOssPath;
             files.forEach(x => {
-                x.viewpath = helper.canPreviewKkfile(x.fileext)
-                    ? this.ctx.app.config.kkfileUrl+ encodeURIComponent(base64.encode(ossPath + x.filepath))
-                    : (helper.canPreview(x.fileext) ? ossPath + x.filepath : '');
                 x.filepath = ossPath + x.filepath;
+                x.viewpath = helper.getPreviewPath(x.fileext, x.filepath);
                 x.fileext_str = helper.fileExtStr(x.fileext);
                 x.canEdit = x.user_id === userId;
             });

+ 1 - 1
app/service/financial_pay_att.js

@@ -33,8 +33,8 @@ module.exports = app => {
                     item.filepath = `/sp/${item.spid}/financial/pay/${item.fpid}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/financial_transfer_att.js

@@ -32,8 +32,8 @@ module.exports = app => {
                     item.filepath = `/financial/${item.spid}/transfer/${item.trid}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/financial_transfer_tender_att.js

@@ -32,8 +32,8 @@ module.exports = app => {
                     item.filepath = `/sp/${this.ctx.subProject.id}/financial/${item.spid}/transfer/${item.trid}/tender/${item.ftid}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 16 - 28
app/service/ledger_att.js

@@ -90,13 +90,7 @@ module.exports = app => {
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.id = ? ORDER BY att.in_time DESC';
             const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, id];
             const result = await this.db.queryOne(sql, sqlParam);
-            result.orginpath = this.ctx.app.config.fujianOssPath + result.filepath;
-            if (!ctx.helper.canPreview(result.fileext)) {
-                result.filepath = `/tender/${ctx.tender.id}/ledger/download/file/${result.id}`;
-            } else {
-                // result.filepath = result.filepath.replace(/^app|\/app/, '');
-                result.filepath = this.ctx.app.config.fujianOssPath + result.filepath;
-            }
+            this._analysisAtt(result);
             return result;
         }
 
@@ -149,17 +143,23 @@ module.exports = app => {
             });
         }
 
+        _analysisAtt(data) {
+            const datas = data instanceof Array ? data : [data];
+            for (const r of datas) {
+                r.orginpath = this.ctx.app.config.fujianOssPath + r.filepath;
+                r.filepath = this.ctx.app.config.fujianOssPath + r.filepath;
+                r.viewpath = this.ctx.helper.getPreviewPath(r.fileext, r.filepath);
+                r.in_time = this.ctx.moment(r.in_time * 1000).format('YYYY-MM-DD');
+            }
+        }
+
         async getViewDataByFid(id) {
             const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.fileext, att.filesize, att.extra_upload, att.remark, att.in_time,' +
                 ' pa.name as `username`' +
                 ' FROM ' + this.tableName + ' att Left Join ' + this.ctx.service.projectAccount.tableName + ' pa On pa.id = att.uid' +
                 ' WHERE att.id = ?';
             const result = await this.db.query(sql, [id]);
-            for (const r of result) {
-                r.filepath = this.ctx.app.config.fujianOssPath + r.filepath;
-                if (this.ctx.helper.canPreview(r.fileext)) r.viewpath = r.filepath;
-                r.in_time = this.ctx.moment(r.in_time * 1000).format('YYYY-MM-DD');
-            }
+            this._analysisAtt(result);
             return result[0];
         }
 
@@ -169,11 +169,7 @@ module.exports = app => {
                 ' FROM ' + this.tableName + ' att Left Join ' + this.ctx.service.projectAccount.tableName + ' pa On pa.id = att.uid' +
                 ' WHERE att.tid = ? AND att.settle_id = ? ORDER BY att.id DESC';
             const result = await this.db.query(sql, [tid, settle_id]);
-            for (const r of result) {
-                r.filepath = this.ctx.app.config.fujianOssPath + r.filepath;
-                if (this.ctx.helper.canPreview(r.fileext)) r.viewpath = r.filepath;
-                r.in_time = this.ctx.moment(r.in_time * 1000).format('YYYY-MM-DD');
-            }
+            this._analysisAtt(result);
             return result;
         }
 
@@ -183,11 +179,7 @@ module.exports = app => {
                 ' FROM ' + this.tableName + ' att Left Join ' + this.ctx.service.projectAccount.tableName + ' pa On pa.id = att.uid' +
                 ' WHERE att.tid = ? AND att.revise_id = ? ORDER BY att.id DESC';
             const result = await this.db.query(sql, [tid, rid]);
-            for (const r of result) {
-                r.filepath = this.ctx.app.config.fujianOssPath + r.filepath;
-                if (this.ctx.helper.canPreview(r.fileext)) r.viewpath = r.filepath;
-                r.in_time = this.ctx.moment(r.in_time * 1000).format('YYYY-MM-DD');
-            }
+            this._analysisAtt(result);
             return result;
         }
 
@@ -195,13 +187,9 @@ module.exports = app => {
             const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.fileext, att.filesize, att.extra_upload, att.remark, att.in_time,' +
                 ' pa.name as `username`' +
                 ' FROM ' + this.tableName + ' att Left Join ' + this.ctx.service.projectAccount.tableName + ' pa On pa.id = att.uid' +
-                ' WHERE att.tid = ? AND att.revising = 0 ORDER BY att.id DESC';
+                ' WHERE att.tid = ? AND att.revising = 0 AND att.settle_id = -1 ORDER BY att.id DESC';
             const result = await this.db.query(sql, [tid]);
-            for (const r of result) {
-                r.filepath = this.ctx.app.config.fujianOssPath + r.filepath;
-                if (this.ctx.helper.canPreview(r.fileext)) r.viewpath = r.filepath;
-                r.in_time = this.ctx.moment(r.in_time * 1000).format('YYYY-MM-DD');
-            }
+            this._analysisAtt(result);
             return result;
         }
     }

+ 1 - 1
app/service/message_att.js

@@ -36,8 +36,8 @@ module.exports = app => {
                     item.filepath = `/wap/message/download/file/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/pay_att.js

@@ -28,7 +28,7 @@ module.exports = app => {
             });
             for (const f of files) {
                 f.filepath = this.ctx.app.config.fujianOssPath + f.filepath;
-                if (this.ctx.helper.canPreview(f.fileext)) f.viewpath = f.filepath;
+                f.viewpath = this.ctx.helper.getPreviewPath(f.fileext, f.filepath);
             }
             return files;
         }

+ 2 - 1
app/service/payment_detail_att.js

@@ -55,12 +55,13 @@ module.exports = app => {
             const result = await this.db.query(sql, sqlParam);
             return result.map(item => {
                 item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
+
                 if (!this.ctx.helper.canPreview(item.fileext)) {
                     item.filepath = `/sp/${this.ctx.subProject.id}/payment/${item.tender_id}/detail/${item.td_id}/file/${item.id}/download`;
                 } else {
                     item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
-                    item.viewpath = item.filepath;
                 }
+                item.viewpath = this.ctx.helper.getPreviewPath(item.fileext, item.orginpath);
                 return item;
             });
         }

+ 1 - 1
app/service/quality_file.js

@@ -30,8 +30,8 @@ module.exports = app => {
             const userId = this.ctx.session.sessionUser.accountId;
             const ossPath = this.ctx.app.config.fujianOssPath;
             files.forEach(x => {
-                x.viewpath = helper.canPreview(x.fileext) ? ossPath + x.filepath : '';
                 x.filepath = ossPath + x.filepath;
+                x.viewpath = helper.getPreviewPath(x.fileext, x.filepath);
                 x.fileext_str = helper.fileExtStr(x.fileext);
                 x.canEdit = x.user_id === userId;
             });

+ 1 - 3
app/service/stage_bonus.js

@@ -30,9 +30,7 @@ module.exports = app => {
                 if (d.proof_file) {
                     d.proof_file = JSON.parse(d.proof_file);
                     d.proof_file.forEach(f => {
-                        if (helper.canPreview(f.fileext)){
-                            f.viewpath = f.filepath.substr(3, f.filepath.length - 3);
-                        }
+                        f.viewpath = helper.getPreviewPath(f.fileext, f.filepath.substr(3, f.filepath.length - 3));
                     });
                 } else {
                     d.proof_file = [];

+ 1 - 4
app/service/stage_detail_att.js

@@ -72,10 +72,7 @@ module.exports = app => {
             const datas = data instanceof Array ? data : [data];
             for (const d of datas) {
                 for (const a of d.attachment) {
-                    if (this.ctx.helper.canPreview(a.fileext)){
-                        // a.viewpath = a.filepath.replace(/^app|\/app/, '');
-                        a.viewpath = this.ctx.app.config.fujianOssPath + a.filepath;
-                    }
+                    a.viewpath = this.ctx.helper.getPreviewPath(a.fileext, this.ctx.app.config.fujianOssPath + a.filepath);
                     a.filepath = this.ctx.app.config.fujianOssPath + a.filepath;
                     a.username = (await this.getUserTemp(a.uid)).name;
                 }

+ 1 - 4
app/service/stage_shoufang_att.js

@@ -99,10 +99,7 @@ module.exports = app => {
             for (const att of result) {
                 // if (!ctx.helper.canPreview(att.fileext)) att.filepath = `/wap/shoufang/download/file/${att.id}`;
                 // else att.filepath = att.filepath.replace(/^app|\/app/, '');
-                if (ctx.helper.canPreview(att.fileext)) {
-                    // att.viewpath = att.filepath.replace(/^app|\/app/, '');
-                    att.viewpath = ctx.app.config.fujianOssPath + att.filepath;
-                }
+                att.viewpath = ctx.helper.getPreviewPath(att.fileext, ctx.app.config.fujianOssPath + att.filepath);
                 att.filepath = `/wap/shoufang/download/file/${att.id}`;
             }
             return result;

+ 1 - 1
app/service/sub_proj_file.js

@@ -27,8 +27,8 @@ module.exports = app => {
             const userId = this.ctx.session.sessionUser.accountId;
             const ossPath = this.ctx.app.config.fujianOssPath;
             files.forEach(x => {
-                x.viewpath = helper.canPreview(x.fileext) ? ossPath + x.filepath : '';
                 x.filepath = ossPath + x.filepath;
+                x.viewpath = helper.getPreviewPath(x.fileext, x.filepath);
                 x.fileext_str = helper.fileExtStr(x.fileext);
                 x.canEdit = x.user_id === userId;
             });

+ 1 - 4
config/config.local.js

@@ -116,9 +116,6 @@ module.exports = appInfo => {
     config.managementProxyPath = 'http://192.168.1.76:2020';
 
     config.url3f = 'http://127.0.0.1:7005/3f';
-    config.table_depart = {
-        heavy: 100,
-        light: 10,
-    };
+    config.kkfileUrl = 'http://jlqa.smartcost.com.cn:8012/onlinePreview?url=';
     return config;
 };

+ 1 - 4
config/config.qa.js

@@ -91,9 +91,6 @@ module.exports = appInfo => {
     config.managementProxyPath = 'http://192.168.1.76:2020';
 
     config.url3f = 'http://jlqa.smartcost.com.cn:7005/3f';
-    config.table_depart = {
-        heavy: 100,
-        light: 10,
-    };
+    config.kkfileUrl = 'http://jlqa.smartcost.com.cn:8012/onlinePreview?url=';
     return config;
 };