Skip to content

Commit 9721a12

Browse files
author
liuyi
committed
fix: #33 sort
1 parent 1fbce5b commit 9721a12

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

server/utils/mongodb.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ const getArticleList = async (page, pageSize, sort_type, tag_id) => {
118118
})
119119
}
120120

121-
const start = (page - 1) * pageSize
122-
let articleList = allArticleList.slice(start, start + pageSize)
123-
121+
let articleList = allArticleList
124122
// 1 按热门排序,2 按时间排序
125123
if (sort_type === '1') {
126124
articleList = articleList.sort((a, b) => b?.view_count - a?.view_count)
127125
}
128126

127+
// 先排序再分页
128+
const start = (page - 1) * pageSize
129+
articleList = allArticleList.slice(start, start + pageSize)
130+
129131
const data = {
130132
totalCount,
131133
total: allArticleList.length,

0 commit comments

Comments
 (0)