Files
rui-docs/api-request-user-password.md

69 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# [API-REQ] 用户编辑接口密码字段处理优化
## 接口地址
PUT /user/admin/user
## 功能描述
当前编辑用户时,如果前端不传 `password` 字段或传空字符串,后端会报错或把密码更新为空。期望后端能处理以下逻辑:
## 请求参数
```json
{
"id": 1,
"username": "admin",
"userType": 1,
"status": 1
// 注意:没有 password 字段
}
```
## 期望行为
1. **编辑用户时**,如果请求体中**不包含** `password` 字段,或 `password`**null/空字符串**,应**不修改**用户密码
2. **编辑用户时**,如果请求体中**包含** `password` 字段且**不为空**,应**更新**用户密码
3. **新增用户时**`password` 字段**必填**,保持现有逻辑
## 当前问题
- 编辑用户时如果不传密码,后端可能报错或把密码置空
- 前端需要在编辑时特殊处理密码字段(已临时处理:编辑时密码为空则不提交该字段)
## 前端使用场景
编辑用户弹框中,密码输入框提示"留空表示不修改密码"。用户留空时,前端不提交 password 字段,期望后端保持原密码不变。
## 优先级
高 - 影响用户编辑功能正常使用
## 相关代码
前端文件:`admin-ui/src/views/user/info/UserFormDialog.vue`
```typescript
// 编辑时如果密码为空,删除该字段,避免后端修改密码
if (isEdit && !data.password) {
delete data.password
}
```
## 建议实现
`UserService.update()` 或 Controller 层添加判断:
```java
if (userDTO.getPassword() != null && !userDTO.getPassword().isEmpty()) {
// 更新密码
user.setPassword(encrypt(userDTO.getPassword()));
}
// 否则不修改密码字段
```
---
> 提交者:前端开发(admin-ui
> 日期:2026-06-06