mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-11 20:43:44 +08:00
修复树表上级关系绑定验证,优化CURD代码生成
This commit is contained in:
@@ -3,16 +3,99 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package adminin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/model"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/form"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// GetPermissionsInp 获取指定角色的菜单权限
|
||||
type GetPermissionsInp struct {
|
||||
RoleId int64 `json:"id"`
|
||||
}
|
||||
|
||||
type GetPermissionsModel struct {
|
||||
MenuIds []int64 `json:"menuIds"`
|
||||
}
|
||||
|
||||
// UpdatePermissionsInp 更新指定角色的菜单权限
|
||||
type UpdatePermissionsInp struct {
|
||||
RoleId int64 `json:"id"`
|
||||
MenuIds []int64 `json:"menuIds"`
|
||||
}
|
||||
|
||||
// RoleDeleteInp 删除角色
|
||||
type RoleDeleteInp struct {
|
||||
Id int64 `json:"id" v:"required"`
|
||||
}
|
||||
|
||||
func (in *RoleDeleteInp) Filter(ctx context.Context) (err error) {
|
||||
if in.Id <= 0 {
|
||||
err = gerror.New("ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// RoleEditInp 获取列表
|
||||
type RoleEditInp struct {
|
||||
entity.AdminRole
|
||||
}
|
||||
|
||||
func (in *RoleEditInp) Filter(ctx context.Context) (err error) {
|
||||
if in.Name == "" {
|
||||
err = gerror.New("名称不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Key == "" {
|
||||
err = gerror.New("编码不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Id > 0 && in.Id == in.Pid {
|
||||
err = gerror.New("上级角色不能是自己")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// RoleUpdateFields 修改数据字段过滤
|
||||
type RoleUpdateFields struct {
|
||||
Id int64 `json:"id" description:"角色ID"`
|
||||
Name string `json:"name" description:"角色名称"`
|
||||
Key string `json:"key" description:"角色权限字符串"`
|
||||
DataScope int `json:"dataScope" description:"数据范围"`
|
||||
CustomDept *gjson.Json `json:"customDept" description:"自定义部门权限"`
|
||||
Pid int64 `json:"pid" description:"上级角色ID"`
|
||||
Level int `json:"level" description:"关系树等级"`
|
||||
Tree string `json:"tree" description:"关系树"`
|
||||
Remark string `json:"remark" description:"备注"`
|
||||
Sort int `json:"sort" description:"排序"`
|
||||
Status int `json:"status" description:"角色状态"`
|
||||
}
|
||||
|
||||
// RoleInsertFields 新增数据字段过滤
|
||||
type RoleInsertFields struct {
|
||||
Name string `json:"name" description:"角色名称"`
|
||||
Key string `json:"key" description:"角色权限字符串"`
|
||||
DataScope int `json:"dataScope" description:"数据范围"`
|
||||
CustomDept *gjson.Json `json:"customDept" description:"自定义部门权限"`
|
||||
Pid int64 `json:"pid" description:"上级角色ID"`
|
||||
Level int `json:"level" description:"关系树等级"`
|
||||
Tree string `json:"tree" description:"关系树"`
|
||||
Remark string `json:"remark" description:"备注"`
|
||||
Sort int `json:"sort" description:"排序"`
|
||||
Status int `json:"status" description:"角色状态"`
|
||||
}
|
||||
|
||||
// RoleListInp 获取列表
|
||||
type RoleListInp struct {
|
||||
form.PageReq
|
||||
@@ -29,18 +112,6 @@ type RoleListModel struct {
|
||||
List []*RoleTree `json:"list"`
|
||||
}
|
||||
|
||||
func Sort(v []*RoleTree) {
|
||||
sort.SliceStable(v, func(i, j int) bool {
|
||||
if v[i].Sort < v[j].Sort {
|
||||
return true
|
||||
}
|
||||
if v[i].Sort > v[j].Sort {
|
||||
return false
|
||||
}
|
||||
return v[i].Id < v[j].Id
|
||||
})
|
||||
}
|
||||
|
||||
// RoleMemberListInp 查询列表
|
||||
type RoleMemberListInp struct {
|
||||
form.PageReq
|
||||
@@ -68,8 +139,16 @@ type MenuRoleListModel struct {
|
||||
CheckedKeys []int64 `json:"checkedKeys" dc:"选择的菜单ID"`
|
||||
}
|
||||
|
||||
// DataScopeEditInp 获取数据权限选项
|
||||
type DataScopeEditInp struct {
|
||||
Id int64 `json:"id" v:"required" dc:"角色ID"`
|
||||
DataScope int `json:"dataScope" v:"required" dc:"数据范围"`
|
||||
CustomDept []int64 `json:"customDept" dc:"自定义部门权限"`
|
||||
}
|
||||
|
||||
func (in *DataScopeEditInp) Filter(ctx context.Context) (err error) {
|
||||
if in.Id <= 0 {
|
||||
return gerror.New("角色ID不正确!")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user