样式修改
This commit is contained in:
1 parent
96947d7636
commit
f3511e5cd0
15 files changed
+933
-84
No files matched your search
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Literal
|
||||
from urllib.parse import urlparse
|
||||
from uuid import uuid4
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -13,6 +14,8 @@ from app.gateway.auth.password import hash_password_async
|
||||
from app.gateway.deps import get_optional_user_from_request
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.system_settings import (
|
||||
AppearanceRouteParam,
|
||||
CompactShortcutButton,
|
||||
LeaderboardSettings,
|
||||
ModelConcurrencySettings,
|
||||
PluginDomainAgentMapping,
|
||||
@@ -537,6 +540,7 @@ class AppearanceResponse(BaseModel):
|
||||
default_skill_view: Literal["card", "list"] = Field(..., description="System default skill list display mode — card or list")
|
||||
default_agent_view: Literal["card", "list"] = Field(..., description="System default agent list display mode — card or list")
|
||||
default_layout_mode: Literal["full", "compact"] = Field(..., description="System default interface layout — full (sidebar + header) or compact (hidden)")
|
||||
compact_shortcut_buttons: list[CompactShortcutButton] = Field(default_factory=list, description="Shortcut buttons rendered in top bars")
|
||||
|
||||
|
||||
class AppearanceUpdateRequest(BaseModel):
|
||||
@@ -544,6 +548,61 @@ class AppearanceUpdateRequest(BaseModel):
|
||||
default_skill_view: Literal["card", "list"] | None = Field(default=None)
|
||||
default_agent_view: Literal["card", "list"] | None = Field(default=None)
|
||||
default_layout_mode: Literal["full", "compact"] | None = Field(default=None)
|
||||
compact_shortcut_buttons: list[CompactShortcutButton] | None = Field(default=None)
|
||||
|
||||
|
||||
def _normalize_compact_shortcut_buttons(
|
||||
buttons: list[CompactShortcutButton] | None,
|
||||
) -> list[CompactShortcutButton]:
|
||||
normalized: list[CompactShortcutButton] = []
|
||||
seen_ids: set[str] = set()
|
||||
for index, item in enumerate(buttons or []):
|
||||
label = (item.label or "").strip() or "快捷入口"
|
||||
url = (item.url or "").strip()
|
||||
row_id = (item.id or "").strip() or uuid4().hex
|
||||
if row_id in seen_ids:
|
||||
row_id = uuid4().hex
|
||||
seen_ids.add(row_id)
|
||||
|
||||
route_params: list[AppearanceRouteParam] = []
|
||||
for param in item.route_params or []:
|
||||
key = (param.key or "").strip()
|
||||
if not key:
|
||||
continue
|
||||
if param.paramType == "theme":
|
||||
route_params.append(
|
||||
AppearanceRouteParam(
|
||||
key=key,
|
||||
paramType="theme",
|
||||
themeValue=(param.themeValue or "").strip()
|
||||
or "red=red;blue=blue;dark-blue=dark-blue",
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
source = (param.source or "access_token").strip() or "access_token"
|
||||
route_params.append(
|
||||
AppearanceRouteParam(
|
||||
key=key,
|
||||
paramType="login",
|
||||
source=source,
|
||||
customValue=(param.customValue or "").strip()
|
||||
if source == "other"
|
||||
else None,
|
||||
)
|
||||
)
|
||||
|
||||
normalized.append(
|
||||
CompactShortcutButton(
|
||||
id=row_id,
|
||||
label=label,
|
||||
url=url,
|
||||
route_params=route_params,
|
||||
enabled=bool(item.enabled),
|
||||
sort_order=index,
|
||||
)
|
||||
)
|
||||
return normalized
|
||||
|
||||
|
||||
def _appearance_response(appearance) -> AppearanceResponse:
|
||||
@@ -552,6 +611,10 @@ def _appearance_response(appearance) -> AppearanceResponse:
|
||||
default_skill_view=appearance.default_skill_view,
|
||||
default_agent_view=appearance.default_agent_view,
|
||||
default_layout_mode=appearance.default_layout_mode,
|
||||
compact_shortcut_buttons=sorted(
|
||||
appearance.compact_shortcut_buttons,
|
||||
key=lambda item: item.sort_order,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -574,6 +637,10 @@ async def update_appearance_settings(
|
||||
for key in ("default_theme", "default_skill_view", "default_agent_view", "default_layout_mode"):
|
||||
if key in fields and fields[key] is not None:
|
||||
update[key] = fields[key]
|
||||
if "compact_shortcut_buttons" in fields and body.compact_shortcut_buttons is not None:
|
||||
update["compact_shortcut_buttons"] = _normalize_compact_shortcut_buttons(
|
||||
body.compact_shortcut_buttons
|
||||
)
|
||||
if update:
|
||||
updated_appearance = current.appearance.model_copy(update=update)
|
||||
saved = save_system_settings(
|
||||
|
||||
Reference in new issue
Block a user