新增示例

This commit is contained in:
啊平 2019-09-29 19:18:34 +08:00
parent 74e6f2ffdd
commit 1cd1aa1639
2 changed files with 34 additions and 26 deletions

View File

@ -2,6 +2,7 @@
* 演示地址https://show.cool-admin.com
* 文档地址https://docs.cool-admin.com
* 官网https://www.cool-admin.com
## 技术选型
Node版后台基础框架基于[Egg.js](https://eggjs.org/zh-cn/)(阿里出品)
* 基础:**[egg.js](https://eggjs.org/zh-cn/)**
@ -42,6 +43,8 @@ Node版后台基础框架基于[Egg.js](https://eggjs.org/zh-cn/)(阿里出品)
![努力开发中](https://cool-admin.com/img/work3.png)
## 快速开发6个接口
<iframe src="//player.bilibili.com/player.html?aid=69398358&cid=120277692&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
## 数据模型
数据模型必须放在`app/entities/*`下,否则[typeorm](https://typeorm.io "typeorm")无法识别,如:
```js

View File

@ -170,38 +170,43 @@ export abstract class BaseService extends Service {
const find = entity
.createQueryBuilder()
.take(parseInt(size))
.skip(String((page - 1) * size))
.where(option.where);
// 附加排序
if (!_.isEmpty(option.addOrderBy)) {
for (const key in option.addOrderBy) {
find.addOrderBy(key, option.addOrderBy[key].toUpperCase());
.skip(String((page - 1) * size));
if (option) {
// 默认条件
if (option.where) {
find.where(option.where);
}
// 附加排序
if (!_.isEmpty(option.addOrderBy)) {
for (const key in option.addOrderBy) {
find.addOrderBy(key, option.addOrderBy[key].toUpperCase());
}
}
// 关键字模糊搜索
if (keyWord) {
keyWord = `%${ keyWord }%`;
find.andWhere(new Brackets(qb => {
const keyWordLikeFields = option.keyWordLikeFields;
for (let i = 0; i < option.keyWordLikeFields.length; i++) {
qb.orWhere(`${ keyWordLikeFields[i] } like :keyWord`, { keyWord });
}
}));
}
// 字段全匹配
if (!_.isEmpty(option.fieldEq)) {
for (const key of option.fieldEq) {
const c = {};
if (query[key]) {
c[key] = query[key];
find.andWhere(`${ key } = :${ key }`, c);
}
}
}
}
// 接口请求的排序
if (sort && order) {
find.addOrderBy(order, sort.toUpperCase());
}
// 关键字模糊搜索
if (keyWord) {
keyWord = `%${ keyWord }%`;
find.andWhere(new Brackets(qb => {
const keyWordLikeFields = option.keyWordLikeFields;
for (let i = 0; i < option.keyWordLikeFields.length; i++) {
qb.orWhere(`${ keyWordLikeFields[i] } like :keyWord`, { keyWord });
}
}));
}
// 字段全匹配
if (!_.isEmpty(option.fieldEq)) {
for (const key of option.fieldEq) {
const c = {};
if (query[key]) {
c[key] = query[key];
find.andWhere(`${ key } = :${ key }`, c);
}
}
}
return find;
}