fix(role): 修复 roleSort 默认值与后端验证不一致

前端 initialValue 从 0 改为 1,min 从 0 改为 1,添加前端验证规则;
后端 RoleUpdateRequest.roleSort 补充 @Min(value=1) 验证注解。
统一前后端约束,避免默认值提交时触发验证错误。
This commit is contained in:
张翔
2026-05-06 14:15:55 +08:00
committed by zhangxiang
parent 000a137a3d
commit 380a7a7dbe
2 changed files with 8 additions and 15 deletions
@@ -1,21 +1,14 @@
package cn.novalon.manage.sys.dto.request;
/**
* 角色更新请求DTO
*
* 文件定义:用于更新角色的请求DTO对象,封装HTTP请求参数
* 涉及业务:角色管理、权限分配等场景
* 算法:支持部分字段更新,通过验证注解确保请求参数的有效性
*
* @author 张翔
* @date 2026-03-13
*/
import jakarta.validation.constraints.Min;
public class RoleUpdateRequest {
private String roleName;
private String roleKey;
@Min(value = 1, message = "显示顺序必须大于0")
private Integer roleSort;
private Integer status;
@@ -41,7 +41,7 @@ export default function RoleManagement() {
try {
const res = await roleApi.getAllPermissions()
setPermissions(Array.isArray(res) ? res : [])
} catch {}
} catch { /* ignored */ }
}
function handleAdd() {
@@ -86,7 +86,7 @@ export default function RoleManagement() {
}
setModalOpen(false)
loadRoles()
} catch {}
} catch { /* ignored */ }
}
const permissionTreeData = buildPermissionTree(permissions)
@@ -154,7 +154,7 @@ export default function RoleManagement() {
open={modalOpen}
onOk={handleSubmit}
onCancel={() => setModalOpen(false)}
destroyOnClose
destroyOnHidden
width={600}
>
<Form form={form} layout="vertical">
@@ -164,8 +164,8 @@ export default function RoleManagement() {
<Form.Item name="roleKey" label="角色标识" rules={[{ required: true, message: '请输入角色标识' }]}>
<Input />
</Form.Item>
<Form.Item name="roleSort" label="排序" initialValue={0}>
<InputNumber min={0} style={{ width: '100%' }} />
<Form.Item name="roleSort" label="排序" initialValue={1} rules={[{ type: 'number' as const, min: 1, message: '排序必须大于0' }]}>
<InputNumber min={1} style={{ width: '100%' }} />
</Form.Item>
<Form.Item name="status" label="状态" initialValue={RoleStatus.ACTIVE}>
<Select options={Object.entries(roleStatusMap).map(([value, info]) => ({ label: info.label, value }))} />