Browse Source

查看文件时, 需要在线预览的pdf类文件, 直接打开新窗口

Pojun 7 months ago
parent
commit
ea168bda74

+ 10 - 8
tip-front/src/main/java/com/minto/web/tc/FileController.java

@@ -5,21 +5,21 @@
 
 package com.minto.web.tc;
 
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.minto.app.behavior.beans.BehSummaryBean;
 import com.minto.app.behavior.enums.BehaviorEnum;
 import com.minto.app.behavior.manager.IBehManager;
-import com.minto.app.behavior.beans.BehSummaryBean;
-import com.minto.app.resource.enums.ResourceEnum;
-import com.minto.app.tc.knowledge.enums.KmEnum;
 import com.minto.app.organization.manager.IOrgManager;
-import com.minto.app.space.manager.ISpaceManager;
-import com.minto.app.space.bo.SpaceFileBO;
+import com.minto.app.resource.enums.ResourceEnum;
 import com.minto.app.space.beans.SpaceFileBean;
+import com.minto.app.space.bo.SpaceFileBO;
+import com.minto.app.space.manager.ISpaceManager;
 import com.minto.app.task.util.TaskByTypeUtil;
+import com.minto.app.tc.knowledge.enums.KmEnum;
 import com.minto.core.common.AppContext;
 import com.minto.core.util.*;
 import com.minto.tip.common.exceptions.BusinessException;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -192,7 +192,9 @@ public class FileController {
             if(fileBean == null){
                 throw new BusinessException("文件不存在");
             }
-            result.put("onlineShow", onShowTypes.contains(fileBean.getFileType()));
+            if (onShowTypes.contains(fileBean.getFileType())) {
+                result.put("onlineShow", "/td/file/showWord?fileId=" + fileId.toString());
+            }
             result.put("state", "success");
         } catch(Exception e){
             result.put("state", "error");

+ 27 - 7
tip-front/src/main/webapp/tc_ttp/common/tc.js

@@ -681,11 +681,31 @@
          * @param {String} title  tab的显示名称
          */
         this.openTab = function(url, title) {
-            // 直接调用 openResource
-            TC.ui.openResource({
-                label:title || "",
-                url:url
-            });
+            // 2024-7-31 11:28:09 , 由于在线预览需要部署单独服务、并且在内嵌iframe会导致同源策略报错, 这里单独打开浏览器标签页
+            if(url.indexOf("/file/showFileInfo?fileId") > -1){
+                let params = url.split("fileId=")[1];
+                let fileId = params.split("&")[0];
+                $.ajax({
+                    type:"get",
+                    url:TC.config.baseUrl+ '/file/isOnlineShow?fileId='+fileId,
+                    dataType:"JSON",
+                    async:false,
+                    cache:false,
+                    success:function (data){
+                        if(data.state==='success' && data.onlineShow){
+                            window.open(TC.config.baseUrl + '' + data.onlineShow)
+                            return
+                        }else {
+                            // 直接调用 openResource
+                            TC.ui.openResource({
+                                label:title || "",
+                                url:url
+                            });
+                        }
+                    }
+                })
+            }
+
         };
 
         this.openDialog = function(url, title) {
@@ -1373,7 +1393,7 @@
                 if(!this.allowAddTab()){
                     return;
                 }
-                
+
                 if(this.counter > 13){
                     // TC.ui.closeTab(1);
                     $.dialog({
@@ -3321,4 +3341,4 @@ function processHtmlValue(value){
         value = value.replace(/\t/g,"	");
     }
     return value
-}
+}