修改权限

This commit is contained in:
啊平 2021-03-02 18:36:01 +08:00
parent 301c5a31c1
commit 46e745b8d1
4 changed files with 61 additions and 8 deletions

View File

@ -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"

View File

@ -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;
}

View 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)
}
}

View 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;
}