1.需求
获取当前的分页数据 cool有自己的封装的一套东西
2.解决
controller
注意注意注意
在这之前 配置 数据表和service
@Provide()
@CoolController({api: [],entity: BusinessOrderEntity,service: BusinessOrderService,
})
/*** 获取分页数据*/@Post('/page', { summary: '获取分页数据' })async getPageByUser(@Body() body) {const result = await this.businessOrderService.getPageByUser(body);return this.ok(result);}
service
async getPageByUser(query) {const { userId } = this.ctx.admin;console.log(userId);const option = {fieldEq: ['payStatus', 'userId', 'orderProgress'], keyWordLikeFields: ['orderNo', 'lpOrderNo', 'phone'],//关键子搜索条件 对应数据表中的字段where: async (ctx: Context) => {const res = [];if (query.date) {const date_query = ['createTime > :date_start AND createTime < :date_end',{date_start: `${query.date} 00:00:00`,date_end: `${query.date} 23:59:59`,},];res.push(date_query);}return res;},};query.userId = userId;const result = await super.page(query, option);return result;}