|
|
@@ -137,9 +137,10 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 处理字段名映射:后端返回 postIds,表单字段名是 workstationIds
|
|
|
form.setFieldsValue({
|
|
|
...userData,
|
|
|
- workstationIds: userData.workstationIds || [],
|
|
|
+ workstationIds: userData.postIds || userData.workstationIds || [],
|
|
|
deptId: userData.deptId,
|
|
|
sex: sexValue, // 使用处理后的性别值
|
|
|
});
|
|
|
@@ -176,7 +177,18 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
setFormLoading(true);
|
|
|
try {
|
|
|
if (formType === 'create') {
|
|
|
- await userApi.createUser(values as UserVO);
|
|
|
+ // 新增模式下,处理字段名映射:workstationIds -> postIds
|
|
|
+ const createData: any = {
|
|
|
+ ...values,
|
|
|
+ };
|
|
|
+ // 将 workstationIds 映射为 postIds
|
|
|
+ if (createData.workstationIds) {
|
|
|
+ createData.postIds = createData.workstationIds;
|
|
|
+ // 删除 workstationIds 字段,避免传递错误的字段名
|
|
|
+ delete createData.workstationIds;
|
|
|
+ }
|
|
|
+ console.log('新增用户数据:', createData); // 调试用
|
|
|
+ await userApi.createUser(createData as UserVO);
|
|
|
message.success(t('form.createSuccess'));
|
|
|
} else {
|
|
|
// 编辑模式下,合并原始数据和表单数据,确保所有必要字段都被传递
|
|
|
@@ -194,10 +206,11 @@ const UserForm = forwardRef<UserFormRef, UserFormProps>(({ onSuccess }, ref) =>
|
|
|
delete updateData.password;
|
|
|
}
|
|
|
|
|
|
- // 处理字段名映射:workstationIds -> postIds(如果后端需要 postIds)
|
|
|
- // 如果后端需要 postIds,则使用 workstationIds 的值
|
|
|
- if (updateData.workstationIds && !updateData.postIds) {
|
|
|
+ // 处理字段名映射:workstationIds -> postIds(后端需要 postIds)
|
|
|
+ if (updateData.workstationIds) {
|
|
|
updateData.postIds = updateData.workstationIds;
|
|
|
+ // 删除 workstationIds 字段,避免传递错误的字段名
|
|
|
+ delete updateData.workstationIds;
|
|
|
}
|
|
|
|
|
|
// 确保必要字段存在
|