重构前保存现有 apps/ 结构基线,供后续各阶段回滚。 Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
3.3 KiB
Python
62 lines
3.3 KiB
Python
from datetime import date
|
|
from typing import Any, Optional
|
|
|
|
from pydantic import BaseModel, Field, model_validator
|
|
|
|
# 用户表单验证
|
|
class UserForm(BaseModel):
|
|
id: Optional[int] = Field(None, description="用户ID")
|
|
realname: str = Field(..., min_length=1, max_length=150, description="用户姓名")
|
|
nickname: str = Field(..., min_length=1, max_length=150, description="用户昵称")
|
|
gender: int = Field(..., ge=1, le=3, description="性别")
|
|
avatar: str = Field(..., min_length=1, max_length=255, description="头像")
|
|
mobile: str = Field(..., min_length=1, max_length=30, description="手机号")
|
|
email: str = Field(..., min_length=1, max_length=30, description="邮箱")
|
|
birthday: date
|
|
dept_id: int = Field(..., ge=0, description="部门ID")
|
|
level_id: int = Field(..., ge=0, description="职级ID")
|
|
position_id: int = Field(..., ge=0, description="岗位ID")
|
|
city: Any = Field(..., description="行政区划")
|
|
province_code: Optional[str] = Field(None, max_length=30, description="省份编码")
|
|
city_code: Optional[str] = Field(None, max_length=30, description="城市编码")
|
|
district_code: Optional[str] = Field(None, max_length=30, description="县区编码")
|
|
address: str = Field(..., min_length=1, max_length=255, description="详细地址")
|
|
username: str = Field(..., min_length=1, max_length=30, description="登录账号")
|
|
password: Optional[str] = Field(None, min_length=6, max_length=128, description="登录密码")
|
|
intro: Optional[str] = Field(None, max_length=255, description="个人简介")
|
|
status: int = Field(..., ge=1, le=2, description="用户状态")
|
|
note: Optional[str] = Field(None, max_length=255, description="用户备注")
|
|
sort: int = Field(..., ge=0, le=99999, description="用户排序")
|
|
roles: Optional[Any] = Field(default=[], description="用户角色")
|
|
|
|
# 设置状态表单
|
|
class UserStatusForm(BaseModel):
|
|
id: int = Field(..., gt=0, description="用户ID")
|
|
status: int = Field(..., ge=1, le=2, description="用户状态")
|
|
|
|
# 修改个人信息表单验证
|
|
class UserInfoForm(BaseModel):
|
|
realname: str = Field(..., min_length=1, max_length=150, description="用户姓名")
|
|
nickname: str = Field(..., min_length=1, max_length=150, description="用户昵称")
|
|
gender: int = Field(..., ge=1, le=3, description="性别")
|
|
mobile: str = Field(..., min_length=1, max_length=30, description="手机号")
|
|
email: str = Field(..., min_length=1, max_length=30, description="邮箱")
|
|
address: str = Field(..., min_length=1, max_length=255, description="详细地址")
|
|
intro: Optional[str] = Field(None, max_length=255, description="个人简介")
|
|
|
|
# 修改密码表单验证
|
|
class UpdatePwdForm(BaseModel):
|
|
oldPassword: str = Field(..., min_length=6, max_length=128, description="原始密码")
|
|
newPassword: str = Field(..., min_length=6, max_length=128, description="新密码")
|
|
rePassword: str = Field(..., min_length=6, max_length=128, description="确认密码")
|
|
|
|
@model_validator(mode='after')
|
|
def check_passwords_match(self):
|
|
if self.newPassword != self.rePassword:
|
|
raise ValueError('rePassword: 两次输入的密码不一致')
|
|
return self
|
|
|
|
# 重置密码表单
|
|
class ResetPwdForm(BaseModel):
|
|
id: int = Field(..., gt=0, description="用户ID")
|