用户信息添加修改
This commit is contained in:
@@ -360,5 +360,17 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.UpdateInfo(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<summary>
|
||||
更新用户信息
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.UserController.AddInfo(Yi.Framework.DTOModel.UserInfoDto)">
|
||||
<summary>
|
||||
添加用户
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
var userEntiy = await _iUserService._repository.GetByIdAsync(userId);
|
||||
|
||||
//判断输入的老密码是否和原密码相同
|
||||
if (_iUserService.JudgePassword(userEntiy, updatePasswordDto.OldPassword))
|
||||
if (userEntiy.JudgePassword(updatePasswordDto.OldPassword))
|
||||
{
|
||||
userEntiy.Password = updatePasswordDto.NewPassword;
|
||||
userEntiy.BuildPassword();
|
||||
|
||||
@@ -94,5 +94,26 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetInfoById(id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateInfo(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddInfo(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.AddInfo(userDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs
Normal file
17
Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
{
|
||||
public class UserInfoDto
|
||||
{
|
||||
public UserEntity User { get; set; }
|
||||
public List<long> RoleIds { get; set; }
|
||||
public List<long> PostId { get; set; }
|
||||
public long? DeptId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -68,13 +68,7 @@ namespace Yi.Framework.Interface
|
||||
/// <returns></returns>
|
||||
Task<UserRoleMenuDto> GetUserAllInfo(long userId);
|
||||
|
||||
/// <summary>
|
||||
/// 判断用户密码是否和原密码相同
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
bool JudgePassword(UserEntity user, string password);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态条件分页查询
|
||||
@@ -90,5 +84,19 @@ namespace Yi.Framework.Interface
|
||||
/// <param name="menus"></param>
|
||||
/// <returns></returns>
|
||||
List<VueRouterModel> RouterBuild(List<MenuEntity> menus);
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> UpdateInfo(UserInfoDto userDto);
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddInfo(UserInfoDto userDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Common.Helper;
|
||||
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
public partial class UserEntity
|
||||
@@ -26,5 +28,19 @@ namespace Yi.Framework.Model.Models
|
||||
this.Salt = Common.Helper.MD5Helper.GenerateSalt();
|
||||
this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断密码和加密后的密码是否相同
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public bool JudgePassword(string password)
|
||||
{
|
||||
if (this.Password == MD5Helper.SHA2Encode(password, this.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,12 @@ namespace Yi.Framework.Service
|
||||
//多次操作,需要事务确保原子性
|
||||
return await _repositoryUserRole.UseTranAsync(async () =>
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId));
|
||||
|
||||
//遍历用户
|
||||
foreach (var userId in userIds)
|
||||
{
|
||||
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
|
||||
await _repositoryUserRole.DeleteAsync(u => u.UserId == userId);
|
||||
|
||||
//添加新的关系
|
||||
List<UserRoleEntity> userRoleEntities = new();
|
||||
foreach (var roleId in roleIds)
|
||||
@@ -154,14 +153,7 @@ namespace Yi.Framework.Service
|
||||
return userRoleMenu;
|
||||
}
|
||||
|
||||
public bool JudgePassword(UserEntity user, string password)
|
||||
{
|
||||
if (user.Password == MD5Helper.SHA2Encode(password, user.Salt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<PageModel<List<UserEntity>>> SelctPageList(UserEntity user, PageParModel page)
|
||||
@@ -222,5 +214,26 @@ namespace Yi.Framework.Service
|
||||
}
|
||||
return routers;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateInfo(UserInfoDto userDto)
|
||||
{
|
||||
//未填写密码,可不更新
|
||||
userDto.User.Salt = null;
|
||||
if (userDto.User.Password.IsNotNull())
|
||||
{
|
||||
userDto.User.BuildPassword();
|
||||
}
|
||||
var res1 = await _repository.UpdateIgnoreNullAsync(userDto.User);
|
||||
var res2 = await GiveUserSetRole(new List<long> { userDto.User.Id }, userDto.RoleIds);
|
||||
return res1 && res2;
|
||||
}
|
||||
|
||||
public async Task<bool> AddInfo(UserInfoDto userDto)
|
||||
{
|
||||
userDto.User.BuildPassword();
|
||||
var res1 = await _repository.InsertReturnSnowflakeIdAsync(userDto.User);
|
||||
var res2 = await GiveUserSetRole(new List<long> { res1 }, userDto.RoleIds);
|
||||
return !0.Equals(res1) && res2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export function getUser(userId) {
|
||||
// 新增用户
|
||||
export function addUser(data) {
|
||||
return request({
|
||||
url: '/system/user',
|
||||
url: '/user/addInfo',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
@@ -30,7 +30,7 @@ export function addUser(data) {
|
||||
// 修改用户
|
||||
export function updateUser(data) {
|
||||
return request({
|
||||
url: '/system/user',
|
||||
url: '/user/updateInfo',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
@@ -38,9 +38,14 @@ export function updateUser(data) {
|
||||
|
||||
// 删除用户
|
||||
export function delUser(userId) {
|
||||
if("string"==typeof(userId))
|
||||
{
|
||||
userId=[userId];
|
||||
}
|
||||
return request({
|
||||
url: '/system/user/' + userId,
|
||||
method: 'delete'
|
||||
url: '/user/delList',
|
||||
method: 'delete',
|
||||
data:userId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -88,19 +88,19 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top" v-if="scope.row.userId !== 1">
|
||||
<el-tooltip content="修改" placement="top" v-if="scope.row.userName !== 'cc'">
|
||||
<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['system:user:edit']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top" v-if="scope.row.userId !== 1">
|
||||
<el-tooltip content="删除" placement="top" v-if="scope.row.userName !== 'cc'">
|
||||
<el-button type="text" icon="Delete" @click="handleDelete(scope.row)"
|
||||
v-hasPermi="['system:user:remove']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="重置密码" placement="top" v-if="scope.row.userId !== 1">
|
||||
<el-tooltip content="重置密码" placement="top" v-if="scope.row.userName !== 'cc'">
|
||||
<el-button type="text" icon="Key" @click="handleResetPwd(scope.row)"
|
||||
v-hasPermi="['system:user:resetPwd']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="分配角色" placement="top" v-if="scope.row.userId !== 1">
|
||||
<el-tooltip content="分配角色" placement="top" v-if="scope.row.userName !== 'cc'">
|
||||
<el-button type="text" icon="CircleCheck" @click="handleAuthRole(scope.row)"
|
||||
v-hasPermi="['system:user:edit']"></el-button>
|
||||
</el-tooltip>
|
||||
@@ -143,12 +143,12 @@
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item v-if="form.userId == undefined" label="用户名称" prop="userName">
|
||||
<el-form-item v-if="form.id == undefined" label="用户名称" prop="userName">
|
||||
<el-input v-model="form.user.userName" placeholder="请输入用户名称" maxlength="30" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
|
||||
<el-form-item v-if="form.id == undefined" label="用户密码" prop="password">
|
||||
<el-input v-model="form.user.password" placeholder="请输入用户密码" type="password" maxlength="20"
|
||||
show-password />
|
||||
</el-form-item>
|
||||
@@ -296,11 +296,11 @@ const data = reactive({
|
||||
deptId: undefined
|
||||
},
|
||||
rules: {
|
||||
userName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }, { min: 2, max: 20, message: "用户名称长度必须介于 2 和 20 之间", trigger: "blur" }],
|
||||
nickName: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
|
||||
password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }],
|
||||
email: [{ type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] }],
|
||||
phonenumber: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }]
|
||||
// userName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }, { min: 2, max: 20, message: "用户名称长度必须介于 2 和 20 之间", trigger: "blur" }],
|
||||
// nick: [{ required: true, message: "用户昵称不能为空", trigger: "blur" }],
|
||||
// // password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }],
|
||||
// email: [{ type: "email", message: "请输入正确的邮箱地址", trigger: ["blur", "change"] }],
|
||||
// phone: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }]
|
||||
}
|
||||
});
|
||||
|
||||
@@ -349,7 +349,7 @@ function resetQuery() {
|
||||
};
|
||||
/** 删除按钮操作 */
|
||||
function handleDelete(row) {
|
||||
const userIds = row.userId || ids.value;
|
||||
const userIds = row.id || ids.value;
|
||||
proxy.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?').then(function () {
|
||||
return delUser(userIds);
|
||||
}).then(() => {
|
||||
@@ -389,7 +389,7 @@ function handleCommand(command, row) {
|
||||
};
|
||||
/** 跳转角色分配 */
|
||||
function handleAuthRole(row) {
|
||||
const userId = row.userId;
|
||||
const userId = row.id;
|
||||
router.push("/system/user-auth/role/" + userId);
|
||||
};
|
||||
/** 重置密码按钮操作 */
|
||||
@@ -401,14 +401,14 @@ function handleResetPwd(row) {
|
||||
inputPattern: /^.{5,20}$/,
|
||||
inputErrorMessage: "用户密码长度必须介于 5 和 20 之间",
|
||||
}).then(({ value }) => {
|
||||
resetUserPwd(row.userId, value).then(response => {
|
||||
resetUserPwd(row.id, value).then(response => {
|
||||
proxy.$modal.msgSuccess("修改成功,新密码是:" + value);
|
||||
});
|
||||
}).catch(() => { });
|
||||
};
|
||||
/** 选择条数 */
|
||||
function handleSelectionChange(selection) {
|
||||
ids.value = selection.map(item => item.userId);
|
||||
ids.value = selection.map(item => item.id);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
@@ -456,36 +456,47 @@ function reset() {
|
||||
deptId: undefined
|
||||
};
|
||||
proxy.resetForm("userRef");
|
||||
|
||||
// console.log(postOptions.value==[],123)
|
||||
// console.log( JSON.stringify(postOptions.value) =='{}',456)
|
||||
|
||||
// //如果有任何下拉框为空直接重置获取
|
||||
// if(postOptions.value=={}||roleOptions.value=={})
|
||||
// {
|
||||
roleOptionselect().then(response=>{
|
||||
//岗位从另一个接口获取全量
|
||||
postOptions.value = [];
|
||||
roleOptions.value = response.data;
|
||||
})
|
||||
// }
|
||||
|
||||
|
||||
};
|
||||
/** 取消按钮 */
|
||||
function cancel() {
|
||||
open.value = false;
|
||||
reset();
|
||||
};
|
||||
|
||||
|
||||
/** 新增按钮操作 */
|
||||
function handleAdd() {
|
||||
reset();
|
||||
getUser().then(response => {
|
||||
postOptions.value = response.posts;
|
||||
roleOptions.value = response.roles;
|
||||
open.value = true;
|
||||
|
||||
open.value = true;
|
||||
title.value = "添加用户";
|
||||
form.value.password = initPassword.value;
|
||||
});
|
||||
// getUser().then(response => {
|
||||
// postOptions.value = response.posts;
|
||||
// roleOptions.value = response.roles;
|
||||
// open.value = true;
|
||||
// title.value = "添加用户";
|
||||
// form.value.password = initPassword.value;
|
||||
// });
|
||||
};
|
||||
/** 修改按钮操作 */
|
||||
function handleUpdate(row) {
|
||||
reset();
|
||||
const userId = row.id || ids.value;
|
||||
roleOptionselect().then(response=>{
|
||||
//岗位从另一个接口获取全量
|
||||
postOptions.value = [];
|
||||
roleOptions.value = response.data;
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
getUser(userId).then(response => {
|
||||
form.value.user = response.data;
|
||||
form.value.postIds = [];
|
||||
@@ -494,14 +505,14 @@ function handleUpdate(row) {
|
||||
});
|
||||
open.value = true;
|
||||
title.value = "修改用户";
|
||||
form.password = "";
|
||||
form.value.user.password = null;
|
||||
});
|
||||
};
|
||||
/** 提交按钮 */
|
||||
function submitForm() {
|
||||
proxy.$refs["userRef"].validate(valid => {
|
||||
if (valid) {
|
||||
if (form.value.userId != undefined) {
|
||||
if (form.value.user.id != undefined) {
|
||||
updateUser(form.value).then(response => {
|
||||
proxy.$modal.msgSuccess("修改成功");
|
||||
open.value = false;
|
||||
|
||||
Reference in New Issue
Block a user