index.html
7 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
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>罗电物联网APP</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<style>
html,body{
/*background: #FFFFFF; /*linear-gradient(90deg,rgba(91,127,248,1) 0%,rgba(75,175,239,1) 90%)*/*/
}
</style>
</head>
<body>
<footer>
</footer>
</body>
</html>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
var NVTabBar;
apiready = function() {
initHeaderH();
var footer = $api.dom('footer'); // 获取 footer 标签元素
var footerH = $api.fixTabBar(footer);
api.addEventListener({
name:'resume'
}, function(ret, err){
if (api.systemType == "ios") {
var ajpush = api.require('ajpush');
ajpush.setBadge({
badge:0
});
}
});
// $api.clearStorage();
if (!check()) {
return false;
}
api.addEventListener({
name:'keyback'
},function(ret,err){
api.confirm({
title:'提示',
msg:'是否退出罗电?',
buttons:['确定','取消']
},function(ret,err){
if(ret.buttonIndex==1){
api.closeWidget({
silent: true
});
}
});
});
api.addEventListener({
name: 'change_device'
}, function(ret, err){
if( ret ){
getAlarmCountByUser();
}
});
initPush();//推送相关
NVTabBar = api.require('NVTabBar');
$api.setStorage('curIndex', 0); //默认显示首页
initTabBar(footerH); //底部导航
$api.setStorage('indexFooterH', footerH);
}
function initTabBar(footerH) {
NVTabBar.close();
NVTabBar.open({
styles: {
bg: '#FFFFFF',
h: 49,
dividingLine: { //(可选项)JSON对象;模块顶部的分割线配置
width: 0.5, //(可选项)数字类型;分割线粗细;默认:0.5
color: 'rgba(255,255,255,1)' //(可选项)字符串类型;分割线颜色;默认:#000
},
badge: {
bgColor: '#F26161',
numColor: '#FFFFFF',
size: 5,
}
},
items: [{
w: api.winWidth / 3.0,
bg: {
marginB: 0,
image: '#FFFFFF'
},
iconRect: {
w: 21.5,
h: 21,
},
icon: {
normal: 'widget://image/tabar-home-normal.png',
highlight: 'widget://image/tabar-home-actived.png',
selected: 'widget://image/tabar-home-actived.png'
},
title: {
text: '首页',
size: 11.0,
normal: '#9EA9B6',
selected: '#1D2229',
marginB: 0
}
}, {
w: api.winWidth / 3.0,
bg: {
marginB: 0,
image: '#FFFFFF'
},
iconRect: {
w: 21.5,
h: 21,
},
icon: {
normal: 'widget://image/tabar-alarm-normal.png',
highlight: 'widget://image/tabar-alarm-actived.png',
selected: 'widget://image/tabar-alarm-actived.png'
},
title: {
text: '所有报警',
size: 11.0,
normal: '#9EA9B6',
selected: '#1D2229',
marginB: 0
}
}, {
w: api.winWidth / 3.0,
bg: {
marginB: 0,
image: '#FFFFFF'
},
iconRect: {
w: 21.5,
h: 21,
},
icon: {
normal: 'widget://image/tabar-mine-normal.png',
highlight: 'widget://image/tabar-mine-actived.png',
selected: 'widget://image/tabar-mine-actived.png'
},
title: {
text: '我的',
size: 11.0,
normal: '#9EA9B6',
selected: '#1D2229',
marginB: 0
}
}],
selectedIndex: 0
}, function(ret, err) {
var index;
var goIndex = '';
var currentIndex = $api.getStorage('curIndex');
if (ret.index == currentIndex && ret.index != undefined) {
return;
}else if (ret.index == undefined) {
index = 0;
}else {
index = ret.index;
}
switch (index) {
case 0:
goIndex = 'home';
closeWins('alarm');
break;
case 1:
goIndex = 'alarm';
closeWins('home');
break;
case 2:
goIndex = 'mine';
break;
default:
goIndex = 'home';
}
$api.setStorage('curIndex', index);
getAlarmCountByUser();
api.openFrame({
name: goIndex + 'Index',
url: './' + goIndex + '/' + goIndex + '.html',
reload: true,
rect: {
x: 0,
y: 0,
w: api.winWidth,
h: api.winHeight-49-footerH
},
animation: {
type:"fade", //动画类型(详见动画类型常量)
subType:"from_bottom", //动画子类型(详见动画子类型常量)
duration:300 //动画过渡时间,默认300毫秒
}
});
});
}
function closeWins(frm) {
api.closeFrame({
name: frm + 'Frm'
});
api.closeFrame({
name: 'mineIndex'
});
}
function getAlarmCountByUser() {
//查询该用户下的所有未处理报警总数
var userId = $api.getStorage('userID');
var token = $api.getStorage('userToken');
api.ajax({
url: HOST + '/iot_api/v1/app/get_unsloved_warning_count?user_id='+userId,
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': token
}
}, function(ret, err) {
if (ret.code == 0 && ret.data > 0) {
NVTabBar.setBadge({
index: 1,
badge: ret.data
});
}
});
//---
}
</script>