Vben + Abp vnext 设置页面权限

一、Abp后台配置

1、在Admin.Application.Contracts配制权限常量

  public static class DemoPermissions
    {
        public const string BaseService = "Demo";

        public static class Customer
        {
            public const string Default = BaseService + ".Customer";
            public const string Delete = Default + ".Delete";
            public const string Update = Default + ".Update";
            public const string Create = Default + ".Create";

        }
}

2、继承abp的PermissionDefinitionProvider类添加权限

 public class DemoPermissionDefinitionProvider : PermissionDefinitionProvider
    {

        public override void Define(IPermissionDefinitionContext context)
        {
            var business = context.AddGroup(DemoPermissions.BaseService, L(DemoPermissions.BaseService), MultiTenancySides.Tenant);


            var Customer = business.AddPermission(DemoPermissions.Customer.Default, L("Customer"));
            Customer.AddChild(DemoPermissions.Customer.Update, L("Edit"));
            Customer.AddChild(DemoPermissions.Customer.Delete, L("Delete"));
            Customer.AddChild(DemoPermissions.Customer.Create, L("Create"));
        }       

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<DemoResource>(name);
        }


 }

3.在Admin.Application中的业务类中添加权限特性

    [Authorize(DemoPermissions.Customer.Default)]
    public class CustomerAppService : ApplicationService, ICustomerAppService
    { 
  
        [Authorize(DemoPermissions.Customer.Create)]
        public async Task<CustomerDto> CreateAsync(CreateUpdateCustomerDto input)
        {
          //...

        }
            //忽略权限验证,匿名访问
         [AllowAnonymous]
         public async Task<CustomerDto> GetAsync(long? id)
        {
            //...
        }
    }

二、Vben前端,在Routes中配置页面权限


const setup: AppRouteModule = {
  path: '',
  name: '',
  component: LAYOUT,
  redirect: '',
  meta: {
    orderNo: 90000,
    hideChildrenInMenu: true,
    icon: 'ant-design:user-outlined',
    title: '',
  },
  children: [
    {
      path: '',
      name: '',
      component: () => import(''),
      meta: {
        title: t('会员信息'),
        icon: 'ant-design:user-outlined',
        hideMenu: true,
        ignoreKeepAlive: true,
        roles: ['Demo.Customer.MemberInfo'],  //设置页面对应的权限
      },
    },
  ],
};

三、在后台给角色配置会员权限,然后强制刷新浏览器,权限就生效了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值