图片预览可在viewjs中大图预览&翻页

This commit is contained in:
陈精华 2019-04-26 14:10:37 +08:00 committed by kl
parent ae40d0233b
commit a49ee9d726
3 changed files with 13 additions and 8 deletions

View File

@ -41,6 +41,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
public static final String OFFICE_PREVIEW_TYPE_PDF = "pdf";
public static final String OFFICE_PREVIEW_TYPE_IMAGE = "image";
public static final String OFFICE_PREVIEW_TYPE_ALLIMAGES = "allImages";
@Override
public String filePreviewHandle(String url, Model model) {
@ -78,7 +79,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
fileUtils.addConvertedFile(pdfName, fileUtils.getRelativePath(outFilePath));
}
}
if (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType)) {
if (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType) || OFFICE_PREVIEW_TYPE_ALLIMAGES.equals(officePreviewType)) {
List<String> imageUrls = pdfUtils.pdf2jpg(outFilePath, pdfName, url);
if (imageUrls == null || imageUrls.size() < 1) {
model.addAttribute("msg", "office转图片异常请联系管理员");
@ -87,7 +88,11 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
model.addAttribute("imgurls", imageUrls);
model.addAttribute("currentUrl", imageUrls.get(0));
return "officePicture";
if (OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType)) {
return "officePicture";
} else {
return "picture";
}
}
model.addAttribute("pdfUrl", pdfName);
return isHtml ? "html" : "pdf";

View File

@ -18,20 +18,20 @@
<div class="container">
<#list imgurls as img>
<div class="img-area">
<img class="my-photo" alt="loading" data-src="${img}" src="images/loading.gif">
<img class="my-photo" alt="loading" title="查看大图" style="cursor: pointer;" data-src="${img}" src="images/loading.gif" onclick="changePreviewType('allImages')">
</div>
</#list>
</div>
<img src="images/left.png" style="position: fixed; cursor: pointer; top: 40%; left: 50px; z-index: 999;" alt="PDF预览" onclick="goForPdf()"/>
<img src="images/right.png" style="position: fixed; cursor: pointer; top: 40%; right: 70px; z-index: 999;" alt="使用PDF预览" title="使用PDF预览" onclick="changePreviewType('pdf')"/>
<script>
window.onload=checkImgs;
window.onscroll = throttle(checkImgs);
function goForPdf() {
function changePreviewType(previewType) {
var url = window.location.href;
if (url.indexOf("officePreviewType=image") != -1) {
url = url.replace("officePreviewType=image", "officePreviewType=pdf");
url = url.replace("officePreviewType=image", "officePreviewType="+previewType);
} else {
url = url + "&officePreviewType=pdf";
url = url + "&officePreviewType="+previewType;
}
window.location.href=url;
}

View File

@ -18,7 +18,7 @@
</#if>
<iframe src="/pdfjs/web/viewer.html?file=${finalUrl}" width="100%" frameborder="0"></iframe>
<img src="images/right.png" style="position: fixed; cursor: pointer; top: 40%; right: 50px; z-index: 999;" alt="图片预览" onclick="goForImage()"/>
<img src="images/left.png" style="position: fixed; cursor: pointer; top: 40%; right: 70px; z-index: 999;" alt="使用图片预览" title="使用图片预览" onclick="goForImage()"/>
</body>
<script type="text/javascript">