mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-27 12:00:17 +00:00
修改权限
This commit is contained in:
parent
301c5a31c1
commit
46e745b8d1
@ -13,7 +13,7 @@
|
||||
"ipip-ipdb": "^0.3.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"md5": "^2.3.0",
|
||||
"midwayjs-cool-core": "^3.0.3",
|
||||
"midwayjs-cool-core": "/Users/ap/Documents/srcs/cool-admin/midway-core/core/dist",
|
||||
"mysql2": "^2.2.5",
|
||||
"svg-captcha": "^1.4.0",
|
||||
"svg-to-dataurl": "^1.0.0"
|
||||
|
||||
@ -24,22 +24,19 @@ export class BaseAuthorityMiddleware implements IWebMiddleware {
|
||||
const token = ctx.get('Authorization');
|
||||
let { prefix } = this.coolConfig.router;
|
||||
const adminUrl = prefix ? `${prefix}/admin/` : '/admin/';
|
||||
// 只要登录每个人都有权限的接口
|
||||
const commUrl = prefix ? `${prefix}/admin/comm/` : '/admin/comm/';
|
||||
// 不需要登录的接口
|
||||
const openUrl = prefix ? `${prefix}/admin/open/` : '/admin/open/';
|
||||
// 路由地址为 admin前缀的 需要权限校验
|
||||
if (_.startsWith(url, adminUrl)) {
|
||||
try {
|
||||
ctx.admin = jwt.verify(token, this.coolConfig.jwt.secret);
|
||||
} catch (err) { }
|
||||
// comm 不需要登录 无需权限校验
|
||||
if (_.startsWith(url, openUrl)) {
|
||||
// 不需要登录 无需权限校验
|
||||
if (new RegExp(`^${adminUrl}?.*/open/`).test(url)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
if (ctx.admin) {
|
||||
if (_.startsWith(url, commUrl)) {
|
||||
// 要登录每个人都有权限的接口
|
||||
if (new RegExp(`^${adminUrl}?.*/comm/`).test(url)) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
36
src/app/modules/demo/controller/app/goods.ts
Normal file
36
src/app/modules/demo/controller/app/goods.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Get, Provide } from '@midwayjs/decorator';
|
||||
import { InjectEntityModel } from '@midwayjs/orm';
|
||||
import { CoolController, BaseController } from 'midwayjs-cool-core';
|
||||
import { DemoAppGoodsEntity } from '../../entity/goods';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseSysMenuEntity } from '../../../base/entity/sys/menu';
|
||||
|
||||
/**
|
||||
* 商品
|
||||
*/
|
||||
@Provide()
|
||||
@CoolController({
|
||||
api: ['add', 'delete', 'update', 'info', 'list', 'page'],
|
||||
entity: DemoAppGoodsEntity
|
||||
})
|
||||
export class DemoAppGoodsController extends BaseController {
|
||||
|
||||
@InjectEntityModel(BaseSysMenuEntity)
|
||||
baseSysMenuEntity: Repository<BaseSysMenuEntity>;
|
||||
|
||||
@Get('/123')
|
||||
async 123() {
|
||||
const ms = await this.baseSysMenuEntity.find();
|
||||
for (const item of ms) {
|
||||
if(item.perms){
|
||||
let a = item.perms.split(',')
|
||||
a = a.map(e=>{
|
||||
return 'base:'+e;
|
||||
})
|
||||
item.perms = a.join(',')
|
||||
this.baseSysMenuEntity.update(item.id, item)
|
||||
}
|
||||
}
|
||||
return this.ok(122)
|
||||
}
|
||||
}
|
||||
20
src/app/modules/demo/entity/goods.ts
Normal file
20
src/app/modules/demo/entity/goods.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { EntityModel } from '@midwayjs/orm';
|
||||
import { BaseEntity } from 'midwayjs-cool-core';
|
||||
import { Column } from 'typeorm';
|
||||
|
||||
/**
|
||||
* 商品
|
||||
*/
|
||||
@EntityModel('demo_app_goods')
|
||||
export class DemoAppGoodsEntity extends BaseEntity {
|
||||
|
||||
@Column({ comment: '标题' })
|
||||
title: string;
|
||||
|
||||
@Column({ comment: '图片' })
|
||||
pic: string;
|
||||
|
||||
@Column({ comment: '价格', type: 'decimal', precision: 5, scale: 2 })
|
||||
price: number;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user