align(用户管理): 超管新建普通账号补所属管理员(createdBy)下拉,payload 仅 normal+已选时带 createdById(对齐 admin.js created_by_id 语义)
This commit is contained in:
@@ -12,6 +12,8 @@ export interface CreateUserForm {
|
||||
role: CreatableUserRole
|
||||
/** 授权菜单 id(后端 replaceDirectPermissions 用)。 */
|
||||
columnIds: number[]
|
||||
/** 所属管理员 id(超管创建普通账号时可指定,对齐 admin 的 created_by_id)。 */
|
||||
createdBy?: number | null
|
||||
}
|
||||
|
||||
export interface CreateUserFormErrors {
|
||||
@@ -25,10 +27,12 @@ export interface CreateUserPayload {
|
||||
password: string
|
||||
role: string
|
||||
columnIds: number[]
|
||||
/** 仅 role=normal 且选了所属管理员时发送,与参考 admin.js 的 created_by_id 语义一致。 */
|
||||
createdById?: number
|
||||
}
|
||||
|
||||
export function createEmptyCreateUserForm(): CreateUserForm {
|
||||
return { username: '', password: '', role: 'normal', columnIds: [] }
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null }
|
||||
}
|
||||
|
||||
/** 未知/空白/超管角色一律归一到 normal,与后端 "admin"/"normal" 白名单一致。 */
|
||||
@@ -54,12 +58,17 @@ export function validateCreateUserForm(form: CreateUserForm): { valid: boolean;
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
/** 表单 → 创建请求体:用户名去空格、角色归一、菜单 id 拷贝不共享引用。 */
|
||||
/** 表单 → 创建请求体:用户名去空格、角色归一、菜单 id 拷贝不共享引用;
|
||||
* createdById 仅在 role=normal 且选了所属管理员时携带(对齐 admin.js 的 created_by_id 语义)。 */
|
||||
export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
|
||||
return {
|
||||
const payload: CreateUserPayload = {
|
||||
username: (form.username || '').trim(),
|
||||
password: form.password || '',
|
||||
role: normalizeCreateRole(form.role),
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
}
|
||||
if (payload.role === 'normal' && form.createdBy != null) {
|
||||
payload.createdById = form.createdBy
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user