mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +08:00 
			
		
		
		
	新增:新增系统管理/用户管理重置密码、分配角色功能
This commit is contained in:
		| @@ -0,0 +1,46 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||||
|  |  * | ||||||
|  |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  |  * you may not use this file except in compliance with the License. | ||||||
|  |  * You may obtain a copy of the License at | ||||||
|  |  * | ||||||
|  |  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  |  * | ||||||
|  |  * Unless required by applicable law or agreed to in writing, software | ||||||
|  |  * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  |  * See the License for the specific language governing permissions and | ||||||
|  |  * limitations under the License. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | package top.charles7c.cnadmin.system.model.request; | ||||||
|  |  | ||||||
|  | import java.io.Serializable; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | import javax.validation.constraints.NotEmpty; | ||||||
|  |  | ||||||
|  | import lombok.Data; | ||||||
|  |  | ||||||
|  | import io.swagger.v3.oas.annotations.media.Schema; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * 修改用户角色信息 | ||||||
|  |  * | ||||||
|  |  * @author Charles7c | ||||||
|  |  * @since 2023/2/24 23:05 | ||||||
|  |  */ | ||||||
|  | @Data | ||||||
|  | @Schema(description = "修改用户角色信息") | ||||||
|  | public class UpdateUserRoleRequest implements Serializable { | ||||||
|  |  | ||||||
|  |     private static final long serialVersionUID = 1L; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 角色 ID 列表 | ||||||
|  |      */ | ||||||
|  |     @Schema(description = "所属角色") | ||||||
|  |     @NotEmpty(message = "所属角色不能为空") | ||||||
|  |     private List<Long> roleIds; | ||||||
|  | } | ||||||
| @@ -18,10 +18,7 @@ package top.charles7c.cnadmin.system.model.request; | |||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import javax.validation.constraints.NotBlank; | import javax.validation.constraints.*; | ||||||
| import javax.validation.constraints.NotNull; |  | ||||||
| import javax.validation.constraints.Null; |  | ||||||
| import javax.validation.constraints.Pattern; |  | ||||||
|  |  | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
|  |  | ||||||
| @@ -106,12 +103,14 @@ public class UserRequest extends BaseRequest { | |||||||
|     /** |     /** | ||||||
|      * 部门 ID |      * 部门 ID | ||||||
|      */ |      */ | ||||||
|     @Schema(description = "部门 ID") |     @Schema(description = "所属部门") | ||||||
|  |     @NotNull(message = "所属部门不能为空") | ||||||
|     private Long deptId; |     private Long deptId; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 角色 ID 列表 |      * 角色 ID 列表 | ||||||
|      */ |      */ | ||||||
|     @Schema(description = "角色 ID 列表") |     @Schema(description = "所属角色") | ||||||
|  |     @NotEmpty(message = "所属角色不能为空") | ||||||
|     private List<Long> roleIds; |     private List<Long> roleIds; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile; | |||||||
| import top.charles7c.cnadmin.common.base.BaseService; | import top.charles7c.cnadmin.common.base.BaseService; | ||||||
| import top.charles7c.cnadmin.system.model.entity.UserDO; | import top.charles7c.cnadmin.system.model.entity.UserDO; | ||||||
| import top.charles7c.cnadmin.system.model.query.UserQuery; | import top.charles7c.cnadmin.system.model.query.UserQuery; | ||||||
|  | import top.charles7c.cnadmin.system.model.request.UpdateUserRoleRequest; | ||||||
| import top.charles7c.cnadmin.system.model.request.UserRequest; | import top.charles7c.cnadmin.system.model.request.UserRequest; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserVO; | import top.charles7c.cnadmin.system.model.vo.UserVO; | ||||||
| @@ -79,6 +80,24 @@ public interface UserService extends BaseService<UserVO, UserDetailVO, UserQuery | |||||||
|      */ |      */ | ||||||
|     void updateEmail(String newEmail, String currentPassword, Long userId); |     void updateEmail(String newEmail, String currentPassword, Long userId); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 重置密码 | ||||||
|  |      * | ||||||
|  |      * @param userId | ||||||
|  |      *            用户 ID | ||||||
|  |      */ | ||||||
|  |     void resetPassword(Long userId); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 修改角色 | ||||||
|  |      * | ||||||
|  |      * @param request | ||||||
|  |      *            修改信息 | ||||||
|  |      * @param userId | ||||||
|  |      *            用户 ID | ||||||
|  |      */ | ||||||
|  |     void updateUserRole(UpdateUserRoleRequest request, Long userId); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 根据部门 ID 列表查询 |      * 根据部门 ID 列表查询 | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -47,6 +47,7 @@ import top.charles7c.cnadmin.common.util.validate.CheckUtils; | |||||||
| import top.charles7c.cnadmin.system.mapper.UserMapper; | import top.charles7c.cnadmin.system.mapper.UserMapper; | ||||||
| import top.charles7c.cnadmin.system.model.entity.UserDO; | import top.charles7c.cnadmin.system.model.entity.UserDO; | ||||||
| import top.charles7c.cnadmin.system.model.query.UserQuery; | import top.charles7c.cnadmin.system.model.query.UserQuery; | ||||||
|  | import top.charles7c.cnadmin.system.model.request.UpdateUserRoleRequest; | ||||||
| import top.charles7c.cnadmin.system.model.request.UserRequest; | import top.charles7c.cnadmin.system.model.request.UserRequest; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserVO; | import top.charles7c.cnadmin.system.model.vo.UserVO; | ||||||
| @@ -173,7 +174,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO, | |||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void updatePassword(String oldPassword, String newPassword, Long userId) { |     public void updatePassword(String oldPassword, String newPassword, Long userId) { | ||||||
|         CheckUtils.throwIfEqual(newPassword, oldPassword, "新密码不能与当前密码相同"); |         CheckUtils.throwIfEqual(newPassword, oldPassword, "新密码不能与当前密码相同"); | ||||||
|         UserDO userDO = this.getById(userId); |         UserDO userDO = super.getById(userId); | ||||||
|         CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(oldPassword, userId.toString()), userDO.getPassword(), "当前密码错误"); |         CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(oldPassword, userId.toString()), userDO.getPassword(), "当前密码错误"); | ||||||
|  |  | ||||||
|         // 更新密码和密码重置时间 |         // 更新密码和密码重置时间 | ||||||
| @@ -190,7 +191,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO, | |||||||
|     @Override |     @Override | ||||||
|     @Transactional(rollbackFor = Exception.class) |     @Transactional(rollbackFor = Exception.class) | ||||||
|     public void updateEmail(String newEmail, String currentPassword, Long userId) { |     public void updateEmail(String newEmail, String currentPassword, Long userId) { | ||||||
|         UserDO userDO = this.getById(userId); |         UserDO userDO = super.getById(userId); | ||||||
|         CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(currentPassword, userId.toString()), userDO.getPassword(), |         CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(currentPassword, userId.toString()), userDO.getPassword(), | ||||||
|             "当前密码错误"); |             "当前密码错误"); | ||||||
|         Long count = super.lambdaQuery().eq(UserDO::getEmail, newEmail).count(); |         Long count = super.lambdaQuery().eq(UserDO::getEmail, newEmail).count(); | ||||||
| @@ -206,6 +207,21 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO, | |||||||
|         LoginHelper.updateLoginUser(loginUser); |         LoginHelper.updateLoginUser(loginUser); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void resetPassword(Long userId) { | ||||||
|  |         UserDO userDO = super.getById(userId); | ||||||
|  |         userDO.setPassword(SecureUtils.md5Salt(Constants.DEFAULT_PASSWORD, userId.toString())); | ||||||
|  |         userDO.setPwdResetTime(LocalDateTime.now()); | ||||||
|  |         baseMapper.updateById(userDO); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void updateUserRole(UpdateUserRoleRequest request, Long userId) { | ||||||
|  |         super.getById(userId); | ||||||
|  |         // 保存用户和角色关联 | ||||||
|  |         userRoleService.save(request.getRoleIds(), userId); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public Long countByDeptIds(List<Long> deptIds) { |     public Long countByDeptIds(List<Long> deptIds) { | ||||||
|         return super.lambdaQuery().in(UserDO::getDeptId, deptIds).count(); |         return super.lambdaQuery().in(UserDO::getDeptId, deptIds).count(); | ||||||
|   | |||||||
| @@ -61,3 +61,15 @@ export function updateUser(req: UserRecord) { | |||||||
| export function deleteUser(ids: number | Array<number>) { | export function deleteUser(ids: number | Array<number>) { | ||||||
|   return axios.delete(`${BASE_URL}/${ids}`); |   return axios.delete(`${BASE_URL}/${ids}`); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export function resetPassword(id: number) { | ||||||
|  |   return axios.patch(`${BASE_URL}/${id}/password`); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface UpdateUserRoleReq { | ||||||
|  |   roleIds?: Array<number>; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function updateUserRole(req: UpdateUserRoleReq, id: number) { | ||||||
|  |   return axios.patch(`${BASE_URL}/${id}/role`, req); | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								continew-admin-ui/src/assets/icons/svg/privacy.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								continew-admin-ui/src/assets/icons/svg/privacy.svg
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | <svg width="24" height="24" viewBox="0 0 48 48" fill="currentColor"><g clip-path="url(#svg_21cec257fe__clip0_0:2566)"><path fill-rule="evenodd" clip-rule="evenodd" d="M24.999.347l1.077.757c.083.059.162.123.234.194-.06-.06-.057-.064-.055-.067.001-.002-.003-.005-.035-.027l-.014-.01c.085.059.19.128.312.207.373.24.816.509 1.318.795a37.83 37.83 0 004.824 2.306c1.659.654 3.43 1.093 5.19 1.353.619.092 1.191.154 1.7.192.294.022.542.034.6.034l1.783.028a1.91 1.91 0 011.879 1.908l.001 1.837.002 4.38.001 2.61a24347.202 24347.202 0 01.002 8.072V25.63l-.001.046v.014c-.014 9.194-11.785 20.13-19.911 20.13C15.78 45.818 4 34.868 4 25.671V8.018a1.91 1.91 0 011.879-1.909l1.818-.028c.026 0 .275-.012.568-.034.509-.038 1.08-.1 1.7-.192 1.759-.26 3.53-.699 5.184-1.352a38.254 38.254 0 004.825-2.31c.844-.48 1.603-.968 1.755-1.084l1.068-.757a1.909 1.909 0 012.202-.005zm14.999 16.499l-.001-2.61-.002-4.339c-.531-.012-1.565-.096-2.703-.264-2.03-.3-4.078-.808-6.033-1.58-3.093-1.22-6.283-2.988-7.356-3.804-.344.244-1.157.759-2.04 1.261a42.053 42.053 0 01-5.31 2.544c-1.953.77-4 1.278-6.03 1.579-1.159.17-2.21.255-2.705.265v15.774C7.818 32.695 17.828 42 23.906 42c6.082 0 16.093-9.304 16.093-16.328v-.757-1.999l-.001-6.07zM32 18c0 3.728-2.55 6.86-6 7.748V28h3a1 1 0 011 1v2a1 1 0 01-1 1h-3v3a1 1 0 01-1 1h-2a1 1 0 01-1-1v-9.252A8 8 0 1132 18zm-8 4a4 4 0 110-8 4 4 0 010 8z" fill="currentColor"/></g><defs><clipPath id="svg_21cec257fe__clip0_0:2566"><path fill="currentColor" d="M0 0h48v48H0z"/></clipPath></defs></svg> | ||||||
| After Width: | Height: | Size: 1.5 KiB | 
							
								
								
									
										1
									
								
								continew-admin-ui/src/assets/icons/svg/reference.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								continew-admin-ui/src/assets/icons/svg/reference.svg
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | <svg width="24" height="24" viewBox="0 0 48 48" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M24.05 26a1 1 0 011 1v2a1 1 0 01-1 1H16c-3.73 0-6.86 2.55-7.75 6A8.226 8.226 0 008 38v2h16.05a1 1 0 011 1v2a1 1 0 01-1 1H6c-1.1 0-2-.895-2-2v-4c0-6.627 5.37-12 12-12h8.05zm12.728-.707l7.071 7.071a1 1 0 010 1.414l-1.414 1.414a1 1 0 01-1.414 0l-2.937-2.937v10.33a1 1 0 01-1 1h-2a1 1 0 01-1-1V32.229l-2.963 2.964a1 1 0 01-1.414 0l-1.414-1.414a1 1 0 010-1.414l7.071-7.071a1 1 0 011.414 0zM21 3c5.52 0 10 4.477 10 10s-4.48 10-10 10-10-4.477-10-10S15.48 3 21 3zm0 4c-3.31 0-6 2.686-6 6s2.69 6 6 6 6-2.686 6-6-2.69-6-6-6z" fill="currentColor"/></svg> | ||||||
| After Width: | Height: | Size: 660 B | 
| @@ -121,6 +121,10 @@ body { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .arco-form-item-layout-inline { | ||||||
|  |   margin-right: 15px; | ||||||
|  | } | ||||||
|  |  | ||||||
| fieldset { | fieldset { | ||||||
|   padding: 15px 15px 0 15px; |   padding: 15px 15px 0 15px; | ||||||
|   margin-bottom: 15px; |   margin-bottom: 15px; | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
|     <Breadcrumb :items="['menu.system', 'menu.system.user.list']" /> |     <Breadcrumb :items="['menu.system', 'menu.system.user.list']" /> | ||||||
|     <a-card class="general-card" :title="$t('menu.system.user.list')"> |     <a-card class="general-card" :title="$t('menu.system.user.list')"> | ||||||
|       <a-row> |       <a-row> | ||||||
|         <a-col :xs="9" :sm="6" :md="5" :lg="4" :xl="4" style="margin-right: 12px"> |         <a-col :xs="9" :sm="6" :md="5" :lg="4" :xl="4" style="margin-right: 10px"> | ||||||
|           <a-input-search |           <a-input-search | ||||||
|             v-model="deptName" |             v-model="deptName" | ||||||
|             placeholder="输入部门名称搜索" |             placeholder="输入部门名称搜索" | ||||||
| @@ -182,7 +182,7 @@ | |||||||
|                 title="操作" |                 title="操作" | ||||||
|                 align="center" |                 align="center" | ||||||
|                 fixed="right" |                 fixed="right" | ||||||
|                 :width="120" |                 :width="90" | ||||||
|               > |               > | ||||||
|                 <template #cell="{ record }"> |                 <template #cell="{ record }"> | ||||||
|                   <a-button |                   <a-button | ||||||
| @@ -192,7 +192,7 @@ | |||||||
|                     title="修改" |                     title="修改" | ||||||
|                     @click="toUpdate(record.userId)" |                     @click="toUpdate(record.userId)" | ||||||
|                   > |                   > | ||||||
|                     <template #icon><icon-edit /></template>修改 |                     <template #icon><icon-edit /></template> | ||||||
|                   </a-button> |                   </a-button> | ||||||
|                   <a-popconfirm |                   <a-popconfirm | ||||||
|                     content="确定要删除当前选中的数据吗?" |                     content="确定要删除当前选中的数据吗?" | ||||||
| @@ -206,9 +206,32 @@ | |||||||
|                       title="删除" |                       title="删除" | ||||||
|                       :disabled="record.disabled" |                       :disabled="record.disabled" | ||||||
|                     > |                     > | ||||||
|                       <template #icon><icon-delete /></template>删除 |                       <template #icon><icon-delete /></template> | ||||||
|                     </a-button> |                     </a-button> | ||||||
|                   </a-popconfirm> |                   </a-popconfirm> | ||||||
|  |                   <a-popconfirm | ||||||
|  |                     content="确定要重置当前用户的密码吗?" | ||||||
|  |                     type="warning" | ||||||
|  |                     @ok="handleResetPassword(record.userId)" | ||||||
|  |                   > | ||||||
|  |                     <a-button | ||||||
|  |                       v-permission="['admin']" | ||||||
|  |                       type="text" | ||||||
|  |                       size="small" | ||||||
|  |                       title="重置密码" | ||||||
|  |                     > | ||||||
|  |                       <template #icon><svg-icon icon-class="privacy" /></template> | ||||||
|  |                     </a-button> | ||||||
|  |                   </a-popconfirm> | ||||||
|  |                   <a-button | ||||||
|  |                     v-permission="['admin']" | ||||||
|  |                     type="text" | ||||||
|  |                     size="small" | ||||||
|  |                     title="分配角色" | ||||||
|  |                     @click="toUpdateRole(record.userId)" | ||||||
|  |                   > | ||||||
|  |                     <template #icon><svg-icon icon-class="reference" /></template> | ||||||
|  |                   </a-button> | ||||||
|                 </template> |                 </template> | ||||||
|               </a-table-column> |               </a-table-column> | ||||||
|             </template> |             </template> | ||||||
| @@ -308,6 +331,32 @@ | |||||||
|         </a-form> |         </a-form> | ||||||
|       </a-modal> |       </a-modal> | ||||||
|  |  | ||||||
|  |       <!-- 表单区域 --> | ||||||
|  |       <a-modal | ||||||
|  |         title="分配角色" | ||||||
|  |         :visible="userRoleVisible" | ||||||
|  |         :mask-closable="false" | ||||||
|  |         unmount-on-close | ||||||
|  |         render-to-body | ||||||
|  |         @ok="handleUpdateUserRole" | ||||||
|  |         @cancel="handleCancel" | ||||||
|  |       > | ||||||
|  |         <a-form ref="userRoleFormRef" :model="form" :rules="rules" size="large"> | ||||||
|  |           <a-form-item label="所属角色" field="roleIds"> | ||||||
|  |             <a-select | ||||||
|  |               v-model="form.roleIds" | ||||||
|  |               :options="roleOptions" | ||||||
|  |               placeholder="请选择所属角色" | ||||||
|  |               :loading="roleLoading" | ||||||
|  |               multiple | ||||||
|  |               allow-clear | ||||||
|  |               :allow-search="{ retainInputValue: true }" | ||||||
|  |               style="width: 416px" | ||||||
|  |             /> | ||||||
|  |           </a-form-item> | ||||||
|  |         </a-form> | ||||||
|  |       </a-modal> | ||||||
|  |  | ||||||
|       <!-- 详情区域 --> |       <!-- 详情区域 --> | ||||||
|       <a-drawer |       <a-drawer | ||||||
|         title="用户详情" |         title="用户详情" | ||||||
| @@ -420,6 +469,8 @@ | |||||||
|     addUser, |     addUser, | ||||||
|     updateUser, |     updateUser, | ||||||
|     deleteUser, |     deleteUser, | ||||||
|  |     resetPassword, | ||||||
|  |     updateUserRole, | ||||||
|   } from '@/api/system/user'; |   } from '@/api/system/user'; | ||||||
|   import { listRoleDict, listDeptTree } from '@/api/common'; |   import { listRoleDict, listDeptTree } from '@/api/common'; | ||||||
|   import getAvatar from '@/utils/avatar'; |   import getAvatar from '@/utils/avatar'; | ||||||
| @@ -452,6 +503,7 @@ | |||||||
|   const detailLoading = ref(false); |   const detailLoading = ref(false); | ||||||
|   const exportLoading = ref(false); |   const exportLoading = ref(false); | ||||||
|   const visible = ref(false); |   const visible = ref(false); | ||||||
|  |   const userRoleVisible = ref(false); | ||||||
|   const detailVisible = ref(false); |   const detailVisible = ref(false); | ||||||
|   const statusOptions = ref<SelectOptionData[]>([ |   const statusOptions = ref<SelectOptionData[]>([ | ||||||
|     { label: '启用', value: 1 }, |     { label: '启用', value: 1 }, | ||||||
| @@ -550,6 +602,20 @@ | |||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 打开分配角色对话框 | ||||||
|  |    * | ||||||
|  |    * @param id ID | ||||||
|  |    */ | ||||||
|  |   const toUpdateRole = (id: number) => { | ||||||
|  |     reset(); | ||||||
|  |     getRoleOptions(); | ||||||
|  |     getUser(id).then((res) => { | ||||||
|  |       form.value = res.data; | ||||||
|  |       userRoleVisible.value = true; | ||||||
|  |     }); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 查询角色列表 |    * 查询角色列表 | ||||||
|    */ |    */ | ||||||
| @@ -591,7 +657,7 @@ | |||||||
|       phone: undefined, |       phone: undefined, | ||||||
|       description: '', |       description: '', | ||||||
|       status: 1, |       status: 1, | ||||||
|       roleIds: [], |       roleIds: [] as Array<number>, | ||||||
|       deptId: undefined, |       deptId: undefined, | ||||||
|     }; |     }; | ||||||
|     proxy.$refs.formRef?.resetFields(); |     proxy.$refs.formRef?.resetFields(); | ||||||
| @@ -602,7 +668,9 @@ | |||||||
|    */ |    */ | ||||||
|   const handleCancel = () => { |   const handleCancel = () => { | ||||||
|     visible.value = false; |     visible.value = false; | ||||||
|     proxy.$refs.formRef.resetFields(); |     userRoleVisible.value = false; | ||||||
|  |     proxy.$refs.formRef?.resetFields(); | ||||||
|  |     proxy.$refs.userRoleFormRef?.resetFields(); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -628,6 +696,23 @@ | |||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 修改用户角色 | ||||||
|  |    */ | ||||||
|  |   const handleUpdateUserRole = () => { | ||||||
|  |     proxy.$refs.userRoleFormRef.validate((valid: any) => { | ||||||
|  |       if (!valid && form.value.userId !== undefined) { | ||||||
|  |         updateUserRole({ roleIds: form.value.roleIds }, form.value.userId).then( | ||||||
|  |           (res) => { | ||||||
|  |             handleCancel(); | ||||||
|  |             getList(); | ||||||
|  |             proxy.$message.success(res.msg); | ||||||
|  |           } | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 查看详情 |    * 查看详情 | ||||||
|    * |    * | ||||||
| @@ -684,6 +769,17 @@ | |||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * 重置密码 | ||||||
|  |    * | ||||||
|  |    * @param id ID | ||||||
|  |    */ | ||||||
|  |   const handleResetPassword = (id: number) => { | ||||||
|  |     resetPassword(id).then((res) => { | ||||||
|  |       proxy.$message.success(res.msg); | ||||||
|  |     }); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 已选择的数据行发生改变时触发 |    * 已选择的数据行发生改变时触发 | ||||||
|    * |    * | ||||||
|   | |||||||
| @@ -16,9 +16,12 @@ | |||||||
|  |  | ||||||
| package top.charles7c.cnadmin.webapi.controller.system; | package top.charles7c.cnadmin.webapi.controller.system; | ||||||
|  |  | ||||||
|  | import io.swagger.v3.oas.annotations.Operation; | ||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | import io.swagger.v3.oas.annotations.tags.Tag; | ||||||
|  |  | ||||||
| import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||||
|  | import org.springframework.web.bind.annotation.PatchMapping; | ||||||
|  | import org.springframework.web.bind.annotation.PathVariable; | ||||||
| import org.springframework.web.bind.annotation.RequestBody; | import org.springframework.web.bind.annotation.RequestBody; | ||||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||||
|  |  | ||||||
| @@ -28,6 +31,7 @@ import top.charles7c.cnadmin.common.base.BaseRequest; | |||||||
| import top.charles7c.cnadmin.common.consts.Constants; | import top.charles7c.cnadmin.common.consts.Constants; | ||||||
| import top.charles7c.cnadmin.common.model.vo.R; | import top.charles7c.cnadmin.common.model.vo.R; | ||||||
| import top.charles7c.cnadmin.system.model.query.UserQuery; | import top.charles7c.cnadmin.system.model.query.UserQuery; | ||||||
|  | import top.charles7c.cnadmin.system.model.request.UpdateUserRoleRequest; | ||||||
| import top.charles7c.cnadmin.system.model.request.UserRequest; | import top.charles7c.cnadmin.system.model.request.UserRequest; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | import top.charles7c.cnadmin.system.model.vo.UserDetailVO; | ||||||
| import top.charles7c.cnadmin.system.model.vo.UserVO; | import top.charles7c.cnadmin.system.model.vo.UserVO; | ||||||
| @@ -40,6 +44,7 @@ import top.charles7c.cnadmin.system.service.UserService; | |||||||
|  * @since 2023/2/20 21:00 |  * @since 2023/2/20 21:00 | ||||||
|  */ |  */ | ||||||
| @Tag(name = "用户管理 API") | @Tag(name = "用户管理 API") | ||||||
|  | @Validated | ||||||
| @RestController | @RestController | ||||||
| @CrudRequestMapping("/system/user") | @CrudRequestMapping("/system/user") | ||||||
| public class UserController extends BaseController<UserService, UserVO, UserDetailVO, UserQuery, UserRequest> { | public class UserController extends BaseController<UserService, UserVO, UserDetailVO, UserQuery, UserRequest> { | ||||||
| @@ -49,4 +54,18 @@ public class UserController extends BaseController<UserService, UserVO, UserDeta | |||||||
|         Long id = baseService.add(request); |         Long id = baseService.add(request); | ||||||
|         return R.ok(String.format("新增成功,请牢记默认密码:%s", Constants.DEFAULT_PASSWORD), id); |         return R.ok(String.format("新增成功,请牢记默认密码:%s", Constants.DEFAULT_PASSWORD), id); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Operation(summary = "重置密码", description = "重置用户登录密码为默认密码") | ||||||
|  |     @PatchMapping("/{userId}/password") | ||||||
|  |     public R resetPassword(@PathVariable Long userId) { | ||||||
|  |         baseService.resetPassword(userId); | ||||||
|  |         return R.ok(String.format("重置密码成功,请牢记默认密码:%s", Constants.DEFAULT_PASSWORD)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Operation(summary = "分配角色", description = "为用户新增或移除角色") | ||||||
|  |     @PatchMapping("/{userId}/role") | ||||||
|  |     public R updateUserRole(@PathVariable Long userId, @Validated @RequestBody UpdateUserRoleRequest request) { | ||||||
|  |         baseService.updateUserRole(request, userId); | ||||||
|  |         return R.ok("分配成功"); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user