首页 > 技术文章 > 预览图片用插件view

Esther-yan 2020-11-04 14:53 原文


<link rel="stylesheet" href="${basePath}/resources/vendor/viewer/css/viewer.min.css" />
<script src="resources/vendor/viewer/js/viewer-jquery.min.js"></script>


<div id="PDFPanel" style="width: 1172px;height: 781px;"></div>
<a class="cellBtn" href="javascript:yulanpdf(\''+row.id+'\')">预览</a>
<a class="cellBtn" href="javascript:;" onclick="yulanimg(this,\''+row.id+'\')">查看</a>

function
yulanimg(obj,fileid){ console.log($(obj),fileid); $.ajax({ type: "POST", url: "up/lookimgfile", dataType:"json", data: {"fileid":fileid}, success: function (result) { if(result.code==200){ var wjtype = result.extend.wjlx; var td = $(obj).parent(); td.empty(); var img = $("<img src= data:image/jpeg;base64,"+result.msg+" onclick='clickimg()' width='40px' height='30px' title='点击查看原图'>"); td.append(img); }else{ toastr.info(result.msg); } } }); } function clickimg(){ $('body').viewer('destroy'); $('body').viewer(); } function yulanpdf(fileid){ $('#PDFPanelModal').modal({ keyboard: false, show: true, backdrop: "static" }); previewPDF(fileid,"PDFPanel"); }

function previewPDF(fileId,PDFElement){
var baseStr=$("base").attr("href");
if(document.getElementById("PDFIFEAME")){
document.getElementById("PDFIFEAME").src="resources/vendor/pdf.js/web/viewer.html?file="+baseStr+"up/filePreView/"+fileId;
}else{
var iframe = document.createElement("iframe");
iframe.id = "PDFIFEAME";
iframe.style.border = "none";
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.src = "resources/vendor/pdf.js/web/viewer.html?file="+baseStr+"up/filePreView/"+fileId;
document.getElementById(PDFElement).appendChild(iframe);
}
}

 

 

推荐阅读