forked from dcloudio/casecode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
247 lines (229 loc) · 6.7 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!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>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
</head>
<body>
<script type="text/javascript">
var subpage_style = {
top: '0px',
bottom: '51px'
},
subpages = ['html/tab-webview-subpage-about.html', 'html/tab-webview-subpage-chat.html', 'html/tab-webview-subpage-contact.html'],
aniShow = {};
/**
* 简单封装了绘制原生view控件的方法
* 绘制内容支持font(文本,字体图标),图片img , 矩形区域rect
*
*/
function drawNative(id, styles, tags) {
var view = new plus.nativeObj.View(id, styles, tags);
return view
}
mui.plusReady(function() {
var self = plus.webview.currentWebview(),
nviews = self.getSubNViews(),
active_color = '#007aff',
normal_color = '#000',
leftPos = Math.ceil((window.innerWidth - 60) / 2);
/**
* drawNativeIconBg 绘制带边框的半圆,
* 实现原理:
* id为bg的tag 创建带边框的圆
* id为bg2的tag 创建白色矩形遮住圆下半部分,只显示凸起带边框部分
* 注意创建先后顺序,创建越晚的层级越高
*/
var drawNativeIconBg = drawNative('iconBg', {
bottom: '5px',
left: leftPos + 'px',
width: '60px',
height: '60px',
position:'dock'
}, [{
tag: 'rect',
id: 'bg',
position: {
top: '0px',
left: '0px',
width: '100%',
height: '100%'
},
rectStyles: {
color: '#fff',
radius: '30px',
borderColor: '#ccc',
borderWidth: '1px'
}
},{
tag: 'rect',
id: 'bg2',
position: {
bottom: '0px',
left: '0px',
width: '100%',
height: '45px'
},
rectStyles: {
color: '#fff'
}
}]);
/**
* 凸起图标最后创建 浮在最顶层
* id为iconBg的红色背景图
* id为icon的字体图标
*
*/
var drawNativeIcon = drawNative('tabIcon', {
bottom: '10px',
left: leftPos + 5 + 'px',
width: '50px',
height: '50px',
position:'dock' //此种停靠方式表明该控件应浮在窗口最上层,以免被其他窗口遮住
}, [{
tag: 'rect',
id: 'iconBg',
position: {
top: '0px',
left: '0px',
width: '50px',
height: '100%'
},
rectStyles: {
color: '#d74b28',
size: '50px',
radius:'50%'
}
},{
tag: 'font',
id: 'icon',
text: '\ue600', //此为字体图标Unicode码'\e600'转换为'\ue600'
position: {
top: '0px',
left: '0px',
width: '50px',
height: '100%'
},
textStyles: {
fontSrc: '_www/fonts/iconfont.ttf',
align:'center',
color: '#fff',
size: '30px'
}
}]);
// append 到父webview中
self.append(drawNativeIconBg);
self.append(drawNativeIcon);
//自定义监听图标点击事件
drawNativeIcon.addEventListener('click', function(e) {
mui.alert('你点击了图标,你在此可以打开摄像头或者新窗口等自定义点击事件。','悬浮球点击事件');
});
//创建子webview窗口 并初始化
for(var i = 0; i < 3; i++) {
var temp = {};
if(!plus.webview.getWebviewById(subpages[i])) {
var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
if(i > 0) {
sub.hide();
} else {
temp[subpages[i]] = "true";
mui.extend(aniShow, temp);
toggleNview(self.getStyle().subNViews[0], 0);
}
// append到当前父webview
self.append(sub);
}
}
var activePage = plus.webview.getWebviewById(subpages[0]);
//给每个view 添加监听点击切换
for(var i = 0; i < 4; i++){
nviews[i].addEventListener('click', clickEvent, false);
}
// 自定义 tab 点击事件
function clickEvent(e) {
var currId = e.target.id,
currIndex = parseInt(currId.substr(currId.length - 1, 1) - 1),
currView = self.getStyle().subNViews[currIndex];
targetPage = plus.webview.getWebviewById(subpages[currIndex]);
if(targetPage == activePage) {
return;
}
if(currIndex !== 3){
//若为iOS平台或非首次显示,则直接显示
if(mui.os.ios || aniShow[targetPage]) {
plus.webview.show(targetPage);
} else {
//否则,使用fade-in动画,且保存变量
var temp = {};
temp[targetPage] = "true";
mui.extend(aniShow, temp);
plus.webview.show(targetPage, "fade-in", 300);
}
//隐藏当前;
plus.webview.hide(activePage);
//更改当前活跃的页面
activePage = targetPage;
//底部选项卡切换
toggleNview(currView, currIndex);
}else{
//第四个tab 打开新窗口
var newWV = plus.webview.create('html/new-webview.html','new');
newWV.show('slide-in-right',200);
}
}
//更改颜色
function changeColor(obj, color) {
obj.color = color;
return obj
}
function toggleNview(currObj, currIndex) {
// 重绘当前nview
self.updateSubNViews([{
id: currObj.id,
tags: [{
tag: 'font', //currObj.tag
id: currObj.id + 1,
position: currObj.tags[0].position,
text: currObj.tags[0].text,
textStyles: changeColor(currObj.tags[0].textStyles, active_color)
}, {
tag: 'font',
id: currObj.id + 2,
position: currObj.tags[1].position,
text: currObj.tags[1].text,
textStyles: changeColor(currObj.tags[1].textStyles, active_color)
}]
}])
// 重绘兄弟nview
for(var i = 0; i < 4; i++) {
var viewObj = self.getStyle().subNViews[i];
if(i !== currIndex) {
updateSubNView(viewObj);
}
}
};
function updateSubNView(obj) {
self.updateSubNViews([{
id: obj.id,
tags: [{
tag: 'font', //obj.tag
id: obj.id + 1,
position: obj.tags[0].position,
text: obj.tags[0].text,
textStyles: changeColor(obj.tags[0].textStyles, normal_color)
}, {
tag: 'font',
id: obj.id + 2,
position: obj.tags[1].position,
text: obj.tags[1].text,
textStyles: changeColor(obj.tags[1].textStyles, normal_color)
}]
}])
}
});
</script>
</body>
</html>