mirror of
https://github.com/apgzs/cool-admin-api.git
synced 2025-04-06 03:58:06 +08:00
新增示例
This commit is contained in:
parent
74e6f2ffdd
commit
1cd1aa1639
@ -2,6 +2,7 @@
|
|||||||
* 演示地址:https://show.cool-admin.com
|
* 演示地址:https://show.cool-admin.com
|
||||||
* 文档地址:https://docs.cool-admin.com
|
* 文档地址:https://docs.cool-admin.com
|
||||||
* 官网:https://www.cool-admin.com
|
* 官网:https://www.cool-admin.com
|
||||||
|
|
||||||
## 技术选型
|
## 技术选型
|
||||||
Node版后台基础框架基于[Egg.js](https://eggjs.org/zh-cn/)(阿里出品)
|
Node版后台基础框架基于[Egg.js](https://eggjs.org/zh-cn/)(阿里出品)
|
||||||
* 基础:**[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/)(阿里出品)
|
|||||||

|

|
||||||
|
|
||||||
## 快速开发6个接口
|
## 快速开发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")无法识别,如:
|
数据模型必须放在`app/entities/*`下,否则[typeorm](https://typeorm.io "typeorm")无法识别,如:
|
||||||
```js
|
```js
|
||||||
|
@ -170,38 +170,43 @@ export abstract class BaseService extends Service {
|
|||||||
const find = entity
|
const find = entity
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.take(parseInt(size))
|
.take(parseInt(size))
|
||||||
.skip(String((page - 1) * size))
|
.skip(String((page - 1) * size));
|
||||||
.where(option.where);
|
if (option) {
|
||||||
// 附加排序
|
// 默认条件
|
||||||
if (!_.isEmpty(option.addOrderBy)) {
|
if (option.where) {
|
||||||
for (const key in option.addOrderBy) {
|
find.where(option.where);
|
||||||
find.addOrderBy(key, option.addOrderBy[key].toUpperCase());
|
}
|
||||||
|
// 附加排序
|
||||||
|
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) {
|
if (sort && order) {
|
||||||
find.addOrderBy(order, sort.toUpperCase());
|
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;
|
return find;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user