Commit f59952e6 by luyt

feat:调整分页逻辑

1 parent 627d0175
...@@ -35,19 +35,21 @@ class TrackService extends Service { ...@@ -35,19 +35,21 @@ class TrackService extends Service {
// console.log('params: ', params); // console.log('params: ', params);
const { app } = this; const { app } = this;
// 分页 // 分页
const page = +params.page || 1;
const pageSize = +params.pageSize || 10;
const blogPageList = await app.model.Track.findAll({ const blogPageList = await app.model.Track.findAll({
// order: [ // order: [
// [ 'id', 'desc' ], // [ 'id', 'desc' ],
// ], // ],
limit: +params.pageSize || 10, limit: pageSize,
offset: +params.page || 1, offset: (page - 1) * pageSize,
}); });
const blogListAndCount = await app.model.Track.findAndCountAll(); const blogListAndCount = await app.model.Track.findAndCountAll();
return { return {
code: 200, code: 200,
message: '查询成功', message: '查询成功',
data: blogPageList || [], data: blogPageList || [],
total: blogListAndCount, total: blogListAndCount.count,
}; };
} }
} }
......
...@@ -27,7 +27,7 @@ module.exports = appInfo => { ...@@ -27,7 +27,7 @@ module.exports = appInfo => {
config.sequelize = { config.sequelize = {
dialect: 'mysql', // support: mysql, mariadb, postgres, mssql dialect: 'mysql', // support: mysql, mariadb, postgres, mssql
timezone: '+08:00', // 时区问题 // timezone: '+08:00', // 时区问题
database: 'track_info', database: 'track_info',
host: '192.168.3.210', host: '192.168.3.210',
port: 3308, port: 3308,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!