mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-01-18 19:48:11 +00:00
4.x 就绪
This commit is contained in:
parent
a3f1ef9edc
commit
725649d0ee
@ -5,7 +5,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cool-midway/alipay": "^4.0.3",
|
"@cool-midway/alipay": "^4.0.3",
|
||||||
"@cool-midway/core": "^4.0.6",
|
"@cool-midway/core": "/Users/mac/Documents/src/cool/admin/midway-core/core/dist/",
|
||||||
"@cool-midway/es": "^4.0.2",
|
"@cool-midway/es": "^4.0.2",
|
||||||
"@cool-midway/oss": "^4.0.2",
|
"@cool-midway/oss": "^4.0.2",
|
||||||
"@cool-midway/queue": "^4.0.3",
|
"@cool-midway/queue": "^4.0.3",
|
||||||
|
|||||||
@ -12,6 +12,10 @@ import { BaseSysLogService } from '../../../service/sys/log';
|
|||||||
@CoolController({
|
@CoolController({
|
||||||
api: ['page'],
|
api: ['page'],
|
||||||
entity: BaseSysLogEntity,
|
entity: BaseSysLogEntity,
|
||||||
|
urlTag: {
|
||||||
|
name: 'a',
|
||||||
|
url: ['add'],
|
||||||
|
},
|
||||||
pageQueryOp: {
|
pageQueryOp: {
|
||||||
keyWordLikeFields: ['b.name', 'a.params', 'a.ipAddr'],
|
keyWordLikeFields: ['b.name', 'a.params', 'a.ipAddr'],
|
||||||
select: ['a.*', 'b.name'],
|
select: ['a.*', 'b.name'],
|
||||||
|
|||||||
@ -89,9 +89,9 @@ export class BaseSysUserService extends BaseService {
|
|||||||
*/
|
*/
|
||||||
async person() {
|
async person() {
|
||||||
const info = await this.baseSysUserEntity.findOne({
|
const info = await this.baseSysUserEntity.findOne({
|
||||||
id: this.ctx.admin.userId,
|
id: this.ctx.admin?.userId,
|
||||||
});
|
});
|
||||||
delete info.password;
|
delete info?.password;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,5 +12,7 @@ export default (app: Application) => {
|
|||||||
description: '演示示例',
|
description: '演示示例',
|
||||||
// 中间件
|
// 中间件
|
||||||
middlewares: ['testMiddleware'],
|
middlewares: ['testMiddleware'],
|
||||||
|
// 全局中间件
|
||||||
|
globalMiddlewares: ['demoUserMiddleware'],
|
||||||
} as ModuleConfig;
|
} as ModuleConfig;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { Get, Provide } from '@midwayjs/decorator';
|
import { Get, Provide } from '@midwayjs/decorator';
|
||||||
import { Context } from 'egg';
|
import { Context } from 'egg';
|
||||||
import { CoolController, BaseController } from '@cool-midway/core';
|
import { CoolController, BaseController, CoolUrlTag } from '@cool-midway/core';
|
||||||
import { DemoGoodsEntity } from '../../entity/goods';
|
import { DemoGoodsEntity } from '../../entity/goods';
|
||||||
|
import { SelectQueryBuilder } from 'typeorm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品
|
* 商品
|
||||||
@ -18,6 +19,11 @@ import { DemoGoodsEntity } from '../../entity/goods';
|
|||||||
userId: ctx.admin.userId,
|
userId: ctx.admin.userId,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// 给请求路径打上标签
|
||||||
|
urlTag: {
|
||||||
|
name: 'ignoreToken',
|
||||||
|
url: ['page'],
|
||||||
|
},
|
||||||
// info接口忽略价格字段
|
// info接口忽略价格字段
|
||||||
infoIgnoreProperty: ['price'],
|
infoIgnoreProperty: ['price'],
|
||||||
// 分页查询配置
|
// 分页查询配置
|
||||||
@ -26,6 +32,10 @@ import { DemoGoodsEntity } from '../../entity/goods';
|
|||||||
keyWordLikeFields: ['title'],
|
keyWordLikeFields: ['title'],
|
||||||
// 让type字段支持筛选
|
// 让type字段支持筛选
|
||||||
fieldEq: ['type'],
|
fieldEq: ['type'],
|
||||||
|
// 4.x 新增 追加其他条件
|
||||||
|
extend: async (find: SelectQueryBuilder<DemoGoodsEntity>) => {
|
||||||
|
find.groupBy('a.id');
|
||||||
|
},
|
||||||
// 增加其他条件
|
// 增加其他条件
|
||||||
where: async (ctx: Context) => {
|
where: async (ctx: Context) => {
|
||||||
return [
|
return [
|
||||||
@ -44,6 +54,7 @@ export class DemoAdminGoodsController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* 其他接口
|
* 其他接口
|
||||||
*/
|
*/
|
||||||
|
@CoolUrlTag('ignoreToken')
|
||||||
@Get('/other')
|
@Get('/other')
|
||||||
async other() {
|
async other() {
|
||||||
return this.ok('hello, cool-admin!!!');
|
return this.ok('hello, cool-admin!!!');
|
||||||
|
|||||||
33
src/app/modules/demo/middleware/user.ts
Normal file
33
src/app/modules/demo/middleware/user.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { ICoolUrlTag } from '@cool-midway/core';
|
||||||
|
import { App, Provide } from '@midwayjs/decorator';
|
||||||
|
import {
|
||||||
|
IWebMiddleware,
|
||||||
|
IMidwayWebNext,
|
||||||
|
IMidwayWebApplication,
|
||||||
|
} from '@midwayjs/web';
|
||||||
|
import { Context } from 'egg';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@Provide()
|
||||||
|
export class DemoUserMiddleware implements IWebMiddleware {
|
||||||
|
@App()
|
||||||
|
app: IMidwayWebApplication;
|
||||||
|
|
||||||
|
resolve() {
|
||||||
|
return async (ctx: Context, next: IMidwayWebNext) => {
|
||||||
|
// 获得请求路径标签,可以利用此处来判断是否忽略token校验,以及其他需求场景
|
||||||
|
const urlTag: ICoolUrlTag = await this.app
|
||||||
|
.getApplicationContext()
|
||||||
|
.getAsync('cool:urlTag');
|
||||||
|
console.log('urlTag', urlTag);
|
||||||
|
// 控制器前执行的逻辑
|
||||||
|
const startTime = Date.now();
|
||||||
|
// 执行下一个 Web 中间件,最后执行到控制器
|
||||||
|
await next();
|
||||||
|
// 控制器之后执行的逻辑
|
||||||
|
console.log(Date.now() - startTime);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,6 +13,6 @@ export class WelcomeController extends BaseController {
|
|||||||
|
|
||||||
@Get('/')
|
@Get('/')
|
||||||
public async welcome() {
|
public async welcome() {
|
||||||
await this.ctx.render('welcome', { text: 'HELLO COOL-ADMIN' });
|
await this.ctx.render('welcome', { text: 'HELLO COOL-ADMIN 4.x' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user