Commit be724be5 by liuyang

1、同步汉光文档库功能

parent 452cea71
......@@ -8,6 +8,8 @@
package com.baosight.hpjx.core.constant;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
/**
* 与操作系统 有关的一些常量.
*
......@@ -15,6 +17,11 @@ package com.baosight.hpjx.core.constant;
* @date:2019/12/12,16:32
*/
public class OSConstant {
/**
* docRootDir
*/
public static String DOC_ROOT_DIR = PlatApplicationContext.getProperty("docRootDir");
/**
* 文件夹分隔符,不同OS下分隔符不同
......@@ -45,5 +52,10 @@ public class OSConstant {
* 压缩包目录
*/
public final static String ZIP_DIR = USER_DIR + SEPARATOR + "file" + SEPARATOR + "zip";
/**
* 文件下载上下文
*/
public final static String FILE_DOWNLOAD = "file-download";
}
......@@ -118,7 +118,43 @@ public class Iplat4jTools {
return results;
}
}
/**
* 上传的文件
*
* @author:songx
* @date:2024/8/8,16:47
*/
public static class EuDm02 {
/**
* 查询
*
* @param docId
* @return
*/
public static Map getByDocId(String docId) {
AssertUtils.isEmpty(docId, "文件ID不能为空!");
Map<String, String> paramMap = new HashMap();
paramMap.put("docId", docId);
List<Map> results = DaoBase.getInstance().query("EUDM02.queryDocById", paramMap);
return CollectionUtils.isEmpty(results) ? null : results.get(0);
}
/**
* 查询
*
* @param docIds
* @return
*/
public static List<Map> listByDocId(List<String> docIds) {
AssertUtils.isEmpty(docIds, "文件ID不能为空!");
Map<String, Object> paramMap = new HashMap();
paramMap.put("docIds", docIds);
return DaoBase.getInstance().query("EUDM02.queryDocById", paramMap);
}
}
/**
* 上传的文件
*
......
......@@ -13,6 +13,7 @@ import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext;
import com.baosight.iplat4j.eu.dm.util.PlatFileUploader;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
......@@ -79,6 +80,31 @@ public class Iplat4jUtils {
}
/**
* 构建文件HTTP地址
*
* @param docId
* @return
* @throws Exception
*/
public static String buildDocUrl(String docId) throws Exception {
if (StringUtils.isEmpty(docId)) {
return null;
}
if ("s3".equalsIgnoreCase(S3Constant.FILE_LOCATION)) {
return S3Utils.buildUrl(docId).getUrl();
} else {
Map dbDm02Map = Iplat4jTools.EuDm02.getByDocId(docId);
if (MapUtils.isEmpty(dbDm02Map)) {
return null;
}
String chgName = dbDm02Map.get("chgName").toString();
String realPath = dbDm02Map.get("realPath").toString();
return S3Constant.RESOURCE + "/" + OSConstant.FILE_DOWNLOAD + "/" + realPath
+ URLEncoder.encode(chgName, "UTF-8");
}
}
/**
* 压缩文件
*
* @param docIds
......@@ -86,8 +112,8 @@ public class Iplat4jUtils {
* @return
*/
public static String compressFile(List<String> docIds, String zipName) throws Exception {
String zipFolderPath = OSConstant.ZIP_DIR + OSConstant.SEPARATOR + DateUtils.shortDate()
+ OSConstant.SEPARATOR + zipName;
String mainFolderPath = OSConstant.ZIP_DIR + OSConstant.SEPARATOR + DateUtils.shortDate();
String zipFolderPath = mainFolderPath + OSConstant.SEPARATOR + zipName;
FileUtils.createDirs(zipFolderPath);
String zipFilePath = zipFolderPath + ".zip";
if (CommonConstant.FileLocation.S3.equalsIgnoreCase(S3Constant.FILE_LOCATION)) {
......@@ -112,8 +138,10 @@ public class Iplat4jUtils {
// 压缩完删除本地文件
FileUtils.deleteFiles(zipFolderPath);
// 替换成HTTP地址
return S3Constant.RESOURCE + zipFilePath.replace(OSConstant.USER_DIR, "")
.replace(OSConstant.SEPARATOR, "/");
return S3Constant.RESOURCE + "/" + OSConstant.FILE_DOWNLOAD
+ mainFolderPath.replace(OSConstant.DOC_ROOT_DIR, "")
.replace(OSConstant.SEPARATOR, "/") + "/"
+ URLEncoder.encode(zipName, "UTF-8").replace("\\+", "%20") + ".zip";
}
}
......@@ -3,6 +3,7 @@ package com.baosight.hpjx.hp.wd.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.common.ChangeTypeEnum;
import com.baosight.hpjx.common.DdynamicEnum;
import com.baosight.hpjx.common.DeleteFlagEnum;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.core.security.UserSessionUtils;
......@@ -14,10 +15,7 @@ import com.baosight.hpjx.hp.sc.domain.HPSC001;
import com.baosight.hpjx.hp.sc.enums.ProjectSourceEnum;
import com.baosight.hpjx.hp.wd.constant.HpWdConstant;
import com.baosight.hpjx.hp.wd.constant.HpWdSqlConstant;
import com.baosight.hpjx.hp.wd.domain.HPWD001;
import com.baosight.hpjx.hp.wd.domain.HPWD001A;
import com.baosight.hpjx.hp.wd.domain.HPWD003;
import com.baosight.hpjx.hp.wd.domain.HPWD099;
import com.baosight.hpjx.hp.wd.domain.*;
import com.baosight.hpjx.hp.wd.tools.HPWDTools;
import com.baosight.hpjx.hp.wd.utils.HpWdUtils;
import com.baosight.hpjx.hp.xs.domain.User;
......@@ -218,9 +216,6 @@ public class ServiceHPWD001 extends ServiceEPBase {
Map<?, ?> map = eiBlock.getRow(i);
HPWD099 hgwd099 = new HPWD099();
hgwd099.fromMap(map);
if (hgwd099.getOperStatus() == 0){
hgwd099.setDocVersion(hgwd099.getDocVersion() + 1);
}
hgwd099.setStatus(HpWdConstant.FileStatus.S_1);
hgwd099.setReleaseDate(DateUtils.shortDateTime());
hgwd099.setOperStatus(HpWdConstant.OperStatus.S_0);
......@@ -552,7 +547,8 @@ public class ServiceHPWD001 extends ServiceEPBase {
public EiInfo queryProjectManager(EiInfo inInfo) {
try {
Map queryRow =EiInfoUtils.getFirstRow(inInfo);
Integer isManager =HPWDTools.HpWd003.isProjectManager(queryRow.get(HPWD001.FIELD_FILE_ID).toString());
String fileId = MapUtils.getString(queryRow,HPWD001.FIELD_FILE_ID);
Integer isManager = HPWDTools.HpWd003.isProjectManager(fileId);
inInfo.set("isManager", isManager);
}catch (Exception e){
LogUtils.setMsg(inInfo, e, "查询失败");
......@@ -560,24 +556,6 @@ public class ServiceHPWD001 extends ServiceEPBase {
return inInfo;
}
/**
* 批量下载
*
* @param inInfo
* @return
*/
public EiInfo batchDownload(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String fileName = MapUtils.getString(queryMap, HPWD001.FIELD_FILE_NAME);
String zipName = fileName + "_" + DateUtils.shortDateTime();
List<String> docIds = ObjectUtils.listKey(inInfo, HPWD099.FIELD_DOC_ID);
inInfo.set("downloadUrl", Iplat4jUtils.compressFile(docIds, zipName));
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "批量下载失败");
}
return inInfo;
}
/**
* 清理下载的文件
......
......@@ -3,13 +3,12 @@ package com.baosight.hpjx.hp.wd.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.common.DeleteFlagEnum;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.core.utils.Iplat4jUtils;
import com.baosight.hpjx.hp.wd.domain.HPWD001B;
import com.baosight.hpjx.hp.wd.domain.HPWD002;
import com.baosight.hpjx.hp.wd.domain.HPWD099;
import com.baosight.hpjx.hp.wd.tools.HPWDTools;
import com.baosight.hpjx.util.EiInfoUtils;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.MapUtils;
import com.baosight.hpjx.util.StringUtils;
import com.baosight.hpjx.util.*;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
......@@ -88,15 +87,19 @@ public class ServiceHPWD001B extends ServiceEPBase {
*/
public EiInfo add(EiInfo inInfo) {
try {
List<HPWD001B> fWd001bs = MapUtils.toDaoEPBases(inInfo, HPWD001B.class);
for (HPWD001B fWd001b : fWd001bs) {
// AssertUtils.isEmpty(fWd001b.getFileId(), "文件ID不能为空");
// 预览记录+1
HPWDTools.HpWd099.previewIncr(fWd001b.getDocId());
// 新增
fWd001b.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HPWD001B.INSERT, fWd001b);
}
HPWD001B fWd001b = MapUtils.toDaoEPBase(inInfo, EiConstant.resultBlock, HPWD001B.class);
HPWD099 dbWd099 = HPWDTools.HpWd099.getByDocId("WD",fWd001b.getDocId());
AssertUtils.isNull(dbWd099, "文件不存在");
HPWDTools.HpWd099.previewIncr(fWd001b.getDocId());
//新增 预览记录+1
fWd001b.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HPWD001B.INSERT, fWd001b);
// 构建文件HTTP地址
String url = Iplat4jUtils.buildDocUrl(fWd001b.getDocId());
AssertUtils.isEmpty(url, "文件地址异常,请联系管理人员!");
inInfo.set("url", url);
inInfo.set("docType", dbWd099.getDocType());
inInfo.setStatus(EiConstant.STATUS_SUCCESS);
inInfo.setMsg("操作成功");
} catch (Exception e) {
......
......@@ -3,8 +3,11 @@ package com.baosight.hpjx.hp.wd.service;
import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.common.DeleteFlagEnum;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.core.utils.Iplat4jUtils;
import com.baosight.hpjx.hp.wd.domain.HPWD001;
import com.baosight.hpjx.hp.wd.domain.HPWD001C;
import com.baosight.hpjx.hp.wd.domain.HPWD002;
import com.baosight.hpjx.hp.wd.domain.HPWD099;
import com.baosight.hpjx.hp.wd.tools.HPWDTools;
import com.baosight.hpjx.util.*;
import com.baosight.iplat4j.core.ei.EiBlock;
......@@ -85,20 +88,57 @@ public class ServiceHPWD001C extends ServiceEPBase {
*/
public EiInfo add(EiInfo inInfo) {
try {
List<HPWD001C> fWd001cs = MapUtils.toDaoEPBases(inInfo, HPWD001C.class);
for (HPWD001C fWd001c : fWd001cs) {
AssertUtils.isEmpty(fWd001c.getFileId(), "文件ID不能为空");
// 下载记录+1
HPWDTools.HpWd099.downloadIncr(fWd001c.getDocId());
// 新增
fWd001c.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HPWD001C.INSERT, fWd001c);
}
inInfo.setStatus(EiConstant.STATUS_SUCCESS);
HPWD001C fWd001c = MapUtils.toDaoEPBase(inInfo, EiConstant.resultBlock,HPWD001C.class);
this.saveData(inInfo, fWd001c.getFileId());
// 构建文件HTTP地址
//String url = Iplat4jUtils.buildDocUrl(fWd001c.getDocId());
//AssertUtils.isEmpty(url, "文件地址异常,请联系管理人员!");
//inInfo.set("url", url);
inInfo.setMsg("操作成功");
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "操作失败");
}
return inInfo;
}
/**
* 批量下载
*
* @param inInfo
* @return
*/
public EiInfo batchDownload(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String fileId = MapUtils.getString(queryMap, HPWD001.FIELD_FILE_ID);
String fileName = MapUtils.getString(queryMap, HPWD001.FIELD_FILE_NAME);
String zipName = fileName + "_" + DateUtils.shortDateTime();
List<String> docIds = ObjectUtils.listKey(inInfo, HPWD099.FIELD_DOC_ID);
inInfo.set("downloadUrl", Iplat4jUtils.compressFile(docIds, zipName));
//写入下载记录
this.saveData(inInfo, fileId);
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "批量下载失败");
}
return inInfo;
}
/**
* 保存数据
*
* @param inInfo
*/
private void saveData(EiInfo inInfo, String fileId) {
AssertUtils.isEmpty(fileId, "文件ID不能为空");
List<HPWD001C> fWd001Cs = MapUtils.toDaoEPBases(inInfo, HPWD001C.class);
for (HPWD001C fWd001c : fWd001Cs) {
// 下载记录+1
HPWDTools.HpWd099.downloadIncr(fWd001c.getDocId());
// 新增
fWd001c.setFileId(fileId);
fWd001c.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
DaoUtils.insert(HPWD001C.INSERT, fWd001c);
}
}
}
......@@ -4,7 +4,9 @@ import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.common.ChangeTypeEnum;
import com.baosight.hpjx.common.DdynamicEnum;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.dao.DaoBase;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.core.security.UserSessionUtils;
import com.baosight.hpjx.core.tools.Iplat4jTools;
import com.baosight.hpjx.hp.constant.HPConstant;
import com.baosight.hpjx.hp.sc.domain.HPSC001;
......@@ -12,7 +14,9 @@ import com.baosight.hpjx.hp.sc.tools.HPSCTools;
import com.baosight.hpjx.hp.wd.constant.HpWdConstant;
import com.baosight.hpjx.hp.wd.domain.HPWD001;
import com.baosight.hpjx.hp.wd.domain.HPWD001A;
import com.baosight.hpjx.hp.wd.domain.HPWD003;
import com.baosight.hpjx.hp.wd.tools.HPWDTools;
import com.baosight.hpjx.hp.xs.domain.User;
import com.baosight.hpjx.util.AssertUtils;
import com.baosight.hpjx.util.CommonMethod;
import com.baosight.hpjx.util.LogUtils;
......@@ -21,6 +25,7 @@ import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.ed.util.SequenceGenerator;
import org.apache.commons.collections.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
......@@ -66,6 +71,9 @@ public class ServiceHPWD001E extends ServiceEPBase {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
List<Map<String, Object>> edcm01List = Iplat4jTools.EdCm01.list("hpjx.hpwd.fileType");
List<HPWD001> hgwd001s = new ArrayList<>();
List<User> users = DaoBase.getInstance().query("HPWD003A.query",new HashMap<String, Object>(){{
put("userId", UserSessionUtils.getUserId());
}});
// 写入数据
for (Map resultRow : resultRows) {
HPWD001 hgwd001 = new HPWD001();
......@@ -74,7 +82,7 @@ public class ServiceHPWD001E extends ServiceEPBase {
// 设置项目信息
this.setProjectInfo(hgwd001);
if (hgwd001.getId() == null || hgwd001.getId() == 0) {
this.add(hgwd001);
this.add(hgwd001,users);
} else {
this.modify(hgwd001,edcm01List);
}
......@@ -92,7 +100,7 @@ public class ServiceHPWD001E extends ServiceEPBase {
/**
* 新增操作
*/
public void add(HPWD001 hgwd001) {
public void add(HPWD001 hgwd001,List<User> users) {
hgwd001.setFileId(SequenceGenerator.getNextSequence(HPConstant.SequenceId.WD_FILE_ID));
hgwd001.setDocVersion(hgwd001.getDocVersion() + 1);
DaoUtils.insert(HPWD001.INSERT, hgwd001);
......@@ -106,6 +114,16 @@ public class ServiceHPWD001E extends ServiceEPBase {
hgwd001a.setChangeEnd(hgwd001.getFileName());
hgwd001a.setMatId(hgwd001.getId());
HPWDTools.HpWd001.addHPWD001A(hgwd001a);
if (CollectionUtils.isNotEmpty(users)){
User user = users.get(0);
HPWD003 fWd003 = new HPWD003();
fWd003.setUserId(user.getUserId());
fWd003.setUserName(user.getUserId());
fWd003.setOrgId(user.getDepCode());
fWd003.setOrgCname(user.getDepName());
fWd003.setFileId(hgwd001.getFileId());
DaoUtils.insert(HPWD003.INSERT, fWd003);
}
}
/**
......
......@@ -4,13 +4,17 @@ import com.baosight.hpjx.aspect.annotation.OperationLogAnnotation;
import com.baosight.hpjx.common.ChangeTypeEnum;
import com.baosight.hpjx.common.DdynamicEnum;
import com.baosight.hpjx.core.constant.CommonConstant;
import com.baosight.hpjx.core.dao.DaoBase;
import com.baosight.hpjx.core.dao.DaoUtils;
import com.baosight.hpjx.core.security.UserSessionUtils;
import com.baosight.hpjx.core.tools.Iplat4jTools;
import com.baosight.hpjx.hp.constant.HPConstant;
import com.baosight.hpjx.hp.wd.constant.HpWdConstant;
import com.baosight.hpjx.hp.wd.domain.HPWD001;
import com.baosight.hpjx.hp.wd.domain.HPWD001A;
import com.baosight.hpjx.hp.wd.domain.HPWD003;
import com.baosight.hpjx.hp.wd.tools.HPWDTools;
import com.baosight.hpjx.hp.xs.domain.User;
import com.baosight.hpjx.util.CommonMethod;
import com.baosight.hpjx.util.LogUtils;
import com.baosight.hpjx.util.contants.ACConstants;
......@@ -18,6 +22,7 @@ import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.iplat4j.ed.util.SequenceGenerator;
import org.apache.commons.collections.CollectionUtils;
import java.util.Arrays;
import java.util.HashMap;
......@@ -59,13 +64,16 @@ public class ServiceHPWD001F extends ServiceEPBase {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
List<Map<String, Object>> edcm01List = Iplat4jTools.EdCm01.list("hpjx.hpwd.fileType");
List<User> users = DaoBase.getInstance().query(HPWD003.QUERY,new HashMap<String, Object>(){{
put("userId", UserSessionUtils.getUserId());
}});
// 写入数据
for (Map resultRow : resultRows) {
HPWD001 hpwd001 = new HPWD001();
hpwd001.fromMap(resultRow);
hpwd001.setStatus(HpWdConstant.FileStatus.S_0);
if (hpwd001.getId() == null || hpwd001.getId() == 0) {
this.add(hpwd001);
this.add(hpwd001,users);
} else {
this.modify(hpwd001,edcm01List);
}
......@@ -81,7 +89,7 @@ public class ServiceHPWD001F extends ServiceEPBase {
/**
* 新增操作
*/
public void add(HPWD001 hpwd001) {
public void add(HPWD001 hpwd001,List<User> users) {
hpwd001.setFileId(SequenceGenerator.getNextSequence(HPConstant.SequenceId.WD_FILE_ID));
hpwd001.setDocVersion(hpwd001.getDocVersion() + 1);
DaoUtils.insert(HPWD001.INSERT, hpwd001);
......@@ -95,6 +103,16 @@ public class ServiceHPWD001F extends ServiceEPBase {
hpwd001a.setChangeEnd(hpwd001.getFileName());
hpwd001a.setMatId(hpwd001.getId());
HPWDTools.HpWd001.addHPWD001A(hpwd001a);
if (CollectionUtils.isNotEmpty(users)){
User user = users.get(0);
HPWD003 fWd003 = new HPWD003();
fWd003.setUserId(user.getUserId());
fWd003.setUserName(user.getUserId());
fWd003.setOrgId(user.getDepCode());
fWd003.setOrgCname(user.getDepName());
fWd003.setFileId(hpwd001.getFileId());
DaoUtils.insert(HPWD003.INSERT, fWd003);
}
}
/**
......
......@@ -167,7 +167,7 @@
DOC_NAME = #docName#, <!-- 文件名称 -->
DOC_TYPE = #docType#, <!-- 文件类型 -->
STATUS = #status#,
DOC_VERSION = DOC_VERSION + 1, <!--版本号-->
<!-- DOC_VERSION = DOC_VERSION + 1, 版本号-->
RELEASE_DATE = #releaseDate#, <!--发布时间-->
OPER_STATUS = #operStatus#,
UPDATED_BY = #updatedBy#, <!-- 修改人 -->
......@@ -190,7 +190,7 @@
UPDATE ${hpjxSchema}.T_HPWD099
SET
RELEASE_DATE = #releaseDate#, <!--发布时间-->
DOC_VERSION = #docVersion#, <!--版本号-->
DOC_VERSION = DOC_VERSION + 1, <!--版本号-->
STATUS = #status#, <!-- 状态 -->
OPER_STATUS = #operStatus#,
<include refid="SqlBase.updateRevise"/>
......
......@@ -335,12 +335,13 @@ public class HPWDTools {
public static class HpWd099 {
public static List<HPWD099> getByDocId(String bizType, String docId) {
public static HPWD099 getByDocId(String bizType, String docId) {
AssertUtils.isEmpty(docId, "文件ID不能为空");
Map<String, Object> paramMap = new HashMap();
paramMap.put(HPWD099.FIELD_BIZ_TYPE, bizType);
paramMap.put(HPWD099.FIELD_DOC_ID, docId);
return DaoBase.getInstance().query(HPWD099.QUERY, paramMap);
List<HPWD099> results = DaoBase.getInstance().query(HPWD099.QUERY, paramMap);
return CollectionUtils.isEmpty(results) ? null : results.get(0);
}
/**
......
......@@ -94,7 +94,11 @@ $(function () {
IPLATUI.EFTree = {
"categoryTree": {
ROOT: {label: 'root', text: '目录结构'},
query: function (inInfo, model) {
if (model == null || model.id === "root") {
return inInfo;
}
inInfo.set("inqu_status-0-projCode", $("#inqu_status-0-projCode").val());
return inInfo;
},
......@@ -489,10 +493,15 @@ $(function () {
title: "操作",
readonly: true,
template: function (item) {
let template = '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'href="' + downloadHref(item.docId) + '">下载</a>';
let template = "";
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="showPreview(\'' + item.docId + '\',\'' + item.bizId + '\')" >预览</a>';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="changeFile(\'' + item.docId + '\',\'' + item.bizId + '\')" target="_blank">变更</a><br/>';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="showQueryRecord(\'' + item.docId + '\',\'' + item.bizId + '\')" >预览记录</a>';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="changeFile(\'' + item.docId + '\',\''+item.bizId+'\')" target="_blank">变更</a>';
+ 'onclick="showDownloadRecord(\'' + item.docId + '\',\'' + item.bizId + '\')" >下载记录</a>';
return template;
}
}, {
......@@ -556,7 +565,7 @@ $(function () {
//确认发布
$("#confirmRelease").on("click", updateRelease);
// 批量下载
$("#BATCH_DOWNLOAD").on("click", batchDownload);
$("#BATCH_DOWNLOAD").on("click", download);
});
let query = function () {
......@@ -861,31 +870,79 @@ let showAuthButton = function () {
let parentId = IPLATUI.EFTree.categoryTree.selectTreeNode.fileId;
let leafLevel = IPLATUI.EFTree.categoryTree.selectTreeNode.leafLevel;
let isAuth = IPLATUI.EFTree.categoryTree.selectTreeNode.isAuth;
let changeRecord = $("#CHANGE_RECORD").hide();
if (!isBlank(leafLevel) && leafLevel == 0){
changeRecord.show();
// 隐藏变更记录按钮
if (!isBlank(leafLevel) && leafLevel === 0) {
CommonUtils.showButton("CHANGE_RECORD");
CommonUtils.showButton("COPY_PROT_FILE");
} else {
CommonUtils.hideButton("CHANGE_RECORD");
}
// C:目录
if (isBlank(leafType) || leafType != "C") {
$("#RELEASE").hide();
$("#UPLOAD_FILE").hide();
$("#COPY_FILE").hide();
$("#COPY_PROT_FILE").hide();
$("#PREVIEW").hide();
$("#BATCH_DOWNLOAD").hide();
if (isBlank(leafType) || leafType !== "C") {
CommonUtils.hideButton("RELEASE");
CommonUtils.hideButton("UPLOAD_FILE");
CommonUtils.hideButton("COPY_FILE");
CommonUtils.hideButton("PREVIEW");
CommonUtils.hideButton("BATCH_DOWNLOAD");
return
}
// 0:不授权
if (isAuth == 0) {
$("#RELEASE").show();
$("#UPLOAD_FILE").show();
$("#COPY_FILE").show();
$("#COPY_PROT_FILE").show();
$("#PREVIEW").show();
$("#BATCH_DOWNLOAD").show();
return;
if (isAuth === "0") {
notAuthShowButton();
} else {
isProjectManager(parentId);
}
isProjectManager(parentId);
}
/**
* 不授权显示按钮
*/
function notAuthShowButton() {
CommonUtils.showButton("RELEASE");
CommonUtils.showButton("UPLOAD_FILE");
CommonUtils.showButton("COPY_FILE");
CommonUtils.showButton("COPY_PROT_FILE");
CommonUtils.showButton("PREVIEW");
CommonUtils.showButton("BATCH_DOWNLOAD");
}
/**
* 项目管理人员
*
* @param parentId
*/
let isProjectManager = function (parentId) {
CommonUtils.hideButton("RELEASE");
CommonUtils.hideButton("COPY_PROT_FILE");
CommonUtils.hideButton("COPY_FILE");
CommonUtils.hideButton("UPLOAD_FILE");
CommonUtils.hideButton("PREVIEW");
CommonUtils.hideButton("BATCH_DOWNLOAD");
let inEiInfo = new EiInfo();
inEiInfo.set("inqu_status-0-fileId", parentId);
EiCommunicator.send("HPWD001", "queryProjectManager", inEiInfo, {
onSuccess(ei) {
if (ei.status < 0){
return;
}
let isManager = ei.extAttr.isManager;
let downloadFlag = ei.extAttr.downloadFlag;
// 1-管理员,2-项目经理,3-设计人
if (isManager === 1 || isManager === 2 || isManager === 3) {
if (isManager !== 1 && downloadFlag !== 1) {
$("#BATCH_DOWNLOAD").attr("disabled", true);
}
if (isManager === 1 || isManager === 2) {
CommonUtils.showButton("RELEASE");
}
CommonUtils.showButton("COPY_PROT_FILE");
CommonUtils.showButton("COPY_FILE");
CommonUtils.showButton("UPLOAD_FILE");
CommonUtils.showButton("PREVIEW");
CommonUtils.showButton("BATCH_DOWNLOAD");
}
}
}, {async: false})
}
/**
......@@ -1026,51 +1083,44 @@ let preview = function () {
window.open(url, '_blank');
}
let isProjectManager = function (parentId) {
let inEiInfo = new EiInfo();
inEiInfo.set("inqu_status-0-fileId", parentId);
$("#COPY_PROT_FILE").show();
$("#BATCH_DOWNLOAD").show();
$("#RELEASE").show();
$("#UPLOAD_FILE").show();
$("#COPY_FILE").show();
$("#PREVIEW").show();
EiCommunicator.send("HPWD001", "queryProjectManager", inEiInfo, {
onSuccess(ei) {
if (ei.status != -1){
switch (ei.extAttr.isManager) {
case 1:
case 2:
break
case 3:
$("#RELEASE").hide();
break
default:
$("#RELEASE").hide();
$("#UPLOAD_FILE").hide();
$("#COPY_FILE").hide();
$("#PREVIEW").hide();
$("#COPY_PROT_FILE").hide();
}
}
}
}, {async: false})
/**
* 预览
*
* @param docId
* @param fileId
*/
let showPreview = function (docId, fileId) {
//let fileId = IPLATUI.EFTree.categoryTree.selectTreeNode.fileId;
addRecordWindow(fileId, docId);
}
/**
* 批量下载
* 显示查询记录
*
* @param docId
* @param fileId
*/
let batchDownload = function () {
var rows = resultGrid.getCheckedRows();
if (rows.length == 0) {
message("请先勾选要下载的数据!");
return;
}
JSUtils.submitGridsData("result", "HPWD001", "batchDownload", false,
function (res) {
if (res.status > -1) {
window.open(res.extAttr.downloadUrl, '_blank');
}
}
);
let showQueryRecord = function (docId, fileId) {
//let fileId = IPLATUI.EFTree.categoryTree.selectTreeNode.fileId;
JSColorbox.open({
href: "HPWD001B?inqu_status-0-fileId=" + fileId + "&inqu_status-0-docId=" + docId,
title: "<div style='text-align: center;'>预览记录</div>",
width: "80%",
height: "80%",
});
}
/**
* 显示下载记录
*
* @param docId
*/
let showDownloadRecord = function (docId,fileId) {
//let fileId = IPLATUI.EFTree.categoryTree.selectTreeNode.fileId;
JSColorbox.open({
href: "HPWD001C?inqu_status-0-fileId=" + fileId + "&inqu_status-0-docId=" + docId,
title: "<div style='text-align: center;'>下载记录</div>",
width: "80%",
height: "80%",
});
}
......@@ -88,7 +88,7 @@
serviceName="HPWD099" queryMethod="query" deleteMethod="delete">
<EF:EFColumn ename="id" cname="ID" hidden="true"/>
<EF:EFColumn ename="docId" cname="文件ID" enable="false" width="180" hidden="true"/>
<EF:EFColumn ename="operator" cname="操作" enable="false" width="100" align="center" sort="false"/>
<EF:EFColumn ename="operator" cname="操作" enable="false" width="150" align="center" sort="false"/>
<EF:EFColumn ename="docName" cname="附件名称" enable="false" width="180"/>
<EF:EFColumn ename="docType" cname="附件类型" enable="false" width="110" align="center"/>
<EF:EFColumn ename="docVersion" cname="版本号" enable="false" width="90" align="center" sort="true"/>
......@@ -219,3 +219,5 @@
</div>
</EF:EFWindow>
<jsp:include page="HPWD002A1.jsp" />
/**
* 下载
*/
let download = function () {
let rows = resultGrid.getCheckedRows();
if (rows.length == 0) {
message("请先勾选要下载的数据!");
return;
}
if (rows.length == 1) {
singleDownload(rows[0]);
} else {
batchDownload();
}
}
/**
* 单个下载
*
* @param row
*/
let singleDownload = function (row) {
//let fileId = $("#inqu_status-0-fileId").val();
let inInfo = new EiInfo();
inInfo.set("result-0-fileId", row['fileId']);
inInfo.set("result-0-docId", row['docId']);
EiCommunicator.send("HPWD001C", "add", inInfo, {
onSuccess(res) {
if (res.status > -1) {
//let url = res.extAttr.url + "?filename=" + row['docName'];
let url = downloadHref(row['docId'],false);
window.open( url, '_blank');
} else {
message(res.msg);
}
}
}, {async: false})
}
/**
* 批量下载
*
* @param fileId
* @param docId
*/
let batchDownload = function () {
JSUtils.submitGridsData("result", "HPWD001C", "batchDownload", false,
function (res) {
if (res.status > -1) {
window.open(res.extAttr.downloadUrl, '_blank');
}
}
);
}
\ No newline at end of file
......@@ -107,11 +107,22 @@ let save = function (btnNode) {
let flag = true;
$.each(rows, function(index, item) {
let projCode= item.get("projCode");
let fileName= item.get("fileName");
if(isBlank(projCode)){
message("选中的第"+(index+1)+"行\"所属项目\",不能为空!");
flag = false;
return false;
}
if(isBlank(fileName)){
message("选中的第"+(index+1)+"行\"目录名称\",不能为空!");
flag = false;
return false;
}
if(isChinese(fileName)){
message("选中的第"+(index+1)+"行\"目录名称\",不能包含特殊字符!");
flag = false;
return false;
}
});
if(flag) {
JSUtils.confirm("确定对勾选中的[" + rows.length + "]条数据做\"保存\"操作? ", {
......
......@@ -91,22 +91,22 @@ $(function () {
IPLATUI.EFTree = {
"docTree": {
ROOT: {label: 'root', text: '目录结构'},
query: function (inInfo, model) {
if (model == null || model.id === "root") {
return inInfo;
}
// 选中树节点
selectTreeId(model.id);
// 设置选中节点
treeSelectClick(model);
inInfo.set("inqu_status-0-projCode", $("#inqu_status-0-projCode").val());
return inInfo;
},
select: function (e) {
var _data = this.dataItem(e.node);
var labelValue = _data.label;
var typeValue = _data.type;
const eNameValue = _data.ename;
setTreeNodeValue(_data);
$("[name = 'inqu_status-0-parentId']").val(labelValue);
$("[name = 'inqu_status-0-fileId']").val(_data.id);
$("[name = 'inqu_status-0-leafLevel']").val(_data.leafLevel==null?0:_data.leafLevel);
$("[name = 'inqu_status-0-projCode']").val(_data.projCode);
$("[name = 'inqu_status-0-companyCode']").val(_data.companyCode);
$("[name = 'inqu_status-0-type']").val(typeValue);
$("[name = 'inqu_status-0-fileName']").val(_data.text);
resultGrid.dataSource.page(1);
// 显示授权按钮
showAuthButton();
let nodeData = this.dataItem(e.node);
// 设置选中节点
treeSelectClick(nodeData);
},
/*ROOT:{label: 'root',text: '组织机构'},*/
template: function (node) {
......@@ -169,12 +169,10 @@ $(function () {
field: "operator",
title: "操作",
template: function (model) {
let param = "'" + model.fileId + "', '" + model.docId + "'";
let param = "'" + model.docId + "'";
let template = '';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="showQueryRecord(' + param + ')" >预览记录</a>';
template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
+ 'onclick="showDownloadRecord(' + param + ')" >下载记录</a>';
+ 'onclick="showPreview(' + param + ')" >预览</a>';
return template;
}
}, {
......@@ -260,9 +258,19 @@ let preview = function () {
}
/**
* 预览
*
* @param docId
*/
let showPreview = function (docId) {
let treeId = IPLATUI.EFTree.docTree.selectTreeNode.treeId;
addRecordWindow(treeId, docId);
}
/**
* 下载
*/
let download = function () {
/*let download = function () {
let rows = resultGrid.getCheckedRows();
if (rows.length < 1) {
message("请选择数据");
......@@ -283,33 +291,104 @@ let download = function () {
);
}
});
}
}*/
/**
* 设置树节点的值
*
* @param nodeData
*/
let setTreeNodeValue = function (nodeData) {
/*let setTreeNodeValue = function (nodeData) {
IPLATUI.EFTree.docTree.selectTreeNode.fileId = nodeData.label;
IPLATUI.EFTree.docTree.selectTreeNode.parentId = nodeData.parentId;
IPLATUI.EFTree.docTree.selectTreeNode.fileName = nodeData.text;
IPLATUI.EFTree.docTree.selectTreeNode.companyCode = nodeData.companyCode;
IPLATUI.EFTree.docTree.selectTreeNode.projCode = nodeData.projCode;
IPLATUI.EFTree.docTree.selectTreeNode.leafLevel = nodeData.leafLevel;
}*/
/**
* 设置树节点的值
*
* @param nodeData
*/
let setTreeNodeValue = function (nodeData) {
IPLATUI.EFTree.docTree.selectTreeNode.treeId = nodeData.id;
IPLATUI.EFTree.docTree.selectTreeNode.projCode = nodeData.projCode;
IPLATUI.EFTree.docTree.selectTreeNode.leafType = nodeData.leafType;
IPLATUI.EFTree.docTree.selectTreeNode.downloadFlag = nodeData.downloadFlag == null ? 0
: nodeData.downloadFlag;
$("[name = 'inqu_status-0-fileId']").val(nodeData.id);
$("[name = 'inqu_status-0-projCode']").val(nodeData.projCode);
}
/**
* 显示授权按钮
*/
let showAuthButton = function () {
let leafType = IPLATUI.EFTree.docTree.selectTreeNode.leafLevel;
// C:目录
if (leafType && leafType >0) {
$("#PREVIEW").attr("disabled", false);
let leafType = IPLATUI.EFTree.docTree.selectTreeNode.leafType;
if (leafType === 'C') {
CommonUtils.showButton("PREVIEW");
CommonUtils.showButton("DOWNLOAD");
} else {
CommonUtils.hideButton("PREVIEW");
CommonUtils.hideButton("DOWNLOAD");
}
// 是否可以下载
let downloadFlag = IPLATUI.EFTree.docTree.selectTreeNode.downloadFlag;
/*if (downloadFlag === "1") {
$("#DOWNLOAD").attr("disabled", false);
} else {
$("#PREVIEW").attr("disabled", true);
$("#DOWNLOAD").attr("disabled", true);
}*/
}
/**
* 选中树节点
*
* @param treeId
*/
let selectTreeId = function (treeId) {
// 刷新树节点
const tree = $("#docTree").data("kendoTreeView");
// 选中的节点
selectTreeNode(tree, treeId);
}
/**
* 选中树节点
*
* @param tree
* @param treeId
*/
let selectTreeNode = (tree, treeId) => {
if (!tree || treeId == null) {
return
}
setTimeout(() => {
let barDataItem = tree.dataSource.get(treeId);
if (barDataItem) {
let barElement = tree.findByUid(barDataItem.uid);
// 刷新完成后选中对应的树节点
tree.select(barElement);
} else {
selectTreeNode(tree, treeId)
}
}, 300)
}
/**
* 树点击事件
*
* @param nodeData
*/
let treeSelectClick = function (nodeData) {
// 设置选择的树节点信息
setTreeNodeValue(nodeData);
// 显示授权按钮
showAuthButton();
// 刷新列表
query();
}
......@@ -18,8 +18,7 @@
<EF:EFRegion title="文档目录树" id="tree" fitHeight="true">
<div id="menu" style="margin-top: 12px; margin-bottom: 8px">
<EF:EFTree bindId="docTree" ename="tree_name" textField="text" valueField="label"
hasChildren="leaf" pid="parentId" serviceName="HPWD001D" methodName="queryTree"
expandLevel="1">
hasChildren="leaf" pid="parentId" serviceName="HPWD001D" methodName="queryTree">
</EF:EFTree>
</div>
</EF:EFRegion>
......@@ -71,3 +70,5 @@
</EF:EFPage>
<jsp:include page="HPWD002A1.jsp" />
.left-flex {
/*display: flex;*/
/*align-items: flex-start;*/
height: 100%;
width: 100%;
overflow: auto;
}
.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;
}
img {
max-width: 100%;
max-height: 100%;
cursor: zoom-in;
transition: transform 0.1s;
}
img:hover {
cursor: zoom-out;
}
.textSpan {
font-size: 16px;
}
.textSpan table {
border: 1px solid black;
}
.textSpan table td {
border: 1px solid black;
}
.imageOuterDiv {
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.7);
z-index: 9999999;
width: 100%;
height: 100%;
display: none;
}
\ No newline at end of file
/**
* 弹窗预览
*
* @param fileId
* @param docId
*/
function addRecordWindow(fileId, docId) {
$("#previewFile").data("kendoWindow").center();
$("#previewFile").data("kendoWindow").open();
addRecord(fileId, docId);
}
/**
* 新增预览记录
*
* @param fileId
* @param docId
*/
function addRecord(fileId, docId) {
if (isBlank(docId)) {
message("附件类型或ID不能为空");
return;
}
// 隐藏预览区域
hideHtml();
IPLAT.progress($("body"), true);
let inInfo = new EiInfo();
inInfo.set("result-0-fileId", fileId);
inInfo.set("result-0-docId", docId);
EiCommunicator.send('HPWD001B', 'add', inInfo, {
onSuccess: function (res) {
if (res.getStatus() >= 0) {
try {
previewFile(res.extAttr.url, res.extAttr.docType);
} catch (e) {
}
} else {
message(res.getMsg());
}
IPLAT.progress($("body"), false);
},
onFail: function (res) {
NotificationUtil("操作失败,原因[" + res.getMsg() + "]", "error");
IPLAT.progress($("body"), false);
}
});
}
/**
* 新增记录后回调
*
* @param url
* @param docType
*/
function previewFile(url, docType) {
// 隐藏文本描述
$("#descDiv").css('display', 'none');
if (isXml(docType)) {
previewXml(url);
} else if (isWord(docType)) {
previewDocx(url);
} else if (isPdf(docType)) {
previewFrame(url);
} else {
previewOnline(url);
}
// else if (isExcel(docType)) {
// previewExcel(url);
// } else if (isText(docType)) {
// previewText(url);
// } else if (isImage(docType)) {
// previewImage(url);
// } else if (isFrame(docType)) {
// previewFrame(url);
// } else {
// otherDownload(false, docId);
// }
}
/**
* 隐藏显示区域
*/
function hideHtml() {
$("#textContainer").css('display', 'none');
$("#textSpan").html("");
$("#docxContainer").css('display', 'none');
$("#imageContainer").css('display', 'none');
$("#image").attr('src', "");
$("#previewFrame").css('display', 'none');
$("#previewFrame").attr("src", "");
}
/**
* 是否文本
*
* @param docType
* @returns {boolean}
*/
function isText(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['txt'];
return extensions.includes(docType.toLowerCase());
}
/**
* 文件预览
*
* @param docId
*/
function previewText(docId) {
fetch(downloadHref(docId, true)).then(res => {
return res.text();
}).then(data => {
let container = document.getElementById("textContainer");
container.style.display = 'block';
// 使用new TextDecoder()指定编码
// let textDecoder;
// try {
// textDecoder = new TextDecoder('GBK', {ignoreBOM: true});
// } catch (e) {
// textDecoder = new TextDecoder('UTF-8', {ignoreBOM: true});
// }
// let dataDecoder = textDecoder.decode(data);
$("#textSpan").text(data);
});
}
/**
* 是否文本
*
* @param docType
* @returns {boolean}
*/
function isXml(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['xml'];
return extensions.includes(docType.toLowerCase());
}
/**
* xml文件预览
*
* @param url
*/
function previewXml(url) {
fetch(url).then(res => {
return res.text();
}).then(data => {
let container = document.getElementById("textContainer");
container.style.display = 'block';
$("#textSpan").text(data);
});
}
/**
* 是否excel
*
* @param docType
* @returns {boolean}
*/
function isExcel(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['xls'];
return extensions.includes(docType.toLowerCase());
}
/**
* 文件预览
*
* @param url
*/
function previewExcel(url) {
fetch(url).then(res => {
return res.blob();
}).then(blob => {
let container = document.getElementById("textContainer");
container.style.display = 'block';
// 使用new TextDecoder()指定编码
// const utf8Decoder = new TextDecoder('GBK', {ignoreBOM: true});
// const text = utf8Decoder.decode(arrayBuffer);
// $("#textSpan").html(text.replace(/\r\n?/g, '\n').replace(/\n/g, '<br/>'));
const reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = function(e) {
let textSpan = document.getElementById('textSpan');
// 清空内容
textSpan.innerHTML = "";
let result = new Uint8Array(e.target.result);
let workbook = XLSX.read(result, {type: 'array'});
let sheetNames = workbook.SheetNames;
for (let i = 0; i < sheetNames.length; i++) {
// 假设我们只需要第一个工作表
var worksheet = workbook.Sheets[sheetNames[i]];
var data = XLSX.utils.sheet_to_html(worksheet);
// 在页面上显示JSON数据
textSpan.innerHTML += data + "<br/>";
}
};
});
}
/**
* 是否WORD
*
* @param docType
* @returns {boolean}
*/
function isWord(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['docx'];
return extensions.includes(docType.toLowerCase());
}
/**
* docx预览
*
* @param url
*/
function previewDocx(url) {
fetch(url).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 docType
* @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', '');
}
/**
* PDF预览
*
* @param docType
* @returns {boolean}
*/
function isPdf(docType) {
if (isBlank(docType)) {
return false;
}
const extensions = ['pdf'];
return extensions.includes(docType.toLowerCase());
}
/**
* frame预览
*
* @param url
*/
function previewFrame(url) {
// 替换地址中的file-download为file-preview
url = url.replace("file-download", "file-preview");
$("#previewFrame").css('display', '');
$("#previewFrame").attr("src", url);
}
/**
* 在线预览
*
* @param url
*/
function previewOnline(url) {
$("#previewFrame").css('display', '');
$("#previewFrame").attr("src", CommonUtils.previewFile(url));
}
/**
* 监听iframe
*/
function iframeLoad() {
$('#previewFrame').on('load', function() {
// 当iframe加载完成后,获取iframe中的元素
let iframeBody = document.getElementById('previewFrame');
// 获取iframe的document对象
let iframeDoc = iframeBody.contentDocument || iframeBody.contentWindow.document;
// 例如,获取iframe中的一个具有特定类的元素
let viewer = iframeDoc.querySelector("#viewer")
let download = viewer.shadowRoot.querySelector("#toolbar")
.shadowRoot.querySelector("#downloads")
.shadowRoot.querySelector("#download");
// let download = iframeBody.find('#download');
download.css('display', 'none');
});
}
/**
* 其他下载
*
* @param isRoot
* @param docId
*/
function otherDownload(isRoot, docId) {
// 隐藏预览区域
hideHtml();
$("#descDiv").css('display', '');
if (isRoot) {
$("#descSpan").html("文件预览区域...");
} else {
$("#descSpan").html("该文件暂不支持预览");
// $("#descSpan").html("该文件暂不支持预览,点击<a href='" + downloadHref(docId, false)
// + "' target='_blank'>下载</a>");
}
}
/**
* 实现图片点击放大、拖拽、滚轴滚动焦点缩放功能,相关参数、函数声明
*/
let imgWidth, imgHeight; // 图片点击放大初始尺寸参数
let maxZoom = 4; //最大缩放倍数
let minReduce = 0.5; // 最小缩放倍数
let initScale = 1; //滚动缩放初始倍数,并不是图片点击放大的倍数
let isPointerdown = false; //鼠标按下的标识
//记录鼠标按下坐标和按下移动时坐标
let lastPointermove = {
x: 0,
y: 0,
};
//移动过程从上一个坐标到下一个坐标之间的差值
let diff = {
x: 0,
y: 0,
};
//图片放大后左上角的坐标,主要结合diff参数用于鼠标焦点缩放时图片偏移坐标
let x = 0;
let y = 0;
// 记录节点
let imageOuterDiv = null;
let realImage = null;
let bigImage = null;
window.onload = function () {
// 监听iframe
// iframeLoad();
// 禁用鼠标右键
document.addEventListener('contextmenu', event => event.preventDefault());
document.addEventListener('copy', event => event.preventDefault());
// 图片预览初始化
// imageShowInit();
};
/**
* 图片预览初始化
*/
function imageShowInit(){
imageOuterDiv = document.querySelector("#imageOuterDiv");
realImage = document.querySelector("#image");
bigImage = document.querySelector("#bigImage");
// 添加事件监听器来拦截右键点击事件
document.addEventListener('contextmenu', function (e) {
// 阻止默认的右键菜单
e.preventDefault();
});
document.getElementById("image").addEventListener("click", (e) => {
const that = e.target;
bigImage.style.transform = "scale(1)";
// 图片放大展示函数调用
clickImageShow(that);
// 监听鼠标滚动事件
window.addEventListener("wheel", handleStopWheel, {
passive: false,
});
// 拖转事件调用
imgDrag();
});
}
/**
* 点击图片放大
*/
function clickImageShow(that) {
let src = that.getAttribute("src");
fetch(src).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.blob();
}).then(blob => {
// 创建一个指向Blob的URL
bigImage.setAttribute("src", URL.createObjectURL(blob));
// 展示大图
imageShow();
}).catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
}
/**
* 放大图片展示
*/
function imageShow() {
// 设置尺寸和调整比例
let windowW = document.documentElement.clientWidth;
let windowH = document.documentElement.clientHeight;
let realWidth = realImage.naturalWidth; //获取图片的原始宽度
let realHeight = realImage.naturalHeight; //获取图片的原始高度
let outsideScale = 0.8;
let belowScale = 1.4;
let realRatio = realWidth / realHeight;
let windowRatio = windowW / windowH;
// 说明:下面是我自己的一些判断逻辑,大致意思就是图片的真实尺寸大于屏幕尺寸则使用屏幕尺寸,如果小于屏幕尺寸就使用自己本身的尺寸;并根据大于或者小于的比例对图片的尺寸进一步调整。coder可以根据自己的要求进行修改。
if (realRatio >= windowRatio) {
if (realWidth > windowW) {
imgWidth = windowH * outsideScale;
imgHeight = (imgWidth / realWidth) * realHeight;
} else {
if (realWidth * belowScale < windowW) {
imgWidth = realWidth * (belowScale - 0.2);
imgHeight = (imgWidth / realWidth) * realHeight;
} else {
imgWidth = realWidth;
imgHeight = realHeight;
}
}
} else {
if (realHeight > windowH) {
imgHeight = windowH * outsideScale;
imgWidth = (imgHeight / realHeight) * realWidth;
} else {
if (realHeight * belowScale < windowW) {
imgHeight = realHeight * (belowScale - 0.2);
imgWidth = (imgHeight / realHeight) * realWidth;
} else {
imgWidth = realWidth;
imgHeight = realHeight;
}
}
}
//设置放大图片的尺寸、偏移量并展示
bigImage.style.width = imgWidth + "px";
bigImage.style.height = imgHeight + "px";
x = (windowW - imgWidth) * 0.5;
y = (windowH - imgHeight) * 0.5;
bigImage.style.transform = `translate3d(${x}px, ${y}px, 0)`;
imageOuterDiv.style.display = "block";
// 点击蒙版及外面区域放大图片关闭
imageOuterDiv.onclick = () => {
imageOuterDiv.style.display = "none";
initScale = 1;
window.removeEventListener("wheel", handleStopWheel);
};
// 阻止事件冒泡
bigImage.onclick = (e) => {
e.stopPropagation();
};
}
/**
* 鼠标滚轮
*
* @param e
*/
function handleStopWheel(e) {
let itemSizeChange = 1.1; //每一次滚动放大的倍数
if (e.target.id == "bigImage") {
// 说明:e.dataY如果大于0则表示鼠标向下滚动,反之则向上滚动,这里设计为向上滚动为放大,向下滚动为缩小
if (e.deltaY > 0) {
itemSizeChange = 1 / 1.1;
}
let _initScale = initScale * itemSizeChange;
// 说明:在超过或低于临界值时,虽然让initScale等于maxZoom或minreduce,但是在后续的判断中放大图片的最终倍数并没有达到maxZoom或minreduce,而是跳过。
if (_initScale > maxZoom) {
initScale = maxZoom;
} else if (_initScale < minReduce) {
initScale = minReduce;
} else {
initScale = _initScale;
}
const origin = {
x: (itemSizeChange - 1) * imgWidth * 0.5,
y: (itemSizeChange - 1) * imgHeight * 0.5,
};
// 计算偏移量
if (_initScale < maxZoom && _initScale > minReduce) {
x -= (itemSizeChange - 1) * (e.clientX - x) - origin.x;
y -= (itemSizeChange - 1) * (e.clientY - y) - origin.y;
e.target.style.transform = `translate3d(${x}px, ${y}px, 0) scale(${initScale})`;
}
}
// 阻止默认事件
e.preventDefault();
}
function imgDrag() {
// 绑定 鼠标按下事件
bigImage.addEventListener("pointerdown", pointerdown);
// 绑定 鼠标移动事件
bigImage.addEventListener("pointermove", pointermove);
bigImage.addEventListener("pointerup", function (e) {
if (isPointerdown) {
isPointerdown = false;
}
});
bigImage.addEventListener("pointercancel", function (e) {
if (isPointerdown) {
isPointerdown = false;
}
});
}
function pointerdown(e) {
isPointerdown = true;
// 说明:Element.setPointerCapture()将特定元素指定为未来指针事件的捕获目标。指针的后续事件将以捕获元素为目标,直到捕获被释放。可以理解为:在窗口不是全屏情况下,我在拖动放大图片时即使鼠标移出可窗口之外,此时事件还是捕获在该放大图片上。
bigImage.setPointerCapture(e.pointerId);
lastPointermove = {
x: e.clientX,
y: e.clientY,
};
}
function pointermove(e) {
if (isPointerdown) {
const current1 = {
x: e.clientX,
y: e.clientY,
};
diff.x = current1.x - lastPointermove.x;
diff.y = current1.y - lastPointermove.y;
lastPointermove = {
x: current1.x,
y: current1.y,
};
x += diff.x;
y += diff.y;
bigImage.style.transform = `translate3d(${x}px, ${y}px, 0) scale(${initScale})`;
}
e.preventDefault();
}
<%--
Created by IntelliJ IDEA.
User: 1
Date: 2024/11/26
Time: 16:28
To change this template use File | Settings | File Templates.
--%>
<!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" %>
<script src="${ctx}/common/docxjs/jszip.min.js"></script>
<script src="${ctx}/common/docxjs/docx-preview.js"></script>
<script src="${ctx}/common/js/xlsx.full.min.js"></script>
<script src="${ctx}/HP/WD/HPWD001C1.js"></script>
<script src="${ctx}/HP/WD/HPWD002A1.js"></script>
<link rel="stylesheet" href="${ctx}/HP/WD/HPWD002A1.css">
<%-- 预览文件 --%>
<EF:EFWindow id="previewFile" title="附件预览" height="100%" width="100%">
<div id="descDiv" class="center-flex">
<span id="descSpan" style="font-weight: bold;font-size: 18px">附件预览区域...</span>
</div>
<%-- 文本预览 --%>
<div id="textContainer" class="left-flex" style="display: none;">
<pre id="textSpan" class="textSpan"></pre>
</div>
<%-- docx文件预览--%>
<div id="docxContainer" style="display: none;"></div>
<%-- IMAGE文件预览--%>
<div id="imageContainer" class="left-flex" style="display: none;">
<img id="image" src="" style="border: 1px solid gray;width: 100%;height: 100%;"/>
</div>
<%-- other --%>
<iframe id="previewFrame" src="" style="display: none;"></iframe>
</EF:EFWindow>
<%-- 图片放大区域 --%>
<div id="imageOuterDiv" class="imageOuterDiv">
<img id="bigImage" src=""/>
</div>
\ No newline at end of file
......@@ -54,6 +54,12 @@ function isPositiveNumber(input) {
return !isBlank(input) && isNumber(input) && (input > 0);
}
/*校验是否中文名称组成 */
function isChinese(str) {
let reg=/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/; /*定义验证表达式*/
return !reg.test(str); /*进行验证*/
}
/**
* 消息提示
*
......@@ -558,9 +564,9 @@ function loadChange(grid,e,field) {
/**
* 上传文件
*
* @param bizType
* @param bizId
* @param
* @param bizType 业务类型
* @param bizId 业务ID
* @param callback 函数是含税就回调
*/
let uploadFile = function (bizType, bizId, callback) {
let params = {
......@@ -593,6 +599,35 @@ function loadChange(grid,e,field) {
}
/**
* 隐藏按钮
*
* @param name
*/
function hideButton(name) {
let button = $("#" + name);
button.hide();
// 隐藏父级标签,防止按钮重叠
button.parent().css("display", "none");
}
/**
* 显示按钮
*
* @param name
*/
function showButton(name) {
let button = $("#" + name);
let parent = button.parent();
if (!CommonUtils.isBlank(button.attr("uuid"))) {
button.show();
parent.css("display", "");
} else {
// 隐藏父级标签,防止按钮重叠
parent.css("display", "none");
}
}
/**
* 导入
*
* @param id 路由ID
......@@ -609,13 +644,61 @@ function loadChange(grid,e,field) {
});
}
/**
* 文件下载路径
*
* @param docId
* @param isPreview 是否预览,true:预览
* @returns {string}
*/
let downloadFile = function (docId, isPreview) {
if (isPreview) {
return IPLATUI.CONTEXT_PATH + '/file/download/preview/' + docId;
} else {
// S3地址必须支持公网
return IPLATUI.CONTEXT_PATH + '/file/download/' + docId;
}
}
/**
* 预览
*
* @param url 文件URL
*/
let previewFile = function (url) {
// Base64转码
let urlEncode;
try {
urlEncode = encodeURIComponent(btoa(url));
} catch (e) {
console.error("encodeURIComponent fail:", e)
message("预览失败,文件地址存在非法字符!");
return;
}
if (isBlank(urlEncode)) {
message("预览失败,文件地址为空!");
return;
}
if (PROJECT_ENV === "run" || PROJECT_ENV === "RUN") {
return "https://www.eis-paas.com/preview/onlinePreview?url=" + urlEncode
} else {
return "http://139.224.202.156:8012/preview/onlinePreview?url=" + urlEncode;
}
// 本地调试使用
// return "http://localhost:8012/preview/onlinePreview?url=" + urlEncode;
}
// export 到全局作用域 window对象
$.extend(window, {
CommonUtils: {
showFile: showFile,
uploadFile: uploadFile,
isBlank: isBlank,
importData: importData
importData: importData,
downloadFile: downloadFile,
previewFile: previewFile,
hideButton: hideButton,
showButton: showButton,
}
});
})(window.jQuery);
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