-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
136 lines (104 loc) · 3.75 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
{{extend './_layouts/home.html'}}
{{block 'title'}}{{'SCF - 首页'}}{{/block}}
{{block 'body'}}
<section class="container" >
<ul class="media-list" style="margin-bottom: 100px;">
</ul>
<nav aria-label="Page navigation" class="pull-left">
<div id="page" class="page"></div>
</nav>
</section>
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script src="../public/js/jquery.cookie.js"></script>
<script>
var aj = [];
var num = [];
$.ajax({
url: '/',
type: 'post',
success: function (res, err) {
// console.log(res);
aj.push(res.aa);
if (err) {
console.log(err);
}
// 页码
var oPage = $(".page");
getPage();
function getPage() {
var pageNum = parseInt(res.aa.length / 10);
for (var i = 0; i < pageNum + 1; i++) {
//添加页码
var $a = $("<a>" + (i + 1) + "</a>");
$a.attr({
src: "javascript:;",
class: "page_number"
});
oPage.append($a);
if (i === 0) {
$a.addClass("current");
}
}
}
getMsgList(1);
function getMsgList(number) {
num = [];
num.push(number);
var count = ((number == Math.ceil(res.aa.length / 10)) ? (parseInt(res.aa.length % 10)) : 10);
for (i = (number - 1) * 10; i < ((number - 1) * 10 + count); i++) {
$('.media-list').append(`
<li class="media list-shadow" style="line-height: 38px;">
<div class="pull-left" style="margin-left: 20px; margin-top: 20px;">
<a href="#">
<img width="40" height="40" class="media-object" src="../public/img/logo3.png" alt="...">
</a>
</div>
<div class="media-body" >
<h4 class="media-heading" style="margin-top: 20px;"><a href="/article">` + res.aa[i].theme + `</a></h4>
<p>` + res.aa[i].nickname + ` 发布了文章 • ` + now(res.aa[i].last_modified_time) + `</p>
</div>
</li>
`)
}
console.log(res.aa[i].last_modified_time);
}
$(".container").delegate(".page_number", "click", function () {
// 设置选中状态
$(this).addClass("current");
// 排它
$(this).siblings().removeClass("current");
$('.media-list').html("");
num = [];
// 添加新数据
getMsgList($(this).text());
// console.log($(this).text());
num.push($(this).text())
});
}
});
//监听文章点击
$(".media-list").delegate(".media-heading", "click", function () {
// alert(num);
window.event ? window.event.cancelBubble = true : e.stopPropagation();
var articleIndex = $(".media-heading").index($(this));
// $.addCookie("pageNumber", num[0]);
// window.location.hash = $(this).html();
// document.cookie="pageNumber=num[0]"
var id = aj[0][articleIndex + 10 * (num[0] - 1)]._id;
// alert(id);
$.ajax({
url: '/art',
type: 'get',
data: {
id: id,
},
success: function (err, data) {
// console.log(data);
if (err) {
console.log(err);
}
}
})
});
</script>
{{/block}}