pdf增加倒计时
This commit is contained in:
parent
65d58c56f1
commit
f2b41bd2ff
|
|
@ -28,10 +28,18 @@
|
|||
padding: 10px;
|
||||
color: #999999;
|
||||
}
|
||||
.tip {
|
||||
font-size: 50px;
|
||||
position: fixed;
|
||||
top: 50px;
|
||||
right: 0;
|
||||
z-index: 99999999;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p class="desc">web-view 组件加载本地 html 示例,仅在 App 环境下生效。点击下列按钮,跳转至其它页面。</p>
|
||||
<div class="tip">你看看</div>
|
||||
<div class="btn-list">
|
||||
<button class="btn" type="button" data-action="navigateTo">navigateTo</button>
|
||||
<button class="btn" type="button" data-action="redirectTo">redirectTo</button>
|
||||
|
|
@ -44,7 +52,8 @@
|
|||
<button class="btn btn-red" type="button" id="postMessage">postMessage</button>
|
||||
</div>
|
||||
<!-- uni 的 SDK -->
|
||||
<script type="text/javascript" src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.1/index.js"></script>
|
||||
<!-- <script type="text/javascript" src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.1/index.js"></script> -->
|
||||
<script type="text/javascript" src="./local.js"></script>
|
||||
<script type="text/javascript">
|
||||
document.addEventListener('UniAppJSBridgeReady', function() {
|
||||
document.querySelector('.btn-list').addEventListener('click', function(evt) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,(function(){"use strict";try{var e={};Object.defineProperty(e,"passive",{get:function(){!0}}),window.addEventListener("test-passive",null,e)}catch(e){}var n=Object.prototype.hasOwnProperty;function t(e,t){return n.call(e,t)}var i=[],a=function(e,n){var t={options:{timestamp:+new Date},name:e,arg:n};if(window.__dcloud_weex_postMessage||window.__dcloud_weex_){if("postMessage"===e){var a={data:[n]};return window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(a):window.__dcloud_weex_.postMessage(JSON.stringify(a))}var o={type:"WEB_INVOKE_APPSERVICE",args:{data:t,webviewIds:i}};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessageToService(o):window.__dcloud_weex_.postMessageToService(JSON.stringify(o))}if(!window.plus)return window.parent.postMessage({type:"WEB_INVOKE_APPSERVICE",data:t,pageId:""},"*");if(0===i.length){var r=plus.webview.currentWebview();if(!r)throw new Error("plus.webview.currentWebview() is undefined");var d=r.parent(),s="";s=d?d.id:r.id,i.push(s)}if(plus.webview.getWebviewById("__uniapp__service"))plus.webview.postMessageToUniNView({type:"WEB_INVOKE_APPSERVICE",args:{data:t,webviewIds:i}},"__uniapp__service");else{var w=JSON.stringify(t);plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat("WEB_INVOKE_APPSERVICE",'",').concat(w,",").concat(JSON.stringify(i),");"))}},o={navigateTo:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("navigateTo",{url:encodeURI(n)})},navigateBack:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.delta;a("navigateBack",{delta:parseInt(n)||1})},switchTab:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("switchTab",{url:encodeURI(n)})},reLaunch:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("reLaunch",{url:encodeURI(n)})},redirectTo:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.url;a("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a("postMessage",e.data||{})}},r=/uni-app/i.test(navigator.userAgent),d=/Html5Plus/i.test(navigator.userAgent),s=/complete|loaded|interactive/;var w=window.my&&navigator.userAgent.indexOf("AlipayClient")>-1;var u=window.swan&&window.swan.webView&&/swan/i.test(navigator.userAgent);var c=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var g=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var v=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var p=window.qa&&/quickapp/i.test(navigator.userAgent);for(var l,_=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},f=[function(e){if(r||d)return window.__dcloud_weex_postMessage||window.__dcloud_weex_?document.addEventListener("DOMContentLoaded",e):window.plus&&s.test(document.readyState)?setTimeout(e,0):document.addEventListener("plusready",e),o},function(e){if(v)return window.WeixinJSBridge&&window.WeixinJSBridge.invoke?setTimeout(e,0):document.addEventListener("WeixinJSBridgeReady",e),window.wx.miniProgram},function(e){if(c)return window.QQJSBridge&&window.QQJSBridge.invoke?setTimeout(e,0):document.addEventListener("QQJSBridgeReady",e),window.qq.miniProgram},function(e){if(w){document.addEventListener("DOMContentLoaded",e);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(u)return document.addEventListener("DOMContentLoaded",e),window.swan.webView},function(e){if(g)return document.addEventListener("DOMContentLoaded",e),window.tt.miniProgram},function(e){if(p){window.QaJSBridge&&window.QaJSBridge.invoke?setTimeout(e,0):document.addEventListener("QaJSBridgeReady",e);var n=window.qa;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){return document.addEventListener("DOMContentLoaded",e),o}],m=0;m<f.length&&!(l=f[m](_));m++);l||(l={});var E="undefined"!=typeof uni?uni:{};if(!E.navigateTo)for(var b in l)t(l,b)&&(E[b]=l[b]);return E.webView=l,E}));
|
||||
|
|
@ -28,6 +28,15 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||
<meta name="google" content="notranslate">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>PDF播放器</title>
|
||||
<style>
|
||||
.tip {
|
||||
position: fixed;
|
||||
top: 45px;
|
||||
right: 25px;
|
||||
z-index: 99999999;
|
||||
color: #2979ff;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="viewer.css">
|
||||
<!-- This snippet is used in production (included from viewer.html) -->
|
||||
<link rel="resource" type="application/l10n" href="locale/locale.properties">
|
||||
|
|
@ -468,6 +477,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||
|
||||
</div> <!-- outerContainer -->
|
||||
<div id="printContainer"></div>
|
||||
<div class="tip" id="tip"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -478,6 +488,42 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
let params = window.location.search;
|
||||
console.log('🚀 ~ params:', params)
|
||||
params = decodeURIComponent(params).split('.pdf?')[1].split('&')[0].split('=')[1]
|
||||
console.log('params:',params)
|
||||
if (params > 0) {
|
||||
let minute = Math.floor(params / 60);
|
||||
let second = params % 60;
|
||||
let time = minute + ':' + second;
|
||||
let interval = setInterval(() => {
|
||||
if (time == 0) {
|
||||
clearInterval(interval);
|
||||
document.getElementById('tip').innerText = '已完成学习';
|
||||
} else {
|
||||
let arr = time.split(':');
|
||||
let minute = parseInt(arr[0]);
|
||||
let second = parseInt(arr[1]);
|
||||
if (second == 0) {
|
||||
minute -= 1;
|
||||
second = 59;
|
||||
if (minute < 10) {
|
||||
minute = '0' + minute;
|
||||
}
|
||||
} else {
|
||||
second -= 1;
|
||||
if (second < 10) {
|
||||
second = '0' + second;
|
||||
}
|
||||
}
|
||||
time = minute + ':' + second;
|
||||
document.getElementById('tip').innerText = '剩余学习时间:' + time;
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
document.getElementById('tip').innerText = '已完成学习';
|
||||
}
|
||||
|
||||
var interval = setInterval('loadPdf()', 300);
|
||||
function loadPdf() {
|
||||
if (PDFViewerApplication.pdfDocument == null) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@ export default {
|
|||
isShow: true,
|
||||
path: '',
|
||||
params: {},
|
||||
timer: null
|
||||
timer: null,
|
||||
// 剩余时间
|
||||
surplusTime: null
|
||||
}
|
||||
},
|
||||
onLoad(opt) {
|
||||
|
|
@ -26,25 +28,29 @@ export default {
|
|||
this.params = JSON.parse(JSON.stringify(opt))
|
||||
this.params.studyDuration = Number(opt.studyDuration)
|
||||
this.params.allStudyDuration = Number(opt.allStudyDuration)
|
||||
// 如果路径中带有http或者https则直接使用路径,否则拼接路径
|
||||
if (opt.path.indexOf('http') !== -1) {
|
||||
this.path = opt.path
|
||||
} else {
|
||||
this.path = config.fileUrl + opt.path
|
||||
}
|
||||
console.log('🚀 ~ onLoad ~ this.params:', this.path)
|
||||
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
|
||||
if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) {
|
||||
this.surplusTime = Number(opt.allStudyDuration) - Number(opt.studyDuration)
|
||||
console.log('🚀 ~ onLoad ~ surplusTime:', this.surplusTime)
|
||||
setTimeout(() => {
|
||||
this.countDown()
|
||||
}, 1000)
|
||||
}, 1300)
|
||||
} else {
|
||||
this.surplusTime = 0
|
||||
// 提示-学习时长已满
|
||||
uni.showToast({
|
||||
title: '学习时长已满, 随时可以结束学习',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
// 如果路径中带有http或者https则直接使用路径,否则拼接路径
|
||||
if (opt.path.indexOf('http') !== -1) {
|
||||
this.path = opt.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
|
||||
} else {
|
||||
this.path = config.fileUrl + opt.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
|
||||
}
|
||||
console.log('🚀 ~ onLoad ~ this.params:', this.path)
|
||||
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
|
||||
|
||||
},
|
||||
onHide() {
|
||||
clearInterval(this.timer)
|
||||
|
|
|
|||
Loading…
Reference in New Issue