From ec683bd2fe9d5da3f625ba8ebcf57963efd82e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 18 Nov 2022 15:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Model/MenuManage.cs | 4 +- .../Pages/Model/UserInfo.cs | 2 +- .../Pages/ViewModel/LoginViewModel.cs | 67 +++++++++++++++---- DosingSystem/App.xaml.cs | 36 +++++----- 4 files changed, 77 insertions(+), 32 deletions(-) diff --git a/BPASmartClient.CustomResource/Pages/Model/MenuManage.cs b/BPASmartClient.CustomResource/Pages/Model/MenuManage.cs index be1ff668..52e0ac49 100644 --- a/BPASmartClient.CustomResource/Pages/Model/MenuManage.cs +++ b/BPASmartClient.CustomResource/Pages/Model/MenuManage.cs @@ -75,7 +75,7 @@ namespace BPASmartClient.CustomResource.Pages.Model /// 主菜单的显示隐藏设置 /// public Visibility MainMenuVisibility { get { return _mMainMenuVisibility; } set { _mMainMenuVisibility = value; OnPropertyChanged(); } } - private Visibility _mMainMenuVisibility; + private Visibility _mMainMenuVisibility = Visibility.Visible; /// /// 子菜单集合 @@ -114,7 +114,7 @@ namespace BPASmartClient.CustomResource.Pages.Model /// 子菜单的显示隐藏设置 /// public Visibility SubMenuVisibility { get { return _mSubMenuVisibility; } set { _mSubMenuVisibility = value; OnPropertyChanged(); } } - private Visibility _mSubMenuVisibility = Visibility.Collapsed; + private Visibility _mSubMenuVisibility = Visibility.Visible; diff --git a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs index 019e2250..203d70e0 100644 --- a/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs +++ b/BPASmartClient.CustomResource/Pages/Model/UserInfo.cs @@ -22,7 +22,7 @@ namespace BPASmartClient.CustomResource.Pages.Model private Permission _perimission; public string UserName { get { return _userName; } set { _userName = value; OnPropertyChanged(); } } - private string _userName ; + private string _userName; public string Password { get { return _password; } set { _password = value; OnPropertyChanged(); } } private string _password; diff --git a/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs b/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs index 85faa469..11f61598 100644 --- a/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs +++ b/BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs @@ -85,25 +85,52 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel Global.userInfo.LastLogInTime = DateTime.Now.ToString(); res.LastLogInTime = DateTime.Now.ToString(); Config.GetInstance.SaveUser(); + //permission权限 - for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++) + if (res.userTreeViewModels != null) { - if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission)) - MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Visible; - else - MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; - - if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.permission)) == null) - MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; - - for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++) + VisibilityState(Visibility.Collapsed); + for (int i = 0; i < res.userTreeViewModels?.Count; i++) { - if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.permission)) - MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Visible; - else - MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed; + var menName = res.userTreeViewModels.ElementAt(i).Name;//获取子菜单的名称 + + var res1 = MenuManage.GetInstance.menuModels.FirstOrDefault(p => p.subMenumodels.FirstOrDefault(s => s.SubMenuName.Equals(menName)) != null);//通过子菜单获取主菜单的信息 + if (res1 != null) + { + res1.MainMenuVisibility = Visibility.Visible; + var res2 = res1.subMenumodels.FirstOrDefault(p => p.SubMenuName.Equals(menName)); + if (res2 != null) res2.SubMenuVisibility = Visibility.Visible; + } } } + else + { + VisibilityState(Visibility.Visible); + } + + + + + + //permission权限 + //for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++) + //{ + // if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission)) + // MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Visible; + // else + // MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; + + // if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.SubMenuPermission.Contains(res.permission)) == null) + // MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = Visibility.Collapsed; + + // for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++) + // { + // if (MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuPermission.Contains(res.permission)) + // MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Visible; + // else + // MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = Visibility.Collapsed; + // } + //} ////分配后的权限 //if (res.permission == Enums.Permission.管理员) @@ -149,6 +176,18 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel } } + private void VisibilityState(Visibility tempVisibility) + { + for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++) + { + MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuVisibility = tempVisibility; + for (int m = 0; m < MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.Count; m++) + { + MenuManage.GetInstance.menuModels.ElementAt(i).subMenumodels.ElementAt(m).SubMenuVisibility = tempVisibility; + } + } + } + public RelayCommand LoginCommand { get; set; } public RelayCommand ExitCommand { get; set; } diff --git a/DosingSystem/App.xaml.cs b/DosingSystem/App.xaml.cs index dbe281db..3a1ba87f 100644 --- a/DosingSystem/App.xaml.cs +++ b/DosingSystem/App.xaml.cs @@ -62,7 +62,7 @@ namespace BPASmartClient.DosingSystem RecipeManage.Add(new SubMenumodel() { SubMenuName = "配方管理", - SubMenuPermission = new Permission[] { Permission.管理员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.RecipeSettingsView" }); @@ -70,7 +70,7 @@ namespace BPASmartClient.DosingSystem RecipeManage.Add(new SubMenumodel() { SubMenuName = "配方下发", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.RecipeControlView" }); @@ -78,6 +78,7 @@ namespace BPASmartClient.DosingSystem MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, MainMenuName = "配方管理", Alias = "Recipe Management", subMenumodels = RecipeManage, @@ -89,7 +90,7 @@ namespace BPASmartClient.DosingSystem ParSet.Add(new SubMenumodel() { SubMenuName = "原料参数设置", - SubMenuPermission = new Permission[] { Permission.管理员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.DeviceMaterialParView" }); @@ -97,7 +98,7 @@ namespace BPASmartClient.DosingSystem ParSet.Add(new SubMenumodel() { SubMenuName = "设备参数设置", - SubMenuPermission = new Permission[] { Permission.管理员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.CommParSetView" }); @@ -113,6 +114,7 @@ namespace BPASmartClient.DosingSystem MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, MainMenuName = "参数设置", Alias = "Parameter Set", subMenumodels = ParSet, @@ -124,7 +126,7 @@ namespace BPASmartClient.DosingSystem ManualControl.Add(new SubMenumodel() { SubMenuName = "气缸手动控制", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.ManualControlView" }); @@ -132,7 +134,7 @@ namespace BPASmartClient.DosingSystem ManualControl.Add(new SubMenumodel() { SubMenuName = "输送带手动控制", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.ConveyerBeltManualView" }); @@ -147,6 +149,7 @@ namespace BPASmartClient.DosingSystem { MainMenuIcon = "", MainMenuName = "手动控制", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "Parameter Set", subMenumodels = ManualControl, }); @@ -157,7 +160,7 @@ namespace BPASmartClient.DosingSystem InfoLog.Add(new SubMenumodel() { SubMenuName = "操作日志", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.UserLogView" }); @@ -165,7 +168,7 @@ namespace BPASmartClient.DosingSystem InfoLog.Add(new SubMenumodel() { SubMenuName = "运行日志", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.RunLogView" }); @@ -173,7 +176,7 @@ namespace BPASmartClient.DosingSystem InfoLog.Add(new SubMenumodel() { SubMenuName = "报警记录", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.AlarmView" }); @@ -181,7 +184,7 @@ namespace BPASmartClient.DosingSystem InfoLog.Add(new SubMenumodel() { SubMenuName = "调试日志", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.DebugLogView" }); @@ -198,6 +201,7 @@ namespace BPASmartClient.DosingSystem { MainMenuIcon = "", MainMenuName = "消息日志", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "Message Log", subMenumodels = InfoLog, }); @@ -208,7 +212,7 @@ namespace BPASmartClient.DosingSystem DeviceMonitor.Add(new SubMenumodel() { SubMenuName = "原料设备列表", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.DeviceListView" }); @@ -216,7 +220,7 @@ namespace BPASmartClient.DosingSystem DeviceMonitor.Add(new SubMenumodel() { SubMenuName = "设备状态", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.DosingSystem", ToggleWindowPath = "View.HardwareStatusView" }); @@ -225,6 +229,7 @@ namespace BPASmartClient.DosingSystem { MainMenuIcon = "", MainMenuName = "设备监控", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "Device Monitor", subMenumodels = DeviceMonitor, }); @@ -235,7 +240,7 @@ namespace BPASmartClient.DosingSystem UserManager.Add(new SubMenumodel() { SubMenuName = "用户登录", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.SubPagLoginView" }); @@ -243,14 +248,14 @@ namespace BPASmartClient.DosingSystem UserManager.Add(new SubMenumodel() { SubMenuName = "密码修改", - SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.PasswordChangeView" }); UserManager.Add(new SubMenumodel() { SubMenuName = "用户管理", - SubMenuPermission = new Permission[] { Permission.管理员 }, + SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.UserManagerView" }); @@ -267,6 +272,7 @@ namespace BPASmartClient.DosingSystem { MainMenuIcon = "", MainMenuName = "用户管理", + MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "User Management", subMenumodels = UserManager, });