Files
disknext/sqlmodels/color.py
于小丘 4c1b7a8aad 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>
2026-02-12 19:34:41 +08:00

72 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from enum import StrEnum
from .base import SQLModelBase
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):
"""嵌套颜色 DTOAPI 请求/响应层使用"""
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,
)