246 lines
8.0 KiB
HTML
246 lines
8.0 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<meta charset="utf-8">
|
||
|
|
<title>文档</title>
|
||
|
|
<script src="../../../js/libs/jquery-3.6.0.js"></script>
|
||
|
|
<!-- <script src="../../js/public.js"></script>-->
|
||
|
|
<script src="../../../js/publicJs.js"></script>
|
||
|
|
</head>
|
||
|
|
<style>
|
||
|
|
body,html{
|
||
|
|
width: 100%;
|
||
|
|
height: 100%;
|
||
|
|
margin: 0;
|
||
|
|
padding: 0;
|
||
|
|
float: left;
|
||
|
|
}
|
||
|
|
#dataDiv{
|
||
|
|
width: 100%;
|
||
|
|
height: 95%;
|
||
|
|
float: left;
|
||
|
|
}
|
||
|
|
|
||
|
|
#downloadBtn{
|
||
|
|
background-color: rgb(2, 167, 240);
|
||
|
|
color: #FFFFFF;
|
||
|
|
border: none;
|
||
|
|
margin-right: 20px;
|
||
|
|
border-radius: 5px;
|
||
|
|
margin-top: 5px;
|
||
|
|
width: 60px;
|
||
|
|
height: 39px;
|
||
|
|
font-size: 18px;
|
||
|
|
margin-bottom: 5px;
|
||
|
|
position: absolute;
|
||
|
|
right: 1%;
|
||
|
|
}
|
||
|
|
|
||
|
|
</style>
|
||
|
|
<body>
|
||
|
|
<div id="dataDiv">
|
||
|
|
<div style="width:100%;text-align: right;float: left">
|
||
|
|
<!-- <p id="fileName" style="float: left;margin-left: 30px;font-weight: bold"></p>-->
|
||
|
|
<!-- <button id="downloadBtn">下载</button>-->
|
||
|
|
</div>
|
||
|
|
<iframe id="iframe" style="width:98%;height: 100%;border: none;margin-left: 1%;"></iframe>
|
||
|
|
|
||
|
|
</div>
|
||
|
|
</body>
|
||
|
|
<script type="text/javascript">
|
||
|
|
var Base64 = {
|
||
|
|
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||
|
|
encode: function(e) {
|
||
|
|
var t = "";
|
||
|
|
var n, r, i, s, o, u, a;
|
||
|
|
var f = 0;
|
||
|
|
e = Base64._utf8_encode(e);
|
||
|
|
while (f < e.length) {
|
||
|
|
n = e.charCodeAt(f++);
|
||
|
|
r = e.charCodeAt(f++);
|
||
|
|
i = e.charCodeAt(f++);
|
||
|
|
s = n >> 2;
|
||
|
|
o = (n & 3) << 4 | r >> 4;
|
||
|
|
u = (r & 15) << 2 | i >> 6;
|
||
|
|
a = i & 63;
|
||
|
|
if (isNaN(r)) {
|
||
|
|
u = a = 64
|
||
|
|
} else if (isNaN(i)) {
|
||
|
|
a = 64
|
||
|
|
}
|
||
|
|
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
|
||
|
|
}
|
||
|
|
return t
|
||
|
|
},
|
||
|
|
decode: function(e) {
|
||
|
|
var t = "";
|
||
|
|
var n, r, i;
|
||
|
|
var s, o, u, a;
|
||
|
|
var f = 0;
|
||
|
|
e = e.replace(/[^A-Za-z0-9+/=]/g, "");
|
||
|
|
while (f < e.length) {
|
||
|
|
s = this._keyStr.indexOf(e.charAt(f++));
|
||
|
|
o = this._keyStr.indexOf(e.charAt(f++));
|
||
|
|
u = this._keyStr.indexOf(e.charAt(f++));
|
||
|
|
a = this._keyStr.indexOf(e.charAt(f++));
|
||
|
|
n = s << 2 | o >> 4;
|
||
|
|
r = (o & 15) << 4 | u >> 2;
|
||
|
|
i = (u & 3) << 6 | a;
|
||
|
|
t = t + String.fromCharCode(n);
|
||
|
|
if (u != 64) {
|
||
|
|
t = t + String.fromCharCode(r)
|
||
|
|
}
|
||
|
|
if (a != 64) {
|
||
|
|
t = t + String.fromCharCode(i)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
t = Base64._utf8_decode(t);
|
||
|
|
return t
|
||
|
|
},
|
||
|
|
_utf8_encode: function(e) {
|
||
|
|
e = e.replace(/rn/g, "n");
|
||
|
|
var t = "";
|
||
|
|
for (var n = 0; n < e.length; n++) {
|
||
|
|
var r = e.charCodeAt(n);
|
||
|
|
if (r < 128) {
|
||
|
|
t += String.fromCharCode(r)
|
||
|
|
} else if (r > 127 && r < 2048) {
|
||
|
|
t += String.fromCharCode(r >> 6 | 192);
|
||
|
|
t += String.fromCharCode(r & 63 | 128)
|
||
|
|
} else {
|
||
|
|
t += String.fromCharCode(r >> 12 | 224);
|
||
|
|
t += String.fromCharCode(r >> 6 & 63 | 128);
|
||
|
|
t += String.fromCharCode(r & 63 | 128)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return t
|
||
|
|
},
|
||
|
|
_utf8_decode: function(e) {
|
||
|
|
var t = "";
|
||
|
|
var n = 0;
|
||
|
|
var r = c1 = c2 = 0;
|
||
|
|
while (n < e.length) {
|
||
|
|
r = e.charCodeAt(n);
|
||
|
|
if (r < 128) {
|
||
|
|
t += String.fromCharCode(r);
|
||
|
|
n++
|
||
|
|
} else if (r > 191 && r < 224) {
|
||
|
|
c2 = e.charCodeAt(n + 1);
|
||
|
|
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
|
||
|
|
n += 2
|
||
|
|
} else {
|
||
|
|
c2 = e.charCodeAt(n + 1);
|
||
|
|
c3 = e.charCodeAt(n + 2);
|
||
|
|
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
|
||
|
|
n += 3
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return t
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//kk file 路径
|
||
|
|
// var filePreviewPathAll = filePreviewUrl;
|
||
|
|
|
||
|
|
var fileUploadPath = "";
|
||
|
|
|
||
|
|
function setParam(filePath, fileNames, fileTimes, fileDownloadName){
|
||
|
|
var suffix ="";
|
||
|
|
if(fileNames !=null && fileNames !=undefined && fileNames !='null' && fileNames !='undefined'){
|
||
|
|
suffix = fileNames.substring(fileNames.lastIndexOf(".")+1);
|
||
|
|
}
|
||
|
|
|
||
|
|
fileUploadPath = filePath;
|
||
|
|
// filePath = "https://gzsbdgs.obs.cn-southwest-2.myhuaweicloud.com/bns/gz/fileTemp/2023/01/09/1673248379018满江错误人员名单.xlsx";
|
||
|
|
let filePreviewPath;
|
||
|
|
if(suffix == "pdf"){ //pdf 预览不需要插件
|
||
|
|
if(filePath.indexOf("http") != -1){
|
||
|
|
filePreviewPath = filePath;
|
||
|
|
}else{
|
||
|
|
filePreviewPath = lookFile+"/"+filePath;
|
||
|
|
}
|
||
|
|
//filePreviewPath = encodeURI(filePreviewPath);
|
||
|
|
$("#downloadBtn").css("display","none")
|
||
|
|
$("#iframe").attr("src", filePreviewPath);
|
||
|
|
}else{
|
||
|
|
if(filePath.indexOf("http") != -1){
|
||
|
|
filePreviewPath = filePreviewPathAll + Base64.encode(encodeURI(filePath));
|
||
|
|
}else{
|
||
|
|
filePreviewPath = filePreviewPathAll + Base64.encode(encodeURI(lookFile+"/"+filePath));
|
||
|
|
}
|
||
|
|
if(fileNames !=null && fileNames !=undefined && fileNames !='null' && fileNames !='undefined' && fileNames.length > 50){
|
||
|
|
fileNames = fileNames.substring(0,50)+"...";
|
||
|
|
}
|
||
|
|
$("#fileName").text(fileNames);
|
||
|
|
if(suffix == "jpg" || suffix == "png" || suffix == "JPG" || suffix == "PNG"){
|
||
|
|
$("#downloadBtn").css("display","none");
|
||
|
|
}
|
||
|
|
console.log("filePreviewPath="+filePreviewPath)
|
||
|
|
$("#iframe").attr("src", filePreviewPath);
|
||
|
|
|
||
|
|
//限制onclick事件只触发一次
|
||
|
|
$("#downloadBtn").one('click',function () {
|
||
|
|
window.location.href = fileUploadPath;
|
||
|
|
// if(!!fileDownloadName){
|
||
|
|
// download(filePreviewPath, fileDownloadName);
|
||
|
|
// }else{
|
||
|
|
// download(filePreviewPath, "文档下载");
|
||
|
|
// }
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* 下载
|
||
|
|
* @param {String} url 目标文件地址
|
||
|
|
* @param {String} filename 想要保存的文件名称
|
||
|
|
*/
|
||
|
|
function download(url, filename) {
|
||
|
|
getBlob(url).then(blob => {
|
||
|
|
saveAs(blob, filename);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取 blob
|
||
|
|
* @param {String} url 目标文件地址
|
||
|
|
* @return {Promise}
|
||
|
|
*/
|
||
|
|
function getBlob(url) {
|
||
|
|
return new Promise(resolve => {
|
||
|
|
const xhr = new XMLHttpRequest();
|
||
|
|
xhr.open('GET', url, true);
|
||
|
|
xhr.responseType = 'blob';
|
||
|
|
xhr.onload = () => {
|
||
|
|
if (xhr.status === 200) {
|
||
|
|
resolve(xhr.response);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
xhr.send();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 保存
|
||
|
|
* @param {Blob} blob
|
||
|
|
* @param {String} filename 想要保存的文件名称
|
||
|
|
*/
|
||
|
|
function saveAs(blob, filename) {
|
||
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
||
|
|
navigator.msSaveBlob(blob, filename);
|
||
|
|
} else {
|
||
|
|
const link = document.createElement('a');
|
||
|
|
const body = document.querySelector('body');
|
||
|
|
link.href = window.URL.createObjectURL(blob);
|
||
|
|
link.download = filename;
|
||
|
|
// fix Firefox
|
||
|
|
link.style.display = 'none';
|
||
|
|
body.appendChild(link);
|
||
|
|
link.click();
|
||
|
|
body.removeChild(link);
|
||
|
|
window.URL.revokeObjectURL(link.href);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
</script>
|
||
|
|
</html>
|