- 前端: React 18 + TypeScript + Vite + Tailwind CSS + shadcn/ui - 后端: Go + Gin + GORM + JWT (golang-jwt/jwt/v5) - 功能: 服务器管理、K8s集群、监控告警、CI/CD、自动化运维、审批流程、审计日志 - 文档: 设计文档(ROADMAP/PDD/架构/模块)
112 lines
3.7 KiB
Go
112 lines
3.7 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// User 用户模型
|
|
type User struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
|
|
Password string `gorm:"size:255;not null" json:"-"`
|
|
Email string `gorm:"size:128;uniqueIndex" json:"email"`
|
|
Phone string `gorm:"size:32" json:"phone"`
|
|
RealName string `gorm:"size:64" json:"real_name"`
|
|
Avatar string `gorm:"size:255" json:"avatar"`
|
|
Status int `gorm:"default:1" json:"status"` // 0:禁用 1:启用
|
|
IsAdmin bool `gorm:"default:false" json:"is_admin"`
|
|
LastLogin *time.Time `json:"last_login"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// 关联
|
|
Roles []Role `gorm:"many2many:user_roles;" json:"roles,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|
|
|
|
// Role 角色模型
|
|
type Role struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:255" json:"description"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// 关联
|
|
Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Role) TableName() string {
|
|
return "roles"
|
|
}
|
|
|
|
// Permission 权限模型
|
|
type Permission struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:64;not null" json:"name"`
|
|
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
|
|
Type string `gorm:"size:32" json:"type"` // menu, button, api
|
|
Path string `gorm:"size:255" json:"path"`
|
|
Method string `gorm:"size:32" json:"method"`
|
|
ParentID *uint `json:"parent_id"`
|
|
Sort int `gorm:"default:0" json:"sort"`
|
|
Status int `gorm:"default:1" json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (Permission) TableName() string {
|
|
return "permissions"
|
|
}
|
|
|
|
// LoginRequest 登录请求
|
|
type LoginRequest struct {
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
// LoginResponse 登录响应
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
ExpiresIn int `json:"expires_in"`
|
|
User *User `json:"user"`
|
|
}
|
|
|
|
// CreateUserRequest 创建用户请求
|
|
type CreateUserRequest struct {
|
|
Username string `json:"username" binding:"required,min=3,max=64"`
|
|
Password string `json:"password" binding:"required,min=6,max=32"`
|
|
Email string `json:"email" binding:"required,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// UpdateUserRequest 更新用户请求
|
|
type UpdateUserRequest struct {
|
|
Email string `json:"email" binding:"omitempty,email"`
|
|
Phone string `json:"phone"`
|
|
RealName string `json:"real_name"`
|
|
Status *int `json:"status"`
|
|
RoleIDs []uint `json:"role_ids"`
|
|
}
|
|
|
|
// ChangePasswordRequest 修改密码请求
|
|
type ChangePasswordRequest struct {
|
|
OldPassword string `json:"old_password" binding:"required"`
|
|
NewPassword string `json:"new_password" binding:"required,min=6,max=32"`
|
|
}
|