Commit 9b592510 authored by shiyunjie's avatar shiyunjie

init

parents
<!--
* @Author: Zhang HuiJian
* @Date: 2020-11-05 14:46:41
* @LastEditors: Zhang HuiJian
* @LastEditTime: 2021-01-22 21:22:54
* @Description: file content
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
body {
margin: 0;
}
.container {
width: 100vw;
height: 100vh;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
background-color: #f5f5f5;
}
.iframe {
width: 100vw;
height: 100vh;
display: block;
border: none;
z-index: 1;
}
.tag {
position: absolute;
z-index: 999;
top: 25px;
left: 22px;
background-color: #eee;
border-radius: 5px;
box-sizing: border-box;
padding: 2px 10px;
display: flex;
}
</style>
<body>
<div id="container" class="container">
<!-- <div class="tag">
<div id="currentPage">0</div>
<div id="pagination">/0</div>
</div> -->
<iframe
id="myIframe"
name="myIframe"
class="iframe"
></iframe>
</div>
<script>
let _bridge;
function hideLoading(){
let iframeDom = window.frames['myIframe'].document;
let dom = iframeDom.getElementById('loading');
if(dom){
dom.style.display = 'none'
}
}
window.onload = () => {
function setSrc() {
let dom = document.getElementById('myIframe');
let server = './iframe/web/viewer.html'; // pdf地址
let search = location.search.substring(1);
let PDF = search;
let hash = location.hash;
let page = 1;
// let str = "security-token=";
// let url_arr = PDF.split(str);
// let str2 = "Signature=";
// let url_arr2 = url_arr[0].split(str2);
//
// console.log('url_arr2:',url_arr2)
//
//
// console.log('Signature=',url_arr2[1].slice(0,url_arr2[1].length-1),decodeURIComponent(url_arr2[1].slice(0,url_arr2[1].length-1)))
//
//PDF = url_arr2[0] + str2 + decodeURIComponent(url_arr2[1].slice(0,url_arr2[1].length-1)) + "&"
// + str + decodeURIComponent(url_arr[1]);
//PDF = url_arr[0] + str + encodeURIComponent(url_arr[1]);
if(search && !sessionStorage.getItem('file')){
console.log('sessionStorage no file');
sessionStorage.setItem("file", search);
}
if (hash) page = hash.split('=')[1];
sessionStorage.setItem("page", page);
let title = sessionStorage.getItem('PDFtitle');
if(title){
document.title = title
}
setupWebViewJavascriptBridge(function (bridge) {
//console.log('setupWebViewJavascriptBridge',bridge);
_bridge = bridge;
console.log('_bridge:', _bridge);
/* Initialize your app here */
//所有与iOS交互的JS代码放这里!
_bridge.callHandler(
'getSecurityToken',
{},
(response) => {
console.log('getSecurityToken:',response.data);
console.log('dom.src:',server + '?file=' + PDF + "&security-token=" + response.data + '#page=' + page);
sessionStorage.setItem("file", PDF + "&security-token=" +response.data);
}
);
});
dom.src = server + '?file=' + PDF + '#page=' + page
}
setSrc();
function setupWebViewJavascriptBridge(callback) {
if (window.WebViewJavascriptBridge) {
return callback(WebViewJavascriptBridge);
}
if (window.WVJBCallbacks) {
return window.WVJBCallbacks.push(callback);
}
window.WVJBCallbacks = [callback];
var WVJBIframe = document.createElement('iframe');
WVJBIframe.style.display = 'none';
WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
document.documentElement.appendChild(WVJBIframe);
setTimeout(() => {
document.documentElement.removeChild(WVJBIframe);
}, 0);
}
/*与OC交互的所有JS方法都要放在此处注册,才能调用通过JS调用OC或者让OC调用这里的JS*/
let interval, iframeDom, currentPage;
// 设置iframe的src
// 判断是否加载完成
setTimeout(() => {
interval = setInterval(() => {
iframeDom = window.frames['myIframe'].document;
let dom = iframeDom.getElementById('pageNumber');
if (dom) setPageNum();
}, 50);
}, 200);
// 用来设置页数
function setPageNum() {
clearInterval(interval);
setInterval(function () {
// pagination.innerText = iframeDom.getElementById(
// 'numPages'
// ).innerHTML;
// currentPageDom.innerText = iframeDom.getElementById(
// 'pageNumber'
// ).value;
//console.log('_bridge:',_bridge)
if (
currentPage !==
iframeDom.getElementById('pageNumber').value
) {
currentPage = iframeDom.getElementById('pageNumber')
.value;
if(currentPage > 0){
hideLoading();
}
setupWebViewJavascriptBridge(function (bridge) {
//console.log('setupWebViewJavascriptBridge',bridge);
_bridge = bridge;
console.log('_bridge:', _bridge);
/* Initialize your app here */
//所有与iOS交互的JS代码放这里!
_bridge.callHandler(
'getPageInfo',
{
nowPage: iframeDom.getElementById(
'pageNumber'
).value,
totalPage: iframeDom.getElementById(
'numPages'
).innerHTML,
},
(response) => {}
);
});
}
}, 250);
}
};
</script>
</body>
</html>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment