Ver Fonte

添加修改密码功能
第一次登录提示修改密码

luocaiyang há 3 anos atrás
pai
commit
d27b135e39

+ 18 - 0
wispro.sp.api/Controllers/AccountController.cs

@@ -51,6 +51,24 @@ namespace wispro.sp.api.Controllers
             
         }
 
+        [HttpGet, HttpPost, Route("ChangePassword")]
+        public bool ChangePassword(changePasswordDto dto)
+        {
+            Staff staff = dbContext.Staffs.Where<Staff>(s => s.Id  == dto.UserId  && s.Password == utility.MD5Utility.GetMD5(dto.oldPassword)).FirstOrDefault();
+
+            if (staff != null)
+            {
+                staff.Password = utility.MD5Utility.GetMD5(dto.newPassword);
+                dbContext.SaveChanges();
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+
         [HttpGet,Route("GetUser")]
         public userToken GetUser()
         {

+ 14 - 0
wispro.sp.api/Controllers/CalMonthController.cs

@@ -34,5 +34,19 @@ namespace wispro.sp.api.Controllers
                 return calMonth;
             }
         }
+
+        public List<CalMonth> GetAll()
+        {
+            var lstAll= Context.CalMonths.ToList();
+
+            lstAll.Sort((x,y)=> {
+                DateTime str1 = DateTime.Parse( $"{x.Year}-{x.Month}-01");
+                DateTime str2 = DateTime.Parse($"{y.Year}-{y.Month}-01");
+
+                return str2.CompareTo(str1);
+            });
+
+            return lstAll;
+        }
     }
 }

+ 11 - 2
wispro.sp.api/Controllers/PerformanceItemController.cs

@@ -1002,14 +1002,23 @@ namespace wispro.sp.api.Controllers
         {
             string strExpress = "";
 
+            string strCalMonth = "";
+            if (queryFilter.CalMonthId.HasValue)
+            {
+                strCalMonth = $"s.CalMonthId == {queryFilter.CalMonthId}";
+            }
+            else
+            {
+                strCalMonth = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
+            }
 
             if (!string.IsNullOrEmpty(strExpress))
             {
-                strExpress = $"{strExpress} && s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
+                strExpress = $"{strExpress} && {strCalMonth}";
             }
             else
             {
-                strExpress = $"s.CalMonth.Status == {Convert.ToInt32(queryFilter.jxType)}";
+                strExpress = strCalMonth;
             }
 
             if (queryFilter.ConditionTree != null)

+ 6 - 4
wispro.sp.share/QueryFilter.cs

@@ -7,15 +7,17 @@ namespace wispro.sp.share
     {
         public int userId { get; set; }
 
-        public IList<FieldCondition> ConditionTree { get; set; }
+        public int? CalMonthId { get; set; }
+
+        public IList<FieldCondition> ConditionTree { get; set; } =new  List<FieldCondition>();
 
         public jxType jxType { get; set; }
 
-        public IList<OrderField> Sorts { get; set; }
+        public IList<OrderField> Sorts { get; set; } = new List<OrderField>();
 
-        public int PageSize { get; set; }
+        public int PageSize { get; set; } = 1;
 
-        public int PageIndex { get; set; }
+        public int PageIndex { get; set; } = 10;
     }
 
     

+ 10 - 0
wispro.sp.share/webViewObject/loginDto.cs

@@ -15,4 +15,14 @@ namespace wispro.sp.share.webViewObject
         [Required(ErrorMessage = "请填写密码")]
         public string Password { get; set; }
     }
+
+    public class changePasswordDto
+    {
+        public int UserId { get; set; }
+
+        public string oldPassword { get; set; }
+
+        public string newPassword { get; set; }
+
+    }
 }

+ 6 - 6
wispro.sp.web/Components/RightContent.razor

@@ -2,7 +2,7 @@
 @inherits AntDomComponentBase
 
 <Space Class="@ClassMapper.Class" Size="@("24")">
-    <SpaceItem>
+    @*<SpaceItem>
         <HeaderSearch Class="action search"
                       Placeholder="Site Search"
                       DefaultValue="umi ui"
@@ -16,8 +16,8 @@
                 </span>
             </Unbound>
         </AntDesign.Tooltip>
-    </SpaceItem>
-    <SpaceItem>
+    </SpaceItem>*@
+    <!--<SpaceItem>
         <NoticeIcon ClearText="清空"
                     ViewMoreText="更多..."
                     Count="_count"
@@ -32,14 +32,14 @@
                         Title="处理事项"
                         EmptyText="你没有需要处理的新事项"
                         ShowViewMore
-                        Data="_messages" />
+                        Data="_messages" />-->
             @*<NoticeList TabKey="event"
                         Title="Upcoming"
                         EmptyText="You have completed all to do"
                         ShowViewMore
                         Data="_events" />*@
-        </NoticeIcon>
-    </SpaceItem>
+        <!--</NoticeIcon>
+    </SpaceItem>-->
     <SpaceItem>
         <AvatarDropdown Name="@_currentUser.Name"
                         Avatar="@_currentUser.Avatar"

+ 8 - 8
wispro.sp.web/Components/RightContent.razor.cs

@@ -40,8 +40,8 @@ namespace wispro.sp.web.Components
 
         public AvatarMenuItem[] AvatarMenuItems { get; set; } = new AvatarMenuItem[]
         {
-            new() { Key = "center", IconType = "user", Option = "个人中心"},
-            new() { Key = "setting", IconType = "setting", Option = "个人设置"},
+            //new() { Key = "center", IconType = "user", Option = "个人中心"},
+            new() { Key = "setting", IconType = "lock", Option = "修改密码"},
             new() { IsDivider = true },
             new() { Key = "logout", IconType = "logout", Option = "退出登录"}
         };
@@ -59,11 +59,11 @@ namespace wispro.sp.web.Components
             await base.OnInitializedAsync();
             SetClassMap();
             _currentUser = await UserService.GetUser();
-            var notices = await ProjectService.GetNoticesAsync();
-            _notifications = notices.Where(x => x.Type == "notification").Cast<NoticeIconData>().ToArray();
-            _messages = notices.Where(x => x.Type == "message").Cast<NoticeIconData>().ToArray();
-            _events = notices.Where(x => x.Type == "event").Cast<NoticeIconData>().ToArray();
-            _count = notices.Length;
+            //var notices = await ProjectService.GetNoticesAsync();
+            //_notifications = notices.Where(x => x.Type == "notification").Cast<NoticeIconData>().ToArray();
+            //_messages = notices.Where(x => x.Type == "message").Cast<NoticeIconData>().ToArray();
+            //_events = notices.Where(x => x.Type == "event").Cast<NoticeIconData>().ToArray();
+            //_count = notices.Length;
         }
 
         protected void SetClassMap()
@@ -81,7 +81,7 @@ namespace wispro.sp.web.Components
                     NavigationManager.NavigateTo("/account/center");
                     break;
                 case "setting":
-                    NavigationManager.NavigateTo("/account/settings");
+                    NavigationManager.NavigateTo("/ChangePassword/false");
                     break;
                 case "logout":
                     authorProvider.LogoutAsync();

Diff do ficheiro suprimidas por serem muito extensas
+ 24 - 4
wispro.sp.web/Layouts/BasicLayout.razor


Diff do ficheiro suprimidas por serem muito extensas
+ 166 - 0
wispro.sp.web/Pages/AppCase/CaseManager.razor


+ 111 - 0
wispro.sp.web/Pages/AppCase/CaseManager.razor.cs

@@ -0,0 +1,111 @@
+using AntDesign;
+using AntDesign.TableModels;
+using Microsoft.AspNetCore.Components;
+using ServiceStack;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.entity;
+using wispro.sp.share;
+using wispro.sp.web.Services;
+
+namespace wispro.sp.web.Pages.AppCase
+{
+    public partial class CaseManager
+    {
+        [Inject]
+        protected  IconService iconService { get; set; }
+
+        public TableFilter<string>[] CaseCoeFilters = new TableFilter<string>[] {
+            new() { Text = "S", Value = "S" },
+            new() { Text = "A", Value = "A" },
+            new() { Text = "B", Value = "B" },
+            new() { Text = "C", Value = "C" },
+            new() { Text = "D", Value = "D" }
+        };
+
+        [Inject]
+        protected AppealTypeService apTypeService { get; set; }
+
+        private List<PerformanceItem> _Datas;
+        private List<StaffStatistics> MyStatistics;
+        IEnumerable<PerformanceItem> selectedItems = new List<PerformanceItem>();
+        private CalMonth HandlingCalMonth;
+        private List<CalMonth> calMonths;
+
+        int _pageIndex = 1;
+        int _pageSize = 10;
+        int _total;
+        bool _loading = false;
+        private Table<PerformanceItem> table;
+
+        [Inject] public PerformanceItemServices _ItemService { get; set; }
+        [Inject] public MessageService _message { get; set; }
+        [Inject] protected NavigationManager NavigationManager { get; set; }
+        [Inject] protected IUserService _userService { get; set; }
+
+        [Inject] protected CalMonthServices _CalMonthService { get; set; }
+
+        protected override async Task OnInitializedAsync()
+        {
+            await iconService.CreateFromIconfontCN("//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js");
+            calMonths  = await _CalMonthService.GetAll();
+
+            if (calMonths != null && calMonths.Count > 0)
+            {
+                await calMonthClick(calMonths[0]);
+            }
+
+        }
+
+        private async Task HandleTableChange(QueryModel<PerformanceItem> queryModel)
+        {
+            var _user = await _userService.GetUser();
+            
+            _loading = true;
+            
+            var data = await _ItemService.Query(HandlingCalMonth, queryModel);
+
+            _Datas = data.Results;
+            _total = data.TotalCount;
+            _loading = false;
+            StateHasChanged();
+        }
+
+        private async Task calMonthClick(CalMonth calMonth)
+        {
+            HandlingCalMonth = calMonth;
+
+            var data = await _ItemService.Query(HandlingCalMonth,_pageIndex ,_pageSize,null);
+
+            _Datas = data.Results;
+            _total = data.TotalCount;
+            _loading = false;
+            StateHasChanged();
+        }
+
+        private async Task GuidangCalMonth(CalMonth calMonth)
+        {
+            //还未实现,此处需要添加归档代码
+
+            await Task.Delay(1);
+            StateHasChanged();
+        }
+
+        private int serialNumber(int pageIndex, int pageSize, int id)
+        {
+            int iIndex = 0;
+            foreach (PerformanceItem sf in _Datas)
+            {
+                iIndex++;
+
+                if (sf.Id == id)
+                {
+                    break;
+                }
+            }
+            return (pageIndex - 1) * pageSize + iIndex;
+        }
+    }
+}

+ 2 - 2
wispro.sp.web/Pages/AppCase/MyCaselist.razor

@@ -34,10 +34,10 @@
                     <PageHeader>
                         <PageHeaderTitle>基础点数统计</PageHeaderTitle>
                         <PageHeaderExtra>
-                            <AuthorizeView Roles="@strAddProjectJX">
+                            @*<AuthorizeView Roles="@strAddProjectJX">*@
 
                                 <Button Type="@ButtonType.Primary" OnClick="()=>goAssignPoint()">添加项目绩效</Button>
-                            </AuthorizeView>
+                            @*</AuthorizeView>*@
                             @foreach (AppealType at in apTypeService.GetItems(1))
                             {
                                 <Button Type="@ButtonType.Primary" OnClick="()=>ShowModel(null,at)">@at.Name</Button>

+ 48 - 0
wispro.sp.web/Pages/ChangePassword.razor

@@ -0,0 +1,48 @@
+@page "/ChangePassword/{FirstLogin:bool}"
+
+    <Modal Title="修改密码" 
+       Visible="true"
+       OnOk="@OnSubmit"
+       OnCancel="@OnCancel"
+       OkText="@("修改")"
+       CancelText="@("取消")"
+       MaskClosable="false" DestroyOnClose>
+        <div class="login-NavLogin">
+            <div style="padding:30px">
+                @if (FirstLogin)
+                {
+                    <div><b>您是第一次登录,为保证您的安全,请修改初始密码!</b></div>
+                }
+                @if (!string.IsNullOrEmpty(ErrorMsg))
+                {
+                    <div>@ErrorMsg</div>
+                }
+                <Card  Style="width:400px">
+                    <Body>
+                        <Form Model="@dto">
+                            <FormItem>
+                                <Space Direction="DirectionVHType.Vertical" Style="width:100%">
+                                    <SpaceItem>
+                                        <AntDesign.Input Placeholder="旧密码" Size="@InputSize.Large" @bind-Value="context.oldPassword" type="password">
+                                            <Prefix><Icon Type="lock"></Icon></Prefix>
+                                        </AntDesign.Input>
+                                        <br />
+                                    </SpaceItem>
+                                    <SpaceItem>
+                                        <AntDesign.Input Placeholder="新密码" Size="@InputSize.Large" @bind-Value="context.newPassword" type="password">
+                                            <Prefix><Icon Type="lock"></Icon></Prefix>
+                                        </AntDesign.Input>
+                                    </SpaceItem>
+                                    <SpaceItem>
+                                        <AntDesign.Input Placeholder="新密码确认" Size="@InputSize.Large" @bind-Value="ChecknewPassword" type="password">
+                                            <Prefix><Icon Type="lock"></Icon></Prefix>
+                                        </AntDesign.Input>
+                                    </SpaceItem>
+                                </Space>
+                            </FormItem>
+                        </Form>
+                    </Body>
+                </Card>
+            </div>
+        </div>
+    </Modal>

+ 90 - 0
wispro.sp.web/Pages/ChangePassword.razor.cs

@@ -0,0 +1,90 @@
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using wispro.sp.share.webViewObject;
+using wispro.sp.web.Services;
+
+namespace wispro.sp.web.Pages
+{
+    public partial class ChangePassword
+    {
+        private changePasswordDto dto = new changePasswordDto();
+        private Models.CurrentUser user;
+        private string ChecknewPassword;
+
+        [Parameter]
+        public bool FirstLogin { get; set; }
+
+        [Inject]
+        protected IUserService userService { get; set; }
+
+        [Inject] public NavigationManager navigation { get; set; }
+        [Inject] public IJSRuntime JSRuntime { get; set; }
+
+        [Inject] public IAuthService authService { get; set; }
+
+        protected async override Task OnInitializedAsync()
+        {
+            user =await userService.GetUser();
+            dto = new changePasswordDto();
+            dto.UserId = user.Userid.Value;
+
+            //Console.WriteLine($"OnInitializedAsync:{System.Text.Json.JsonSerializer.Serialize(user)}");
+            await base.OnInitializedAsync();
+        }
+
+        private string ErrorMsg;
+        public async  void OnSubmit()
+        {
+            //Console.WriteLine($"OnSubmit:{System.Text.Json.JsonSerializer.Serialize(user)}");
+            //Console.WriteLine($"用户ID:{dto.UserId}");
+            //Console.WriteLine($"用户名:{user.Name}-{user.Userid}");
+            //Console.WriteLine($"旧密码:{dto.oldPassword}");
+            //Console.WriteLine($"新密码:{dto.newPassword}");
+            //Console.WriteLine($"Check新密码:{ChecknewPassword}");
+            
+            ErrorMsg = "";
+
+            if(dto.newPassword  == ChecknewPassword)
+            {
+                if (string.IsNullOrEmpty(dto.newPassword))
+                {
+                    ErrorMsg = "密码不能为空!";
+                    return;
+                }
+                
+                var result = await authService.ChangePassword(dto);
+
+                if (result)
+                {
+                    OnCancel();
+                }
+                else
+                {
+                    ErrorMsg = "修改发生了一些错误,请重试!";
+                }
+            }
+            else
+            {
+                ErrorMsg = "新密码两次输入不一致!";
+            }
+
+            StateHasChanged();
+        }
+
+        public async void OnCancel()
+        {
+            if (FirstLogin)
+            {
+                navigation.NavigateTo("/Home");
+            }
+            else
+            {
+                await JSRuntime.InvokeVoidAsync("history.back");
+            }
+        }
+    }
+}

+ 8 - 1
wispro.sp.web/Pages/LoginPages.razor.cs

@@ -37,7 +37,14 @@ namespace wispro.sp.web.Pages
             
             if (result)
             {
-                navigation.NavigateTo("/Home");
+                if (model.Password == "12345678")
+                {
+                    navigation.NavigateTo("/ChangePassword/true");
+                }
+                else
+                {
+                    navigation.NavigateTo("/Home");
+                }
             }
             else
             {

+ 0 - 1
wispro.sp.web/Pages/Welcome.razor

@@ -21,7 +21,6 @@
                     @(_CurrentUser.Name)好, 祝您一天愉快!
                 </div>
                 <div>
-                    
                     深圳威世博代理事务所 | 工作地:深圳
                 </div>
                 }

+ 6 - 0
wispro.sp.web/Services/AuthService.cs

@@ -48,6 +48,12 @@ namespace wispro.sp.web.Services
             return result;
         }
 
+        public async Task<bool> ChangePassword(changePasswordDto dto)
+        {
+            var httpResponse = await httpClient.Post<bool>($"account/ChangePassword", dto);
+            return httpResponse;
+        }
+
         public async Task LogoutAsync()
         {
             await localStorageService.RemoveItemAsync("authToken");

+ 13 - 0
wispro.sp.web/Services/CalMonthServices.cs

@@ -30,5 +30,18 @@ namespace wispro.sp.web.Services
                 return null;
             }
         }
+
+        public async Task<List<CalMonth>> GetAll()
+        {
+            try
+            {
+                var data = await _httpClient.Get<List<CalMonth>>($"CalMonth/GetAll");
+                return data;
+            }
+            catch
+            {
+                return null;
+            }
+        }
     }
 }

+ 2 - 0
wispro.sp.web/Services/IAuthService.cs

@@ -13,5 +13,7 @@ namespace wispro.sp.web.Services
         Task LogoutAsync();
 
         Task<List<string>> GetRoles(string ResourceId);
+
+        Task<bool> ChangePassword(changePasswordDto dto);
     }
 }

+ 121 - 0
wispro.sp.web/Services/PerformanceItemServices.cs

@@ -71,6 +71,127 @@ namespace wispro.sp.web.Services
             return fileData;
         }
 
+        public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth,int pageIndex,int pageSize,string sortFieldName)
+        {
+            QueryFilter query = new QueryFilter();
+            query.userId = 0;
+            query.jxType = jxType.all;
+            query.CalMonthId = calMonth.Id;
+            query.PageIndex = pageIndex;
+            query.PageSize = pageSize;
+
+            if (!string.IsNullOrEmpty(sortFieldName))
+            {
+                query.Sorts = new List<OrderField>()
+                {
+                    new OrderField(){FieldName = sortFieldName}
+                };
+            }
+
+            
+
+            var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
+            return data;
+
+        }
+
+        public async Task<ListApiResponse<PerformanceItem>> Query(CalMonth calMonth, QueryModel<PerformanceItem> queryModel)
+        {
+            QueryFilter query = new QueryFilter();
+            query.userId = 0;
+            query.jxType = jxType.all;
+            query.CalMonthId = calMonth.Id;
+
+            if (queryModel != null)
+            {
+
+                query.PageIndex = queryModel.PageIndex;
+                query.PageSize = queryModel.PageSize;
+
+                query.ConditionTree = new List<FieldCondition>();
+
+                foreach (var filter in queryModel.FilterModel)
+                {
+                    foreach (var f in filter.Filters)
+                    {
+                        FieldCondition condition = new FieldCondition() { FieldName = filter.FieldName };
+                        condition.Value = f.Value.ToString();
+                        condition.ValueType = typeof(PerformanceItem).GetProperty(filter.FieldName).PropertyType.ToString();
+                        switch (f.FilterCompareOperator)
+                        {
+                            case AntDesign.TableFilterCompareOperator.Contains:
+                                condition.Operator = OperatorEnum.Contains;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.EndsWith:
+                                condition.Operator = OperatorEnum.EndWith;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.Equals:
+                                condition.Operator = OperatorEnum.EndWith;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.GreaterThan:
+                                condition.Operator = OperatorEnum.Greater;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.GreaterThanOrEquals:
+                                condition.Operator = OperatorEnum.GreaterEqual;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.LessThan:
+                                condition.Operator = OperatorEnum.Less;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.LessThanOrEquals:
+                                condition.Operator = OperatorEnum.LessEqual;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.NotContains:
+                                condition.Operator = OperatorEnum.NotContains;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.NotEquals:
+                                condition.Operator = OperatorEnum.NotEqual;
+                                break;
+                            case AntDesign.TableFilterCompareOperator.StartsWith:
+                                condition.Operator = OperatorEnum.StartsWith;
+                                break;
+
+                        }
+
+                        switch (f.FilterCondition)
+                        {
+                            case AntDesign.TableFilterCondition.And:
+                                condition.LogicOperate = LogicEnum.And;
+                                break;
+                            case AntDesign.TableFilterCondition.Or:
+                                condition.LogicOperate = LogicEnum.Or;
+                                break;
+                            default:
+                                condition.LogicOperate = LogicEnum.And;
+                                break;
+                        }
+
+                        query.ConditionTree.Add(condition);
+
+                    }
+                }
+
+                query.Sorts = new List<OrderField>();
+                foreach (var sort in queryModel.SortModel)
+                {
+                    if (!string.IsNullOrEmpty(sort.Sort))
+                    {
+                        query.Sorts.Add(new OrderField() { FieldName = sort.FieldName, Sort = (sort.Sort == "descend" ? 1 : 0) });
+                    }
+                }
+            }
+            else
+            {
+                query.PageIndex = 1;
+                query.PageSize = 1;
+                query.ConditionTree = new List<FieldCondition>();
+                query.Sorts = new List<OrderField>();
+            }
+
+            var data = await _httpClient.Post<ListApiResponse<PerformanceItem>>($"PerformanceItem/QueryFilter", query);
+            //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(queryModel));
+            return data;
+
+        }
         public async Task<ListApiResponse<PerformanceItem>> Query(int userid, jxType type, QueryModel<PerformanceItem> queryModel)
         {
             QueryFilter query = new QueryFilter();

+ 2 - 0
wispro.sp.web/Services/UserService.cs

@@ -63,6 +63,8 @@ namespace wispro.sp.web.Services
 
             _user.Userid = tokenInLocalStorage.UserId;
 
+            //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(_user));
+
             return _user;
         }
 

+ 1 - 0
wispro.sp.web/wispro.sp.web.csproj

@@ -43,6 +43,7 @@
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
     <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
+    <PackageReference Include="ServiceStack" Version="5.13.2" />
     <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
     <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
   </ItemGroup>