From e535133ecae23a2c284738861b3641cf7f4e34fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Wed, 14 Sep 2022 20:35:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=AD=E5=BF=83=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=9B=B4=E6=96=B0=E3=80=81=E9=87=8D=E7=BD=AEcc?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 13 ++++ .../Controllers/AccountController.cs | 14 ++++ .../Controllers/UserController.cs | 12 ++++ .../yi-sqlsugar-dev.db | Bin 151552 -> 151552 bytes .../Yi.Framework.Interface/IUserService.cs | 7 ++ .../Yi.Framework.Service/UserService.cs | 66 ++++++++++++------ Yi.Vue3.X.RuoYi/src/api/system/user.js | 4 +- .../src/directive/permission/hasPermi.js | 1 - Yi.Vue3.X.RuoYi/src/permission.js | 5 +- Yi.Vue3.X.RuoYi/src/store/modules/user.js | 5 +- .../src/views/system/user/index.vue | 8 +-- 11 files changed, 106 insertions(+), 29 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index c081745b..5c7257c5 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -9,6 +9,12 @@ 账户管理 + + + 重置管理员CC的密码 + + + 没啥说,登录 @@ -432,6 +438,13 @@ + + + 更新个人中心信息 + + + + 添加用户 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index fad47913..e9527636 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -36,6 +36,20 @@ namespace Yi.Framework.ApiMicroservice.Controllers _logger = logger; } + /// + /// 重置管理员CC的密码 + /// + /// + [HttpGet] + public async Task RestCC() + { + var user= await _iUserService._repository.GetFirstAsync(u => u.UserName == "cc"); + user.Password = "123456"; + user.BuildPassword(); + await _iUserService._repository.UpdateIgnoreNullAsync(user); + return Result.Success(); + } + /// /// 没啥说,登录 /// diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index d82df68e..f8406471 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -90,6 +90,18 @@ namespace Yi.Framework.ApiMicroservice.Controllers return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto)); } + + /// + /// 更新个人中心信息 + /// + /// + /// + [HttpPut] + public async Task UpdateProfile(UserInfoDto userDto) + { + return Result.Success().SetStatus(await _iUserService.UpdateProfile(userDto)); + } + /// /// 添加用户 /// diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index 73355b6df9dc1713cbe8f713e813f0b0c634575d..6b62182e49aa08886dc48df008666acc385cce7f 100644 GIT binary patch delta 705 zcmZozz}c{XbAmMEyNNQ+jPEuke324#ESL_uLT;=GTZxB{u zP!jIxQ50qF7?B=Sno$uMWnP>gnrNErQ|eu2s+*GQ;b-Jhp<9t2oRSk15mJ;G z>YwZH8WCQQ8<^->kYW%nkd^E17HW}Q<{X%wlpUa-K6#a#0i)66TXKGz+htN1g^d}U zq3+fs;BF%WD`OKY69YXnQxgL-OS9x;@67PBYzvp104GcHFoQzR?1F;$lnS4;B1iXt z?6Rt=@KST%B3(;!$0!45FH0lGto(SB_~Zyj%OG>Fw2(}vR3FPkOM@V{fUu~b2($FW zuq;atQ^&jv??6+5;(YDU%>3{|zZ8QgqhLSF$t&dyIgCw=42=zqOg7(=(-LGB=3YOU z-9VLzd;Mlbg+^{EOGPd=HZ}%p1|SeUc_*={Nq|vQ_~Bhgrpfp1MS0-vH#acd{L1<- z6EjfBdd~J74H_b^|6sJ{F++wojL_WAfy_lh_V)q{u(h z!==*~+B1o$m?$8uG&Zqj$OscT#4$r?atzzk9&sg>r_QZ^>y1G7E9Pn#^vXx>-?SANS^0 z)_<9pcYC!=eq|@eWoTh#XkcYvre`u)$o?Q3P}oU;aq>-jX<>wnfhiaN0R|y{uF32U zAT#dqP3H1{BmhyXz{AYOD0&jeY5wEC{f|E*#{*^#K8fw@226r{EY=)6Y|~}zm^?*x zdvzWXU=;ahdbqSnfI;*`Ql#Ob={9yuQc`R@Y;0@{)(l_(G6|@V0jzNPLVG5W>F#z+ j{M#?sF_|!KXF0$)n_mvBf{6oWG00qY1ZVnQe /// Task UpdatePassword(UpdatePasswordDto dto, long userId); + + /// + /// 个人中心信息更新 + /// + /// + /// + Task UpdateProfile(UserInfoDto userDto); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs index 1887c3e2..3c5eb373 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs @@ -84,19 +84,25 @@ namespace Yi.Framework.Service //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId)); - //遍历用户 - foreach (var userId in userIds) + if (roleIds is not null) { - //添加新的关系 - List userRoleEntities = new(); - foreach (var roleId in roleIds) + //遍历用户 + foreach (var userId in userIds) { - userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId }); - } + //添加新的关系 + List userRoleEntities = new(); - //一次性批量添加 - await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities); + foreach (var roleId in roleIds) + { + userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId }); + } + + //一次性批量添加 + await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities); + } } + + }); } @@ -110,19 +116,22 @@ namespace Yi.Framework.Service { //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) await _repositoryUserPost.DeleteAsync(u => userIds.Contains((long)u.UserId)); - - //遍历用户 - foreach (var userId in userIds) + if (postIds is not null) { - //添加新的关系 - List userPostEntities = new(); - foreach (var post in postIds) + //遍历用户 + foreach (var userId in userIds) { - userPostEntities.Add(new UserPostEntity() { UserId = userId, PostId = post }); + //添加新的关系 + List userPostEntities = new(); + foreach (var post in postIds) + { + userPostEntities.Add(new UserPostEntity() { UserId = userId, PostId = post }); + } + + //一次性批量添加 + await _repositoryUserPost.InsertReturnSnowflakeIdAsync(userPostEntities); } - //一次性批量添加 - await _repositoryUserPost.InsertReturnSnowflakeIdAsync(userPostEntities); } }); } @@ -131,7 +140,10 @@ namespace Yi.Framework.Service public async Task GetInfoById(long userId) { - return await _repository._DbQueryable.Includes(u => u.Roles).Includes(u => u.Posts).Includes(u => u.Dept).InSingleAsync(userId); + var data = await _repository._DbQueryable.Includes(u => u.Roles).Includes(u => u.Posts).Includes(u => u.Dept).InSingleAsync(userId); + data.Password = null; + data.Salt = null; + return data; } public async Task GetUserAllInfo(long userId) @@ -142,7 +154,8 @@ namespace Yi.Framework.Service //得到用户 var user = await _repository._DbQueryable.Includes(u => u.Roles.Where(r => r.IsDeleted == false).ToList(), r => r.Menus.Where(m => m.IsDeleted == false).ToList()).InSingleAsync(userId); - + user.Password = null; + user.Salt = null; //得到角色集合 var roleList = user.Roles; @@ -207,6 +220,9 @@ namespace Yi.Framework.Service data = await query.OrderBy(u => u.OrderNum, OrderByType.Desc) .ToPageListAsync(page.PageNum, page.PageSize, total); + + + data.ForEach(u => { u.Password = null; u.Salt = null; }); return new PageModel>(data, total); } @@ -268,5 +284,15 @@ namespace Yi.Framework.Service newUser.BuildPassword(); return await _repository.UpdateIgnoreNullAsync(newUser); } + + + public async Task UpdateProfile(UserInfoDto userDto) + { + userDto.User.Salt = null; + userDto.User.Password = null; + userDto.User.DeptId = null; + return await _repository.UpdateIgnoreNullAsync(userDto.User); + } + } } diff --git a/Yi.Vue3.X.RuoYi/src/api/system/user.js b/Yi.Vue3.X.RuoYi/src/api/system/user.js index 308a6256..aa88ec0f 100644 --- a/Yi.Vue3.X.RuoYi/src/api/system/user.js +++ b/Yi.Vue3.X.RuoYi/src/api/system/user.js @@ -83,9 +83,9 @@ export function getUserProfile() { // 修改用户个人信息 export function updateUserProfile(data) { return request({ - url: '/system/user/profile', + url: '/user/UpdateProfile', method: 'put', - data: data + data: {user:data} }) } diff --git a/Yi.Vue3.X.RuoYi/src/directive/permission/hasPermi.js b/Yi.Vue3.X.RuoYi/src/directive/permission/hasPermi.js index 44ef3f82..95fb3f4f 100644 --- a/Yi.Vue3.X.RuoYi/src/directive/permission/hasPermi.js +++ b/Yi.Vue3.X.RuoYi/src/directive/permission/hasPermi.js @@ -10,7 +10,6 @@ export default { const { value } = binding const all_permission = "*:*:*"; const permissions = useUserStore().permissions - if (value && value instanceof Array && value.length > 0) { const permissionFlag = value diff --git a/Yi.Vue3.X.RuoYi/src/permission.js b/Yi.Vue3.X.RuoYi/src/permission.js index a7447aa4..5492dda1 100644 --- a/Yi.Vue3.X.RuoYi/src/permission.js +++ b/Yi.Vue3.X.RuoYi/src/permission.js @@ -15,6 +15,7 @@ const whiteList = ['/login', '/auth-redirect', '/bind', '/register']; router.beforeEach((to, from, next) => { NProgress.start() + if (getToken()) { to.meta.title && useSettingsStore().setTitle(to.meta.title) /* has token*/ @@ -22,7 +23,9 @@ router.beforeEach((to, from, next) => { next({ path: '/' }) NProgress.done() } else { - if (useUserStore().roles.length === 0) { + + if (useUserStore().roles.length === 0) + { isRelogin.show = true // 判断当前用户是否已拉取完user_info信息 useUserStore().getInfo().then(() => { diff --git a/Yi.Vue3.X.RuoYi/src/store/modules/user.js b/Yi.Vue3.X.RuoYi/src/store/modules/user.js index f709f2d4..e856e983 100644 --- a/Yi.Vue3.X.RuoYi/src/store/modules/user.js +++ b/Yi.Vue3.X.RuoYi/src/store/modules/user.js @@ -37,15 +37,18 @@ const useUserStore = defineStore( const res=response.data; const user = res.user const avatar = (user.avatar == "" || user.avatar == null) ? defAva : import.meta.env.VITE_APP_BASE_API + user.avatar; - + if (res.roleCodes && res.roleCodes.length > 0) { // 验证返回的roles是否是一个非空数组 // this.roles = res.roleCodes // this.permissions = res.permissionCodes this.roles = ["admin"]; this.permissions=["*:*:*"] + } else { this.roles = ['ROLE_DEFAULT'] } + this.roles = ["admin"]; + this.permissions=["*:*:*"] this.name = user.userName this.avatar = avatar; resolve(res) diff --git a/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue b/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue index 2e5354d9..89ad5b23 100644 --- a/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue @@ -88,19 +88,19 @@