141 lines
4.3 KiB
HTML
141 lines
4.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
<title>
|
|
<%= htmlWebpackPlugin.options.title %>
|
|
</title>
|
|
<script>
|
|
var UA = window.navigator.userAgent.toLowerCase();
|
|
var isAndroid = UA.indexOf('android') > 0;
|
|
var isIOS = /iphone|ipad|ipod|ios/.test(UA);
|
|
if (!(isAndroid || isIOS)) {
|
|
// TODO 正式发布的时候使用,开发期间不启用。
|
|
//window.location.href = '/pcguide.html';
|
|
}
|
|
|
|
let SYS = {};
|
|
SYS.DEBUG = false;
|
|
SYS.SW_ENABLE = false;
|
|
SYS.VER = '1.0.6';
|
|
|
|
if (SYS.SW_ENABLE && !SYS.DEBUG && navigator.serviceWorker) {
|
|
// 注册Service Worker scope表示作用的页面的path
|
|
// register函数返回Promise
|
|
|
|
navigator.serviceWorker.register('<%= htmlWebpackPlugin.options.baseUrl %>../sw.js?ver=' + SYS.VER, {
|
|
scope: '<%= htmlWebpackPlugin.options.baseUrl %>../'
|
|
})
|
|
.then(function(registration) {
|
|
|
|
//像我之前说的,当页面刷新或者执行功能性事件时,浏览器会自动检查更新,其实我们也可以手动的来触发更新:
|
|
registration.update();
|
|
|
|
// 主页面监听 message 事件
|
|
navigator.serviceWorker.addEventListener('message', function(e) {
|
|
|
|
// Service Worker 如果更新成功会 postMessage 给页面,内容为 'sw.update'
|
|
if (e.data === 'sw.update') {
|
|
|
|
// 开发者这自定义处理函数,也可以使用默认提供的用户提示,引导用户刷新
|
|
// 这里建议引导用户 reload 处理,详细查看项目具体文件
|
|
// location.reload();
|
|
}
|
|
});
|
|
|
|
console.log(registration);
|
|
})
|
|
.catch(function(e) {
|
|
console.error(e);
|
|
})
|
|
} else {
|
|
console.log('Service Worker is not supported in this browser.')
|
|
}
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
|
|
})
|
|
</script>
|
|
|
|
<link rel="stylesheet" href="<%= htmlWebpackPlugin.options.baseUrl %>static/index.css" />
|
|
</head>
|
|
<body>
|
|
<noscript>
|
|
<strong>Please enable JavaScript to continue.</strong>
|
|
</noscript>
|
|
<div id="app"></div>
|
|
<!-- built files will be auto injected -->
|
|
|
|
<script>
|
|
if (/uni-app/i.test(navigator.userAgent))
|
|
{
|
|
//读取状态栏高度
|
|
//document.querySelector("body").style.marginTop = "30px";
|
|
|
|
}
|
|
|
|
// H5 plus事件处理
|
|
function plusReady(){
|
|
// 获取自身webview窗口
|
|
var ws=plus.webview.currentWebview();
|
|
console.log('窗口标识: '+ws.id);
|
|
|
|
|
|
console.info(JSON.stringify(plus))
|
|
uni.getSystemInfo({
|
|
success: (res) => {
|
|
console.info(JSON.stringify(res))
|
|
}
|
|
})
|
|
|
|
/*
|
|
//定义全局变量保存分享对象
|
|
var shareObj = null, wxShareObj = null;
|
|
//1. 初始化加载分享模块
|
|
plus.share.getServices(function(s){console.log(JSON.stringify(s)); shareObj = s;},function(e){
|
|
alert( "获取分享服务列表失败:"+e.message );
|
|
});
|
|
|
|
function share(){
|
|
if(shareObj == null){plus.nativeUI.toast('分享组件加载中,请稍候!'); return false;}
|
|
//微信分享
|
|
//1、判断微信分享模块是否存在
|
|
for(var k in shareObj){if(shareObj[k].id == 'weixin'){wxShareObj = shareObj[k];}}
|
|
if(wxShareObj == null){plus.nativeUI.toast('微信分享组件启动失败!'); return false;}
|
|
//2、分享
|
|
wxShareObj.send(
|
|
{
|
|
content : "hcoder.net 为了更好的开发!",
|
|
href : "http://www.hcoder.net/",
|
|
thumbs : ["_www/img/share.jpg"],
|
|
extra : {scene : "WXSceneTimeline"}
|
|
},
|
|
function(){plus.nativeUI.toast( "分享成功!" );},
|
|
function(e){plus.nativeUI.toast( "分享失败:"+e.message );}
|
|
);
|
|
}
|
|
|
|
setTimeout(share, 5000)
|
|
*/
|
|
}
|
|
if(window.plus){
|
|
plusReady();
|
|
}else{
|
|
document.addEventListener('plusready', plusReady, false);
|
|
}
|
|
|
|
|
|
document.addEventListener('UniAppJSBridgeReady', function() {
|
|
console.info(plus)
|
|
uni.getEnv(function(res) {
|
|
console.log('当前环境:' + JSON.stringify(res));
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|