acl ACL - 图1 This article has not been translated, hope that your can PR to translated it. Help us!acl ACL - 图2

acl ACL

结合 @delon/acl 权限可以利用一个 Schema 来构建不同角色或权限点的表单。

代码演示

acl ACL - 图3

基础样例

最简单的用法。

  1. import { Component } from '@angular/core';
  2. import { ACLService } from '@delon/acl';
  3. import { SFSchema } from '@delon/form';
  4. import { NzMessageService } from 'ng-zorro-antd/message';
  5. @Component({
  6. selector: 'form-acl-simple',
  7. template: `
  8. <sf [schema]="schema" (formSubmit)="submit($event)"></sf>
  9. <button nz-button nzType="primary" (click)="acl.setFull(true)">Full</button>
  10. <button nz-button nzType="primary" (click)="acl.setFull(false)">Not Full</button>
  11. <button nz-button nzType="primary" (click)="acl.setRole(['admin'])">Admin Role</button>
  12. <button nz-button nzType="primary" (click)="acl.setRole(['user'])">User Role</button>
  13. `,
  14. })
  15. export class FormAclSimpleComponent {
  16. schema: SFSchema = {
  17. properties: {
  18. name: {
  19. type: 'string',
  20. title: 'name-user',
  21. ui: {
  22. acl: 'user',
  23. },
  24. },
  25. age: {
  26. type: 'string',
  27. title: 'age-admin',
  28. ui: {
  29. acl: 'admin',
  30. },
  31. },
  32. },
  33. required: ['name'],
  34. };
  35. constructor(public msg: NzMessageService, public acl: ACLService) {
  36. }
  37. submit(value: any) {
  38. this.msg.success(JSON.stringify(value));
  39. }
  40. }