-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
507 lines (478 loc) · 17.8 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Color theme for statusbar -->
<meta name="theme-color" content="#000">
<!-- Your app title -->
<title>首页</title>
<!-- Path to Framework7 Library CSS -->
<link rel="stylesheet" href="css/framework7.css">
<link rel="stylesheet" href="css/framework7-icons.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="app">
<div class="view view-main view-init">
<div class="page">
<div class="navbar">
<div class="navbar-inner index">
<div class="subnavbar">
<form class="searchbar">
<div class="searchbar-inner">
<div class="searchbar-input-wrap">
<input type="search" placeholder="搜索">
<i class="searchbar-icon"></i>
<span class="input-clear-button"></span>
</div>
<span class="searchbar-disable-button">取消</span>
</div>
</form>
</div>
</div>
</div>
<div class="subnavbar">
<div class="subnavbar-inner">
<div class="segmented segmented-raised">
<a class="button tab-link tab-link-active" href="#tab1">推荐</a>
<a class="button tab-link" href="#tab2" id="rank">排行</a>
</div>
</div>
</div>
<!-- 工具栏标签 -->
<div class="toolbar tabbar-labels">
<div class="toolbar-inner">
<a href="#" class="tab-link-active an-button link external">
<!-- Different icons for iOS and MD themes -->
<i class="icon f7-icons">home_fill</i>
<span class="tabbar-label">首页</span>
</a>
<a href="#" class="tab-link an-button link external" id="jump">
<i class="icon f7-icons">layers_fill</i>
<span class="tabbar-label">班级</span>
</a>
<a href="#" class="tab-link an-button link external" id="group_btn">
<i class="icon f7-icons">persons</i>
<span class="tabbar-label">群组</span>
</a>
<a href="person.html" class="tab-link an-button link external">
<i class="icon f7-icons">person_fill</i>
<span class="tabbar-label">我的</span>
</a>
</div>
</div>
<div class="page-content ptr-content index">
<!-- <div class="searchbar-backdrop"></div> -->
<div class="tabs">
<div class="tab tab-active" id="tab1">
<div class="ptr-preloader">
<div class="preloader"></div>
<div class="ptr-arrow"></div>
</div>
<div class="list media-list index ">
<ul class="index">
</ul>
</div>
</div>
<div class="tab" id="tab2">
<div class="ptr-preloader">
<div class="preloader"></div>
<div class="ptr-arrow"></div>
</div>
<div class="list media-list index">
<ul class="rank" style="background:none;">
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/framework7.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/app.js"></script>
<script src="js/panpan.js"></script>
<script>
window.onload = index(); //index函数里的是需要加载完页面立即执行的函数
function index() {
// 获取文章
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/getAllPassages',
type: "post",
cache: true,
success: function (data) {
$$("ul[class=index]").html("");
$.each(data, function (i, item) {
if (item.photo) { //如果有图片则添加图片card
$("ul[class=index]").append(
`<div class="card demo-card-header-pic">
<a href="anntator.html?id=` +
item
.id +
`" class="link external black" style="width:100%;">
<div style="background-image:url(http://212.64.11.56:8080/` +
item.photo + `); width:100%;" class="card-header align-items-flex-end">` + item.title +
`</div>
</a>
<div class="card-content card-content-padding">
<p class="date index">` +
item.theme + ` · ` + getDateDiff(item.releaseTime) +
`</p>
<p>
<a href="anntator.html?id=` + item.id +
`" class="link external color-black text_overflow2">` + getcontent(item.content) +
`</a>
</p>
</div>
<div class="card-footer">
<a href="#" class="link" id="` +
item.id + `" ontouchstart="like(` +
item.id +
`)">
<i class="f7-icons size-18">heart_fill</i><span class="` + item.id +
`">` +
item.likeCount +
`</span> 喜欢
</a>
</div>
</div>
`
)
if (localStorage.id != -1) {
isLike(item.id);
};
} else { //无图片card
$("ul[class=index]").append(
`<div class="card">
<div class="card-header">` + item.title +
`</div>
<div class="card-content card-content-padding">
<p class="date index">` +
item.theme + ` · ` + getDateDiff(item.releaseTime) +
`</p>
<a href="anntator.html?id=` + item.id +
`" class="link" style="color: black">
<p style="margin-top: 0; margin-bottom: 0;" class="text_overflow">` +
getcontent(item.content) +
`</p>
</a>
</div>
<div class="card-footer">
<a href="#" class="link" style="color" id="` +
item.id + `" ontouchstart="like(` +
item.id +
`)">
<i class="f7-icons size-18">heart_fill</i><span class="` + item.id +
`">` +
item.likeCount +
`</span> 喜欢
</a>
</a>
</div>
</div>`
)
if (localStorage.id != -1) {
isLike(item.id);
};
}
})
},
error: function (e) { }
})
}
//限制首页显示字数
function getcontent(text) {
var html = text;
return html.replace(/<[^>]*>|/g, "");
}
//时间格式化函数
function getDateDiff(dateTimeStamp) {
var dateTimeStamp = new Date(Date.parse(dateTimeStamp.replace(/-/gi, "-")));
dateTimeStamp = dateTimeStamp.getTime();
var result;
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var halfamonth = day * 15;
var month = day * 30;
var now = new Date().getTime();
var diffValue = now - dateTimeStamp;
if (diffValue < 0) {
return;
}
var monthC = diffValue / month;
var weekC = diffValue / (7 * day);
var dayC = diffValue / day;
var hourC = diffValue / hour;
var minC = diffValue / minute;
if (monthC >= 1) {
if (monthC <= 12)
result = "" + parseInt(monthC) + "个月前";
else {
result = "" + parseInt(monthC / 12) + "年前";
}
} else if (weekC >= 1) {
result = "" + parseInt(weekC) + "周前";
} else if (dayC >= 1) {
result = "" + parseInt(dayC) + "天前";
} else if (hourC >= 1) {
result = "" + parseInt(hourC) + "小时前";
} else if (minC >= 1) {
result = "" + parseInt(minC) + "分钟前";
} else {
result = "刚刚";
}
return result;
};
//判断文章是否已经点赞
function isLike(id) {
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/isLike?passageId=' + id + '&userId=' + localStorage.id,
type: "POST",
success: function (data) {
if (data == true) {
$('#' + id).css("color", "#d33a32");
$('#rank' + id).css("color", "#d33a32");
}
}
})
}
//判断批注是否已经点赞
function anisLike(passageId, annotationId) {
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/isLike?passageId=' + passageId + '&userId=' + localStorage.id +
'&annotationId=' + annotationId,
type: "POST",
success: function (data) {
if (data == true) {
$('#rank' + annotationId).css("color", "#d33a32");
}
}
})
}
//文章点赞函数
function like(id) {
//先判断有没有登录
if (localStorage.id == -1) {
app.dialog.create({
text: '请先登录',
buttons: [{
text: '确定',
onClick: function () {
window.location.href = "person.html";
}
},],
verticalButtons: true,
}).open();
}
//用颜色判断是点赞还是取消点赞,如果已经点过赞了颜色为蓝色
else if ($('#' + id).css("color") == "rgb(129, 132, 139)" || $('#rank' + id).css("color") ==
"rgb(129, 132, 139)") {
$('#' + id).css("color", "#d33a32");
$('#rank' + id).css("color", "#d33a32"); //排行榜也一起变化
var count = $("span[class='" + id + "']").html();
$("span[class='" + id + "']").html(parseInt(count) + 1);
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/setLike?passageId=' + id + '&userId=' + localStorage.id,
type: 'post',
success: function (data) { },
error: function () { }
})
}
//颜色为蓝色,取消点赞调用取消点赞接口并把颜色重置为灰色
else {
$('#' + id).css("color", "rgb(129, 132, 139)");
$('#rank' + id).css("color", "rgb(129, 132, 139)");
var count = $("span[class='" + id + "']").html();
$("span[class='" + id + "']").html(parseInt(count) - 1);
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/cancelLike?passageId=' + id + '&userId=' + localStorage.id,
type: 'post',
success: function (data) {
},
error: function () { }
})
}
}
//批注点赞函数
function anlike(passageId,id) {
//先判断有没有登录
if (localStorage.id == -1) {
app.dialog.create({
text: '请先登录',
buttons: [{
text: '确定',
onClick: function () {
window.location.href = "person.html";
}
},],
verticalButtons: true,
}).open();
}
//用颜色判断是点赞还是取消点赞,如果已经点过赞了颜色为蓝色
else if ($('#' + id).css("color") == "rgb(129, 132, 139)" || $('#rank' + id).css("color") ==
"rgb(129, 132, 139)") {
$('#' + id).css("color", "#d33a32");
$('#rank' + id).css("color", "#d33a32"); //排行榜也一起变化
var count = $("span[class='" + id + "']").html();
$("span[class='" + id + "']").html(parseInt(count) + 1);
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/setLike?passageId=' + passageId + '&userId=' + localStorage.id+'&annotationId=' + id,
type: 'post',
success: function (data) { },
error: function () { }
})
}
//颜色为蓝色,取消点赞调用取消点赞接口并把颜色重置为灰色
else {
$('#' + id).css("color", "rgb(129, 132, 139)");
$('#rank' + id).css("color", "rgb(129, 132, 139)");
var count = $("span[class='" + id + "']").html();
$("span[class='" + id + "']").html(parseInt(count) - 1);
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/cancelLike?passageId=' + passageId + '&userId=' + localStorage.id+'&annotationId=' + id,
type: 'post',
success: function (data) {
},
error: function () { }
})
}
}
//获取排行
$('#rank').on("touchstart", function () {
$("ul[class=rank]").html(" "); //清空排行内容,防止重复出现
rank();
});
//排行榜渲染函数,原理同渲染推荐
function rank() {
$.ajax({
url: 'http://212.64.11.56:8080/EAnnotation/getRank',
type: "post",
cache: true,
success: function (data) {
$$("ul[class=rank]").html("");
$.each(data, function (i, item) {
console.log(item.type)
if (item.type != "annotation") {
if (item.photo) {
$("ul[class=rank]").append(
`<div class="card demo-card-header-pic">
<a href="anntator.html?id=` +
item.passageId +
`" class="link external black" style="width:100%;">
<div style="background-image:url(http://212.64.11.56:8080/` +
item.photo + `); width:100%;" class="card-header align-items-flex-end">` + item.title +
`</div>
</a>
<div class="card-content card-content-padding">
<p class="date index">` +
item.theme + ` · ` + getDateDiff(item.releaseTime) +
`</p>
<p>
<a href="anntator.html?id=` + item.passageId +
`" class="link external color-black text_overflow2">` + getcontent(item.content) +
`</a>
</p>
</div>
<div class="card-footer">
<a href="#" class="link" style="color" id="rank` +
item.passageId + `" ontouchstart="like(` +
item.passageId +
`)">
<i class="f7-icons size-18">heart_fill</i><span class="` +
item.passageId +
`">` +
item.likecount +
`</span> 喜欢
</a>
</div>
</div>
`
)
if (localStorage.id != -1) {
isLike(item.passageId);
};
//无图card
} else if (!item.photo && item.type == "passage") {
$("ul[class=rank]").append(
`<div class="card">
<div class="card-header">` + item.title +
`</div>
<div class="card-content card-content-padding">
<p class="date index">` +
item.theme + ` · </p>
<a href="anntator.html?id=` + item.passageId +
`" class="link" style="color: black">
<p style="margin-top: 0; margin-bottom: 0;" class="text_overflow">` +
getcontent(item.content) +
`</p>
</a>
</div>
<div class="card-footer">
<a href="#" class="link" style="color" id="rank` +
item.passageId + `" ontouchstart="like(` +
item.passageId +
`)">
<i class="f7-icons size-18">heart_fill</i><span class="` +
item.passageId +
`">` +
item.likecount +
`</span> 喜欢
</a>
</a>
</div>
</div>`
)
if (localStorage.id != -1) {
isLike(item.passageId);
};
}
//批注card
} else {
$("ul[class='rank']").append(
`<div class="card">
<div class="card-header">` + item.title +
`</div>
<div class="card-content card-content-padding">
<p class="date index">批注</p>
<blockquote class="blockquote bqcolor` +
item.style + `">
<p>` + item.selected +
`</p>
</blockquote>
<p>` + getcontent(item.content) +
`
</p>
</div>
<div class="card-footer">
<a href="#" class="link" id="rank` +
item.id + `" ontouchstart="anlike(` +
item.passageId +
`,`+ item.id +`)">
<i class="f7-icons size-18">heart_fill</i><span class="` +
item.id +
`">` +
item.likecount +
`</span>喜欢</a>
<a href="#" class="link">
` +
item.auth + `
</a>
</div>`
);
if (localStorage.id != null && localStorage.id != "undefined") {
anisLike(item.passageId, item.id);
};
}
})
},
error: function (e) { }
})
}
</script>
</body>
</html>