forked from aOrz/Wordpress-Mobile-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.html
252 lines (247 loc) · 8.23 KB
/
list.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
248
249
250
251
252
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章列表</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="css/mui.min.css">
<link rel="stylesheet" href="css/mystyle.css" />
</head>
<body>
<div id="content">
<!--下拉刷新容器-->
<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
<div class="mui-scroll">
<!--数据列表-->
<ul class="mui-table-view">
<my-img-list v-for="item in imglist" :id="item.id" :date="item.date" :author="item.author" :title="item.title.rendered" :excerpt="item.excerpt.rendered" :key="item.id">
</my-img-list>
</ul>
</div>
</div>
</div>
<script src="./js/mui.min.js"></script>
<script type="text/javascript" src="js/vue.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script>
var wp = new WP();
/*
* VUE
*/
var list = new Vue({
el: '#content',
data: {
imglist: JSON.parse(localStorage.getItem('list_data')) || new Array(),
page: 2,
down_refresh: {
page: 1,
context: 'embed',
'filter[cat]': ''
}
},
computed: {
up_refresh: function() {
var up = this.down_refresh;
up.page = this.page;
return up;
}
},
methods: {
pullupRefresh: function() {
wp.getData({
route: 'posts',
data: this.up_refresh,
success: function(data) {
list.page++;
var next = data.length < app.per_page ? true : false;
// console.log('da' + data.length + 'd' + app.per_page + 'n' + next)
list.imglist = list.imglist.concat(data);
mui('#pullrefresh').pullRefresh().endPullupToRefresh(next);
// console.log('上');
},
error: function() {
mui('#pullrefresh').pullRefresh().endPullupToRefresh(0);
mui.alert('好像出错了哦~')
}
})
},
pulldownRefresh: function() {
this.page = 2;
this.down_refresh.page = 1;
wp.getData({
route: 'posts',
data: this.down_refresh,
success: function(data) {
var next = data.length < app.per_page ? true : false;
// console.log('da' + data.length + 'd' + app.per_page + 'n' + next)
localStorage.setItem('list_data', JSON.stringify(data))
list.imglist = data;
mui('#pullrefresh').pullRefresh().refresh(true);
mui('#pullrefresh').pullRefresh().endPullupToRefresh(next);
mui('#pullrefresh').pullRefresh().endPulldownToRefresh(next);
},
error: function() {
mui('#pullrefresh').pullRefresh().endPulldownToRefresh(0);
mui.alert('好像出错了哦~')
}
})
}
},
components: {
'my-img-list': MyImgList
}
})
// alert(list.down_refresh['filter[cat]'])
mui.init({
preloadPages: [{
url: 'detail.html',
id: 'detail.html'
}],
pullRefresh: {
container: '#pullrefresh',
down: {
callback: list.pulldownRefresh
},
up: {
contentrefresh: '正在加载...',
callback: list.pullupRefresh
}
}
});
/*
* 监听点击事件
*/
mui(".mui-table-view").on('tap', '.mui-table-view-cell', function() {
//获取id
var id = this.getAttribute("data-id");
var author = this.getAttribute("data-author");
var detail_page = plus.webview.getWebviewById('detail.html');
mui.fire(detail_page, 'getDetail', {
id: id,
author: author
});
//打开新闻详情
mui.openWindow({
id: 'detail.html',
}); //打开新闻详情
})
mui.plusReady(function() {
var main = plus.webview.getLaunchWebview();
var listpage = plus.webview.getWebviewById('list.html');
listpage.addEventListener('maskClick', closeMenu);
var isInTransition = false;
var showMenu = false;
/**
* 显示侧滑菜单
*/
function openMenu() {
if(isInTransition) {
return;
}
if(!showMenu) {
mui.fire(main, 'menu:open');
//侧滑菜单处于隐藏状态,则立即显示出来;
isInTransition = true;
main.setStyle({
mask: 'rgba(0,0,0,0)'
}); //menu设置透明遮罩防止点击
//主窗体开始侧滑并显示遮罩
listpage.setStyle({
mask: 'rgba(0,0,0,0)',
left: '40%',
transition: {
duration: 150
}
});
mui.later(function() {
isInTransition = false;
main.setStyle({
mask: "none"
}); //移除menu的mask
listpage.setStyle({
mask: 'rgba(0,0,0,0.4)'
})
}, 160);
showMenu = true;
}
};
/**
* 关闭菜单
*/
function closeMenu() {
if(isInTransition) {
return;
}
if(showMenu) {
mui.fire(main, 'menu:close');
//关闭遮罩;主窗体开始侧滑;
isInTransition = true;
listpage.setStyle({
mask: 'none',
left: '0',
transition: {
duration: 200
}
});
showMenu = false;
isInTransition = false;
}
};
//处理逻辑:1秒内,连续两次按返回键,则后台运行应用;
//处理逻辑:1秒内,连续两次按返回键,则退出应用;
var first = null;
mui.back = function() {
if(showMenu) {
closeMenu();
} else {
//首次按键,提示‘再按一次退出应用’
if(!first) {
first = new Date().getTime();
mui.toast('再按一次退出应用');
setTimeout(function() {
first = null;
}, 1000);
} else {
if(new Date().getTime() - first < 1000) {
plus.runtime.quit();
}
}
}
};
//主界面向右滑动,若菜单未显示,则显示菜单;否则不做任何操作
window.addEventListener("swiperight", openMenu);
//主界面向左滑动,若菜单已显示,则关闭菜单;否则,不做任何操作;
window.addEventListener("swipeleft", closeMenu);
//侧滑菜单触发关闭菜单命令
window.addEventListener("menu:close", closeMenu);
window.addEventListener("menu:open", openMenu);
window.addEventListener("menu", function() {
if(showMenu) {
closeMenu();
} else {
openMenu();
}
});
window.addEventListener('reload', function(event) {
console.log(JSON.stringify(event.detail))
list.down_refresh = event.detail;
closeMenu();
mui('#pullrefresh').pullRefresh().pulldownLoading();
})
})
if(mui.os.plus) {
mui.plusReady(function() {
setTimeout(function() {
mui('#pullrefresh').pullRefresh().pulldownLoading()
}, 1000);
});
} else {
mui.ready(function() {
mui('#pullrefresh').pullRefresh().pulldownLoading();
});
}
</script>
</body>
</html>