<div field="title" renderer="onRenderer" width="70%" visible="true" allowSort="false" align="left" headerAlign="center">放置文件名(已加密)</div>
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="modalImage" draggable="true">
</div>
var onRenderer = function(e){
var fileUrl = e.record.url;
var fileType = fileUrl.substr(fileUrl.lastIndexOf('.') + 1);
return "<a href='"+加密文件路径(fileUrl)+"' data-type='"+fileType+"' target='_blank' style='text-decoration: none;' οnclick='handleClick(event)'>"+e.value+"</a>";
};
var modal = document.getElementById("myModal");
var imageLink = document.getElementById("imageLink");
var modalImage = document.getElementById("modalImage");
var closeBtn = document.getElementsByClassName("close")[0];
var scale = 1;
var isDragging = false;
var startX, startY;
var minScale = 0.5;
var maxScale = 2.0;
var handleClick = function(event){
var fileName = event.srcElement.attributes.href.value;
var fileType = event.srcElement.attributes[1].value;
event.preventDefault();
$.ajax({
url: '请求路径',
type: 'GET',
data: {u:已加密的文件名字 }
})
.done(function(response) {
if(fileType.indexOf("jpg")!=-1||fileType.indexOf("png")!=-1||fileType.indexOf("jpeg")!=-1){
modal.style.display = "block";
modalImage.src = 'data:images/jpg;base64,'+response;
}else if(fileType.indexOf("pdf")!=-1){
window.open('data:application/pdf;base64,'+response, '_blank');
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.error('请求失败:', errorThrown);
});
};
closeBtn.addEventListener("click", function() {
modal.style.display = "none";
scale = 1;
modalImage.style.transform = "scale(1)";
modalImage.style.left = "0px";
modalImage.style.top = "0px";
});
window.addEventListener("click", function(event) {
if (event.target == modal) {
modal.style.display = "none";
scale = 1;
modalImage.style.transform = "scale(1)";
modalImage.style.left = "0px";
modalImage.style.top = "0px";
}
});
window.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
modalImage.addEventListener("wheel", function(event) {
event.preventDefault();
if (event.deltaY < 0) {
scale += 0.3;
} else {
scale -= 0.2;
if (scale < minScale) {
scale = minScale;
}
if (scale > maxScale) {
scale = maxScale;
}
}
modalImage.style.transform = "scale(" + scale + ")";
});
modalImage.addEventListener("mousedown", function(event) {
event.preventDefault();
isDragging = true;
startX = event.clientX;
startY = event.clientY;
});
modalImage.addEventListener("mousemove", function(event) {
if (isDragging) {
var deltaX = (event.clientX - startX)*1.9;
var deltaY = (event.clientY - startY)*1.9;
var currentX = parseFloat(getComputedStyle(modalImage).left) + deltaX;
var currentY = parseFloat(getComputedStyle(modalImage).top) + deltaY;
modalImage.style.left = currentX + "px";
modalImage.style.top = currentY + "px";
startX = event.clientX;
startY = event.clientY;
}
});
modalImage.addEventListener("mouseup", function(event) {
isDragging = false;
});
modalImage.addEventListener("mouseleave", function(event) {
isDragging = false;
});
String fileUrl = "";
String rootPath = SysConfig.getSysConfig("UploadPath", "");;
try {
fileUrl = request.getParameter("u").replace(" ", "+");
fileUrl = new String(解密文件路径(fileUrl));
} catch (Exception e1) {
Log.printLog("通知文件路径解密出错:" + Tools.toString(e1.getMessage()));
}
Path file = Paths.get(rootPath+fileUrl);
if (Files.exists(file)) {
byte[] fileContent = Files.readAllBytes(file);
String base64FileContent = java.util.Base64.getEncoder().encodeToString(fileContent);
response.getWriter().write(base64FileContent);
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}