Skip to content

权限体系

三级权限模型

层级作用范围声明位置无权限行为
Type 级整个组件schema.permission不渲染组件,触发 @denied
Action 级操作按钮rowActions / toolbarActionspermission不渲染按钮
Cell 级单个字段Cell 声明的 permissionview 无权限:不渲染;edit 无权限:降级为 display

Cell 级权限声明

json
{
  "key": "amount",
  "label": "金额",
  "cell": "currency",
  "permission": { "view": true, "edit": "order:amount:edit" }
}
字段类型默认值说明
viewstring / booleantruetrue = 所有人可见,string = 权限标识
editstring / booleantruetrue = 所有人可编辑,string = 权限标识

不声明 permission 等同于 { view: true, edit: true }

简写: "permission": "code" 等价于 { "view": "code", "edit": "code" }

权限判定流程

Type 级

schema.permission 存在?
├── 否 → 正常渲染
└── 是 → hasPermission(code)
    ├── true → 正常渲染
    └── false → 不渲染,触发 @denied

Cell 级(display 模式)

permission.view?
├── 未声明或 true → 正常渲染
└── string → hasPermission(code) → true: 渲染 / false: 不渲染该列

Cell 级(edit 模式)

permission.view?
├── 无权限 → 不渲染
└── 有权限 → permission.edit?
    ├── 未声明或 true → 可编辑
    └── string → hasPermission(code) → true: 可编辑 / false: 降级为 display

Action 级

action.permission → hasPermission(code) → true: 渲染 / false: 不渲染

表单中的权限覆盖

createForm / updateFormoverrides 中可覆盖 Cell 原始 permission,优先级:form overrides > Cell 原始声明

json
{
  "createForm": { "overrides": { "amount": { "permission": { "edit": true } } } },
  "updateForm": { "overrides": { "amount": { "permission": { "edit": "order:amount:edit" } } } }
}

权限注入

javascript
providers = {
  auth: {
    hasPermission: (code) => currentUser.permissions.includes(code)
  }
}

Released under the MIT License.