feat: RBAC 基本完成

This commit is contained in:
Blizzard
2025-09-14 21:58:44 +08:00
parent 2ec091bf59
commit 9be75d53fe
35 changed files with 615 additions and 87 deletions
+5 -5
View File
@@ -29,20 +29,20 @@ func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
// GetById Find by id structure
type GetById struct {
ID int `json:"id" form:"id"` // 主键ID
ID string `json:"id" form:"id"` // 主键ID
}
func (r *GetById) Uint() uint {
return uint(r.ID)
func (r *GetById) Uint() string {
return string(r.ID)
}
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
Ids []string `json:"ids" form:"ids"`
}
// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
AuthorityId uint `json:"authorityId" form:"authorityId"` // 角色ID
AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID
}
type Empty struct{}
+1 -1
View File
@@ -13,6 +13,6 @@ type CustomClaims struct {
type BaseClaims struct {
UUID uuid.UUID
ID uint
ID string
Account string
}
+6
View File
@@ -0,0 +1,6 @@
package request
type GetMenuTree struct {
Category int `json:"category" form:"category"`
ParentId string `json:"parentId" form:"parentId"`
}
+5
View File
@@ -7,3 +7,8 @@ type GetRoleList struct {
Code string `json:"code" form:"code"`
Name string `json:"name" form:"name"`
}
type GrantMenu struct {
RoleId string `json:"roleId"`
MenuIds []string `json:"menuIds"`
}
+10
View File
@@ -14,3 +14,13 @@ type GetUserList struct {
Account string `json:"account" form:"account"`
Phone string `json:"phone" form:"phone"`
}
type ChangePwd struct {
Id string `json:"id"`
NewPwd string `json:"newPwd"`
}
type GrantRole struct {
UserId string `json:"userId"`
RoleIds []string `json:"roleIds"`
}
-4
View File
@@ -2,10 +2,6 @@ package response
import "sundynix-go/model/system"
type SysUserResponse struct {
User system.User `json:"user"`
}
type LoginResponse struct {
User system.User `json:"user"`
Token string `json:"token"`
+1 -1
View File
@@ -8,5 +8,5 @@ type Client struct {
Name string `gorm:"size:50;" json:"name"`
GrantType string `gorm:"size:50;" json:"grantType"`
AdditionalInfo string `gorm:"type:text" json:"additionalInfo"`
ActiveTimeout uint `json:"activeTimeout"`
ActiveTimeout int64 `json:"activeTimeout"`
}
+17
View File
@@ -0,0 +1,17 @@
package system
import "sundynix-go/global"
type Menu struct {
global.BaseModel
ParentId string `gorm:"size:100;default:'0'" json:"parentId" form:"parentId"`
Category int `json:"category" form:"category"`
Name string `gorm:"size:20" json:"name" form:"name"`
Title string `gorm:"size:20" json:"title" form:"title"`
Code string `gorm:"size:20" json:"code" form:"code"`
Permission string `gorm:"size:20" json:"permission" form:"permission"`
Locale string `gorm:"size:50" json:"locale" form:"locale"`
Icon string `gorm:"size:20" json:"icon" form:"icon"`
Sort int `json:"sort" form:"sort"`
Children []*Menu `json:"children" gorm:"-"`
}
+4 -3
View File
@@ -4,7 +4,8 @@ import "sundynix-go/global"
type Role struct {
global.BaseModel
Name string `json:"name" form:"name"`
Code string `json:"code" form:"code"`
Sort int `json:"sort" form:"sort"`
Name string `gorm:"size:20" json:"name" form:"name"`
Code string `gorm:"size:20" json:"code" form:"code"`
Sort int `json:"sort" form:"sort"`
Menus []Menu `gorm:"many2many:role_menu;"`
}
+6
View File
@@ -0,0 +1,6 @@
package system
type RoleMenu struct {
RoleId string `json:"roleId" gorm:"size:100;column:role_id;comment:角色id"`
MenuId string `json:"menuId" gorm:"size:100;column:menu_id;comment:菜单id"`
}
+4 -2
View File
@@ -6,21 +6,23 @@ import (
type Login interface {
GetAccount() string
GetUserId() uint
GetUserId() string
GetUserInfo() any
}
type User struct {
global.BaseModel
TenantId string `gorm:"size:20;" json:"tenantId" form:"tenantId"`
ClientId string `gorm:"size:20;" json:"clientId"`
Account string `gorm:"size:11;unique;" json:"account" form:"account"`
Password string `gorm:"size:100;" json:"-" form:"password"`
Phone string `gorm:"size:11;" json:"phone" form:"phone"`
Roles []Role `gorm:"many2many:user_role;" json:"roles"`
}
func (u *User) GetAccount() string {
return u.Account
}
func (u *User) GetUserId() uint {
func (u *User) GetUserId() string {
return u.Id
}
+6
View File
@@ -0,0 +1,6 @@
package system
type UserRole struct {
UserId string `json:"userId" gorm:"size:100;column:user_id;comment:用户id"`
RoleId string `json:"roleId" gorm:"size:100;column:role_id;comment:角色id"`
}