个人设置更新密码.

This commit is contained in:
许晓东
2023-05-09 20:44:54 +08:00
parent da1ddeb1e7
commit be8e567684
11 changed files with 131 additions and 35 deletions

View File

@@ -71,4 +71,10 @@ public class UserManageController {
public Object deleteUser(@RequestParam Long id) {
return userManageService.deleteUser(id);
}
@ControllerLog("更新密码")
@PostMapping("/user/password")
public Object updatePassword(@RequestBody SysUserDTO userDTO) {
return userManageService.updatePassword(userDTO);
}
}

View File

@@ -35,4 +35,6 @@ public interface UserManageService {
ResponseData deleteRole(Long id);
ResponseData deleteUser(Long id);
ResponseData updatePassword(SysUserDTO userDTO);
}

View File

@@ -192,6 +192,12 @@ public class UserManageServiceImpl implements UserManageService {
@Override
public ResponseData deleteRole(Long id) {
QueryWrapper<SysUserDO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(true, "role_ids", id);
Integer count = userMapper.selectCount(queryWrapper);
if (count > 0) {
return ResponseData.create().failed("存在用户被分配为当前角色,不允许删除");
}
roleMapper.deleteById(id);
return ResponseData.create().success();
}
@@ -201,4 +207,13 @@ public class UserManageServiceImpl implements UserManageService {
userMapper.deleteById(id);
return ResponseData.create().success();
}
@Override
public ResponseData updatePassword(SysUserDTO userDTO) {
SysUserDO userDO = userDTO.toDO();
userDO.setSalt(UUIDStrUtil.random());
userDO.setPassword(UUIDStrUtil.generate(userDTO.getPassword(), userDO.getSalt()));
userMapper.updateById(userDO);
return ResponseData.create().success();
}
}

View File

@@ -1,32 +0,0 @@
<template>
<div class="hello">
<h1>{{ msg }}</h1>
</div>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>

View File

@@ -342,4 +342,8 @@ export const UserManageApi = {
url: "/sys/user/manage/user",
method: "delete",
},
updatePassword: {
url: "/sys/user/manage/user/password",
method: "post",
},
};

View File

@@ -79,6 +79,9 @@ export default {
watch: {
visible(v) {
this.show = v;
if (this.show) {
this.getRoles();
}
},
},
methods: {

View File

@@ -76,6 +76,9 @@ export default {
watch: {
visible(v) {
this.show = v;
if (this.show) {
this.getRoles();
}
},
},
methods: {

View File

@@ -96,7 +96,7 @@ import request from "@/utils/request";
import notification from "ant-design-vue/lib/notification";
import { UserManageApi } from "@/utils/api";
import CreateUser from "@/views/user/CreateUser.vue";
import MessageBox from "@/views/components/MessageBox.vue";
import MessageBox from "@/components/MessageBox.vue";
import UpdateUserRole from "@/views/user/UpdateUserRole.vue";
export default {

View File

@@ -11,7 +11,9 @@
<a-tab-pane key="3" tab="权限列表">
<Permission></Permission>
</a-tab-pane>
<a-tab-pane key="4" tab="个人设置"> </a-tab-pane>
<a-tab-pane key="4" tab="个人设置">
<UserSetting></UserSetting>
</a-tab-pane>
</a-tabs>
</a-spin>
</div>
@@ -21,9 +23,10 @@
import Permission from "@/views/user/Permission.vue";
import Role from "@/views/user/Role.vue";
import User from "@/views/user/User.vue";
import UserSetting from "@/views/user/UserSetting.vue";
export default {
name: "UserManage",
components: { Permission, Role, User },
components: { Permission, Role, User, UserSetting },
data() {
return {
loading: false,

View File

@@ -0,0 +1,92 @@
<template>
<div class="content">
<a-spin :spinning="loading">
<a-form :form="form" @submit="handleSubmit">
<a-form-item label="新密码">
<a-input-password
v-decorator="[
'password',
{ rules: [{ required: true, message: '请输入密码' }] },
]"
/>
</a-form-item>
<a-form-item label="确认密码">
<a-input-password
v-decorator="[
'confirmPassword',
{
rules: [
{
required: true,
message: '两次密码不一致',
pattern: new RegExp(
'^' + form.getFieldValue('password') + '$'
),
},
],
},
]"
/>
</a-form-item>
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
<a-button type="primary" html-type="submit"> 提交 </a-button>
</a-form-item>
</a-form>
</a-spin>
</div>
</template>
<script>
import request from "@/utils/request";
import { UserManageApi } from "@/utils/api";
import notification from "ant-design-vue/lib/notification";
export default {
name: "UserSetting",
components: {},
props: {
topicList: {
type: Array,
},
},
data() {
return {
form: this.$form.createForm(this, { name: "user_setting" }),
loading: false,
};
},
methods: {
handleSubmit(e) {
e.preventDefault();
this.form.validateFields((err, values) => {
if (!err) {
const param = Object.assign({}, values);
this.loading = true;
request({
url: UserManageApi.updatePassword.url,
method: UserManageApi.updatePassword.method,
data: param,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.$message.success(res.msg);
} else {
notification.error({
message: "error",
description: res.msg,
});
}
});
}
});
},
},
};
</script>
<style scoped>
.content {
padding-left: 30%;
padding-right: 30%;
}
</style>