feat: add theme preset system with admin CRUD, public listing, and user theme settings
- Add ChromaticColor (17 Tailwind colors) and NeutralColor (5 grays) enums - Add ThemePreset table with flat color columns and unique name constraint - Add admin theme endpoints (CRUD + set default) at /api/v1/admin/theme - Add public theme listing at /api/v1/site/themes - Add user theme settings (PATCH /theme) with color snapshot on User model - User.color_* columns store per-user overrides; fallback to default preset then builtin - Initialize default theme preset in migration - Remove legacy defaultTheme/themes settings Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,71 @@
|
||||
from enum import StrEnum
|
||||
|
||||
from .base import SQLModelBase
|
||||
|
||||
class ThemeResponse(SQLModelBase):
|
||||
"""主题响应 DTO"""
|
||||
|
||||
pass
|
||||
|
||||
class ChromaticColor(StrEnum):
|
||||
"""有彩色枚举(17种 Tailwind 调色板颜色)"""
|
||||
|
||||
RED = "red"
|
||||
ORANGE = "orange"
|
||||
AMBER = "amber"
|
||||
YELLOW = "yellow"
|
||||
LIME = "lime"
|
||||
GREEN = "green"
|
||||
EMERALD = "emerald"
|
||||
TEAL = "teal"
|
||||
CYAN = "cyan"
|
||||
SKY = "sky"
|
||||
BLUE = "blue"
|
||||
INDIGO = "indigo"
|
||||
VIOLET = "violet"
|
||||
PURPLE = "purple"
|
||||
FUCHSIA = "fuchsia"
|
||||
PINK = "pink"
|
||||
ROSE = "rose"
|
||||
|
||||
|
||||
class NeutralColor(StrEnum):
|
||||
"""无彩色枚举(5种灰色调)"""
|
||||
|
||||
SLATE = "slate"
|
||||
GRAY = "gray"
|
||||
ZINC = "zinc"
|
||||
NEUTRAL = "neutral"
|
||||
STONE = "stone"
|
||||
|
||||
|
||||
class ThemeColorsBase(SQLModelBase):
|
||||
"""嵌套颜色 DTO,API 请求/响应层使用"""
|
||||
|
||||
primary: ChromaticColor
|
||||
"""主色调"""
|
||||
|
||||
secondary: ChromaticColor
|
||||
"""辅助色"""
|
||||
|
||||
success: ChromaticColor
|
||||
"""成功色"""
|
||||
|
||||
info: ChromaticColor
|
||||
"""信息色"""
|
||||
|
||||
warning: ChromaticColor
|
||||
"""警告色"""
|
||||
|
||||
error: ChromaticColor
|
||||
"""错误色"""
|
||||
|
||||
neutral: NeutralColor
|
||||
"""中性色"""
|
||||
|
||||
|
||||
BUILTIN_DEFAULT_COLORS = ThemeColorsBase(
|
||||
primary=ChromaticColor.GREEN,
|
||||
secondary=ChromaticColor.BLUE,
|
||||
success=ChromaticColor.GREEN,
|
||||
info=ChromaticColor.BLUE,
|
||||
warning=ChromaticColor.YELLOW,
|
||||
error=ChromaticColor.RED,
|
||||
neutral=NeutralColor.ZINC,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user