mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-28 19:16:43 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3414844bfb | ||
|
|
656c6748e9 | ||
|
|
12120d076e | ||
|
|
eb00385d76 | ||
|
|
986f562266 | ||
|
|
11d0441ed4 | ||
|
|
ef46e2c51e | ||
|
|
0a3c03f18b |
@@ -201,6 +201,12 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath>
|
<systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- url 规范化 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.mola.galimatias</groupId>
|
||||||
|
<artifactId>galimatias</artifactId>
|
||||||
|
<version>0.2.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
[#ftl]
|
[#ftl]
|
||||||
[#-- @implicitly included --]
|
[#-- @implicitly included --]
|
||||||
|
[#-- @ftlvariable name="file" type="cn.keking.model.FileAttribute" --]
|
||||||
|
[#-- @ftlvariable name="fileName" type="java.lang.String" --]
|
||||||
[#-- @ftlvariable name="fileTree" type="java.lang.String" --]
|
[#-- @ftlvariable name="fileTree" type="java.lang.String" --]
|
||||||
[#-- @ftlvariable name="baseUrl" type="java.lang.String" --]
|
[#-- @ftlvariable name="baseUrl" type="java.lang.String" --]
|
||||||
[#-- @ftlvariable name="imgUrls" type="String" --]
|
[#-- @ftlvariable name="imgUrls" type="String" --]
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public interface FilePreview {
|
|||||||
String OFFICE_PICTURE_FILE_PREVIEW_PAGE = "officePicture";
|
String OFFICE_PICTURE_FILE_PREVIEW_PAGE = "officePicture";
|
||||||
String TXT_FILE_PREVIEW_PAGE = "txt";
|
String TXT_FILE_PREVIEW_PAGE = "txt";
|
||||||
String EXEL_FILE_PREVIEW_PAGE = "html";
|
String EXEL_FILE_PREVIEW_PAGE = "html";
|
||||||
|
String XML_FILE_PREVIEW_PAGE = "xml";
|
||||||
|
String MARKDOWN_FILE_PREVIEW_PAGE = "markdown";
|
||||||
String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported";
|
String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported";
|
||||||
|
|
||||||
String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);
|
String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import cn.keking.service.FilePreview;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
import static cn.keking.service.impl.SimTextFilePreviewImpl.TEXT_TYPE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kl (http://kailing.pub)
|
* @author kl (http://kailing.pub)
|
||||||
* @since 2020/12/25
|
* @since 2020/12/25
|
||||||
@@ -23,7 +21,7 @@ public class MarkdownFilePreviewImpl implements FilePreview {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||||
model.addAttribute(TEXT_TYPE,"markdown");
|
simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
||||||
return simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
return MARKDOWN_FILE_PREVIEW_PAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
@Service
|
@Service
|
||||||
public class SimTextFilePreviewImpl implements FilePreview {
|
public class SimTextFilePreviewImpl implements FilePreview {
|
||||||
|
|
||||||
public static final String TEXT_TYPE = "textType";
|
|
||||||
public static final String DEFAULT_TEXT_TYPE = "simText";
|
|
||||||
|
|
||||||
private final OtherFilePreviewImpl otherFilePreview;
|
private final OtherFilePreviewImpl otherFilePreview;
|
||||||
|
|
||||||
public SimTextFilePreviewImpl(OtherFilePreviewImpl otherFilePreview) {
|
public SimTextFilePreviewImpl(OtherFilePreviewImpl otherFilePreview) {
|
||||||
@@ -43,9 +40,6 @@ public class SimTextFilePreviewImpl implements FilePreview {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
|
return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
if (!model.containsAttribute(TEXT_TYPE)) {
|
|
||||||
model.addAttribute(TEXT_TYPE, DEFAULT_TEXT_TYPE);
|
|
||||||
}
|
|
||||||
return TXT_FILE_PREVIEW_PAGE;
|
return TXT_FILE_PREVIEW_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import cn.keking.service.FilePreview;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
import static cn.keking.service.impl.SimTextFilePreviewImpl.TEXT_TYPE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kl (http://kailing.pub)
|
* @author kl (http://kailing.pub)
|
||||||
* @since 2020/12/25
|
* @since 2020/12/25
|
||||||
@@ -22,7 +20,7 @@ public class XmlFilePreviewImpl implements FilePreview {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||||
model.addAttribute(TEXT_TYPE,"xml");
|
simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
||||||
return simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
return XML_FILE_PREVIEW_PAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants;
|
|||||||
import cn.keking.model.FileAttribute;
|
import cn.keking.model.FileAttribute;
|
||||||
import cn.keking.model.FileType;
|
import cn.keking.model.FileType;
|
||||||
import cn.keking.model.ReturnResponse;
|
import cn.keking.model.ReturnResponse;
|
||||||
|
import io.mola.galimatias.GalimatiasParseException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -81,7 +82,6 @@ public class DownloadUtils {
|
|||||||
public static byte[] getBytesFromUrl(String urlStr) throws IOException {
|
public static byte[] getBytesFromUrl(String urlStr) throws IOException {
|
||||||
InputStream is = getInputStreamFromUrl(urlStr);
|
InputStream is = getInputStreamFromUrl(urlStr);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
// urlStr = URLUtil.normalize(urlStr, true, true);
|
|
||||||
is = getInputStreamFromUrl(urlStr);
|
is = getInputStreamFromUrl(urlStr);
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
logger.error("文件下载异常:url:{}", urlStr);
|
logger.error("文件下载异常:url:{}", urlStr);
|
||||||
@@ -98,13 +98,14 @@ public class DownloadUtils {
|
|||||||
|
|
||||||
private static InputStream getInputStreamFromUrl(String urlStr) {
|
private static InputStream getInputStreamFromUrl(String urlStr) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlStr);
|
|
||||||
|
URL url = io.mola.galimatias.URL.parse(urlStr).toJavaURL();
|
||||||
URLConnection connection = url.openConnection();
|
URLConnection connection = url.openConnection();
|
||||||
if (connection instanceof HttpURLConnection) {
|
if (connection instanceof HttpURLConnection) {
|
||||||
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||||
}
|
}
|
||||||
return connection.getInputStream();
|
return connection.getInputStream();
|
||||||
} catch (IOException e) {
|
} catch (IOException | GalimatiasParseException e) {
|
||||||
logger.warn("连接url异常:url:{}", urlStr);
|
logger.warn("连接url异常:url:{}", urlStr);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public class OnlinePreviewController {
|
|||||||
return otherFilePreview.notSupportedFile(model, errorMsg);
|
return otherFilePreview.notSupportedFile(model, errorMsg);
|
||||||
}
|
}
|
||||||
FileAttribute fileAttribute = fileHandlerService.getFileAttribute(fileUrl, req);
|
FileAttribute fileAttribute = fileHandlerService.getFileAttribute(fileUrl, req);
|
||||||
|
model.addAttribute("file", fileAttribute);
|
||||||
FilePreview filePreview = previewFactory.get(fileAttribute);
|
FilePreview filePreview = previewFactory.get(fileAttribute);
|
||||||
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
||||||
return filePreview.filePreviewHandle(fileUrl, model, fileAttribute);
|
return filePreview.filePreviewHandle(fileUrl, model, fileAttribute);
|
||||||
|
|||||||
@@ -19,18 +19,17 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div class="panel-group container" id="accordion">
|
||||||
<h1>文件预览项目接入和测试界面</h1>
|
<h1>文件预览项目接入和测试界面</h1>
|
||||||
<div class="panel-group" id="accordion">
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
<a data-toggle="collapse" data-parent="#accordion"
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
href="#collapseOne">
|
|
||||||
接入说明
|
接入说明
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseOne" class="panel-collapse collapse">
|
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div>
|
<div>
|
||||||
如果你的项目需要接入文件预览项目,达到对docx、excel、ppt、jpg等文件的预览效果,那么通过在你的项目中加入下面的代码就可以
|
如果你的项目需要接入文件预览项目,达到对docx、excel、ppt、jpg等文件的预览效果,那么通过在你的项目中加入下面的代码就可以
|
||||||
@@ -49,7 +48,6 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
@@ -59,12 +57,11 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseTwo" class="panel-collapse collapse">
|
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div style="padding: 10px">
|
<div style="padding: 10px">
|
||||||
<form enctype="multipart/form-data" id="fileUpload">
|
<form enctype="multipart/form-data" id="fileUpload">
|
||||||
<input type="file" name="file"/>
|
<input type="file" name="file"/>
|
||||||
<input type="button" id="btnsubmit" value=" 上 传 " />
|
<input type="button" id="btnSubmit" value=" 上 传 "/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -72,21 +69,18 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4 class="panel-title">
|
<h4 class="panel-title">
|
||||||
<a data-toggle="collapse" data-parent="#accordion"
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
|
||||||
href="#collapseThree">
|
发版记录
|
||||||
更新记录
|
|
||||||
</a>
|
</a>
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="collapseThree" class="panel-collapse collapse in">
|
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div>
|
<div>
|
||||||
2020年12月27日 :<br>
|
2020年12月27日 :<br>
|
||||||
2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设
|
2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设<br>
|
||||||
1. 架构模块调整,大量的代码重构,代码质量提升N个等级,欢迎品鉴<br>
|
1. 架构模块调整,大量的代码重构,代码质量提升N个等级,欢迎品鉴<br>
|
||||||
2. 增强XML文件预览效果,新增XML文档数结构预览<br>
|
2. 增强XML文件预览效果,新增XML文档数结构预览<br>
|
||||||
3. 新增markdown文件预览支持,预览支持md渲染和源文本切换支持<br>
|
3. 新增markdown文件预览支持,预览支持md渲染和源文本切换支持<br>
|
||||||
@@ -154,7 +148,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
2.项目github开源:<a href="https://github.com/kekingcn/kkFileView" target="_blank">https://github.com/kekingcn/kkFileView</a>
|
2.项目github开源:<a href="https://github.com/kekingcn/kkFileView" target="_blank">https://github.com/kekingcn/kkFileView</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div id="comments"></div>
|
<div id="comments"></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -190,7 +184,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
url: '${baseUrl}deleteFile?fileName=' + encodeURIComponent(fileName),
|
url: '${baseUrl}deleteFile?fileName=' + encodeURIComponent(fileName),
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
// 删除完成,刷新table
|
// 删除完成,刷新table
|
||||||
if (1 == data.code) {
|
if (1 === data.code) {
|
||||||
alert(data.msg);
|
alert(data.msg);
|
||||||
} else {
|
} else {
|
||||||
$('#table').bootstrapTable('refresh', {});
|
$('#table').bootstrapTable('refresh', {});
|
||||||
@@ -201,6 +195,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
$('#table').bootstrapTable({
|
$('#table').bootstrapTable({
|
||||||
url: 'listFiles',
|
url: 'listFiles',
|
||||||
@@ -228,12 +223,12 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
|||||||
$(".loading_container").css("height", height).show();
|
$(".loading_container").css("height", height).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#btnsubmit").click(function () {
|
$("#btnSubmit").click(function () {
|
||||||
showLoadingDiv();
|
showLoadingDiv();
|
||||||
$("#fileUpload").ajaxSubmit({
|
$("#fileUpload").ajaxSubmit({
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
// 上传完成,刷新table
|
// 上传完成,刷新table
|
||||||
if (1 == data.code) {
|
if (1 === data.code) {
|
||||||
alert(data.msg);
|
alert(data.msg);
|
||||||
} else {
|
} else {
|
||||||
$('#table').bootstrapTable('refresh', {});
|
$('#table').bootstrapTable('refresh', {});
|
||||||
|
|||||||
118
server/src/main/resources/web/markdown.ftl
Normal file
118
server/src/main/resources/web/markdown.ftl
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
|
||||||
|
<title>普通文本预览</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<input hidden id="textData" value="${textData}"/>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div id="markdown_btn" class="panel-heading">
|
||||||
|
<h4 class="panel-title">
|
||||||
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
|
${file.name}
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div id="text_btn" class="panel-heading">
|
||||||
|
<h4 class="panel-title">
|
||||||
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
|
${file.name}
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div id="markdown"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
||||||
|
|
||||||
|
<script src="js/jquery-3.0.0.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/jquery.form.min.js" type="text/javascript"></script>
|
||||||
|
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/watermark.js" type="text/javascript"></script>
|
||||||
|
<script src="js/marked.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/base64.min.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
window.onload = function () {
|
||||||
|
$("#markdown_btn").hide()
|
||||||
|
initWaterMark();
|
||||||
|
loadMarkdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化水印
|
||||||
|
*/
|
||||||
|
function initWaterMark() {
|
||||||
|
let watermarkTxt = '${watermarkTxt}';
|
||||||
|
if (watermarkTxt !== '') {
|
||||||
|
watermark.init({
|
||||||
|
watermark_txt: '${watermarkTxt}',
|
||||||
|
watermark_x: 0,
|
||||||
|
watermark_y: 0,
|
||||||
|
watermark_rows: 0,
|
||||||
|
watermark_cols: 0,
|
||||||
|
watermark_x_space: ${watermarkXSpace},
|
||||||
|
watermark_y_space: ${watermarkYSpace},
|
||||||
|
watermark_font: '${watermarkFont}',
|
||||||
|
watermark_fontsize: '${watermarkFontsize}',
|
||||||
|
watermark_color: '${watermarkColor}',
|
||||||
|
watermark_alpha: ${watermarkAlpha},
|
||||||
|
watermark_width: ${watermarkWidth},
|
||||||
|
watermark_height: ${watermarkHeight},
|
||||||
|
watermark_angle: ${watermarkAngle},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载markdown
|
||||||
|
*/
|
||||||
|
function loadMarkdown() {
|
||||||
|
var textData = Base64.decode($("#textData").val())
|
||||||
|
window.textPreData = "<pre style='background-color: #FFFFFF;border:none'>" + textData + "</pre>";
|
||||||
|
window.textMarkdownData = marked(textData);
|
||||||
|
$("#markdown").html(window.textMarkdownData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$("#markdown_btn").click(function () {
|
||||||
|
$("#markdown").html(window.textMarkdownData);
|
||||||
|
$("#text_btn").show()
|
||||||
|
$("#markdown_btn").hide()
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#text_btn").click(function () {
|
||||||
|
$("#markdown_btn").show()
|
||||||
|
$("#text_btn").hide();
|
||||||
|
$("#markdown").html(window.textPreData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -6,32 +6,29 @@
|
|||||||
<title>普通文本预览</title>
|
<title>普通文本预览</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<input hidden id="textType" value="${textType}"/>
|
|
||||||
<input hidden id="textData" value="${textData}"/>
|
<input hidden id="textData" value="${textData}"/>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<#if textType?? && textType == "markdown">
|
<div class="panel panel-default">
|
||||||
<p>
|
<div class="panel-heading">
|
||||||
<button id="markdown_btn" type="button" class="btn btn-primary">切换markdown</button>
|
<h4 class="panel-title">
|
||||||
<button id="text_btn" type="button" class="btn btn-primary">切换text</button>
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
</p>
|
${file.name}
|
||||||
<div id="markdown" style="padding: 18px;"></div>
|
</a>
|
||||||
<#elseif textType?? && textType == "xml" >
|
</h4>
|
||||||
<div id="xml" style="padding: 18px;"></div>
|
</div>
|
||||||
<#else>
|
<div class="panel-body">
|
||||||
<div id="text"></div>
|
<div id="text"></div>
|
||||||
</#if>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<link rel="stylesheet" href="css/xmlTreeViewer.css"/>
|
|
||||||
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
||||||
|
|
||||||
<script src="js/jquery-3.0.0.min.js" type="text/javascript"></script>
|
<script src="js/jquery-3.0.0.min.js" type="text/javascript"></script>
|
||||||
<script src="js/jquery.form.min.js" type="text/javascript"></script>
|
<script src="js/jquery.form.min.js" type="text/javascript"></script>
|
||||||
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||||
<script src="js/watermark.js" type="text/javascript"></script>
|
<script src="js/watermark.js" type="text/javascript"></script>
|
||||||
<script src="js/marked.min.js" type="text/javascript"></script>
|
|
||||||
<script src="js/xmlTreeViewer.js" type="text/javascript"></script>
|
|
||||||
<script src="js/base64.min.js" type="text/javascript"></script>
|
<script src="js/base64.min.js" type="text/javascript"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -39,12 +36,8 @@
|
|||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
$("#markdown_btn").hide()
|
|
||||||
initWaterMark();
|
initWaterMark();
|
||||||
fetchData();
|
|
||||||
loadText();
|
loadText();
|
||||||
loadXmlData()
|
|
||||||
loadMarkdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,55 +65,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文本数据
|
|
||||||
*/
|
|
||||||
function fetchData() {
|
|
||||||
window.textData = Base64.decode($("#textData").val())
|
|
||||||
window.textPreData = "<pre>" + window.textData + "</pre>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*加载普通文本
|
*加载普通文本
|
||||||
*/
|
*/
|
||||||
function loadText() {
|
function loadText() {
|
||||||
$("#text").html(window.textPreData);
|
var textData = Base64.decode($("#textData").val())
|
||||||
}
|
var textPreData = "<pre style='background-color: #FFFFFF;border:none'>" + textData + "</pre>";
|
||||||
|
|
||||||
/**
|
$("#text").html(textPreData);
|
||||||
* 加载markdown
|
|
||||||
*/
|
|
||||||
function loadMarkdown() {
|
|
||||||
if ($("#textType").val() === "markdown") {
|
|
||||||
window.textMarkdownData = marked(window.textData);
|
|
||||||
$("#markdown").html(window.textMarkdownData);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载xml数据
|
|
||||||
*/
|
|
||||||
function loadXmlData() {
|
|
||||||
if ($("#textType").val() === "xml") {
|
|
||||||
var xmlNode = xmlTreeViewer.parseXML(window.textData);
|
|
||||||
var retNode = xmlTreeViewer.getXMLViewerNode(xmlNode.xml);
|
|
||||||
$("#xml").html(retNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function () {
|
|
||||||
$("#markdown_btn").click(function () {
|
|
||||||
$("#markdown").html(window.textMarkdownData);
|
|
||||||
$("#text_btn").show()
|
|
||||||
$("#markdown_btn").hide()
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#text_btn").click(function () {
|
|
||||||
$("#markdown_btn").show()
|
|
||||||
$("#text_btn").hide();
|
|
||||||
$("#markdown").html(window.textPreData);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
@@ -134,13 +87,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#markdown, #xml {
|
|
||||||
height: 97%;
|
|
||||||
max-height: 97%;
|
|
||||||
border: 1px solid #ece7e7;
|
|
||||||
overflow-y: scroll;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
97
server/src/main/resources/web/xml.ftl
Normal file
97
server/src/main/resources/web/xml.ftl
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
|
||||||
|
<title>普通文本预览</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<input hidden id="textData" value="${textData}"/>
|
||||||
|
<div class="container">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h4 class="panel-title">
|
||||||
|
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||||
|
${file.name}
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div id="xml"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="css/xmlTreeViewer.css"/>
|
||||||
|
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
||||||
|
|
||||||
|
<script src="js/jquery-3.0.0.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/jquery.form.min.js" type="text/javascript"></script>
|
||||||
|
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/watermark.js" type="text/javascript"></script>
|
||||||
|
<script src="js/marked.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/xmlTreeViewer.js" type="text/javascript"></script>
|
||||||
|
<script src="js/base64.min.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
window.onload = function () {
|
||||||
|
initWaterMark();
|
||||||
|
loadXmlData()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化水印
|
||||||
|
*/
|
||||||
|
function initWaterMark() {
|
||||||
|
let watermarkTxt = '${watermarkTxt}';
|
||||||
|
if (watermarkTxt !== '') {
|
||||||
|
watermark.init({
|
||||||
|
watermark_txt: '${watermarkTxt}',
|
||||||
|
watermark_x: 0,
|
||||||
|
watermark_y: 0,
|
||||||
|
watermark_rows: 0,
|
||||||
|
watermark_cols: 0,
|
||||||
|
watermark_x_space: ${watermarkXSpace},
|
||||||
|
watermark_y_space: ${watermarkYSpace},
|
||||||
|
watermark_font: '${watermarkFont}',
|
||||||
|
watermark_fontsize: '${watermarkFontsize}',
|
||||||
|
watermark_color: '${watermarkColor}',
|
||||||
|
watermark_alpha: ${watermarkAlpha},
|
||||||
|
watermark_width: ${watermarkWidth},
|
||||||
|
watermark_height: ${watermarkHeight},
|
||||||
|
watermark_angle: ${watermarkAngle},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载xml数据
|
||||||
|
*/
|
||||||
|
function loadXmlData() {
|
||||||
|
var textData = Base64.decode($("#textData").val())
|
||||||
|
var xmlNode = xmlTreeViewer.parseXML(textData);
|
||||||
|
var retNode = xmlTreeViewer.getXMLViewerNode(xmlNode.xml);
|
||||||
|
$("#xml").html(retNode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user