Browse Source

个人信息管理界面去掉工号

LT069288 2 months ago
parent
commit
03a1c4bcc4

+ 3 - 47
UniformMaterialManagementSystem/ViewModels/PersonalInfoPageViewModel.cs

@@ -11,34 +11,8 @@ namespace UniformMaterialManagementSystem.ViewModels
 {
     public partial class PersonalInfoPageViewModel : ObservableValidator
     {
-        [ObservableProperty] 
-        private string _loginName = string.Empty;
-
-        [ObservableProperty] 
-        private string _userName = string.Empty;
-
-        [ObservableProperty] 
-        private string _supervisionUnitName = string.Empty;
-
-        [ObservableProperty] 
-        private string _roleDesc = string.Empty;
-
-        [ObservableProperty] 
-        private string _idNumber = string.Empty;
-
-        [ObservableProperty] 
-        private string _registerDate = string.Empty;
-
-        //所属企业、监管单位可见状态
-        [ObservableProperty]
-        private string _companyVisible = "Visible";//Visible Collapsed  
-
-        //单位可见状态
-        [ObservableProperty] 
-        private string _supervisionVisible = "Collapsed";//Visible Collapsed  
-
         [ObservableProperty]
-        private string? _companyName;
+        private UserModel? _currentUser;
 
         [ObservableProperty]
         [Required(ErrorMessage = "原密码不能为空")]
@@ -61,26 +35,8 @@ namespace UniformMaterialManagementSystem.ViewModels
         {
             _userService = service;
             if (App.CurrentUser == null) return;
-            UserModel userModel = new UserModel(App.CurrentUser);
-
-            //初始化界面数据
-            LoginName = userModel.LoginName;
-            UserName = userModel.UserName;
-            SupervisionUnitName = userModel.SupervisionUnitName;
-            RoleDesc = userModel.RoleDesc;
-            IdNumber = userModel.IdNumber;
-            RegisterDate = userModel.RegisterDate.ToString("yyyy-MM-dd");
-            CompanyName = userModel.CompanyName;
-            if (userModel.RoleName.Contains("CompanyName")) //企业端
-            {
-                CompanyVisible = "Visible";
-                SupervisionVisible = "Collapsed";
-            }
-            else if (userModel.RoleName.Contains("Supervision")) //区域站端
-            {
-                CompanyVisible = "Collapsed";
-                SupervisionVisible = "Visible";
-            }
+
+            CurrentUser = new UserModel(App.CurrentUser);
         }
 
         /// <summary>

+ 17 - 32
UniformMaterialManagementSystem/Views/PersonalInfoPage.xaml

@@ -65,7 +65,7 @@
                         <TextBlock
                             Grid.Row="1"
                             Grid.Column="1"
-                            Text="{Binding LoginName}" />
+                            Text="{Binding CurrentUser.LoginName}" />
                         <TextBlock
                             Grid.Row="2"
                             Grid.Column="0"
@@ -74,67 +74,52 @@
                         <TextBlock
                             Grid.Row="2"
                             Grid.Column="1"
-                            Text="{Binding UserName}" />
+                            Text="{Binding CurrentUser.UserName}" />
                         <TextBlock
+                            x:Name="CompanyText"
                             Grid.Row="3"
                             Grid.Column="0"
                             HorizontalAlignment="Right"
-                            Text="所属企业:"
-                            Visibility="{Binding CompanyVisible}" />
+                            Text="所属企业:" />
                         <TextBlock
+                            x:Name="CompanyNameText"
                             Grid.Row="3"
                             Grid.Column="1"
-                            Text="{Binding CompanyName}"
-                            Visibility="{Binding CompanyVisible}" />
+                            Text="{Binding CurrentUser.CompanyName}" />
                         <TextBlock
+                            x:Name="SupervisionUnitText"
                             Grid.Row="4"
                             Grid.Column="0"
                             HorizontalAlignment="Right"
-                            Text="监管单位:"
-                            Visibility="{Binding CompanyVisible}" />
+                            Text="监管单位:" />
                         <TextBlock
+                            x:Name="UnitText"
                             Grid.Row="4"
-                            Grid.Column="1"
-                            Text="{Binding SupervisionUnitName}"
-                            Visibility="{Binding CompanyVisible}" />
-                        <TextBlock
-                            Grid.Row="5"
                             Grid.Column="0"
                             HorizontalAlignment="Right"
-                            Text="单    位:"
-                            Visibility="{Binding SupervisionVisible}" />
+                            Text="单    位:" />
                         <TextBlock
-                            Grid.Row="5"
+                            Grid.Row="4"
                             Grid.Column="1"
-                            Text="{Binding SupervisionUnitName}"
-                            Visibility="{Binding SupervisionVisible}" />
+                            Text="{Binding CurrentUser.SupervisionUnitName}" />
                         <TextBlock
                             Grid.Row="6"
                             Grid.Column="0"
                             HorizontalAlignment="Right"
-                            Text="证 件 号:" />
+                            Text="用户角色:" />
                         <TextBlock
                             Grid.Row="6"
                             Grid.Column="1"
-                            Text="{Binding IdNumber}" />
-                        <TextBlock
-                            Grid.Row="7"
-                            Grid.Column="0"
-                            HorizontalAlignment="Right"
-                            Text="用户角色:" />
+                            Text="{Binding CurrentUser.RoleDesc}" />
                         <TextBlock
                             Grid.Row="7"
-                            Grid.Column="1"
-                            Text="{Binding RoleDesc}" />
-                        <TextBlock
-                            Grid.Row="8"
                             Grid.Column="0"
                             HorizontalAlignment="Right"
                             Text="注册日期:" />
                         <TextBlock
-                            Grid.Row="8"
+                            Grid.Row="7"
                             Grid.Column="1"
-                            Text="{Binding RegisterDate}" />
+                            Text="{Binding CurrentUser.RegisterDate, StringFormat=yyyy-MM-dd}" />
 
                     </Grid>
                 </AdornerDecorator>
@@ -192,7 +177,7 @@
                                     FontSize="15"
                                     FontWeight="Bold"
                                     Foreground="OrangeRed"
-                                    Text="{Binding LoginName}" />
+                                    Text="{Binding CurrentUser.LoginName}" />
                                 <TextBlock
                                     Grid.Column="2"
                                     FontSize="15"

+ 25 - 0
UniformMaterialManagementSystem/Views/PersonalInfoPage.xaml.cs

@@ -13,6 +13,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using UniformMaterialManagementSystem.Utils;
 using UniformMaterialManagementSystem.ViewModels;
 
 namespace UniformMaterialManagementSystem.Views
@@ -28,6 +29,30 @@ namespace UniformMaterialManagementSystem.Views
 
             this.DataContext = App.Current.Services.GetService<PersonalInfoPageViewModel>();
 
+            //根据用户角色设置显示隐藏内容
+            SetControlVisibility();
+        }
+
+        private void SetControlVisibility()
+        {
+            var roleType = CommonUtil.GetRoleType();
+            switch (roleType)
+            {
+                case RoleType.Admin:
+                case RoleType.Supervision:
+                    SupervisionUnitText.Visibility = Visibility.Collapsed;
+                    UnitText.Visibility = Visibility.Visible;
+                    CompanyText.Visibility = Visibility.Collapsed;
+                    CompanyNameText.Visibility = Visibility.Collapsed;
+                    break;
+                case RoleType.MaterialCompany:
+                case RoleType.ProductCompany:
+                    SupervisionUnitText.Visibility = Visibility.Visible;
+                    UnitText.Visibility = Visibility.Collapsed;
+                    CompanyText.Visibility = Visibility.Visible;
+                    CompanyNameText.Visibility = Visibility.Visible;
+                    break;
+            }
         }
     }
 }