-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
139 lines (120 loc) · 4.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!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>