Commit a904ad6b by 宋祥

1.调整文件预览方式

parent 2f538919
...@@ -34,6 +34,8 @@ public class HgWdConstant { ...@@ -34,6 +34,8 @@ public class HgWdConstant {
public static final String P = "P"; public static final String P = "P";
// 目录 // 目录
public static final String C = "C"; public static final String C = "C";
// 文件
public static final String F = "F";
} }
} }
...@@ -2,10 +2,12 @@ package com.baosight.hggp.hg.wd.service; ...@@ -2,10 +2,12 @@ package com.baosight.hggp.hg.wd.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation; import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.DeleteFlagEnum;
import com.baosight.hggp.hg.cw.tools.HGCWTools; import com.baosight.hggp.hg.cw.tools.HGCWTools;
import com.baosight.hggp.hg.wd.domain.HGWD001B; import com.baosight.hggp.hg.wd.domain.HGWD001B;
import com.baosight.hggp.hg.wd.domain.HGWD002; import com.baosight.hggp.hg.wd.domain.HGWD002;
import com.baosight.hggp.hg.wd.tools.HGWDTools; import com.baosight.hggp.hg.wd.tools.HGWDTools;
import com.baosight.hggp.util.AssertUtils;
import com.baosight.hggp.util.EiInfoUtils; import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils; import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils; import com.baosight.hggp.util.MapUtils;
...@@ -91,9 +93,11 @@ public class ServiceHGWD001B extends ServiceBase { ...@@ -91,9 +93,11 @@ public class ServiceHGWD001B extends ServiceBase {
try { try {
List<HGWD001B> fWd001bs = MapUtils.toDaoEPBases(inInfo, HGWD001B.class); List<HGWD001B> fWd001bs = MapUtils.toDaoEPBases(inInfo, HGWD001B.class);
for (HGWD001B fWd001b : fWd001bs) { for (HGWD001B fWd001b : fWd001bs) {
// AssertUtils.isEmpty(fWd001b.getFileId(), "文件ID不能为空");
// 预览记录+1 // 预览记录+1
HGWDTools.HgWd099.previewIncr(fWd001b.getDocId()); HGWDTools.HgWd099.previewIncr(fWd001b.getDocId());
// 新增 // 新增
fWd001b.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HGWD001B.INSERT, fWd001b); DaoUtils.insert(HGWD001B.INSERT, fWd001b);
} }
inInfo.setStatus(EiConstant.STATUS_SUCCESS); inInfo.setStatus(EiConstant.STATUS_SUCCESS);
......
...@@ -2,10 +2,12 @@ package com.baosight.hggp.hg.wd.service; ...@@ -2,10 +2,12 @@ package com.baosight.hggp.hg.wd.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation; import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.DeleteFlagEnum;
import com.baosight.hggp.hg.cw.tools.HGCWTools; import com.baosight.hggp.hg.cw.tools.HGCWTools;
import com.baosight.hggp.hg.wd.domain.HGWD001C; import com.baosight.hggp.hg.wd.domain.HGWD001C;
import com.baosight.hggp.hg.wd.domain.HGWD002; import com.baosight.hggp.hg.wd.domain.HGWD002;
import com.baosight.hggp.hg.wd.tools.HGWDTools; import com.baosight.hggp.hg.wd.tools.HGWDTools;
import com.baosight.hggp.util.AssertUtils;
import com.baosight.hggp.util.EiInfoUtils; import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils; import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils; import com.baosight.hggp.util.MapUtils;
...@@ -91,9 +93,11 @@ public class ServiceHGWD001C extends ServiceBase { ...@@ -91,9 +93,11 @@ public class ServiceHGWD001C extends ServiceBase {
try { try {
List<HGWD001C> fWd001cs = MapUtils.toDaoEPBases(inInfo, HGWD001C.class); List<HGWD001C> fWd001cs = MapUtils.toDaoEPBases(inInfo, HGWD001C.class);
for (HGWD001C fWd001c : fWd001cs) { for (HGWD001C fWd001c : fWd001cs) {
AssertUtils.isEmpty(fWd001c.getFileId(), "文件ID不能为空");
// 下载记录+1 // 下载记录+1
HGWDTools.HgWd099.downloadIncr(fWd001c.getDocId()); HGWDTools.HgWd099.downloadIncr(fWd001c.getDocId());
// 新增 // 新增
fWd001c.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HGWD001C.INSERT, fWd001c); DaoUtils.insert(HGWD001C.INSERT, fWd001c);
} }
inInfo.setStatus(EiConstant.STATUS_SUCCESS); inInfo.setStatus(EiConstant.STATUS_SUCCESS);
......
package com.baosight.hggp.hg.wd.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.wd.constant.HgWdConstant;
import com.baosight.hggp.hg.wd.domain.HGWD001;
import com.baosight.hggp.hg.wd.domain.HGWD002;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author:songx
* @date:2024/5/9,11:04
*/
public class ServiceHGWD002A extends ServiceEPBase {
/**
* 画面初始化
*
* @param inInfo
* @return
*/
@Override
@OperationLogAnnotation(operModul = "文档浏览", operType = "查询", operDesc = "初始化")
public EiInfo initLoad(EiInfo inInfo) {
try {
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "初始化失败");
}
return inInfo;
}
/**
* 树节点查询
*
* @param inInfo
* @return
*/
public EiInfo queryTree(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String fileId = MapUtils.getString(queryMap, HGWD001.FIELD_FILE_ID);
String node = MapUtils.getString(queryMap, CommonConstant.Field.NODE);
if (CommonConstant.Field.ROOT.equals(node) || CommonConstant.Field.ROOT2.equals(node)) {
inInfo.addBlock(node).setRows(queryTopNode(node, fileId));
} else {
inInfo.addBlock(node).setRows(queryChildNode(node));
}
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "查询节点失败");
}
return inInfo;
}
/**
* 查询树根
*
* @param parentId
* @param fileId
* @return
*/
public List queryTopNode(String parentId, String fileId) {
List<Map> results = new ArrayList();
Map queryMap = new HashMap();
queryMap.put(HGWD001.FIELD_FILE_ID, fileId);
List<HGWD001> dbWd001s = dao.query(HGWD001.QUERY, queryMap);
if (CollectionUtils.isEmpty(dbWd001s)) {
return results;
}
for (HGWD001 dbWd001 : dbWd001s) {
results.add(buildLeaf(parentId, dbWd001.getFileId(), dbWd001.getFileName(),
HgWdConstant.LeafType.C, "", 0));
}
return results;
}
/**
* 查询叶子节点
*
* @param parentId
* @return
*/
public List queryChildNode(String parentId) {
List<Map> results = new ArrayList();
Map queryMap = new HashMap();
queryMap.put("parentId", parentId);
queryMap.put("userId", UserSessionUtils.getLoginName());
List<HGWD002> dbWd002s = dao.query(HGWD002.QUERY, queryMap);
if (CollectionUtils.isEmpty(dbWd002s)) {
return results;
}
for (HGWD002 dbWd002 : dbWd002s) {
results.add(buildLeaf(parentId, dbWd002.getDocId(), dbWd002.getDocName(),
HgWdConstant.LeafType.F, dbWd002.getDocType(), 1));
}
return results;
}
/**
* 构建叶子节点
*
* @param parentId
* @param label
* @param text
* @param leaf
*/
private HashMap buildLeaf(String parentId, String label, String text, String leafType, String docType,
Integer leaf) {
HashMap<String, Object> leafMap = new HashMap();
leafMap.put("parentId", parentId);
leafMap.put("label", label);
leafMap.put("text", text);
leafMap.put("leafType", leafType);
leafMap.put("docType", docType);
leafMap.put("leaf", leaf);
return leafMap;
}
}
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
<input id="__LOGIN_PUBLICKEY__" inline="true" type="hidden" value="<%=loginPublicKey%>"/> <input id="__LOGIN_PUBLICKEY__" inline="true" type="hidden" value="<%=loginPublicKey%>"/>
<div class="col-sm-6 col-sm-offset-2 col-md-4 col-md-offset-4" style="margin-bottom: 1em"> <div class="col-sm-6 col-sm-offset-2 col-md-4 col-md-offset-4" style="margin-bottom: 1em">
<div class="form-header"> <div class="form-header">
<p style="font-size: 28px;"><b>企业经营一体化平台</b></p> <p style="font-size: 28px;"><b>武汉北湖德诚设备有限公司</b></p>
</div> </div>
</div> </div>
<div class="col-sm-6 col-sm-offset-2 col-md-4 col-md-offset-4"> <div class="col-sm-6 col-sm-offset-2 col-md-4 col-md-offset-4">
......
...@@ -258,23 +258,34 @@ let showDownloadRecord = function (fileId, docId) { ...@@ -258,23 +258,34 @@ let showDownloadRecord = function (fileId, docId) {
* 预览 * 预览
*/ */
let preview = function () { let preview = function () {
let rows = resultGrid.getCheckedRows(); let params = {
if (rows.length < 1) { "inqu_status-0-fileId": $("#inqu_status-0-fileId").val()
message("请选择数据");
return;
}
JSUtils.submitGridsData("result", "HGWD001B", "add", false,
function (res) {
if (res.status > -1) {
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
previewDoc(row['docType'], row['docId']);
} }
} else { JSColorbox.open({
message(res.msg); href: "HGWD002A",
} title: "<div style='text-align: center;'>文件预览</div>",
} width: "90%",
); height: "95%",
params: params
});
// let rows = resultGrid.getCheckedRows();
// if (rows.length < 1) {
// message("请选择数据");
// return;
// }
// JSUtils.submitGridsData("result", "HGWD001B", "add", false,
// function (res) {
// if (res.status > -1) {
// for (let i = 0; i < rows.length; i++) {
// let row = rows[i];
// previewDoc(row['docType'], row['docId']);
// }
// } else {
// message(res.msg);
// }
// }
// );
} }
/** /**
......
$(function () {
IPLATUI.EFTree = {
"docTree": {
query: function (inInfo, model) {
inInfo.set("inqu_status-0-fileId", $("#inqu_status-0-fileId").val());
return inInfo;
},
select: function (e) {
var nodeData = this.dataItem(e.node);
let label = nodeData.label;
let leafType = nodeData.leafType;
IPLATUI.EFTree.docTree.selectNode.treeId = label;
IPLATUI.EFTree.docTree.selectNode.leaf = nodeData.leaf;
IPLATUI.EFTree.docTree.selectNode.leafType = leafType;
// 添加预览记录
add(label, leafType, nodeData.docType);
},
template: function (node) {
var item = node.item;
let icon = 'fa fa-globe'
switch (item.leafType) {
case 'P':
icon = 'fa fa-clipboard'
break;
case 'C':
icon = 'fa fa-folder'
break;
}
return '<span class="' + icon + '" style="padding-right: 8px"> </span>'
+ '<span class="titleClass" title="' + item.label + '">'
+ item.text + '</span>'
},
loadComplete: function (options) {
// 保持结点展开状态
let fileId = $("#inqu_status-0-fileId").val();
let tree = $("#docTree").data("kendoTreeView");
expandTreeNode(tree, fileId);
},
selectNode: {
treeId: '',
leaf: false,
leafType: '',
}
// ROOT: {label: "root", text: "系统菜单", leaf: true}
}
};
});
/**
* 页面加载完后执行
*/
$(window).load(function () {
imageMouseListener();
});
/**
* 图片鼠标事件监听
*/
function imageMouseListener() {
document.getElementById('image').addEventListener('mousewheel', function (event) {
var scale = event.wheelDelta / 1000;
var newScale = Math.max(Math.min(this.scale || 1, 3), 0.1);
newScale += scale;
this.style.transform = 'scale(' + newScale + ')';
this.scale = newScale;
event.preventDefault();
});
}
function zoomImage(scale) {
var img = document.getElementById('image');
var width = img.naturalWidth * (scale / 100);
var height = img.naturalHeight * (scale / 100);
img.style.width = width + 'px';
img.style.height = height + 'px';
}
/**
* 批量展开树节点
*
* @param tree
* @param node
*/
function expandTreeNode(tree, node) {
if (node == null || tree == null) {
return;
}
let barDataItem = tree.dataSource.get(node);
if (barDataItem) {
tree.expandPath([node])
} else {
setTimeout(() => {
expandTreeNode(tree, node)
}, 100)
}
}
/**
* 预览
*
* @param label docId
* @param leafType 节点类型:C=目录,F=文件
* @param docType
*/
function add(docId, leafType, docType) {
if (isBlank(leafType) || isBlank(docId)) {
message("文件类型或ID不能为空");
return;
}
let inInfo = new EiInfo();
inInfo.set("result-0-fileId", $("#inqu_status-0-fileId").val());
inInfo.set("result-0-docId", docId);
EiCommunicator.send('HGWD001B', 'add', inInfo, {
onSuccess: function (res) {
if (res.getStatus() >= 0) {
preview(docId, docType);
} else {
message(res.getMsg());
}
},
onFail: function (res) {
NotificationUtil("操作失败,原因[" + res.getMsg() + "]", "error");
}
});
}
/**
* 新增记录后回调
*
* @param docId
* @param docType
*/
function preview(docId, docType) {
// 隐藏预览区域
hideHtml();
// 隐藏文本描述
$("#descDiv").css('display', 'none');
if ("docx" == docType) {
previewDocx(docId);
} else if (isImage(docType)) {
previewImage(docId);
} else if (isFrame(docType)) {
previewFrame(docId);
} else {
otherDownload(docId);
}
}
/**
* 隐藏显示区域
*/
function hideHtml() {
$("#docxContainer").css('display', 'none');
$("#imageContainer").css('display', 'none');
$("#previewFrame").css('display', 'none');
}
/**
* docx预览
*
* @param docId
*/
function previewDocx(docId) {
fetch(downloadHref(docId, true)).then(res => {
return res.arrayBuffer();
}).then(arrayBuffer => {
let container = document.getElementById("docxContainer");
container.style.display = 'block';
docx.renderAsync(arrayBuffer, container).then((x) => {
console.log("docx: finished")
});
});
}
/**
* 判断是否是图片
*
* @param fileName
* @returns {boolean}
*/
function isImage(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
return extensions.includes(docType.toLowerCase());
}
/**
* image预览
*
* @param docId
*/
function previewImage(docId) {
$("#image").attr('src', downloadHref(docId, true));
$("#imageContainer").css('display', '');
}
/**
* 判断是否frame预览
*
* @param fileName
* @returns {boolean}
*/
function isFrame(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['pdf'];
return extensions.includes(docType.toLowerCase());
}
/**
* frame预览
*
* @param docId
*/
function previewFrame(docId) {
$("#previewFrame").css('display', '');
$("#previewFrame").attr("src", downloadHref(docId, true));
}
/**
* 其他下载
*
* @param docId
*/
function otherDownload(docId) {
$("#descDiv").css('display', '');
$("#descSpan").html("该文件暂不支持预览,点击<a href='" + downloadHref(docId, false)
+ "' target='_blank'>下载</a>");
}
<!DOCTYPE html>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="EF" tagdir="/WEB-INF/tags/EF" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<script src="${ctx}/common/docxjs/jszip.min.js"></script>
<script src="${ctx}/common/docxjs/docx-preview.js"></script>
<style>
.left-flex {
display: flex;
align-items: center;
height: 100%;
width: 100%;
overflow: scroll;
}
.center-flex {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
overflow: scroll;
}
iframe {
min-width: 100%;
min-height: 100%;
border: 0px;
}
.imageContainer {
display: flex;
flex-direction: column;
height: 100%;
}
.wide-div {
flex: 1;
flex-basis: 90%;
overflow: scroll;
}
.narrow-div {
flex: 0 0 10%;
}
img {
max-width: 100%;
max-height: 100%;
cursor: zoom-in;
transition: transform 0.1s;
}
img:hover {
cursor: zoom-out;
}
.zoom-slider {
width: 100%;
margin-top: 10px;
}
</style>
<EF:EFPage title="文件预览">
<div class="row" style="margin: 0 -10px;">
<div class="col-md-3">
<EF:EFRegion title="文件目录树" id="tree" fitHeight="true">
<EF:EFInput ename="fileId" cname="文件ID" blockId="inqu_status" row="0" type="hidden"/>
<div id="menu" style="margin-top: 12px; margin-bottom: 8px">
<EF:EFTree bindId="docTree" ename="node" textField="text" valueField="label" hasChildren="leaf"
serviceName="HGWD002A" methodName="queryTree" expandLevel="1">
</EF:EFTree>
</div>
</EF:EFRegion>
</div>
<div class="col-md-9">
<EF:EFRegion title="预览区域" id="preview" fitHeight="true">
<div id="descDiv" class="center-flex">
<span id="descSpan" style="font-weight: bold;font-size: 18px">文件预览区域...</span>
</div>
<%-- docx文件预览--%>
<div id="docxContainer" style="display: none;"></div>
<%-- IMAGE文件预览--%>
<div id="imageContainer" class="left-flex" style="display: none;">
<%-- <div class="wide-div">--%>
<img id="image" src="" style="border: 1px solid gray;"/>
<%-- </div>--%>
<%-- <div class="narrow-div">--%>
<%-- <input type="range" id="zoom-slider" class="zoom-slider" min="10" max="300" value="100"--%>
<%-- oninput="zoomImage(this.value)">--%>
<%-- </div>--%>
</div>
<%-- other --%>
<iframe id="previewFrame" src="" style="display: none;"></iframe>
</EF:EFRegion>
</div>
</div>
</EF:EFPage>
...@@ -9,7 +9,6 @@ $(document).ready(function () { ...@@ -9,7 +9,6 @@ $(document).ready(function () {
}).then(arrayBuffer => { }).then(arrayBuffer => {
renderDocx(arrayBuffer); renderDocx(arrayBuffer);
}); });
}); });
/** /**
......
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
<script src="${ctx}/common/docxjs/jszip.min.js"></script> <script src="${ctx}/common/docxjs/jszip.min.js"></script>
<script src="${ctx}/common/docxjs/docx-preview.js"></script> <script src="${ctx}/common/docxjs/docx-preview.js"></script>
<style>
.fixed-window {
height: 92vh;
overflow-y: scroll;
}
</style>
<EF:EFPage title="WORD预览"> <EF:EFPage title="WORD预览">
<EF:EFRegion id="result" title="展示区域" fitHeight="true">
<EF:EFInput cname="文件ID" ename="docId" blockId="inqu_status" row="0" type="hidden"/> <EF:EFInput cname="文件ID" ename="docId" blockId="inqu_status" row="0" type="hidden"/>
<div id="docx-container"></div> <div id="docx-container" class="fixed-window"></div>
</EF:EFRegion>
</EF:EFPage> </EF:EFPage>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment