-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
150 lines (140 loc) · 3.83 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
<!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" />
</head>
<body>
<header class="mui-bar mui-bar-nav">
<h1 class="mui-title">首页</h1>
</header>
<nav class="mui-bar mui-bar-tab">
<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-xinwen"></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>
<script src="js/mui.min.js"></script>
<script type="text/javascript" charset="utf-8">
mui.init();
mui.plusReady(function() {
/**
* 手动关闭启动界面
*/
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: '45px',
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;
/**
* 点击切换,动态创建其它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>