角色管理页面1)修复bug,先中角色中全部菜单菜单中会包含已选过的菜单的子菜单的第一个页面
2)添加不可重复添加同角色名的角色校验
This commit is contained in:
		
							parent
							
								
									70b86c26a8
								
							
						
					
					
						commit
						66cfc869bd
					
				| 
						 | 
					@ -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,12 +104,21 @@ 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 != null && p.Children != null && it != null && it.Children != null && p.Children.Count == it.Children.Count)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        AllPremissions.RemoveAt(index);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if (p.Id != 6)
 | 
					                        if (p.Id != 6)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            it.Children.ToList().ForEach(it3 =>
 | 
					                            it.Children.ToList().ForEach(it3 =>
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                            int i =p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id);
 | 
					                                int i = p.Children.ToList().FindIndex(it4 => it4.Id == it3.Id);
 | 
				
			||||||
                            if (i > 0 && AllPremissions.ElementAt(index).Children.Count > i) 
 | 
					                                //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);
 | 
					                                    AllPremissions.ElementAt(index).Children.RemoveAt(i);
 | 
				
			||||||
                                }
 | 
					                                }
 | 
				
			||||||
| 
						 | 
					@ -83,11 +127,12 @@ namespace DM_Weight.ViewModels
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                AllPremissions.RemoveAt(index);
 | 
					                                AllPremissions.RemoveAt(index);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                    } else
 | 
					                        }
 | 
				
			||||||
 | 
					                        else
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            AllPremissions.RemoveAt(index);
 | 
					                            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();
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,6 +185,9 @@
 | 
				
			||||||
                            </TreeView>
 | 
					                            </TreeView>
 | 
				
			||||||
                        </ScrollViewer>
 | 
					                        </ScrollViewer>
 | 
				
			||||||
                    </GroupBox>
 | 
					                    </GroupBox>
 | 
				
			||||||
 | 
					                    <materialDesign:Snackbar
 | 
				
			||||||
 | 
					                Background="{Binding SnackbarBackground}"
 | 
				
			||||||
 | 
					                MessageQueue="{Binding SnackbarMessageQueue}"/>
 | 
				
			||||||
                </Grid>
 | 
					                </Grid>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            </Grid>
 | 
					            </Grid>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue