RolesPermissions
TsgcHTMLComponent_RolesPermissions — 一个角色/权限矩阵,每个单元格带复选框,支持分类分组和实时 WebSocket 授权更新,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_RolesPermissions — 一个角色/权限矩阵,每个单元格带复选框,支持分类分组和实时 WebSocket 授权更新,适用于 Delphi、C++ Builder 和 .NET。
添加角色和权限,设置初始授权,然后读取 HTML 属性。每次复选框切换都会发送到服务器,服务器必须先授权才能应用。
TsgcHTMLComponent_RolesPermissions
Bootstrap 5 表格矩阵 + 内联脚本
Delphi, C++ Builder, .NET
调用 AddRole 和 AddPermission 构建矩阵的两个轴,用 SetGrant 设置初始勾选状态,然后读取 HTML。
uses
sgcHTML_Enums, sgcHTML_Component_RolesPermissions;
var
oMatrix: TsgcHTMLComponent_RolesPermissions;
begin
oMatrix := TsgcHTMLComponent_RolesPermissions.Create(nil);
try
oMatrix.MatrixID := 'acl';
oMatrix.StickyHeader := True;
oMatrix.AddRole('admin', 'Administrator').Color := hcDanger;
oMatrix.AddRole('editor', 'Editor');
oMatrix.AddRole('viewer', 'Viewer');
oMatrix.AddPermission('users.edit', 'Edit users', 'Users');
oMatrix.AddPermission('users.delete', 'Delete users', 'Users');
oMatrix.AddPermission('billing.view', 'View invoices', 'Billing');
oMatrix.SetGrant('admin', 'users.edit', True);
oMatrix.SetGrant('admin', 'users.delete', True);
oMatrix.SetGrant('editor', 'users.edit', True);
WebModule.Response := oMatrix.HTML; // matrix table + inline script
finally
oMatrix.Free;
end;
end;
// Server-side handler for a checkbox toggle received over WebSockets.
// ALWAYS verify the acting user is authorized before applying the change:
oMatrix.ProcessGrantChanged('editor', 'users.delete', True);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_RolesPermissions.hpp
TsgcHTMLComponent_RolesPermissions *oMatrix = new TsgcHTMLComponent_RolesPermissions(NULL);
try
{
oMatrix->MatrixID = "acl";
oMatrix->StickyHeader = true;
oMatrix->AddRole("admin", "Administrator")->Color = hcDanger;
oMatrix->AddRole("editor", "Editor");
oMatrix->AddRole("viewer", "Viewer");
oMatrix->AddPermission("users.edit", "Edit users", "Users");
oMatrix->AddPermission("users.delete", "Delete users", "Users");
oMatrix->AddPermission("billing.view", "View invoices", "Billing");
oMatrix->SetGrant("admin", "users.edit", true);
oMatrix->SetGrant("admin", "users.delete", true);
oMatrix->SetGrant("editor", "users.edit", true);
String html = oMatrix->HTML; // matrix table + inline script
// Server-side handler for a checkbox toggle (verify authorization first):
oMatrix->ProcessGrantChanged("editor", "users.delete", true);
}
__finally
{
delete oMatrix;
}
using esegece.sgcWebSockets;
var matrix = new TsgcHTMLComponent_RolesPermissions();
matrix.MatrixID = "acl";
matrix.StickyHeader = true;
matrix.AddRole("admin", "Administrator").Color = TsgcHTMLColor.hcDanger;
matrix.AddRole("editor", "Editor");
matrix.AddRole("viewer", "Viewer");
matrix.AddPermission("users.edit", "Edit users", "Users");
matrix.AddPermission("users.delete", "Delete users", "Users");
matrix.AddPermission("billing.view", "View invoices", "Billing");
matrix.SetGrant("admin", "users.edit", true);
matrix.SetGrant("admin", "users.delete", true);
matrix.SetGrant("editor", "users.edit", true);
string html = matrix.HTML; // matrix table + inline script
// Server-side handler for a checkbox toggle (verify authorization first):
matrix.ProcessGrantChanged("editor", "users.delete", true);
您最常使用的成员。
AddRole(aId, aName) 和 AddPermission(aId, aName, aCategory) 构建矩阵的两个轴;每个角色都有一个彩色徽章,每个权限都有一个可选的分类标题。
SetGrant(aRoleId, aPermissionId, aGranted) / GetGrant 以角色 + 权限 id 为键,读写勾选的单元格。
LoadRolesFromDataSet、LoadPermissionsFromDataSet 和 LoadGrantsFromDataSet 直接从 TDataSet 填充矩阵。
每次复选框切换都会通过 WebSocket 通道发送 JSON 负载,并触发 DOM 事件 sgcRolesPermissions:grantChanged。
ShowDescriptions、ShowCategories、Striped、Bordered、Compact 和 StickyHeader(配合 MaxHeight)设置表格样式;ReadOnly 禁用所有复选框。
此组件仅渲染 UI。只有在宿主程序在服务器端验证操作用户有权更改该角色/权限组合之后,才能调用 ProcessGrantChanged。