提交rbac
提交设置右键错位的bug
This commit is contained in:
@ -8,6 +8,7 @@ using DH.Devices.Camera;
|
||||
using DH.Devices.Motion;
|
||||
using DH.Devices.PLC;
|
||||
using DH.Devices.Vision;
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DHSoftware.Languages;
|
||||
using DHSoftware.Models;
|
||||
using DHSoftware.Utils;
|
||||
@ -169,7 +170,94 @@ namespace DHSoftware
|
||||
segmented1.Items.Remove(itemToHide);
|
||||
}
|
||||
}
|
||||
public List<SysPermission> ButtonPermissionList
|
||||
{
|
||||
set
|
||||
{
|
||||
lbName.Text = DH.RBAC.Common.GlobalConfig.CurrentUser.Account;
|
||||
List<SysPermission> list = value;
|
||||
SetPermission(list, this.Controls);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetPermission(List<SysPermission> list, Control.ControlCollection controls)
|
||||
{
|
||||
foreach (Control control in controls)
|
||||
{
|
||||
if (control.HasChildren)
|
||||
{
|
||||
SetPermission(list, control.Controls);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (control is AntdUI.Button button)
|
||||
{
|
||||
HandleButtonVisibility(button, list);
|
||||
continue;
|
||||
}
|
||||
if (control is AntdUI.Label label)
|
||||
{
|
||||
HandleLabelVisibility(label, list);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (control is AntdUI.Segmented segmented)
|
||||
{
|
||||
HandleSegmentedItems(segmented, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理 Segmented 控件的权限逻辑
|
||||
/// </summary>
|
||||
private void HandleSegmentedItems(Segmented segmented, List<SysPermission> permissions)
|
||||
{
|
||||
|
||||
SysPermission permission = permissions.FirstOrDefault(p => p.EnCode == itemToHide.ID);
|
||||
|
||||
bool itemExists = segmented.Items.Contains(itemToHide);
|
||||
|
||||
if (permission != null)
|
||||
{
|
||||
|
||||
if (!itemExists)
|
||||
{
|
||||
segmented.Items.Insert(4, itemToHide);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (itemExists)
|
||||
{
|
||||
segmented.Items.Remove(itemToHide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理 Button 可见性
|
||||
/// </summary>
|
||||
private void HandleButtonVisibility(AntdUI.Button button, List<SysPermission> permissions)
|
||||
{
|
||||
if (button.Tag is string tag && !string.IsNullOrEmpty(tag))
|
||||
{
|
||||
bool hasPermission = permissions.Any(p => p.EnCode == tag);
|
||||
button.Visible = hasPermission;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理 Label 可见性
|
||||
/// </summary>
|
||||
private void HandleLabelVisibility(AntdUI.Label label, List<SysPermission> permissions)
|
||||
{
|
||||
if (label.Tag is string tag && !string.IsNullOrEmpty(tag))
|
||||
{
|
||||
bool hasPermission = permissions.Any(p => p.EnCode == tag);
|
||||
label.Visible = hasPermission;
|
||||
}
|
||||
}
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -425,6 +513,13 @@ namespace DHSoftware
|
||||
LoggerHelper.LogPrefix = "Process";
|
||||
OnLog -= LogDisplay;
|
||||
OnLog += LogDisplay;
|
||||
|
||||
lbInBackend.Click += LbInBackend_Click;
|
||||
}
|
||||
|
||||
private void LbInBackend_Click(object? sender, EventArgs e)
|
||||
{
|
||||
DH.RBAC.RBACWindow.Instance.Show();
|
||||
}
|
||||
|
||||
private void BtnDeleteProject_Click(object? sender, EventArgs e)
|
||||
@ -1068,7 +1163,7 @@ namespace DHSoftware
|
||||
private void HandleLoginButton()
|
||||
{
|
||||
// Add the code for the "登录" button click here
|
||||
LoginWindow.Instance.Owner = this;
|
||||
LoginWindow.Instance.parentForm = this;
|
||||
LoginWindow.Instance.Show();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user