角色管理页面1)修复bug,先中角色中全部菜单菜单中会包含已选过的菜单的子菜单的第一个页面

2)添加不可重复添加同角色名的角色校验
This commit is contained in:
maqiao 2023-11-13 17:05:38 +08:00
parent 70b86c26a8
commit 66cfc869bd
2 changed files with 86 additions and 17 deletions

View File

@ -16,6 +16,8 @@ using DM_Weight.Models;
using DM_Weight.util; using DM_Weight.util;
using System.Data; using System.Data;
using System.Configuration; using System.Configuration;
using MaterialDesignThemes.Wpf;
using System.Windows.Media;
namespace DM_Weight.ViewModels namespace DM_Weight.ViewModels
{ {
@ -59,6 +61,39 @@ namespace DM_Weight.ViewModels
private void CompareList(RoleDm Role) private void CompareList(RoleDm Role)
{ {
//AllPremissions = Clone<PremissionDm>(defaultAll);
//RightPremissions.Clear();
//if (Role != null && Role.Permissions != null)
//{
// List<PremissionDm> Permissions = Role.Permissions;
// Permissions.ForEach(it =>
// {
// // 父菜单
// PremissionDm p = AllPremissions.ToList().Find(it2 => it2.Id == it.Id);
// int index = AllPremissions.ToList().FindIndex(it2 => it2.Id == it.Id);
// if (p.Id != 6)
// {
// it.Children.ToList().ForEach(it3 =>
// {
// int i =p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id);
// if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i)
// {
// AllPremissions.ElementAt(index).Children.RemoveAt(i);
// }
// });
// if (p.Children.Count == 0)
// {
// AllPremissions.RemoveAt(index);
// }
// } else
// {
// AllPremissions.RemoveAt(index);
// }
// });
// RightPremissions = new ObservableCollection<PremissionDm>(Permissions);
//}
AllPremissions = Clone<PremissionDm>(defaultAll); AllPremissions = Clone<PremissionDm>(defaultAll);
RightPremissions.Clear(); RightPremissions.Clear();
if (Role != null && Role.Permissions != null) if (Role != null && Role.Permissions != null)
@ -69,25 +104,35 @@ namespace DM_Weight.ViewModels
// 父菜单 // 父菜单
PremissionDm p = AllPremissions.ToList().Find(it2 => it2.Id == it.Id); PremissionDm p = AllPremissions.ToList().Find(it2 => it2.Id == it.Id);
int index = AllPremissions.ToList().FindIndex(it2 => it2.Id == it.Id); int index = AllPremissions.ToList().FindIndex(it2 => it2.Id == it.Id);
if (p.Id != 6)
{ if (p != null && p.Children != null && it != null && it.Children != null && p.Children.Count == it.Children.Count)
it.Children.ToList().ForEach(it3 =>
{
int i =p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id);
if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i)
{
AllPremissions.ElementAt(index).Children.RemoveAt(i);
}
});
if (p.Children.Count == 0)
{
AllPremissions.RemoveAt(index);
}
} else
{ {
AllPremissions.RemoveAt(index); AllPremissions.RemoveAt(index);
} }
else
{
if (p.Id != 6)
{
it.Children.ToList().ForEach(it3 =>
{
int i = p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id);
//if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i)
if (p.Children.Count>0&&i >= 0 && p.Children[i] != null)
{
AllPremissions.ElementAt(index).Children.RemoveAt(i);
}
});
if (p.Children.Count == 0)
{
AllPremissions.RemoveAt(index);
}
}
else
{
AllPremissions.RemoveAt(index);
}
}
}); });
RightPremissions = new ObservableCollection<PremissionDm>(Permissions); RightPremissions = new ObservableCollection<PremissionDm>(Permissions);
} }
@ -149,6 +194,7 @@ namespace DM_Weight.ViewModels
PremissionName = "取药记录", PremissionName = "取药记录",
PremissionPath = "TakeRecordWindow", PremissionPath = "TakeRecordWindow",
}; };
quyaoChild.Add(quyao1); quyaoChild.Add(quyao1);
quyaoChild.Add(quyao2); quyaoChild.Add(quyao2);
quyaoChild.Add(quyao3); quyaoChild.Add(quyao3);
@ -594,6 +640,19 @@ namespace DM_Weight.ViewModels
RightPremissions.Clear(); RightPremissions.Clear();
}); });
} }
private ISnackbarMessageQueue _snackbarMessageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(3));
public ISnackbarMessageQueue SnackbarMessageQueue
{
get => _snackbarMessageQueue;
set => SetProperty(ref _snackbarMessageQueue, value);
}
private SolidColorBrush _colorBrush;
public SolidColorBrush SnackbarBackground
{
get => _colorBrush;
set => SetProperty(ref _colorBrush, value);
}
public DelegateCommand AddRole public DelegateCommand AddRole
{ {
@ -602,6 +661,13 @@ namespace DM_Weight.ViewModels
Role.Id = 0; Role.Id = 0;
Role.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1"; Role.MachineId = ConfigurationManager.AppSettings["machineId"] ?? "DM1";
Role.Permissions = RightPremissions.ToList(); Role.Permissions = RightPremissions.ToList();
List<RoleDm> roleList = SqlSugarHelper.Db.Queryable<RoleDm>().Where(r => r.RoleName == Role.RoleName).ToList();
if(roleList.Count>0)
{
SnackbarBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
SnackbarMessageQueue.Enqueue("该角色已存在!");
return;
}
SqlSugarHelper.Db.Insertable<RoleDm>(Role).ExecuteCommand(); SqlSugarHelper.Db.Insertable<RoleDm>(Role).ExecuteCommand();
RequestData(); RequestData();
}); });

View File

@ -185,8 +185,11 @@
</TreeView> </TreeView>
</ScrollViewer> </ScrollViewer>
</GroupBox> </GroupBox>
<materialDesign:Snackbar
Background="{Binding SnackbarBackground}"
MessageQueue="{Binding SnackbarMessageQueue}"/>
</Grid> </Grid>
</Grid> </Grid>
</GroupBox> </GroupBox>
</Grid> </Grid>