-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.html
More file actions
167 lines (156 loc) · 4.59 KB
/
Copy pathmain.html
File metadata and controls
167 lines (156 loc) · 4.59 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>主页面</title>
<link href="css/mui.min.css" rel="stylesheet" />
<link href="css/iconfont.css" rel="stylesheet" />
<!--引入公用样式-->
<link rel="stylesheet" type="text/css" href="css/public.css"/>
</head>
<body class="dp-n" id="body">
<header class="mui-bar mui-bar-nav titleBar-bgcolor" id="header">
<h1 class="mui-title titleBar-color">首页</h1>
</header>
<nav class="mui-bar mui-bar-tab tabBar-bgcolor">
<a class="mui-tab-item mui-active" data-id="home">
<span class="mui-icon iconfont icon-shouye-copy"></span>
<span class="mui-tab-label">首页</span>
</a>
<a class="mui-tab-item" data-id="weather">
<span class="mui-icon iconfont icon-tianqi"></span>
<span class="mui-tab-label">天气</span>
</a>
<a class="mui-tab-item" data-id="news">
<span class="mui-icon iconfont icon-jiqiren"></span>
<span class="mui-tab-label">小艾</span>
</a>
<a class="mui-tab-item" data-id="about">
<span class="mui-icon iconfont icon-guanyu"></span>
<span class="mui-tab-label">关于</span>
</a>
</nav>
<!--这里面是content页面-->
<div class="mui-content"></div>
<script src="js/mui.min.js"></script>
<script src="js/immersed.js"></script>
<script type="text/javascript" charset="utf-8">
mui.init({
statusBarBackground: '#009be0'
});
mui.plusReady(function() {
plus.nativeUI.showWaiting("加载中...");
var topoffset = '45px';
if(plus.navigator.isImmersedStatusbar()){
topoffset = (Math.round(plus.navigator.getStatusbarHeight())+45)+'px';
}
document.getElementById('header').style.height = (immersed+44)+'px';
document.querySelector('.mui-content').style.marginTop = (immersed)+'px';
/**
* 手动关闭启动界面
*/
plus.navigator.closeSplashscreen();
/**
*把页面存在数组里面
**/
var subInfos = [{
url: 'pages/home.html',
id: 'home'
}, {
url: 'pages/weather.html',
id: 'weather',
}, {
url: 'pages/news.html',
id: 'news'
}, {
url: 'pages/about.html',
id: 'about'
}];
/**
*设置头部底部高度
**/
var subStyles = {
top: (immersed+44)+'px',
bottom: '51px'
};
/**
* 根据id查询子页面的信息
*/
var getSubInfoById = function(infoList, id) {
var result = null;
for(var i = 0, len = infoList.length; i < len; i++) {
var _info = infoList[i];
if(_info.id === id) {
result = _info;
break;
}
}
return result;
};
var mainWv = plus.webview.currentWebview();
var titleEL = document.querySelector('.mui-title');
var activeTab = '';
/**
* 默认只加载首页webview
*/
var homeWv = plus.webview.create(subInfos[0].url, subInfos[0].id, subStyles);
mainWv.append(homeWv);
activeTab = subInfos[0].id;
plus.nativeUI.closeWaiting();
document.getElementById("body").className = "";
/**
* 点击切换,动态创建其它webview;
*/
mui('.mui-bar-tab').on('tap', 'a.mui-tab-item', function(e) {
var _self = this;
var targetTab = _self.getAttribute('data-id');
if(targetTab === activeTab) {
return;
}
titleEL.innerText = _self.querySelector('.mui-tab-label').innerText;
var _subWv = plus.webview.getWebviewById(targetTab);
/*
*若webview不存在,则创建;
**/
if(!_subWv) {
var _subInfo = getSubInfoById(subInfos, targetTab);
_subWv = plus.webview.create(_subInfo.url, _subInfo.id, subStyles);
mainWv.append(_subWv);
}
_subWv.show();
/**
* 隐藏之前的webview
*/
plus.webview.getWebviewById(activeTab).hide('none');
activeTab = targetTab;
});
});
/**
* 重写mui.back(),一秒内连续点击两次,退出应用,仅安卓有效;
*/
var first = null;
mui.back = function() {
if(!first) {
first = new Date().getTime();
/**
* 自动消失提示信息
* http://www.html5plus.org/doc/zh_cn/nativeui.html#plus.nativeUI.toast
*/
plus.nativeUI.toast("再按一次退出应用");
setTimeout(function() {
first = null;
}, 1000);
} else {
if(new Date().getTime() - first < 1000) {
/**
* 退出应用,仅安卓有效;
* http://www.html5plus.org/doc/zh_cn/runtime.html#plus.runtime.quit
*/
plus.runtime.quit();
}
}
};
</script>
</body>
</html>