feat():learning后台管理项目初始化
This commit is contained in:
52
internal/models/rbac.go
Normal file
52
internal/models/rbac.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package models
|
||||
|
||||
// RolePagePermission 角色页面权限关联
|
||||
type RolePagePermission struct {
|
||||
BaseModel
|
||||
RoleID uint `gorm:"not null" json:"roleId"`
|
||||
PageID uint `gorm:"not null" json:"pageId"`
|
||||
Role Role `gorm:"foreignKey:RoleID" json:"role,omitempty"`
|
||||
Page Page `gorm:"foreignKey:PageID" json:"page,omitempty"`
|
||||
}
|
||||
|
||||
// Page 页面模型
|
||||
type Page struct {
|
||||
BaseModel
|
||||
Name string `gorm:"size:50;not null" json:"name"`
|
||||
Path string `gorm:"uniqueIndex;size:100;not null" json:"path"`
|
||||
Icon string `gorm:"size:50" json:"icon"`
|
||||
SortOrder int `gorm:"default:0" json:"sortOrder"`
|
||||
IsActive bool `gorm:"default:true" json:"isActive"`
|
||||
}
|
||||
|
||||
func (RolePagePermission) TableName() string {
|
||||
return "admin_role_page_permissions"
|
||||
}
|
||||
|
||||
func (Page) TableName() string {
|
||||
return "admin_pages"
|
||||
}
|
||||
|
||||
// RBAC请求模型
|
||||
type UserRoleAssignRequest struct {
|
||||
UserID uint `json:"userId" binding:"required"`
|
||||
RoleIDs []uint `json:"roleIds"`
|
||||
}
|
||||
|
||||
type RolePagePermissionAssignRequest struct {
|
||||
RoleID uint `json:"roleId" binding:"required"`
|
||||
PageIDs []uint `json:"pageIds"`
|
||||
}
|
||||
|
||||
// 用户权限响应模型
|
||||
type UserPermissionsResponse struct {
|
||||
User User `json:"user"`
|
||||
Roles []Role `json:"roles"`
|
||||
Pages []Page `json:"pages"`
|
||||
}
|
||||
|
||||
// 角色页面权限响应模型
|
||||
type RolePagePermissionsResponse struct {
|
||||
Role Role `json:"role"`
|
||||
Pages []Page `json:"pages"`
|
||||
}
|
||||
Reference in New Issue
Block a user