Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit f9ac234

Browse files
committed
fix search pagination can't be find
1 parent 210963a commit f9ac234

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

core/controllers/column.controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var listsService = require('../services/lists.service');
88
/**
99
* 栏目
1010
* @param {Object} req
11+
* {String} req.query.page
1112
* @param {Object} res
1213
* @param {Function} next
1314
*/

core/controllers/search.controller.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ var listsService = require('../services/lists.service');
88
/**
99
* 搜索页
1010
* @param {Object} req
11+
* {String} req.query.words
12+
* {String} req.query.page
1113
* @param {Object} res
1214
* @param {Function} next
1315
*/
14-
module.exports = function (req, res, next) {
16+
module.exports = function (req, res) {
1517
req.checkQuery({
1618
'words': {
1719
optional: true,
1820
isString: { errorMessage: 'words 需为字符串' }
21+
},
22+
'page': {
23+
optional: true,
24+
isString: { errorMessage: 'page 需为数字' }
1925
}
2026
});
2127

@@ -30,12 +36,37 @@ module.exports = function (req, res, next) {
3036
categoriesService.navigation({ current: '/search' }, callback);
3137
},
3238
list: function (callback) {
33-
listsService.search({ words: req.query.words }, function (err, list) {
39+
var query = {
40+
words: req.query.words,
41+
pageSize: 15
42+
};
43+
44+
if (req.query.page) query.currentPage = parseInt(req.query.page);
45+
46+
listsService.search(query, function (err, result) {
3447
if (err) return callback(err);
3548

36-
if (!list) return callback();
49+
if (!result) return callback();
50+
51+
if (_.get(result, 'pagination.length') <= 1) {
52+
delete result.pagination
53+
return callback(null, result);
54+
}
55+
56+
var pagination = _.map(result.pagination, function (page) {
57+
if (page.index === 1) {
58+
page.url = '/search?words=' + req.query.words;
59+
} else {
60+
page.url = '/search?words=' + req.query.words + '&page=' + page.index;
61+
}
62+
63+
delete page.index;
64+
return page;
65+
});
66+
67+
result.pagination = pagination;
3768

38-
return callback(null, list);
69+
return callback(null, result);
3970
});
4071
},
4172
readingTotal: function (callback) {

0 commit comments

Comments
 (0)