thinkjs / thinkjs

Use full ES2015+ features to develop Node.js applications, Support TypeScript.
https://thinkjs.org/
MIT License
5.31k stars 616 forks source link

model.countSelect 返回的数据结构 #1333

Closed gmk0001 closed 5 years ago

gmk0001 commented 5 years ago

ThinkJS Version:3.0

{
  pageSize: 10, //每页显示的条数, think-model@1.1.8 之前该字段为 pagesize
  currentPage: 1, //当前页
  count: 100, //总条数
  totalPages: 10, //总页数
  data: [{ //当前页下的数据列表
    name: "thinkjs",
    email: "admin@thinkjs.org"
  }, ...]
}

这里的字段名可以修改吗?

lizheming commented 5 years ago

你好,目前是不可以的呢

gmk0001 commented 5 years ago

这个希望未来某个版本能够添加吧,,,

lizheming commented 5 years ago

其实你可以自己实现,写个 base 所有的 model 继承它就好了,下面是个简单的示例。

//base.js
module.exports = class extends think.Model {
    async countSelect(...args) {
        const {
            pageSize: size, 
            currentPage: current, 
            count: counts, 
            totalPages: total, 
            data
        } = await super.countSelect(...args);

        return {size, current, counts, total, data};
    }
}