Skip to content

PRINTFILM: AI short-video marketing and AI short-drama creation platform

Admin: update UI for drama tasks

yi338303564dc8
diff --git a/admin/src/App.tsx b/admin/src/App.tsx
index 2c80a82..08a192e 100644
--- a/admin/src/App.tsx
+++ b/admin/src/App.tsx
@@ -7,6 +7,7 @@ import { OrdersPage } from "@/pages/OrdersPage";
import { ProjectsPage } from "@/pages/ProjectsPage";
import { DramaProjectsPage } from "@/pages/DramaProjectsPage";
import { QueuesPage } from "@/pages/QueuesPage";
+import { SettingsPage } from "@/pages/SettingsPage";
import { TemplatesPage } from "@/pages/TemplatesPage";
import { UsersPage } from "@/pages/UsersPage";
import { WorksPage } from "@/pages/WorksPage";
@@ -36,6 +37,7 @@ export default function App() {
<Route path="works" element={<WorksPage />} />
<Route path="templates" element={<TemplatesPage />} />
<Route path="queues" element={<QueuesPage />} />
+ <Route path="settings" element={<SettingsPage />} />
</Route>
</Route>
<Route path="*" element={<Navigate to="/" replace />} />
diff --git a/admin/src/api/client.ts b/admin/src/api/client.ts
index 6462dcc..240d4fc 100644
--- a/admin/src/api/client.ts
+++ b/admin/src/api/client.ts
@@ -152,7 +152,6 @@ export type AdminQueueTask = {
args_repr: string;
queue: string;
state: string;
- worker?: string | null;
started_at?: number | null;
ref_id?: number | null;
position?: number | null;
@@ -165,59 +164,254 @@ export type AdminQueueSummary = {
sample: AdminQueueTask[];
};
-export type AdminWorkerRow = {
- name: string;
- status: string;
- active_count: number;
- processed?: number | null;
- pool?: string | null;
-};
-
-export type AdminWorkerControl = {
- mode: string;
- systemd_unit?: string | null;
- systemd_active?: boolean | null;
- pools: Array<{
- name: string;
- pool_implementation?: string;
- max_concurrency?: number | null;
- process_count?: number | null;
- }>;
- total_processes: number;
- max_concurrency?: number | null;
- pool_max_limit: number;
- can_pool_grow: boolean;
- can_pool_shrink: boolean;
- can_restart: boolean;
- autoscale_running: boolean;
- autoscale_enabled: boolean;
- autoscale_pid?: number | null;
- autoscale_workers: number;
- bounds_min: number;
- bounds_max: number;
- bounds_source: string;
-};
-
export type AdminQueuesSnapshot = {
ok: boolean;
redis_ok: boolean;
- use_celery: boolean;
- worker_queues: string;
unacked: number;
total_pending: number;
active_count: number;
reserved_count: number;
- workers_online: number;
queues: AdminQueueSummary[];
pending_tasks: AdminQueueTask[];
active_tasks: AdminQueueTask[];
reserved_tasks: AdminQueueTask[];
- workers: AdminWorkerRow[];
- worker_control?: AdminWorkerControl | null;
- autoscale: Record<string, number>;
+ runtime: Record<string, number | string>;
fetched_at: string;
};
+export type AdminTaskRow = {
+ id: number;
+ domain: string;
+ task_type: string;
+ status: string;
+ priority: number;
+ requested_by: number;
+ user_email?: string | null;
+ progress_percent: number;
+ cancel_requested: boolean;
+ cancelable: boolean;
+ current_step_key?: string | null;
+ current_step_status?: string | null;
+ error_message?: string | null;
+ project_id?: number | null;
+ drama_project_id?: number | null;
+ episode_id?: number | null;
+ fragment_id?: number | null;
+ created_at?: string | null;
+ started_at?: string | null;
+ finished_at?: string | null;
+};
+
+export type AdminTaskStep = {
+ id: number;
+ step_key: string;
+ step_type: string;
+ status: string;
+ attempt_count: number;
+ provider_name?: string | null;
+ provider_task_id?: string | null;
+ error_message?: string | null;
+ started_at?: string | null;
+ finished_at?: string | null;
+};
+
+export type AdminTaskEvent = {
+ id: number;
+ event_type: string;
+ status?: string | null;
+ phase?: string | null;
+ message?: string | null;
+ payload?: Record<string, unknown> | null;
+ created_at?: string | null;
+};
+
+export type AdminTaskDetail = AdminTaskRow & {
+ client_request_id?: string | null;
+ dedupe_key?: string | null;
+ batch_key?: string | null;
+ provider_task_id?: string | null;
+ scheduled_at?: string | null;
+ next_action_at?: string | null;
+ lease_until?: string | null;
+ error_code?: string | null;
+ payload?: Record<string, unknown> | null;
+ result_payload?: Record<string, unknown> | null;
+ script_id?: number | null;
+ asset_id?: number | null;
+ shot_id?: number | null;
+ updated_at?: string | null;
+ steps: AdminTaskStep[];
+ events: AdminTaskEvent[];
+ targets: Array<{ id: number; target_type: string; target_id: number }>;
+};
+
+export type AdminTaskStats = {
+ pending_count: number;
+ active_count: number;
+ leased_count: number;
+ running_count: number;
+ awaiting_poll_count: number;
+ cancel_requested_count: number;
+ succeeded_count: number;
+ failed_count: number;
+ cancelled_count: number;
+ scheduler_running_jobs: number;
+ max_concurrency: number;
+ domains: Array<{
+ domain: string;
+ pending: number;
+ active: number;
+ succeeded: number;
+ failed: number;
+ cancelled: number;
+ }>;
+ fetched_at?: string | null;
+};
+
+export type AdminTaskListRes = {
+ items: AdminTaskRow[];
+ meta: PageMeta;
+};
+
+export type ModelCapabilityReadiness = {
+ capability: string;
+ label: string;
+ model: string;
+ ready: boolean;
+ message: string;
+};
+
+export type AdminModelSettings = {
+ openai_api_key: string;
+ openai_base_url: string;
+ model_llm: string;
+ has_openai_api_key: boolean;
+ ark_api_key: string;
+ ark_base_url: string;
+ model_image: string;
+ model_image_45: string;
+ model_video: string;
+ model_audio: string;
+ has_ark_api_key: boolean;
+ volc_tts_app_id: string;
+ volc_tts_access_key: string;
+ volc_tts_api_key: string;
+ volc_tts_resource_id: string;
+ volc_tts_speaker: string;
+ volc_tts_url: string;
+ volc_tts_voice_design_url: string;
+ volc_tts_voice_design_speaker_ids: string;
+ has_volc_tts_access_key: boolean;
+ has_volc_tts_api_key: boolean;
+ ark_image_size: string;
+ ark_video_resolution: string;
+ ark_video_ratio: string;
+ seedance_duration_min: number;
+ seedance_duration_max: number;
+ ark_video_poll_interval: number;
+ ark_video_poll_timeout: number;
+ pipeline_image_concurrency: number;
+ pipeline_video_concurrency: number;
+ pipeline_audio_concurrency: number;
+ task_runtime_max_concurrency: number;
+ task_user_max_concurrency: number;
+ task_poll_max_concurrency: number;
+ drama_user_video_job_limit: number;
+ drama_fragment_max_attempts: number;
+ ark_mock: boolean;
+ oss_enabled: boolean;
+ oss_endpoint: string;
+ oss_region: string;
+ oss_bucket: string;
+ oss_folder: string;
+ oss_access_key_id: string;
+ oss_access_key_secret: string;
+ oss_public_base: string;
+ oss_upload_async: boolean;
+ oss_upload_queue: string;
+ has_oss_access_key_id: boolean;
+ has_oss_access_key_secret: boolean;
+ tos_endpoint: string;
+ tos_bucket: string;
+ tos_access_key: string;
+ tos_secret_key: string;
+ has_tos_access_key: boolean;
+ has_tos_secret_key: boolean;
+ cdn_base: string;
+ epay_api_url: string;
+ epay_pid: string;
+ epay_key: string;
+ epay_notify_url: string;
+ epay_return_url: string;
+ has_epay_key: boolean;
+ billing_enabled: boolean;
+ billing_markup: number;
+ billing_estimate_buffer: number;
+ billing_seedance_video0: number;
+ billing_seedance_video1: number;
+ billing_llm_per_m: number;
+ billing_seedream_per_m: number;
+ billing_tts_per_m: number;
+ billing_est_llm_tokens: number;
+ billing_est_seedream_tokens: number;
+ billing_est_tts_tokens: number;
+ billing_est_seedance_tokens_per_sec: number;
+ billing_signup_grant_fen: number;
+ quota_enabled: boolean;
+ new_user_quota: number;
+ public_base_url: string;
+ ffmpeg_path: string;
+ ffprobe_path: string;
+ source: string;
+ updated_at?: string | null;
+ readiness: ModelCapabilityReadiness[];
+};
+
+export type AdminRoutingChannel = {
+ id: string;
+ name: string;
+ base_url: string;
+ api_key: string;
+ has_api_key: boolean;
+ api_format: "openai" | "ark";
+ protocol: "auto" | "openai" | "ark" | "volc_tts";
+ models: string[];
+ enabled: boolean;
+ sort_order: number;
+};
+
+export type AdminLogicalModelBinding = {
+ id: string;
+ channel_id: string;
+ upstream_model: string;
+ enabled: boolean;
+ priority: number;
+ weight?: number | null;
+};
+
+export type AdminLogicalModel = {
+ id: string;
+ name: string;
+ capability: "text" | "image" | "video" | "audio";
+ enabled: boolean;
+ bindings: AdminLogicalModelBinding[];
+};
+
+export type AdminDefaultModels = {
+ text_model: string;
+ image_model: string;
+ video_model: string;
+ audio_model: string;
+};
+
+export type AdminRoutingSettings = {
+ system_channels: AdminRoutingChannel[];
+ logical_models: AdminLogicalModel[];
+ default_models: AdminDefaultModels;
+ validation_errors: string[];
+ updated_at?: string | null;
+};
+
export type AdminTemplate = {
id: string;
name: string;
diff --git a/admin/src/components/PaginationBar.tsx b/admin/src/components/PaginationBar.tsx
index 557d752..a259b9e 100644
--- a/admin/src/components/PaginationBar.tsx
+++ b/admin/src/components/PaginationBar.tsx
@@ -31,22 +31,19 @@ export function PaginationBar({
return (
<div
- className={cn(
- "flex flex-wrap items-center justify-between gap-3 rounded-xl bg-[#fafbfc] px-3 py-2.5 text-sm text-[#909399]",
- className,
- )}
+ className={cn("admin-pagination", className)}
>
<div className="flex flex-wrap items-center gap-3">
<span>
- 共 <em className="not-italic font-semibold text-[#303133]">{total}</em> 条
- <span className="mx-1.5 text-[#dcdfe6]">·</span>
+ 共 <em className="not-italic font-semibold text-[var(--admin-text)]">{total}</em> 条
+ <span className="mx-1.5 text-[var(--admin-border)]">·</span>
{from}-{to}
</span>
{onPageSizeChange && (
<label className="flex items-center gap-1.5 text-xs">
<span>每页</span>
<select
- className="h-7 rounded-md border border-[#dcdfe6] bg-white px-1.5 text-[#606266] outline-none focus:border-[#67c23a]"
+ className="admin-select !h-7 !min-w-[4rem] !text-xs"
value={pageSize}
onChange={(e) => onPageSizeChange(Number(e.target.value))}
>
diff --git a/admin/src/components/admin/AdminChipFilter.tsx b/admin/src/components/admin/AdminChipFilter.tsx
new file mode 100644
index 0000000..0ab68b3
--- /dev/null
+++ b/admin/src/components/admin/AdminChipFilter.tsx
@@ -0,0 +1,44 @@
+import { cn } from "@/lib/utils";
+
+export type AdminChipOption = {
+ value: string;
+ label: string;
+ count?: number;
+};
+
+type AdminChipFilterProps = {
+ label?: string;
+ value: string;
+ options: AdminChipOption[];
+ onChange: (value: string) => void;
+ className?: string;
+};
+
+// 管理端分类 Chip 筛选
+export function AdminChipFilter({ label, value, options, onChange, className }: AdminChipFilterProps) {
+ return (
+ <div className={cn("admin-chip-filter", className)}>
+ {label ? <span className="admin-chip-filter-label">{label}</span> : null}
+ <div className="admin-chip-filter-list" role="tablist">
+ {options.map((opt) => {
+ const active = value === opt.value;
+ return (
+ <button
+ key={opt.value || "__all"}
+ type="button"
+ role="tab"
+ aria-selected={active}
+ className={cn("admin-chip", active && "is-active")}
+ onClick={() => onChange(opt.value)}
+ >
+ {opt.label}
+ {typeof opt.count === "number" ? (
+ <span className="admin-chip-count">{opt.count}</span>
+ ) : null}
+ </button>
+ );
+ })}
+ </div>
+ </div>
+ );
+}
diff --git a/admin/src/components/admin/AdminConfirmDialog.tsx b/admin/src/components/admin/AdminConfirmDialog.tsx
new file mode 100644
index 0000000..f222840
--- /dev/null
+++ b/admin/src/components/admin/AdminConfirmDialog.tsx
@@ -0,0 +1,53 @@
+import { Loader2 } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { AdminModal } from "@/components/admin/AdminModal";
+
+type AdminConfirmDialogProps = {
+ open: boolean;
+ title: string;
+ description?: string;
+ confirmLabel?: string;
+ cancelLabel?: string;
+ loading?: boolean;
+ destructive?: boolean;
+ onOpenChange: (open: boolean) => void;
+ onConfirm: () => void;
+};
+
+// 管理端确认弹窗(删除等二次确认)
+export function AdminConfirmDialog({
+ open,
+ title,
+ description,
+ confirmLabel = "确认",
+ cancelLabel = "取消",
+ loading = false,
+ destructive = false,
+ onOpenChange,
+ onConfirm,
+}: AdminConfirmDialogProps) {
+ return (
+ <AdminModal
+ open={open}
+ onOpenChange={onOpenChange}
+ size="md"
+ title={title}
+ subtitle={description}
+ footer={
+ <>
+ <Button variant="outline" disabled={loading} onClick={() => onOpenChange(false)}>
+ {cancelLabel}
+ </Button>
+ <Button
+ variant={destructive ? "destructive" : "default"}
+ disabled={loading}
+ onClick={onConfirm}
+ >
+ {loading ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : null}
+ {confirmLabel}
+ </Button>
+ </>
+ }
+ />
+ );
+}
diff --git a/admin/src/components/admin/AdminField.tsx b/admin/src/components/admin/AdminField.tsx
new file mode 100644
index 0000000..e6298f6
--- /dev/null
+++ b/admin/src/components/admin/AdminField.tsx
@@ -0,0 +1,20 @@
+import type { ReactNode } from "react";
+import { cn } from "@/lib/utils";
+
+type AdminFieldProps = {
+ label?: string;
+ hint?: string;
+ className?: string;
+ children: ReactNode;
+};
+
+// 管理端表单字段:标签 + 控件 + 可选说明
+export function AdminField({ label, hint, className, children }: AdminFieldProps) {
+ return (
+ <div className={cn("admin-field", className)}>
+ {label ? <label className="admin-field-label">{label}</label> : null}
+ {children}
+ {hint ? <p className="admin-field-hint">{hint}</p> : null}
+ </div>
+ );
+}
diff --git a/admin/src/components/admin/AdminFilterBar.tsx b/admin/src/components/admin/AdminFilterBar.tsx
new file mode 100644
index 0000000..173d532
--- /dev/null
+++ b/admin/src/components/admin/AdminFilterBar.tsx
@@ -0,0 +1,18 @@
+import type { ReactNode } from "react";
+import { cn } from "@/lib/utils";
+
+type AdminFilterBarProps = {
+ children: ReactNode;
+ trailing?: ReactNode;
+ className?: string;
+};
+
+// 管理端列表筛选条容器
+export function AdminFilterBar({ children, trailing, className }: AdminFilterBarProps) {
+ return (
+ <div className={cn("admin-filter-panel", className)}>
+ <div className="admin-filter-panel-main">{children}</div>
+ {trailing ? <div className="admin-filter-panel-trailing">{trailing}</div> : null}
+ </div>
+ );
+}
diff --git a/admin/src/components/admin/AdminModal.tsx b/admin/src/components/admin/AdminModal.tsx
new file mode 100644
index 0000000..ed1dea3
--- /dev/null
+++ b/admin/src/components/admin/AdminModal.tsx
@@ -0,0 +1,50 @@
+import type { ReactNode } from "react";
+import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import { cn } from "@/lib/utils";
+
+type AdminModalSize = "md" | "lg" | "xl" | "full";
+
+type AdminModalProps = {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ title: ReactNode;
+ subtitle?: ReactNode;
+ children?: ReactNode;
+ footer?: ReactNode;
+ size?: AdminModalSize;
+ className?: string;
+ bodyClassName?: string;
+};
+
+const SIZE_CLASS: Record<AdminModalSize, string> = {
+ md: "admin-modal--md",
+ lg: "admin-modal--lg",
+ xl: "admin-modal--xl",
+ full: "admin-modal--full",
+};
+
+// 管理端统一弹窗壳(标题 / 内容 / 底栏)
+export function AdminModal({
+ open,
+ onOpenChange,
+ title,
+ subtitle,
+ children,
+ footer,
+ size = "lg",
+ className,
+ bodyClassName,
+}: AdminModalProps) {
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent className={cn("admin-modal", SIZE_CLASS[size], className)}>
+ <DialogHeader className="admin-modal-header">
+ <DialogTitle className="admin-modal-title">{title}</DialogTitle>
+ {subtitle ? <p className="admin-modal-subtitle">{subtitle}</p> : null}
+ </DialogHeader>
+ {children ? <div className={cn("admin-modal-body", bodyClassName)}>{children}</div> : null}
+ {footer ? <div className="admin-modal-footer">{footer}</div> : null}
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/admin/src/components/admin/AdminSearchInput.tsx b/admin/src/components/admin/AdminSearchInput.tsx
new file mode 100644
index 0000000..3819a2e
--- /dev/null
+++ b/admin/src/components/admin/AdminSearchInput.tsx
@@ -0,0 +1,35 @@
+import { cn } from "@/lib/utils";
+
+type AdminSearchInputProps = {
+ value: string;
+ onChange: (value: string) => void;
+ placeholder?: string;
+ className?: string;
+};
+
+// 管理端搜索框(带图标)
+export function AdminSearchInput({
+ value,
+ onChange,
+ placeholder = "搜索…",
+ className,
+}: AdminSearchInputProps) {
+ return (
+ <div className={cn("admin-input-search-wrap", className)}>
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" aria-hidden>
+ <path
+ d="M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm10 2-4.35-4.35"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ />
+ </svg>
+ <input
+ className="admin-input"
+ placeholder={placeholder}
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ />
+ </div>
+ );
+}
diff --git a/admin/src/components/admin/AdminSelect.tsx b/admin/src/components/admin/AdminSelect.tsx
new file mode 100644
index 0000000..fefb0ab
--- /dev/null
+++ b/admin/src/components/admin/AdminSelect.tsx
@@ -0,0 +1,52 @@
+import { cn } from "@/lib/utils";
+import { AdminField } from "@/components/admin/AdminField";
+
+export type AdminSelectOption = {
+ value: string;
+ label: string;
+};
+
+type AdminSelectProps = {
+ label?: string;
+ hint?: string;
+ value: string;
+ options: AdminSelectOption[];
+ placeholder?: string;
+ className?: string;
+ onChange: (value: string) => void;
+};
+
+// 管理端下拉选择(统一样式)
+export function AdminSelect({
+ label,
+ hint,
+ value,
+ options,
+ placeholder,
+ className,
+ onChange,
+}: AdminSelectProps) {
+ const control = (
+ <div className={cn("admin-select-wrap", className)}>
+ <select
+ className="admin-select"
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ >
+ {placeholder ? <option value="">{placeholder}</option> : null}
+ {options.map((opt) => (
+ <option key={opt.value || "__empty"} value={opt.value}>
+ {opt.label}
+ </option>
+ ))}
+ </select>
+ </div>
+ );
+
+ if (!label && !hint) return control;
+ return (
+ <AdminField label={label} hint={hint}>
+ {control}
+ </AdminField>
+ );
+}
diff --git a/admin/src/components/admin/PageSection.tsx b/admin/src/components/admin/PageSection.tsx
new file mode 100644
index 0000000..f41fb49
--- /dev/null
+++ b/admin/src/components/admin/PageSection.tsx
@@ -0,0 +1,34 @@
+import type { ReactNode } from "react";
+import { cn } from "@/lib/utils";
+
+type PageSectionProps = {
+ title: string;
+ description?: string;
+ actions?: ReactNode;
+ children: ReactNode;
+ className?: string;
+ bodyClassName?: string;
+};
+
+// 带标题的内容区块(白底卡片)
+export function PageSection({
+ title,
+ description,
+ actions,
+ children,
+ className,
+ bodyClassName,
+}: PageSectionProps) {
+ return (
+ <section className={cn("admin-panel admin-section", className)}>
+ <div className="admin-section-header">
+ <div>
+ <h3 className="admin-section-title">{title}</h3>
+ {description ? <p className="admin-section-desc">{description}</p> : null}
+ </div>
+ {actions ? <div className="admin-section-actions">{actions}</div> : null}
+ </div>
+ <div className={cn("admin-section-body", bodyClassName)}>{children}</div>
+ </section>
+ );
+}
diff --git a/admin/src/components/admin/StatCard.tsx b/admin/src/components/admin/StatCard.tsx
new file mode 100644
index 0000000..872f446
--- /dev/null
+++ b/admin/src/components/admin/StatCard.tsx
@@ -0,0 +1,26 @@
+import type { LucideIcon } from "lucide-react";
+import type { ReactNode } from "react";
+import { cn } from "@/lib/utils";
+
+type StatCardProps = {
+ label: string;
+ value: ReactNode;
+ hint?: string;
+ icon: LucideIcon;
+ tone?: "default" | "success" | "info" | "warn";
+ className?: string;
+};
+
+// 仪表盘 / 任务中心统计卡片
+export function StatCard({ label, value, hint, icon: Icon, tone = "default", className }: StatCardProps) {
+ return (
+ <div className={cn("admin-panel admin-stat-card", `tone-${tone}`, className)}>
+ <div className="admin-stat-icon">
+ <Icon className="h-5 w-5" />
+ </div>
+ <div className="admin-stat-label">{label}</div>
+ <div className="admin-stat-value">{value}</div>
+ {hint ? <div className="admin-stat-hint">{hint}</div> : null}
+ </div>
+ );
+}
diff --git a/admin/src/components/layout/AdminLayout.tsx b/admin/src/components/layout/AdminLayout.tsx
index f68c6c7..d06eb4f 100644
--- a/admin/src/components/layout/AdminLayout.tsx
+++ b/admin/src/components/layout/AdminLayout.tsx
@@ -1,137 +1,353 @@
import { useState } from "react";
+
import { NavLink, Outlet, useLocation, useNavigate } from "react-router-dom";
+
import {
+
Bell,
+
Clapperboard,
+
FileVideo,
+
Film,
+
Layers,
+
LayoutDashboard,
+
LogOut,
+
Maximize2,
+
Menu,
+
Receipt,
+
+ Settings,
+
Shapes,
+
Users,
+
} from "lucide-react";
+
import { clearAuth, getCachedUser } from "@/lib/auth";
+
import { cn } from "@/lib/utils";
-const navItems = [
- { to: "/", label: "仪表盘", icon: LayoutDashboard, end: true },
- { to: "/users", label: "用户管理", icon: Users },
- { to: "/orders", label: "订单流水", icon: Receipt },
- { to: "/projects", label: "项目管理", icon: Clapperboard },
- { to: "/drama-projects", label: "漫剧项目", icon: Film },
- { to: "/works", label: "作品审核", icon: FileVideo },
- { to: "/templates", label: "模板管理", icon: Shapes },
- { to: "/queues", label: "队列任务", icon: Layers },
+
+
+type NavItem = {
+
+ to: string;
+
+ label: string;
+
+ icon: typeof LayoutDashboard;
+
+ end?: boolean;
+
+};
+
+
+
+type NavGroup = {
+
+ label: string;
+
+ items: NavItem[];
+
+};
+
+
+
+const navGroups: NavGroup[] = [
+
+ {
+
+ label: "概览",
+
+ items: [{ to: "/", label: "仪表盘", icon: LayoutDashboard, end: true }],
+
+ },
+
+ {
+
+ label: "业务",
+
+ items: [
+
+ { to: "/users", label: "用户管理", icon: Users },
+
+ { to: "/orders", label: "订单流水", icon: Receipt },
+
+ { to: "/projects", label: "项目管理", icon: Clapperboard },
+
+ { to: "/drama-projects", label: "漫剧项目", icon: Film },
+
+ { to: "/works", label: "作品审核", icon: FileVideo },
+
+ ],
+
+ },
+
+ {
+
+ label: "资源",
+
+ items: [
+
+ { to: "/templates", label: "模板管理", icon: Shapes },
+
+ { to: "/queues", label: "任务中心", icon: Layers },
+
+ ],
+
+ },
+
+ {
+
+ label: "系统",
+
+ items: [{ to: "/settings", label: "系统设置", icon: Settings }],
+
+ },
+
];
+
+
const titles: Record<string, string> = {
+
"/": "仪表盘",
+
"/users": "用户管理",
+
"/orders": "订单流水",
+
"/projects": "项目管理",
+
"/drama-projects": "漫剧项目",
+
"/works": "作品审核",
+
"/templates": "模板管理",
- "/queues": "队列任务",
+
+ "/settings": "系统设置",
+
+ "/queues": "任务中心",
+
};
-// Admin shell: sidebar + top bar matching ops console design
+
+
+// Admin shell: dark sidebar + glass top bar
+
export function AdminLayout() {
+
const navigate = useNavigate();
+
const location = useLocation();
+
const user = getCachedUser();
+
/*
+
* collapsed sidebar collapsed state
+
*/
+
const [collapsed, setCollapsed] = useState(false);
+
+
// Logout and return to login
+
function handleLogout() {
+
clearAuth();
+
navigate("/login");
+
}
+
+
const title = titles[location.pathname] ?? "管理后台";
+
const initial = (user?.nickname || user?.email || "A").slice(0, 1).toUpperCase();
+
+
return (
+
<div className={cn("admin-app", collapsed && "is-collapsed")}>
+
<aside className="admin-sidebar">
+
<div className="admin-brand">
+
<div className="admin-brand-mark">PF</div>
+
{!collapsed && (
+
<div>
+
<div className="admin-brand-name">PRINTFILM</div>
+
<div className="admin-brand-sub">管理后台</div>
+
</div>
+
)}
+
</div>
+
<nav className="admin-nav">
- {navItems.map((item) => (
- <NavLink
- key={item.to}
- to={item.to}
- end={item.end}
- className={({ isActive }) => cn("admin-nav-item", isActive && "is-active")}
- title={item.label}
- >
- <item.icon className="h-[18px] w-[18px] shrink-0" />
- {!collapsed && <span>{item.label}</span>}
- </NavLink>
+
+ {navGroups.map((group) => (
+
+ <div key={group.label} className="admin-nav-group">
+
+ {!collapsed ? <div className="admin-nav-group-label">{group.label}</div> : null}
+
+ {group.items.map((item) => (
+
+ <NavLink
+
+ key={item.to}
+
+ to={item.to}
+
+ end={item.end}
+
+ className={({ isActive }) => cn("admin-nav-item", isActive && "is-active")}
+
+ title={item.label}
+
+ >
+
+ <item.icon className="h-[18px] w-[18px] shrink-0" />
+
+ {!collapsed && <span>{item.label}</span>}
+
+ </NavLink>
+
+ ))}
+
+ </div>
+
))}
+
</nav>
+
<div className="admin-user-card">
+
<div className="admin-avatar">{initial}</div>
+
{!collapsed && (
+
<div className="min-w-0 flex-1">
- <div className="truncate text-[13px] font-medium text-[#303133]">{user?.email}</div>
- <div className="text-xs text-[#909399]">超级管理员</div>
+
+ <div className="truncate text-[13px] font-medium text-[#e8f0eb]">{user?.email}</div>
+
+ <div className="text-xs text-[rgba(240,245,242,0.45)]">超级管理员</div>
+
</div>
+
)}
- <button type="button" className="admin-icon-btn" onClick={handleLogout} title="退出登录">
+
+ <button type="button" className="admin-icon-btn !text-[rgba(240,245,242,0.55)] hover:!text-[#e8f0eb]" onClick={handleLogout} title="退出登录">
+
<LogOut className="h-4 w-4" />
+
</button>
+
</div>
+
</aside>
+
+
<div className="admin-main">
+
<header className="admin-topbar">
+
<div className="flex items-center gap-3">
+
<button
+
type="button"
+
className="admin-icon-btn"
+
onClick={() => setCollapsed((v) => !v)}
+
aria-label="折叠侧栏"
+
>
+
<Menu className="h-4 w-4" />
+
</button>
- <h1 className="text-base font-semibold text-[#303133]">{title}</h1>
+
+ <div>
+
+ <div className="admin-topbar-title">{title}</div>
+
+ <div className="admin-topbar-crumb">PRINTFILM · 运营管理</div>
+
+ </div>
+
</div>
+
<div className="flex items-center gap-1">
+
<button type="button" className="admin-icon-btn" title="通知">
+
<Bell className="h-4 w-4" />
+
</button>
+
<button
+
type="button"
+
className="admin-icon-btn"
+
title="全屏"
+
onClick={() => {
+
if (!document.fullscreenElement) void document.documentElement.requestFullscreen();
+
else void document.exitFullscreen();
+
}}
+
>
+
<Maximize2 className="h-4 w-4" />
+
</button>
+
</div>
+
</header>
+
<main className="admin-content">
+
<Outlet />
+
</main>
+
</div>
+
</div>
+
);
+
}
+
+
diff --git a/admin/src/components/settings/OssSettingsPanel.tsx b/admin/src/components/settings/OssSettingsPanel.tsx
new file mode 100644
index 0000000..c92e589
--- /dev/null
+++ b/admin/src/components/settings/OssSettingsPanel.tsx
@@ -0,0 +1,240 @@
+import { useMemo, useState } from "react";
+import { Cloud, Loader2, Save } from "lucide-react";
+import { LabeledControl, SectionTitle, SettingsPanel, SettingsSurface } from "@/components/settings/SettingsPanel";
+import { SecretField } from "@/components/settings/SecretField";
+import { Switch } from "@/components/ui/switch";
+import { useAdminModelSettings } from "@/hooks/useAdminModelSettings";
+import { cn } from "@/lib/utils";
+
+// OSS / TOS / CDN 存储配置
+export function OssSettingsPanel() {
+ const { form, loading, saving, patchField, save } = useAdminModelSettings();
+ const [ossKeyIdInput, setOssKeyIdInput] = useState("");
+ const [ossKeySecretInput, setOssKeySecretInput] = useState("");
+ const [tosKeyInput, setTosKeyInput] = useState("");
+ const [tosSecretInput, setTosSecretInput] = useState("");
+ const [clearOssId, setClearOssId] = useState(false);
+ const [clearOssSecret, setClearOssSecret] = useState(false);
+ const [clearTosKey, setClearTosKey] = useState(false);
+ const [clearTosSecret, setClearTosSecret] = useState(false);
+
+ const ossReady = useMemo(() => {
+ if (!form?.oss_enabled) return false;
+ const hasCreds =
+ (form.has_oss_access_key_id && !clearOssId) || ossKeyIdInput.trim().length > 0;
+ const hasSecret =
+ (form.has_oss_access_key_secret && !clearOssSecret) || ossKeySecretInput.trim().length > 0;
+ return Boolean(form.oss_bucket && hasCreds && hasSecret);
+ }, [form, clearOssId, clearOssSecret, ossKeyIdInput, ossKeySecretInput]);
+
+ async function handleSave() {
+ if (!form) return;
+ await save(
+ {
+ oss_enabled: form.oss_enabled,
+ oss_endpoint: form.oss_endpoint,
+ oss_region: form.oss_region,
+ oss_bucket: form.oss_bucket,
+ oss_folder: form.oss_folder,
+ oss_public_base: form.oss_public_base,
+ oss_upload_async: form.oss_upload_async,
+ oss_upload_queue: form.oss_upload_queue,
+ oss_access_key_id: ossKeyIdInput.trim() || undefined,
+ oss_access_key_secret: ossKeySecretInput.trim() || undefined,
+ clear_oss_access_key_id: clearOssId,
+ clear_oss_access_key_secret: clearOssSecret,
+ tos_endpoint: form.tos_endpoint,
+ tos_bucket: form.tos_bucket,
+ tos_access_key: tosKeyInput.trim() || undefined,
+ tos_secret_key: tosSecretInput.trim() || undefined,
+ clear_tos_access_key: clearTosKey,
+ clear_tos_secret_key: clearTosSecret,
+ cdn_base: form.cdn_base,
+ },
+ "存储配置已保存",
+ );
+ setOssKeyIdInput("");
+ setOssKeySecretInput("");
+ setTosKeyInput("");
+ setTosSecretInput("");
+ setClearOssId(false);
+ setClearOssSecret(false);
+ setClearTosKey(false);
+ setClearTosSecret(false);
+ }
+
+ if (loading || !form) {
+ return (
+ <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ <Loader2 className="mr-2 h-5 w-5 animate-spin" />
+ 加载中…
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-5">
+ <div className="flex flex-wrap items-end justify-between gap-3">
+ <div>
+ <h2 className="text-xl font-semibold text-[#303133]">存储与 CDN</h2>
+ <p className="mt-1 text-sm text-[#909399]">阿里云 OSS 成片上传;TOS / CDN 为可选扩展</p>
+ </div>
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ disabled={saving}
+ onClick={() => void handleSave()}
+ >
+ {saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ 保存
+ </button>
+ </div>
+
+ <SettingsSurface>
+ <SectionTitle icon={<Cloud className="h-4 w-4" />} title="OSS 状态" />
+ <div className="mt-4 flex flex-wrap items-center gap-3">
+ <span className={cn("admin-status-pill", ossReady ? "is-done" : form.oss_enabled ? "is-warn" : "")}>
+ {form.oss_enabled ? (ossReady ? "OSS 已就绪" : "已启用但凭证不完整") : "OSS 未启用"}
+ </span>
+ <span className="text-xs text-[#909399]">配置来源:{form.source === "db" ? "管理端" : "环境变量"}</span>
+ </div>
+ </SettingsSurface>
+
+ <SettingsPanel title="阿里云 OSS" description="生成文件先落本地 /static,再异步上传 OSS 并回填 URL。">
+ <SettingsSurface>
+ <div className="settings-toggle-row">
+ <div>
+ <strong>启用 OSS</strong>
+ <span>关闭后仅使用本地静态目录</span>
+ </div>
+ <Switch checked={form.oss_enabled} onCheckedChange={(v) => patchField("oss_enabled", v)} />
+ </div>
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="Endpoint">
+ <input
+ className="settings-input"
+ placeholder="oss-cn-beijing.aliyuncs.com"
+ value={form.oss_endpoint}
+ onChange={(e) => patchField("oss_endpoint", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="Region">
+ <input
+ className="settings-input"
+ placeholder="cn-hangzhou"
+ value={form.oss_region}
+ onChange={(e) => patchField("oss_region", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="Bucket">
+ <input
+ className="settings-input"
+ value={form.oss_bucket}
+ onChange={(e) => patchField("oss_bucket", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="目录前缀">
+ <input
+ className="settings-input"
+ placeholder="kepu"
+ value={form.oss_folder}
+ onChange={(e) => patchField("oss_folder", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="公网访问基址" hint="留空则自动拼 https://{bucket}.{endpoint}">
+ <input
+ className="settings-input"
+ placeholder="https://cdn.example.com"
+ value={form.oss_public_base}
+ onChange={(e) => patchField("oss_public_base", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="上传队列名">
+ <input
+ className="settings-input"
+ value={form.oss_upload_queue}
+ onChange={(e) => patchField("oss_upload_queue", e.target.value)}
+ />
+ </LabeledControl>
+ <SecretField
+ label="AccessKey ID"
+ value={ossKeyIdInput}
+ configured={form.has_oss_access_key_id && !clearOssId}
+ onChange={setOssKeyIdInput}
+ onClear={() => {
+ setOssKeyIdInput("");
+ setClearOssId(true);
+ }}
+ />
+ <SecretField
+ label="AccessKey Secret"
+ value={ossKeySecretInput}
+ configured={form.has_oss_access_key_secret && !clearOssSecret}
+ onChange={setOssKeySecretInput}
+ onClear={() => {
+ setOssKeySecretInput("");
+ setClearOssSecret(true);
+ }}
+ />
+ </div>
+ <div className="settings-toggle-row mt-4">
+ <div>
+ <strong>异步上传</strong>
+ <span>先返回本地 URL,后台队列上传 OSS</span>
+ </div>
+ <Switch checked={form.oss_upload_async} onCheckedChange={(v) => patchField("oss_upload_async", v)} />
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+
+ <SettingsPanel title="火山 TOS(可选)" description="历史存储方案,新项目可只配 OSS。">
+ <SettingsSurface>
+ <div className="settings-field-grid">
+ <LabeledControl label="Endpoint">
+ <input
+ className="settings-input"
+ value={form.tos_endpoint}
+ onChange={(e) => patchField("tos_endpoint", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="Bucket">
+ <input
+ className="settings-input"
+ value={form.tos_bucket}
+ onChange={(e) => patchField("tos_bucket", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="CDN 基址">
+ <input
+ className="settings-input"
+ placeholder="http://localhost:8000/static"
+ value={form.cdn_base}
+ onChange={(e) => patchField("cdn_base", e.target.value)}
+ />
+ </LabeledControl>
+ <SecretField
+ label="TOS Access Key"
+ value={tosKeyInput}
+ configured={form.has_tos_access_key && !clearTosKey}
+ onChange={setTosKeyInput}
+ onClear={() => {
+ setTosKeyInput("");
+ setClearTosKey(true);
+ }}
+ />
+ <SecretField
+ label="TOS Secret Key"
+ value={tosSecretInput}
+ configured={form.has_tos_secret_key && !clearTosSecret}
+ onChange={setTosSecretInput}
+ onClear={() => {
+ setTosSecretInput("");
+ setClearTosSecret(true);
+ }}
+ />
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+ </div>
+ );
+}
diff --git a/admin/src/components/settings/PaymentSettingsPanel.tsx b/admin/src/components/settings/PaymentSettingsPanel.tsx
new file mode 100644
index 0000000..8e57055
--- /dev/null
+++ b/admin/src/components/settings/PaymentSettingsPanel.tsx
@@ -0,0 +1,287 @@
+import { useMemo, useState } from "react";
+import { CreditCard, Loader2, Save, Wallet } from "lucide-react";
+import { LabeledControl, SectionTitle, SettingsPanel, SettingsSurface } from "@/components/settings/SettingsPanel";
+import { SecretField } from "@/components/settings/SecretField";
+import { Switch } from "@/components/ui/switch";
+import { useAdminModelSettings } from "@/hooks/useAdminModelSettings";
+import { cn } from "@/lib/utils";
+
+// 易支付与 Token 计费配置
+export function PaymentSettingsPanel() {
+ const { form, loading, saving, patchField, save } = useAdminModelSettings();
+ const [epayKeyInput, setEpayKeyInput] = useState("");
+ const [clearEpayKey, setClearEpayKey] = useState(false);
+
+ const epayReady = useMemo(() => {
+ if (!form) return false;
+ const hasKey = (form.has_epay_key && !clearEpayKey) || epayKeyInput.trim().length > 0;
+ return Boolean(form.epay_pid && form.epay_api_url && hasKey);
+ }, [form, clearEpayKey, epayKeyInput]);
+
+ async function handleSave() {
+ if (!form) return;
+ await save(
+ {
+ epay_api_url: form.epay_api_url,
+ epay_pid: form.epay_pid,
+ epay_key: epayKeyInput.trim() || undefined,
+ clear_epay_key: clearEpayKey,
+ epay_notify_url: form.epay_notify_url,
+ epay_return_url: form.epay_return_url,
+ billing_enabled: form.billing_enabled,
+ billing_markup: form.billing_markup,
+ billing_estimate_buffer: form.billing_estimate_buffer,
+ billing_seedance_video0: form.billing_seedance_video0,
+ billing_seedance_video1: form.billing_seedance_video1,
+ billing_llm_per_m: form.billing_llm_per_m,
+ billing_seedream_per_m: form.billing_seedream_per_m,
+ billing_tts_per_m: form.billing_tts_per_m,
+ billing_est_llm_tokens: form.billing_est_llm_tokens,
+ billing_est_seedream_tokens: form.billing_est_seedream_tokens,
+ billing_est_tts_tokens: form.billing_est_tts_tokens,
+ billing_est_seedance_tokens_per_sec: form.billing_est_seedance_tokens_per_sec,
+ billing_signup_grant_fen: form.billing_signup_grant_fen,
+ quota_enabled: form.quota_enabled,
+ new_user_quota: form.new_user_quota,
+ },
+ "支付与计费已保存",
+ );
+ setEpayKeyInput("");
+ setClearEpayKey(false);
+ }
+
+ if (loading || !form) {
+ return (
+ <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ <Loader2 className="mr-2 h-5 w-5 animate-spin" />
+ 加载中…
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-5">
+ <div className="flex flex-wrap items-end justify-between gap-3">
+ <div>
+ <h2 className="text-xl font-semibold text-[#303133]">支付与计费</h2>
+ <p className="mt-1 text-sm text-[#909399]">易支付充值、Token 扣费与注册赠送</p>
+ </div>
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ disabled={saving}
+ onClick={() => void handleSave()}
+ >
+ {saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ 保存
+ </button>
+ </div>
+
+ <SettingsSurface>
+ <SectionTitle icon={<CreditCard className="h-4 w-4" />} title="支付就绪" />
+ <div className="mt-4 flex flex-wrap gap-3">
+ <span className={cn("admin-status-pill", epayReady ? "is-done" : "is-warn")}>
+ {epayReady ? "易支付已配置" : "易支付未完整配置"}
+ </span>
+ <span className={cn("admin-status-pill", form.billing_enabled ? "is-done" : "")}>
+ {form.billing_enabled ? "Token 计费已开启" : "Token 计费已关闭"}
+ </span>
+ </div>
+ </SettingsSurface>
+
+ <SettingsPanel title="易支付 Epay" description="生产环境回调请用 /epay/notify,勿含 /api/ 前缀。">
+ <SettingsSurface>
+ <div className="settings-field-grid">
+ <LabeledControl label="网关地址">
+ <input
+ className="settings-input"
+ placeholder="https://pay.gitcc.com"
+ value={form.epay_api_url}
+ onChange={(e) => patchField("epay_api_url", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="商户 PID">
+ <input
+ className="settings-input"
+ value={form.epay_pid}
+ onChange={(e) => patchField("epay_pid", e.target.value)}
+ />
+ </LabeledControl>
+ <SecretField
+ label="商户密钥"
+ value={epayKeyInput}
+ configured={form.has_epay_key && !clearEpayKey}
+ onChange={setEpayKeyInput}
+ onClear={() => {
+ setEpayKeyInput("");
+ setClearEpayKey(true);
+ }}
+ />
+ <LabeledControl label="异步通知 URL" hint="生产:{域名}/epay/notify">
+ <input
+ className="settings-input"
+ value={form.epay_notify_url}
+ onChange={(e) => patchField("epay_notify_url", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="同步跳转 URL">
+ <input
+ className="settings-input"
+ value={form.epay_return_url}
+ onChange={(e) => patchField("epay_return_url", e.target.value)}
+ />
+ </LabeledControl>
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+
+ <SettingsPanel title="Token 计费" description="按上游成本 × markup 扣费;未返回 usage 时用估算 token。">
+ <SettingsSurface>
+ <SectionTitle icon={<Wallet className="h-4 w-4" />} title="开关与系数" />
+ <div className="settings-toggle-row mt-4">
+ <div>
+ <strong>启用 Token 计费</strong>
+ <span>关闭后生成不扣余额(管理员可单独豁免)</span>
+ </div>
+ <Switch checked={form.billing_enabled} onCheckedChange={(v) => patchField("billing_enabled", v)} />
+ </div>
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="加价系数 markup">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ min={1}
+ value={form.billing_markup}
+ onChange={(e) => patchField("billing_markup", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="预估缓冲系数">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ min={1}
+ value={form.billing_estimate_buffer}
+ onChange={(e) => patchField("billing_estimate_buffer", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="注册赠送(分)">
+ <input
+ className="settings-input"
+ type="number"
+ min={0}
+ value={form.billing_signup_grant_fen}
+ onChange={(e) => patchField("billing_signup_grant_fen", Number(e.target.value))}
+ />
+ </LabeledControl>
+ </div>
+
+ <SectionTitle icon={<Wallet className="h-4 w-4" />} title="单价(元 / 百万 token)" />
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="LLM">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ value={form.billing_llm_per_m}
+ onChange={(e) => patchField("billing_llm_per_m", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="Seedream 生图">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ value={form.billing_seedream_per_m}
+ onChange={(e) => patchField("billing_seedream_per_m", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="TTS 语音">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ value={form.billing_tts_per_m}
+ onChange={(e) => patchField("billing_tts_per_m", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="Seedance video0">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ value={form.billing_seedance_video0}
+ onChange={(e) => patchField("billing_seedance_video0", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="Seedance video1">
+ <input
+ className="settings-input"
+ type="number"
+ step="0.1"
+ value={form.billing_seedance_video1}
+ onChange={(e) => patchField("billing_seedance_video1", Number(e.target.value))}
+ />
+ </LabeledControl>
+ </div>
+
+ <SectionTitle icon={<Wallet className="h-4 w-4" />} title="估算 token(缺 usage 时)" />
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="LLM 估算">
+ <input
+ className="settings-input"
+ type="number"
+ value={form.billing_est_llm_tokens}
+ onChange={(e) => patchField("billing_est_llm_tokens", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="Seedream 估算">
+ <input
+ className="settings-input"
+ type="number"
+ value={form.billing_est_seedream_tokens}
+ onChange={(e) => patchField("billing_est_seedream_tokens", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="TTS 估算">
+ <input
+ className="settings-input"
+ type="number"
+ value={form.billing_est_tts_tokens}
+ onChange={(e) => patchField("billing_est_tts_tokens", Number(e.target.value))}
+ />
+ </LabeledControl>
+ <LabeledControl label="Seedance token/秒">
+ <input
+ className="settings-input"
+ type="number"
+ value={form.billing_est_seedance_tokens_per_sec}
+ onChange={(e) => patchField("billing_est_seedance_tokens_per_sec", Number(e.target.value))}
+ />
+ </LabeledControl>
+ </div>
+
+ <div className="settings-toggle-row mt-4">
+ <div>
+ <strong>旧版次数配额(quota_enabled)</strong>
+ <span>与 Token 计费并存时以 billing_enabled 为准</span>
+ </div>
+ <Switch checked={form.quota_enabled} onCheckedChange={(v) => patchField("quota_enabled", v)} />
+ </div>
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="新用户默认次数">
+ <input
+ className="settings-input"
+ type="number"
+ min={0}
+ value={form.new_user_quota}
+ onChange={(e) => patchField("new_user_quota", Number(e.target.value))}
+ />
+ </LabeledControl>
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+ </div>
+ );
+}
diff --git a/admin/src/components/settings/RoutingSettingsPanel.tsx b/admin/src/components/settings/RoutingSettingsPanel.tsx
new file mode 100644
index 0000000..6ca0364
--- /dev/null
+++ b/admin/src/components/settings/RoutingSettingsPanel.tsx
@@ -0,0 +1,360 @@
+import { useCallback, useEffect, useMemo, useState } from "react";
+import { Loader2, Plus, Save, Trash2 } from "lucide-react";
+import { toast } from "sonner";
+import { api, type AdminRoutingSettings } from "@/api/client";
+import { LabeledControl, SectionTitle, SettingsPanel, SettingsSurface } from "@/components/settings/SettingsPanel";
+import { cn } from "@/lib/utils";
+
+type ChannelDraft = AdminRoutingSettings["system_channels"][number] & {
+ api_key_input: string;
+};
+
+const CAPABILITY_LABELS: Record<string, string> = {
+ text: "文本",
+ image: "图像",
+ video: "视频",
+ audio: "语音",
+};
+
+// 渠道 + 逻辑模型路由配置面板
+export function RoutingSettingsPanel() {
+ const [data, setData] = useState<AdminRoutingSettings | null>(null);
+ const [apiKeyInputs, setApiKeyInputs] = useState<Record<string, string>>({});
+ const [loading, setLoading] = useState(true);
+ const [saving, setSaving] = useState(false);
+ const [selectedChannelId, setSelectedChannelId] = useState("");
+
+ const load = useCallback(async () => {
+ setLoading(true);
+ try {
+ const res = await api<AdminRoutingSettings>("/api/admin/settings/routing");
+ setData(res);
+ setSelectedChannelId((prev) => prev || res.system_channels[0]?.id || "");
+ setApiKeyInputs({});
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "加载路由配置失败");
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ void load();
+ }, [load]);
+
+ const channels = useMemo<ChannelDraft[]>(
+ () =>
+ (data?.system_channels ?? []).map((channel) => ({
+ ...channel,
+ api_key_input: apiKeyInputs[channel.id] ?? "",
+ })),
+ [apiKeyInputs, data],
+ );
+
+ const selectedChannel = channels.find((item) => item.id === selectedChannelId) ?? channels[0];
+
+ function updateChannel(channelId: string, patch: Partial<AdminRoutingSettings["system_channels"][number]>) {
+ setData((prev) =>
+ prev
+ ? {
+ ...prev,
+ system_channels: prev.system_channels.map((item) =>
+ item.id === channelId ? { ...item, ...patch } : item,
+ ),
+ }
+ : prev,
+ );
+ }
+
+ function addChannel() {
+ const id = `channel-${Date.now()}`;
+ setData((prev) =>
+ prev
+ ? {
+ ...prev,
+ system_channels: [
+ ...prev.system_channels,
+ {
+ id,
+ name: "新渠道",
+ base_url: "",
+ api_key: "",
+ has_api_key: false,
+ api_format: "openai",
+ protocol: "auto",
+ models: [],
+ enabled: true,
+ sort_order: prev.system_channels.length,
+ },
+ ],
+ }
+ : prev,
+ );
+ setSelectedChannelId(id);
+ }
+
+ function removeChannel(channelId: string) {
+ setData((prev) =>
+ prev
+ ? {
+ ...prev,
+ system_channels: prev.system_channels.filter((item) => item.id !== channelId),
+ logical_models: prev.logical_models
+ .map((model) => ({
+ ...model,
+ bindings: model.bindings.filter((binding) => binding.channel_id !== channelId),
+ }))
+ .filter((model) => model.bindings.length > 0),
+ }
+ : prev,
+ );
+ }
+
+ async function handleSave() {
+ if (!data) return;
+ setSaving(true);
+ try {
+ const res = await api<{ settings: AdminRoutingSettings }>("/api/admin/settings/routing", {
+ method: "PATCH",
+ body: JSON.stringify({
+ system_channels: data.system_channels.map((channel) => ({
+ id: channel.id,
+ name: channel.name,
+ base_url: channel.base_url,
+ api_key: apiKeyInputs[channel.id]?.trim() || undefined,
+ api_format: channel.api_format,
+ protocol: channel.protocol,
+ models: channel.models,
+ enabled: channel.enabled,
+ sort_order: channel.sort_order,
+ })),
+ logical_models: data.logical_models,
+ default_models: data.default_models,
+ }),
+ });
+ setData(res.settings);
+ setApiKeyInputs({});
+ toast.success("路由配置已保存");
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "保存失败");
+ } finally {
+ setSaving(false);
+ }
+ }
+
+ if (loading && !data) {
+ return (
+ <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ <Loader2 className="mr-2 h-5 w-5 animate-spin" />
+ 加载路由配置…
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-5">
+ <div className="flex flex-wrap items-end justify-between gap-3">
+ <div>
+ <h2 className="text-xl font-semibold text-[#303133]">模型路由</h2>
+ <p className="mt-1 text-sm text-[#909399]">上游渠道 + 逻辑模型绑定 + 默认模型</p>
+ </div>
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ disabled={saving}
+ onClick={() => void handleSave()}
+ >
+ {saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ 保存路由
+ </button>
+ </div>
+
+ {(data?.validation_errors.length ?? 0) > 0 ? (
+ <SettingsSurface className="border-[#fde2e2] bg-[#fef0f0]">
+ <div className="text-sm font-medium text-[#f56c6c]">配置校验</div>
+ <ul className="mt-2 space-y-1 text-xs text-[#f56c6c]">
+ {data?.validation_errors.map((item) => (
+ <li key={item}>· {item}</li>
+ ))}
+ </ul>
+ </SettingsSurface>
+ ) : null}
+
+ <SettingsPanel title="上游渠道" description="物理网关:Base URL、协议、上游模型列表。">
+ <div className="grid gap-4 xl:grid-cols-[240px_minmax(0,1fr)]">
+ <div className="space-y-2">
+ <button
+ type="button"
+ className="admin-quick-btn !w-full !flex-row items-center gap-2 px-3 py-2"
+ onClick={addChannel}
+ >
+ <Plus className="h-4 w-4" />
+ 新增渠道
+ </button>
+ {channels.map((channel) => (
+ <button
+ key={channel.id}
+ type="button"
+ className={cn(
+ "w-full rounded-lg border px-3 py-2 text-left text-sm transition-colors",
+ selectedChannel?.id === channel.id
+ ? "border-[#67c23a] bg-[#f0f9eb]"
+ : "border-[#ebeef5] bg-white hover:border-[#dcdfe6]",
+ )}
+ onClick={() => setSelectedChannelId(channel.id)}
+ >
+ <div className="font-medium text-[#303133]">{channel.name}</div>
+ <div className="mt-0.5 truncate font-mono text-[11px] text-[#909399]">{channel.id}</div>
+ </button>
+ ))}
+ </div>
+
+ {selectedChannel ? (
+ <SettingsSurface>
+ <div className="mb-3 flex items-center justify-between gap-2">
+ <SectionTitle icon={<Plus className="h-4 w-4" />} title="渠道详情" />
+ <button
+ type="button"
+ className="rounded-lg border border-[#fde2e2] px-2 py-1 text-xs text-[#f56c6c]"
+ onClick={() => removeChannel(selectedChannel.id)}
+ >
+ <Trash2 className="mr-1 inline h-3.5 w-3.5" />
+ 删除
+ </button>
+ </div>
+ <div className="settings-field-grid">
+ <LabeledControl label="名称">
+ <input
+ className="settings-input"
+ value={selectedChannel.name}
+ onChange={(e) => updateChannel(selectedChannel.id, { name: e.target.value })}
+ />
+ </LabeledControl>
+ <LabeledControl label="Base URL">
+ <input
+ className="settings-input"
+ value={selectedChannel.base_url}
+ onChange={(e) => updateChannel(selectedChannel.id, { base_url: e.target.value })}
+ />
+ </LabeledControl>
+ <LabeledControl label="协议">
+ <select
+ className="settings-select"
+ value={selectedChannel.protocol}
+ onChange={(e) =>
+ updateChannel(selectedChannel.id, {
+ protocol: e.target.value as AdminRoutingSettings["system_channels"][number]["protocol"],
+ })
+ }
+ >
+ <option value="auto">自动</option>
+ <option value="openai">OpenAI</option>
+ <option value="ark">ARK</option>
+ <option value="volc_tts">豆包 TTS</option>
+ </select>
+ </LabeledControl>
+ <LabeledControl label="API Key" hint={selectedChannel.has_api_key ? "已保存,留空不修改" : undefined}>
+ <input
+ className="settings-input is-secret"
+ type="password"
+ placeholder={selectedChannel.has_api_key ? "已保存,留空则不修改" : "未配置"}
+ value={selectedChannel.api_key_input}
+ onChange={(e) =>
+ setApiKeyInputs((prev) => ({ ...prev, [selectedChannel.id]: e.target.value }))
+ }
+ />
+ </LabeledControl>
+ <LabeledControl label="上游模型(每行一个)">
+ <textarea
+ className="settings-input min-h-[120px] py-2 font-mono text-xs"
+ value={selectedChannel.models.join("\n")}
+ onChange={(e) =>
+ updateChannel(selectedChannel.id, {
+ models: e.target.value
+ .split("\n")
+ .map((line) => line.trim())
+ .filter(Boolean),
+ })
+ }
+ />
+ </LabeledControl>
+ </div>
+ </SettingsSurface>
+ ) : null}
+ </div>
+ </SettingsPanel>
+
+ <SettingsPanel title="逻辑模型" description="保存渠道后会自动 sync 绑定关系。">
+ <div className="space-y-3">
+ {(data?.logical_models ?? []).map((model) => (
+ <SettingsSurface key={model.id}>
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <div>
+ <div className="text-sm font-medium text-[#303133]">{model.name || model.id}</div>
+ <div className="font-mono text-[11px] text-[#909399]">
+ {model.id} · {CAPABILITY_LABELS[model.capability] ?? model.capability}
+ </div>
+ </div>
+ </div>
+ <div className="mt-3 admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>渠道</th>
+ <th>上游模型</th>
+ <th>优先级</th>
+ </tr>
+ </thead>
+ <tbody>
+ {model.bindings.map((binding) => {
+ const channel = data?.system_channels.find((item) => item.id === binding.channel_id);
+ return (
+ <tr key={binding.id}>
+ <td>{channel?.name ?? binding.channel_id}</td>
+ <td className="font-mono text-xs">{binding.upstream_model}</td>
+ <td>{binding.priority}</td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
+ </div>
+ </SettingsSurface>
+ ))}
+ </div>
+ </SettingsPanel>
+
+ <SettingsPanel title="默认模型" description="各能力默认逻辑模型 ID。">
+ <div className="settings-field-grid">
+ {(["text_model", "image_model", "video_model", "audio_model"] as const).map((key) => (
+ <LabeledControl key={key} label={key}>
+ <select
+ className="settings-select"
+ value={data?.default_models[key] ?? ""}
+ onChange={(e) =>
+ setData((prev) =>
+ prev
+ ? {
+ ...prev,
+ default_models: { ...prev.default_models, [key]: e.target.value },
+ }
+ : prev,
+ )
+ }
+ >
+ <option value="">未设置</option>
+ {(data?.logical_models ?? [])
+ .filter((model) => model.capability === key.replace("_model", ""))
+ .map((model) => (
+ <option key={model.id} value={model.id}>
+ {model.name || model.id}
+ </option>
+ ))}
+ </select>
+ </LabeledControl>
+ ))}
+ </div>
+ </SettingsPanel>
+ </div>
+ );
+}
diff --git a/admin/src/components/settings/RuntimeSettingsPanel.tsx b/admin/src/components/settings/RuntimeSettingsPanel.tsx
new file mode 100644
index 0000000..f6d1155
--- /dev/null
+++ b/admin/src/components/settings/RuntimeSettingsPanel.tsx
@@ -0,0 +1,203 @@
+import { useCallback, useEffect, useMemo, useState } from "react";
+import { Activity, CircleGauge, Loader2, Save, SlidersHorizontal, Sparkles } from "lucide-react";
+import { toast } from "sonner";
+import { api, type AdminModelSettings } from "@/api/client";
+import { LabeledControl, SectionTitle, SettingsPanel, SettingsSurface } from "@/components/settings/SettingsPanel";
+import { Switch } from "@/components/ui/switch";
+import { cn } from "@/lib/utils";
+
+// 运行参数配置(并发、质量、Mock 等 flat 字段)
+export function RuntimeSettingsPanel() {
+ const [form, setForm] = useState<AdminModelSettings | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [saving, setSaving] = useState(false);
+
+ const load = useCallback(async () => {
+ setLoading(true);
+ try {
+ const data = await api<AdminModelSettings>("/api/admin/settings/models");
+ setForm(data);
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "加载失败");
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ void load();
+ }, [load]);
+
+ const readinessReady = useMemo(
+ () => form?.readiness?.every((item) => item.ready) ?? false,
+ [form?.readiness],
+ );
+
+ function patchField<K extends keyof AdminModelSettings>(key: K, value: AdminModelSettings[K]) {
+ setForm((prev) => (prev ? { ...prev, [key]: value } : prev));
+ }
+
+ async function handleSave() {
+ if (!form) return;
+ setSaving(true);
+ try {
+ const body = {
+ ark_image_size: form.ark_image_size,
+ ark_video_resolution: form.ark_video_resolution,
+ ark_video_ratio: form.ark_video_ratio,
+ seedance_duration_min: form.seedance_duration_min,
+ seedance_duration_max: form.seedance_duration_max,
+ ark_video_poll_interval: form.ark_video_poll_interval,
+ ark_video_poll_timeout: form.ark_video_poll_timeout,
+ pipeline_image_concurrency: form.pipeline_image_concurrency,
+ pipeline_video_concurrency: form.pipeline_video_concurrency,
+ pipeline_audio_concurrency: form.pipeline_audio_concurrency,
+ task_runtime_max_concurrency: form.task_runtime_max_concurrency,
+ task_user_max_concurrency: form.task_user_max_concurrency,
+ task_poll_max_concurrency: form.task_poll_max_concurrency,
+ drama_user_video_job_limit: form.drama_user_video_job_limit,
+ drama_fragment_max_attempts: form.drama_fragment_max_attempts,
+ ark_mock: form.ark_mock,
+ };
+ await api("/api/admin/settings/models", { method: "PATCH", body: JSON.stringify(body) });
+ await load();
+ toast.success("运行参数已保存");
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "保存失败");
+ } finally {
+ setSaving(false);
+ }
+ }
+
+ if (loading || !form) {
+ return (
+ <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ <Loader2 className="mr-2 h-5 w-5 animate-spin" />
+ 加载中…
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-5">
+ <div className="flex flex-wrap items-end justify-between gap-3">
+ <div>
+ <h2 className="text-xl font-semibold text-[#303133]">运行参数</h2>
+ <p className="mt-1 text-sm text-[#909399]">质量默认值、并发上限与 Mock 开关</p>
+ </div>
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ disabled={saving}
+ onClick={() => void handleSave()}
+ >
+ {saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ 保存
+ </button>
+ </div>
+
+ <SettingsSurface>
+ <SectionTitle icon={<Sparkles className="h-4 w-4" />} title="路由就绪状态" />
+ <div className="mt-4 flex flex-wrap items-center justify-between gap-2">
+ <span className={cn("admin-status-pill", readinessReady ? "is-done" : "is-warn")}>
+ {readinessReady ? "四类能力已就绪" : "请在「模型路由」补全渠道"}
+ </span>
+ </div>
+ <div className="settings-readiness mt-4">
+ {(form.readiness ?? []).map((item) => (
+ <div key={item.capability} className={cn("settings-readiness-card", item.ready && "is-ready")}>
+ <div className="flex items-center justify-between gap-2">
+ <span className="text-sm font-medium">{item.label}</span>
+ <span className={cn("text-xs", item.ready ? "text-[#67c23a]" : "text-[#e6a23c]")}>
+ {item.ready ? "就绪" : "未就绪"}
+ </span>
+ </div>
+ <div className="mt-1 font-mono text-[11px] text-[#909399]">{item.model || "—"}</div>
+ <div className="mt-1 text-[11px] text-[#909399]">{item.message}</div>
+ </div>
+ ))}
+ </div>
+ </SettingsSurface>
+
+ <SettingsPanel title="质量与默认值" description="生图尺寸、视频清晰度、Seedance 时长与轮询参数。">
+ <SettingsSurface>
+ <SectionTitle icon={<SlidersHorizontal className="h-4 w-4" />} title="生成默认值" />
+ <div className="settings-field-grid">
+ <LabeledControl label="默认生图尺寸">
+ <input className="settings-input" value={form.ark_image_size} onChange={(e) => patchField("ark_image_size", e.target.value)} />
+ </LabeledControl>
+ <LabeledControl label="默认视频清晰度">
+ <input className="settings-input" value={form.ark_video_resolution} onChange={(e) => patchField("ark_video_resolution", e.target.value)} />
+ </LabeledControl>
+ <LabeledControl label="默认视频比例">
+ <input className="settings-input" value={form.ark_video_ratio} onChange={(e) => patchField("ark_video_ratio", e.target.value)} />
+ </LabeledControl>
+ <LabeledControl label="Seedance 最小时长(秒)">
+ <input className="settings-input" type="number" min={1} value={form.seedance_duration_min} onChange={(e) => patchField("seedance_duration_min", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="Seedance 最大时长(秒)">
+ <input className="settings-input" type="number" min={1} value={form.seedance_duration_max} onChange={(e) => patchField("seedance_duration_max", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="视频轮询间隔(秒)">
+ <input className="settings-input" type="number" step="0.5" value={form.ark_video_poll_interval} onChange={(e) => patchField("ark_video_poll_interval", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="视频轮询超时(秒)">
+ <input className="settings-input" type="number" value={form.ark_video_poll_timeout} onChange={(e) => patchField("ark_video_poll_timeout", Number(e.target.value))} />
+ </LabeledControl>
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+
+ <SettingsPanel title="并发与限制" description="管线并发、任务平台槽位与漫剧分镜上限。">
+ <SettingsSurface>
+ <SectionTitle icon={<CircleGauge className="h-4 w-4" />} title="并发上限" />
+ <div className="settings-field-grid">
+ <LabeledControl label="生图并发">
+ <input className="settings-input" type="number" min={1} value={form.pipeline_image_concurrency} onChange={(e) => patchField("pipeline_image_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="视频并发">
+ <input className="settings-input" type="number" min={1} value={form.pipeline_video_concurrency} onChange={(e) => patchField("pipeline_video_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="配音并发">
+ <input className="settings-input" type="number" min={1} value={form.pipeline_audio_concurrency} onChange={(e) => patchField("pipeline_audio_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="任务平台槽位(全站)">
+ <input className="settings-input" type="number" min={1} value={form.task_runtime_max_concurrency} onChange={(e) => patchField("task_runtime_max_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="单用户任务槽位">
+ <input className="settings-input" type="number" min={1} value={form.task_user_max_concurrency} onChange={(e) => patchField("task_user_max_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="Selector 轮询并发">
+ <input className="settings-input" type="number" min={1} value={form.task_poll_max_concurrency} onChange={(e) => patchField("task_poll_max_concurrency", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="单用户漫剧视频在途上限">
+ <input className="settings-input" type="number" min={1} value={form.drama_user_video_job_limit} onChange={(e) => patchField("drama_user_video_job_limit", Number(e.target.value))} />
+ </LabeledControl>
+ <LabeledControl label="分镜视频最大尝试次数">
+ <input className="settings-input" type="number" min={1} value={form.drama_fragment_max_attempts} onChange={(e) => patchField("drama_fragment_max_attempts", Number(e.target.value))} />
+ </LabeledControl>
+ </div>
+ <div className="settings-toggle-row mt-4">
+ <div>
+ <strong>ARK Mock 模式</strong>
+ <span>开发环境模拟生成,不调用真实上游</span>
+ </div>
+ <Switch checked={form.ark_mock} onCheckedChange={(v) => patchField("ark_mock", v)} />
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+
+ <SettingsPanel title="运行时" description="Worker 槽位与 Selector 轮询(NIO:注册项不占 Worker)。">
+ <div className="flex flex-col gap-2 text-sm text-[#606266]">
+ <div className="flex items-center gap-2">
+ <Activity className="h-4 w-4 text-[#67c23a]" />
+ Worker 槽位 {form.task_runtime_max_concurrency} · 单用户 {form.task_user_max_concurrency}
+ </div>
+ <div className="text-xs text-[#909399]">
+ Selector 每轮最多 {form.task_poll_max_concurrency} 路上游非阻塞查询;awaiting_poll 不计入 Worker 占用。
+ </div>
+ </div>
+ </SettingsPanel>
+ </div>
+ );
+}
diff --git a/admin/src/components/settings/SecretField.tsx b/admin/src/components/settings/SecretField.tsx
new file mode 100644
index 0000000..d58fff5
--- /dev/null
+++ b/admin/src/components/settings/SecretField.tsx
@@ -0,0 +1,51 @@
+import { LabeledControl } from "@/components/settings/SettingsPanel";
+import { cn } from "@/lib/utils";
+
+type SecretFieldProps = {
+ label: string;
+ hint?: string;
+ value: string;
+ configured: boolean;
+ placeholder?: string;
+ onChange: (value: string) => void;
+ onClear?: () => void;
+};
+
+// 密钥输入:留空不修改,支持清除已存密钥
+export function SecretField({
+ label,
+ hint,
+ value,
+ configured,
+ placeholder,
+ onChange,
+ onClear,
+}: SecretFieldProps) {
+ return (
+ <LabeledControl
+ label={label}
+ hint={hint ?? (configured ? "已配置;留空保存则不修改,可点清除后保存" : undefined)}
+ >
+ <div className="flex flex-col gap-2">
+ <div className="flex gap-2">
+ <input
+ type="password"
+ className="settings-input flex-1"
+ placeholder={placeholder ?? (configured ? "留空则不修改" : "填写密钥")}
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ autoComplete="new-password"
+ />
+ {configured && onClear ? (
+ <button type="button" className="admin-quick-btn shrink-0 px-3" onClick={onClear}>
+ 清除
+ </button>
+ ) : null}
+ </div>
+ {configured ? (
+ <span className={cn("text-xs font-medium text-[#67c23a]")}>● 已配置</span>
+ ) : null}
+ </div>
+ </LabeledControl>
+ );
+}
diff --git a/admin/src/components/settings/SettingsPanel.tsx b/admin/src/components/settings/SettingsPanel.tsx
new file mode 100644
index 0000000..e7394a3
--- /dev/null
+++ b/admin/src/components/settings/SettingsPanel.tsx
@@ -0,0 +1,50 @@
+import type { ReactNode } from "react";
+
+type PanelProps = {
+ title: string;
+ description: string;
+ actions?: ReactNode;
+ children: ReactNode;
+};
+
+// VOZEB 风格配置面板容器
+export function SettingsPanel({ title, description, actions, children }: PanelProps) {
+ return (
+ <section className="settings-panel">
+ <div className="settings-panel-header">
+ <div className="min-w-0">
+ <h3 className="settings-panel-title">{title}</h3>
+ <p className="settings-panel-desc">{description}</p>
+ </div>
+ {actions ? <div className="settings-panel-actions">{actions}</div> : null}
+ </div>
+ <div className="settings-panel-body">{children}</div>
+ </section>
+ );
+}
+
+// 带图标的区块标题
+export function SectionTitle({ icon, title }: { icon: ReactNode; title: string }) {
+ return (
+ <div className="settings-section-title">
+ <span className="settings-section-icon">{icon}</span>
+ <span>{title}</span>
+ </div>
+ );
+}
+
+// 表单标签 + 控件
+export function LabeledControl({ label, hint, children }: { label: string; hint?: string; children: ReactNode }) {
+ return (
+ <label className="settings-field">
+ <span className="settings-field-label">{label}</span>
+ {children}
+ {hint ? <span className="settings-field-hint">{hint}</span> : null}
+ </label>
+ );
+}
+
+// 内嵌子面板(VOZEB settingsPanelSurfaceClass 风格)
+export function SettingsSurface({ children, className = "" }: { children: ReactNode; className?: string }) {
+ return <div className={`settings-surface ${className}`.trim()}>{children}</div>;
+}
diff --git a/admin/src/components/settings/SiteSettingsPanel.tsx b/admin/src/components/settings/SiteSettingsPanel.tsx
new file mode 100644
index 0000000..9f2b313
--- /dev/null
+++ b/admin/src/components/settings/SiteSettingsPanel.tsx
@@ -0,0 +1,91 @@
+import { Globe, Loader2, Save, Wrench } from "lucide-react";
+import { LabeledControl, SectionTitle, SettingsPanel, SettingsSurface } from "@/components/settings/SettingsPanel";
+import { useAdminModelSettings } from "@/hooks/useAdminModelSettings";
+
+// 站点 URL 与本地工具路径
+export function SiteSettingsPanel() {
+ const { form, loading, saving, patchField, save } = useAdminModelSettings();
+
+ async function handleSave() {
+ if (!form) return;
+ await save(
+ {
+ public_base_url: form.public_base_url,
+ ffmpeg_path: form.ffmpeg_path,
+ ffprobe_path: form.ffprobe_path,
+ },
+ "站点配置已保存",
+ );
+ }
+
+ if (loading || !form) {
+ return (
+ <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ <Loader2 className="mr-2 h-5 w-5 animate-spin" />
+ 加载中…
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-5">
+ <div className="flex flex-wrap items-end justify-between gap-3">
+ <div>
+ <h2 className="text-xl font-semibold text-[#303133]">站点与工具</h2>
+ <p className="mt-1 text-sm text-[#909399]">公网基址、回调拼接与 FFmpeg 可执行路径</p>
+ </div>
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ disabled={saving}
+ onClick={() => void handleSave()}
+ >
+ {saving ? <Loader2 className="h-4 w-4 animate-spin" /> : <Save className="h-4 w-4" />}
+ 保存
+ </button>
+ </div>
+
+ <SettingsPanel title="公网地址" description="用于支付回调、分享链接与 OSS 回填后的绝对 URL。">
+ <SettingsSurface>
+ <SectionTitle icon={<Globe className="h-4 w-4" />} title="PUBLIC_BASE_URL" />
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="后端公网基址" hint="例:https://api.example.com 或 http://127.0.0.1:8000">
+ <input
+ className="settings-input"
+ value={form.public_base_url}
+ onChange={(e) => patchField("public_base_url", e.target.value)}
+ />
+ </LabeledControl>
+ </div>
+ <p className="mt-3 text-xs leading-relaxed text-[#909399]">
+ 数据库、Redis、SECRET_KEY 等基础设施仍通过服务器环境变量配置,不在此页修改。
+ </p>
+ </SettingsSurface>
+ </SettingsPanel>
+
+ <SettingsPanel title="媒体工具" description="合成与抽帧依赖本机 ffmpeg / ffprobe。">
+ <SettingsSurface>
+ <SectionTitle icon={<Wrench className="h-4 w-4" />} title="FFmpeg" />
+ <div className="settings-field-grid mt-4">
+ <LabeledControl label="ffmpeg 路径">
+ <input
+ className="settings-input"
+ placeholder="ffmpeg"
+ value={form.ffmpeg_path}
+ onChange={(e) => patchField("ffmpeg_path", e.target.value)}
+ />
+ </LabeledControl>
+ <LabeledControl label="ffprobe 路径">
+ <input
+ className="settings-input"
+ placeholder="ffprobe"
+ value={form.ffprobe_path}
+ onChange={(e) => patchField("ffprobe_path", e.target.value)}
+ />
+ </LabeledControl>
+ </div>
+ </SettingsSurface>
+ </SettingsPanel>
+ </div>
+ );
+}
diff --git a/admin/src/components/tasks/TaskDetailDialog.tsx b/admin/src/components/tasks/TaskDetailDialog.tsx
new file mode 100644
index 0000000..0cb5bc3
--- /dev/null
+++ b/admin/src/components/tasks/TaskDetailDialog.tsx
@@ -0,0 +1,396 @@
+import { useEffect, useMemo, useState } from "react";
+import { Ban, Loader2, RefreshCw } from "lucide-react";
+import { toast } from "sonner";
+import { api, type AdminTaskDetail } from "@/api/client";
+import { AdminModal } from "@/components/admin/AdminModal";
+import { Button } from "@/components/ui/button";
+import { taskDomainLabel, taskStatusLabel } from "@/lib/statusLabels";
+import { cn } from "@/lib/utils";
+
+type TaskDetailDialogProps = {
+ taskId: number | null;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ onCancelled?: () => void;
+};
+
+type DetailTab = "overview" | "steps" | "events" | "json";
+
+const TERMINAL = new Set(["succeeded", "failed", "cancelled"]);
+
+// 格式化时间为本地字符串
+function fmtTime(value: string | null | undefined): string {
+ if (!value) return "—";
+ return new Date(value).toLocaleString();
+}
+
+// 美化 JSON 展示
+function fmtJson(value: unknown): string {
+ if (value == null) return "—";
+ try {
+ return JSON.stringify(value, null, 2);
+ } catch {
+ return String(value);
+ }
+}
+
+// 状态 pill 样式
+function statusClass(status: string): string {
+ if (status === "running" || status === "leased") return "is-run";
+ if (status === "succeeded") return "is-done";
+ if (status === "failed") return "is-fail";
+ if (status === "cancelled" || status === "cancel_requested") return "is-warn";
+ return "is-warn";
+}
+
+// 任务详情弹窗:概览 / 步骤 / 事件 / 原始 JSON
+export function TaskDetailDialog({ taskId, open, onOpenChange, onCancelled }: TaskDetailDialogProps) {
+ const [task, setTask] = useState<AdminTaskDetail | null>(null);
+ const [loading, setLoading] = useState(false);
+ const [tab, setTab] = useState<DetailTab>("overview");
+ const [cancelling, setCancelling] = useState(false);
+
+ async function loadDetail(id: number) {
+ setLoading(true);
+ try {
+ setTask(await api<AdminTaskDetail>(`/api/admin/tasks/${id}`));
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "加载任务详情失败");
+ onOpenChange(false);
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ useEffect(() => {
+ if (!open || !taskId) {
+ setTask(null);
+ setTab("overview");
+ return;
+ }
+ void loadDetail(taskId);
+ }, [open, taskId]);
+
+ const canCancel = useMemo(() => {
+ if (!task) return false;
+ return task.cancelable && !TERMINAL.has(task.status);
+ }, [task]);
+
+ const waitingChain = useMemo(() => {
+ if (!task) return false;
+ return task.status === "pending" && !task.next_action_at && Boolean(task.batch_key);
+ }, [task]);
+
+ async function handleCancel() {
+ if (!task || !canCancel) return;
+ if (!window.confirm(`确定取消任务 #${task.id}?`)) return;
+ setCancelling(true);
+ try {
+ const updated = await api<AdminTaskDetail>(`/api/admin/tasks/${task.id}/cancel`, { method: "POST" });
+ setTask(updated);
+ toast.success("已提交取消请求");
+ onCancelled?.();
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "取消失败");
+ } finally {
+ setCancelling(false);
+ }
+ }
+
+ const title = task ? `任务 #${task.id} · ${taskDomainLabel(task.domain)}` : "任务详情";
+
+ return (
+ <AdminModal
+ open={open}
+ onOpenChange={onOpenChange}
+ size="full"
+ className="task-detail-modal max-h-[90vh]"
+ bodyClassName="p-0 overflow-hidden"
+ title={title}
+ subtitle={
+ task ? (
+ <span className="font-mono text-xs">
+ {task.task_type}
+ {task.user_email ? ` · ${task.user_email}` : ""}
+ </span>
+ ) : undefined
+ }
+ footer={
+ <>
+ <Button variant="outline" onClick={() => onOpenChange(false)}>
+ 关闭
+ </Button>
+ {taskId ? (
+ <Button variant="outline" disabled={loading} onClick={() => void loadDetail(taskId)}>
+ <RefreshCw className={cn("mr-2 h-4 w-4", loading && "animate-spin")} />
+ 刷新
+ </Button>
+ ) : null}
+ {canCancel ? (
+ <Button variant="destructive" disabled={cancelling} onClick={() => void handleCancel()}>
+ {cancelling ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Ban className="mr-2 h-4 w-4" />}
+ 取消任务
+ </Button>
+ ) : null}
+ </>
+ }
+ >
+ {loading && !task ? (
+ <div className="task-detail-loading">
+ <Loader2 className="h-6 w-6 animate-spin text-[#67c23a]" />
+ <span>加载任务详情…</span>
+ </div>
+ ) : task ? (
+ <div className="task-detail-body">
+ <div className="task-detail-tabs" role="tablist">
+ {(
+ [
+ ["overview", "概览"],
+ ["steps", `步骤 (${task.steps?.length ?? 0})`],
+ ["events", `事件 (${task.events?.length ?? 0})`],
+ ["json", "原始 JSON"],
+ ] as const
+ ).map(([key, label]) => (
+ <button
+ key={key}
+ type="button"
+ role="tab"
+ className={cn("task-detail-tab", tab === key && "is-active")}
+ onClick={() => setTab(key)}
+ >
+ {label}
+ </button>
+ ))}
+ </div>
+
+ <div className="task-detail-panel">
+ {tab === "overview" ? (
+ <div className="task-detail-grid">
+ <section className="task-detail-section">
+ <h4>状态</h4>
+ <div className="flex flex-wrap items-center gap-2">
+ <span className={`admin-status-pill ${statusClass(task.status)}`}>
+ {taskStatusLabel(task.status)}
+ </span>
+ <span className="text-sm text-[#606266]">进度 {task.progress_percent}%</span>
+ {waitingChain ? (
+ <span className="admin-status-pill is-warn">等待前置(序列批次)</span>
+ ) : null}
+ </div>
+ {task.current_step_key ? (
+ <p className="task-detail-meta">
+ 当前步骤 {task.current_step_key}
+ {task.current_step_status ? ` · ${task.current_step_status}` : ""}
+ </p>
+ ) : null}
+ {task.error_message ? (
+ <pre className="task-detail-error">{task.error_message}</pre>
+ ) : null}
+ </section>
+
+ <section className="task-detail-section">
+ <h4>调度</h4>
+ <dl className="task-detail-dl">
+ <div>
+ <dt>优先级</dt>
+ <dd>{task.priority}</dd>
+ </div>
+ <div>
+ <dt>next_action_at</dt>
+ <dd>{fmtTime(task.next_action_at)}</dd>
+ </div>
+ <div>
+ <dt>scheduled_at</dt>
+ <dd>{fmtTime(task.scheduled_at)}</dd>
+ </div>
+ <div>
+ <dt>租约到期</dt>
+ <dd>{fmtTime(task.lease_until)}</dd>
+ </div>
+ <div>
+ <dt>provider_task_id</dt>
+ <dd className="font-mono text-xs">{task.provider_task_id ?? "—"}</dd>
+ </div>
+ </dl>
+ </section>
+
+ <section className="task-detail-section">
+ <h4>关联实体</h4>
+ <dl className="task-detail-dl">
+ <div>
+ <dt>用户</dt>
+ <dd>{task.user_email ?? `#${task.requested_by}`}</dd>
+ </div>
+ <div>
+ <dt>漫剧项目</dt>
+ <dd>{task.drama_project_id ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>分集</dt>
+ <dd>{task.episode_id ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>分镜</dt>
+ <dd>{task.fragment_id ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>科普项目</dt>
+ <dd>{task.project_id ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>镜头</dt>
+ <dd>{task.shot_id ?? "—"}</dd>
+ </div>
+ </dl>
+ </section>
+
+ <section className="task-detail-section">
+ <h4>标识</h4>
+ <dl className="task-detail-dl">
+ <div>
+ <dt>batch_key</dt>
+ <dd className="font-mono text-xs break-all">{task.batch_key ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>dedupe_key</dt>
+ <dd className="font-mono text-xs break-all">{task.dedupe_key ?? "—"}</dd>
+ </div>
+ <div>
+ <dt>client_request_id</dt>
+ <dd className="font-mono text-xs break-all">{task.client_request_id ?? "—"}</dd>
+ </div>
+ </dl>
+ </section>
+
+ <section className="task-detail-section task-detail-section--full">
+ <h4>时间线</h4>
+ <dl className="task-detail-dl task-detail-dl--inline">
+ <div>
+ <dt>创建</dt>
+ <dd>{fmtTime(task.created_at)}</dd>
+ </div>
+ <div>
+ <dt>开始</dt>
+ <dd>{fmtTime(task.started_at)}</dd>
+ </div>
+ <div>
+ <dt>结束</dt>
+ <dd>{fmtTime(task.finished_at)}</dd>
+ </div>
+ <div>
+ <dt>更新</dt>
+ <dd>{fmtTime(task.updated_at)}</dd>
+ </div>
+ </dl>
+ </section>
+
+ {task.result_payload && Object.keys(task.result_payload).length > 0 ? (
+ <section className="task-detail-section task-detail-section--full">
+ <h4>结果摘要</h4>
+ <pre className="task-detail-json">{fmtJson(task.result_payload)}</pre>
+ </section>
+ ) : null}
+ </div>
+ ) : null}
+
+ {tab === "steps" ? (
+ <div className="admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>步骤</th>
+ <th>状态</th>
+ <th>尝试</th>
+ <th>Provider</th>
+ <th>错误</th>
+ <th>时间</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(task.steps?.length ?? 0) === 0 ? (
+ <tr>
+ <td colSpan={6} className="text-center text-sm text-[#909399]">
+ 暂无步骤记录
+ </td>
+ </tr>
+ ) : (
+ task.steps.map((step) => (
+ <tr key={step.id}>
+ <td>
+ <div className="font-mono text-xs">{step.step_key}</div>
+ <div className="text-[11px] text-[#909399]">{step.step_type}</div>
+ </td>
+ <td>
+ <span className={`admin-status-pill ${statusClass(step.status)}`}>
+ {taskStatusLabel(step.status)}
+ </span>
+ </td>
+ <td className="text-xs">{step.attempt_count}</td>
+ <td className="max-w-[140px] truncate font-mono text-[11px]" title={step.provider_task_id ?? ""}>
+ {step.provider_name ?? "—"}
+ {step.provider_task_id ? ` · ${step.provider_task_id}` : ""}
+ </td>
+ <td className="max-w-[200px] truncate text-[11px] text-[#f56c6c]" title={step.error_message ?? ""}>
+ {step.error_message ?? "—"}
+ </td>
+ <td className="text-[11px] text-[#909399]">
+ <div>始 {fmtTime(step.started_at)}</div>
+ <div>终 {fmtTime(step.finished_at)}</div>
+ </td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ ) : null}
+
+ {tab === "events" ? (
+ <div className="task-detail-events">
+ {(task.events?.length ?? 0) === 0 ? (
+ <p className="text-sm text-[#909399]">暂无事件日志</p>
+ ) : (
+ [...(task.events ?? [])]
+ .sort((a, b) => (a.id ?? 0) - (b.id ?? 0))
+ .map((ev) => (
+ <div key={ev.id} className="task-detail-event">
+ <div className="task-detail-event-head">
+ <span className="font-mono text-xs text-[#303133]">{ev.event_type}</span>
+ <span className="text-[11px] text-[#909399]">{fmtTime(ev.created_at)}</span>
+ </div>
+ <div className="mt-1 flex flex-wrap gap-2 text-[11px] text-[#909399]">
+ {ev.status ? <span>status={ev.status}</span> : null}
+ {ev.phase ? <span>phase={ev.phase}</span> : null}
+ </div>
+ {ev.message ? <p className="mt-1 text-sm text-[#606266]">{ev.message}</p> : null}
+ {ev.payload ? (
+ <pre className="task-detail-json task-detail-json--compact">{fmtJson(ev.payload)}</pre>
+ ) : null}
+ </div>
+ ))
+ )}
+ </div>
+ ) : null}
+
+ {tab === "json" ? (
+ <div className="space-y-4">
+ <div>
+ <h4 className="task-detail-json-title">payload</h4>
+ <pre className="task-detail-json">{fmtJson(task.payload)}</pre>
+ </div>
+ <div>
+ <h4 className="task-detail-json-title">result_payload</h4>
+ <pre className="task-detail-json">{fmtJson(task.result_payload)}</pre>
+ </div>
+ <div>
+ <h4 className="task-detail-json-title">targets</h4>
+ <pre className="task-detail-json">{fmtJson(task.targets)}</pre>
+ </div>
+ </div>
+ ) : null}
+ </div>
+ </div>
+ ) : null}
+ </AdminModal>
+ );
+}
diff --git a/admin/src/components/templates/TemplateCard.tsx b/admin/src/components/templates/TemplateCard.tsx
new file mode 100644
index 0000000..61fbdd8
--- /dev/null
+++ b/admin/src/components/templates/TemplateCard.tsx
@@ -0,0 +1,123 @@
+import { Crown, ImageOff, Pencil, Trash2 } from "lucide-react";
+import type { AdminTemplate } from "@/api/client";
+import { Switch } from "@/components/ui/switch";
+import { cn } from "@/lib/utils";
+
+type TemplateCardProps = {
+ template: AdminTemplate;
+ onEdit: (tpl: AdminTemplate) => void;
+ onDelete: (id: string) => void;
+ onToggleActive: (id: string, value: boolean) => void;
+ onTogglePremium: (id: string, value: boolean) => void;
+};
+
+// 解析封面 URL(相对 /static 走 Vite 代理)
+function coverSrc(url: string): string {
+ const trimmed = (url || "").trim();
+ if (!trimmed) return "";
+ if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed;
+ return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
+}
+
+// 模板卡片:封面 + 元信息 + 快捷开关
+export function TemplateCard({
+ template,
+ onEdit,
+ onDelete,
+ onToggleActive,
+ onTogglePremium,
+}: TemplateCardProps) {
+ const src = coverSrc(template.preview_cover);
+ const categories = template.category?.length ? template.category : ["未分类"];
+
+ return (
+ <article
+ className={cn(
+ "template-card group",
+ !template.is_active && "template-card--inactive",
+ )}
+ >
+ <button
+ type="button"
+ className="template-card-cover"
+ onClick={() => onEdit(template)}
+ aria-label={`编辑模板 ${template.name}`}
+ >
+ {src ? (
+ <img src={src} alt={template.name} loading="lazy" className="template-card-cover-img" />
+ ) : (
+ <div className="template-card-cover-fallback">
+ <ImageOff className="h-8 w-8 text-white/70" />
+ </div>
+ )}
+ <div className="template-card-cover-gradient" />
+ <div className="template-card-cover-meta">
+ <span className="template-card-sort">#{template.sort_order}</span>
+ {template.is_premium ? (
+ <span className="template-card-badge template-card-badge--premium">
+ <Crown className="h-3 w-3" />
+ Premium
+ </span>
+ ) : null}
+ {!template.is_active ? (
+ <span className="template-card-badge template-card-badge--off">已下架</span>
+ ) : null}
+ </div>
+ </button>
+
+ <div className="template-card-body">
+ <div className="template-card-head">
+ <div className="min-w-0 flex-1">
+ <h3 className="template-card-title">{template.name}</h3>
+ <p className="template-card-id">{template.id}</p>
+ </div>
+ <div className="template-card-actions">
+ <button type="button" className="template-card-icon-btn" onClick={() => onEdit(template)} title="编辑">
+ <Pencil className="h-4 w-4" />
+ </button>
+ <button
+ type="button"
+ className="template-card-icon-btn template-card-icon-btn--danger"
+ onClick={() => onDelete(template.id)}
+ title="删除"
+ >
+ <Trash2 className="h-4 w-4" />
+ </button>
+ </div>
+ </div>
+
+ {template.description ? (
+ <p className="template-card-desc">{template.description}</p>
+ ) : (
+ <p className="template-card-desc template-card-desc--empty">暂无描述</p>
+ )}
+
+ <div className="template-card-tags">
+ {categories.slice(0, 3).map((tag) => (
+ <span key={tag} className="template-card-tag">
+ {tag}
+ </span>
+ ))}
+ <span className="template-card-tag template-card-tag--muted">{template.default_ratio}</span>
+ </div>
+
+ <div className="template-card-foot">
+ <label className="template-card-toggle">
+ <span>上架</span>
+ <Switch
+ checked={template.is_active}
+ onCheckedChange={(v) => onToggleActive(template.id, v)}
+ />
+ </label>
+ <label className="template-card-toggle">
+ <span>Premium</span>
+ <Switch
+ checked={template.is_premium}
+ onCheckedChange={(v) => onTogglePremium(template.id, v)}
+ />
+ </label>
+ </div>
+ </div>
+ </article>
+ );
+}
diff --git a/admin/src/components/templates/TemplateEditorDialog.tsx b/admin/src/components/templates/TemplateEditorDialog.tsx
new file mode 100644
index 0000000..9a231cf
--- /dev/null
+++ b/admin/src/components/templates/TemplateEditorDialog.tsx
@@ -0,0 +1,283 @@
+import { ImageOff, Loader2, Save } from "lucide-react";
+import { useMemo, useState } from "react";
+import type { AdminTemplate } from "@/api/client";
+import { AdminField } from "@/components/admin/AdminField";
+import { AdminModal } from "@/components/admin/AdminModal";
+import { AdminSelect } from "@/components/admin/AdminSelect";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Switch } from "@/components/ui/switch";
+import { Textarea } from "@/components/ui/select";
+import { cn } from "@/lib/utils";
+
+export type TemplateFormState = {
+ id: string;
+ name: string;
+ description: string;
+ category: string;
+ preview_cover: string;
+ style_prefix: string;
+ character_prompt: string;
+ extra_prompt: string;
+ negative_prompt: string;
+ default_ratio: string;
+ shot_duration_min: number;
+ shot_duration_max: number;
+ llm_system_addon: string;
+ sort_order: number;
+ is_active: boolean;
+ is_premium: boolean;
+};
+
+type TemplateEditorDialogProps = {
+ open: boolean;
+ saving: boolean;
+ editing: AdminTemplate | null;
+ form: TemplateFormState;
+ categorySuggestions?: string[];
+ onOpenChange: (open: boolean) => void;
+ onChange: (patch: Partial<TemplateFormState>) => void;
+ onSave: () => void;
+};
+
+type EditorTab = "basic" | "prompts" | "publish";
+
+const TABS: { id: EditorTab; label: string }[] = [
+ { id: "basic", label: "基础信息" },
+ { id: "prompts", label: "提示词" },
+ { id: "publish", label: "发布设置" },
+];
+
+const RATIO_OPTIONS = [
+ { value: "16:9", label: "16:9 横屏" },
+ { value: "9:16", label: "9:16 竖屏" },
+ { value: "1:1", label: "1:1 方形" },
+ { value: "4:3", label: "4:3" },
+ { value: "3:4", label: "3:4" },
+];
+
+// 解析封面预览地址
+function coverPreviewSrc(url: string): string {
+ const trimmed = (url || "").trim();
+ if (!trimmed) return "";
+ if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) return trimmed;
+ return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
+}
+
+// 模板新建/编辑弹窗(分 Tab + 封面预览)
+export function TemplateEditorDialog({
+ open,
+ saving,
+ editing,
+ form,
+ categorySuggestions = [],
+ onOpenChange,
+ onChange,
+ onSave,
+}: TemplateEditorDialogProps) {
+ const [tab, setTab] = useState<EditorTab>("basic");
+ const previewSrc = useMemo(() => coverPreviewSrc(form.preview_cover), [form.preview_cover]);
+
+ const handleOpenChange = (next: boolean) => {
+ if (!next) setTab("basic");
+ onOpenChange(next);
+ };
+
+ return (
+ <AdminModal
+ open={open}
+ onOpenChange={handleOpenChange}
+ size="full"
+ className="template-editor-dialog max-h-[92vh] overflow-hidden"
+ bodyClassName="p-0 overflow-hidden"
+ title={editing ? `编辑模板 · ${editing.name}` : "新建模板"}
+ subtitle={editing ? editing.id : "填写基础信息与提示词,保存后立即生效"}
+ footer={
+ <>
+ <Button variant="outline" onClick={() => handleOpenChange(false)}>
+ 取消
+ </Button>
+ <Button disabled={saving} onClick={onSave}>
+ {saving ? <Loader2 className="mr-2 h-4 w-4 animate-spin" /> : <Save className="mr-2 h-4 w-4" />}
+ {saving ? "保存中…" : "保存模板"}
+ </Button>
+ </>
+ }
+ >
+ <div className="template-editor-layout">
+ <aside className="template-editor-preview">
+ <div className="template-editor-preview-frame">
+ {previewSrc ? (
+ <img src={previewSrc} alt="封面预览" className="template-editor-preview-img" />
+ ) : (
+ <div className="template-editor-preview-empty">
+ <ImageOff className="h-10 w-10 text-[#c0c4cc]" />
+ <span>封面预览</span>
+ </div>
+ )}
+ </div>
+ <AdminField label="封面 URL" hint="支持相对路径(/static)或 HTTPS;建议 16:9 横图。">
+ <Input
+ className="admin-input h-9"
+ placeholder="/static/templates/covers/xxx.png"
+ value={form.preview_cover}
+ onChange={(e) => onChange({ preview_cover: e.target.value })}
+ />
+ </AdminField>
+ </aside>
+
+ <div className="template-editor-main">
+ <div className="template-editor-tabs" role="tablist">
+ {TABS.map((item) => (
+ <button
+ key={item.id}
+ type="button"
+ role="tab"
+ aria-selected={tab === item.id}
+ className={cn("template-editor-tab", tab === item.id && "is-active")}
+ onClick={() => setTab(item.id)}
+ >
+ {item.label}
+ </button>
+ ))}
+ </div>
+
+ <div className="template-editor-panel">
+ {tab === "basic" ? (
+ <div className="template-editor-grid">
+ {!editing ? (
+ <AdminField label="模板 ID" className="template-editor-field--full">
+ <Input
+ className="admin-input h-9"
+ placeholder="例如 live_street_interview"
+ value={form.id}
+ onChange={(e) => onChange({ id: e.target.value })}
+ />
+ </AdminField>
+ ) : null}
+ <AdminField label="名称" className="template-editor-field--full">
+ <Input
+ className="admin-input h-9"
+ value={form.name}
+ onChange={(e) => onChange({ name: e.target.value })}
+ />
+ </AdminField>
+ <AdminField label="描述" className="template-editor-field--full">
+ <Textarea
+ value={form.description}
+ onChange={(e) => onChange({ description: e.target.value })}
+ className="min-h-[88px]"
+ />
+ </AdminField>
+ <AdminField
+ label="分类(逗号分隔)"
+ hint={
+ categorySuggestions.length
+ ? `常用:${categorySuggestions.slice(0, 8).join("、")}${categorySuggestions.length > 8 ? "…" : ""}`
+ : undefined
+ }
+ >
+ <Input
+ className="admin-input h-9"
+ placeholder="真人感,电影感,商业"
+ value={form.category}
+ onChange={(e) => onChange({ category: e.target.value })}
+ />
+ </AdminField>
+ <AdminSelect
+ label="默认画幅"
+ value={form.default_ratio}
+ options={RATIO_OPTIONS}
+ onChange={(v) => onChange({ default_ratio: v })}
+ />
+ <AdminField label="排序">
+ <Input
+ className="admin-input h-9"
+ type="number"
+ value={form.sort_order}
+ onChange={(e) => onChange({ sort_order: Number(e.target.value) })}
+ />
+ </AdminField>
+ <AdminField label="镜头时长 min(秒)">
+ <Input
+ className="admin-input h-9"
+ type="number"
+ value={form.shot_duration_min}
+ onChange={(e) => onChange({ shot_duration_min: Number(e.target.value) })}
+ />
+ </AdminField>
+ <AdminField label="镜头时长 max(秒)">
+ <Input
+ className="admin-input h-9"
+ type="number"
+ value={form.shot_duration_max}
+ onChange={(e) => onChange({ shot_duration_max: Number(e.target.value) })}
+ />
+ </AdminField>
+ </div>
+ ) : null}
+
+ {tab === "prompts" ? (
+ <div className="template-editor-grid template-editor-grid--prompts">
+ <AdminField label="风格提示词" className="template-editor-field--full">
+ <Textarea
+ value={form.style_prefix}
+ onChange={(e) => onChange({ style_prefix: e.target.value })}
+ className="min-h-[100px] font-mono text-[13px]"
+ />
+ </AdminField>
+ <AdminField label="角色提示词" className="template-editor-field--full">
+ <Textarea
+ value={form.character_prompt}
+ onChange={(e) => onChange({ character_prompt: e.target.value })}
+ className="min-h-[88px] font-mono text-[13px]"
+ />
+ </AdminField>
+ <AdminField label="额外提示词" className="template-editor-field--full">
+ <Textarea
+ value={form.extra_prompt}
+ onChange={(e) => onChange({ extra_prompt: e.target.value })}
+ className="min-h-[88px] font-mono text-[13px]"
+ />
+ </AdminField>
+ <AdminField label="LLM 系统附加说明" className="template-editor-field--full">
+ <Textarea
+ value={form.llm_system_addon}
+ onChange={(e) => onChange({ llm_system_addon: e.target.value })}
+ className="min-h-[88px] font-mono text-[13px]"
+ />
+ </AdminField>
+ <AdminField label="负面提示词" className="template-editor-field--full">
+ <Textarea
+ value={form.negative_prompt}
+ onChange={(e) => onChange({ negative_prompt: e.target.value })}
+ className="min-h-[88px] font-mono text-[13px]"
+ />
+ </AdminField>
+ </div>
+ ) : null}
+
+ {tab === "publish" ? (
+ <div className="template-editor-publish">
+ <div className="template-editor-publish-row">
+ <div>
+ <strong>上架展示</strong>
+ <p>关闭后用户端选模板列表不可见,已有项目不受影响。</p>
+ </div>
+ <Switch checked={form.is_active} onCheckedChange={(v) => onChange({ is_active: v })} />
+ </div>
+ <div className="template-editor-publish-row">
+ <div>
+ <strong>Premium 模板</strong>
+ <p>标记为高级模板,可用于权限或计费策略区分。</p>
+ </div>
+ <Switch checked={form.is_premium} onCheckedChange={(v) => onChange({ is_premium: v })} />
+ </div>
+ </div>
+ ) : null}
+ </div>
+ </div>
+ </div>
+ </AdminModal>
+ );
+}
diff --git a/admin/src/components/ui/page.tsx b/admin/src/components/ui/page.tsx
index dca20e4..3160c07 100644
--- a/admin/src/components/ui/page.tsx
+++ b/admin/src/components/ui/page.tsx
@@ -2,20 +2,18 @@ import type { ReactNode } from "react";
import { cn } from "@/lib/utils";
type PageHeaderProps = {
- title: string;
+ title?: string;
description?: string;
actions?: ReactNode;
className?: string;
};
-// Consistent page title block used across admin pages
-export function PageHeader({ title, description, actions, className }: PageHeaderProps) {
+// 统一页面标题区(标题由顶栏展示,此处仅描述与操作)
+export function PageHeader({ description, actions, className }: PageHeaderProps) {
+ if (!description && !actions) return null;
return (
- <div className={cn("mb-1 flex flex-wrap items-end justify-between gap-3", className)}>
- <div>
- <h2 className="text-xl font-semibold tracking-tight text-[#303133]">{title}</h2>
- {description ? <p className="mt-1 text-sm text-[#909399]">{description}</p> : null}
- </div>
+ <div className={cn("admin-page-header", className)}>
+ {description ? <p className="admin-page-desc">{description}</p> : null}
{actions ? <div className="flex flex-wrap items-center gap-2">{actions}</div> : null}
</div>
);
@@ -27,19 +25,17 @@ type EmptyStateProps = {
className?: string;
};
-// Empty list placeholder
+// 空列表占位
export function EmptyState({
title = "暂无数据",
description = "换个筛选条件再试试",
className,
}: EmptyStateProps) {
return (
- <div className={cn("flex flex-col items-center justify-center gap-1 py-14 text-center", className)}>
- <div className="mb-2 flex h-12 w-12 items-center justify-center rounded-2xl bg-[#f5f7fa] text-lg text-[#c0c4cc]">
- ∅
- </div>
- <div className="text-sm font-medium text-[#606266]">{title}</div>
- <div className="text-xs text-[#909399]">{description}</div>
+ <div className={cn("admin-empty", className)}>
+ <div className="admin-empty-icon">∅</div>
+ <div className="admin-empty-title">{title}</div>
+ <div className="admin-empty-desc">{description}</div>
</div>
);
}
@@ -49,16 +45,7 @@ type ToolbarProps = {
className?: string;
};
-// Filter / search toolbar row
+// 筛选 / 搜索工具条
export function Toolbar({ children, className }: ToolbarProps) {
- return (
- <div
- className={cn(
- "flex flex-wrap items-center gap-2 rounded-xl border border-[#ebeef5] bg-white p-3 shadow-[0_1px_2px_rgba(16,24,40,0.03)]",
- className,
- )}
- >
- {children}
- </div>
- );
+ return <div className={cn("admin-filter-bar", className)}>{children}</div>;
}
diff --git a/admin/src/hooks/useAdminModelSettings.ts b/admin/src/hooks/useAdminModelSettings.ts
new file mode 100644
index 0000000..993c373
--- /dev/null
+++ b/admin/src/hooks/useAdminModelSettings.ts
@@ -0,0 +1,44 @@
+import { useCallback, useEffect, useState } from "react";
+import { toast } from "sonner";
+import { api, type AdminModelSettings } from "@/api/client";
+
+// 加载 / 保存管理端 flat 配置(DB 覆盖 env)
+export function useAdminModelSettings() {
+ const [form, setForm] = useState<AdminModelSettings | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [saving, setSaving] = useState(false);
+
+ const load = useCallback(async () => {
+ setLoading(true);
+ try {
+ setForm(await api<AdminModelSettings>("/api/admin/settings/models"));
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "加载配置失败");
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ void load();
+ }, [load]);
+
+ function patchField<K extends keyof AdminModelSettings>(key: K, value: AdminModelSettings[K]) {
+ setForm((prev) => (prev ? { ...prev, [key]: value } : prev));
+ }
+
+ async function save(body: Record<string, unknown>, successMessage = "配置已保存") {
+ setSaving(true);
+ try {
+ await api("/api/admin/settings/models", { method: "PATCH", body: JSON.stringify(body) });
+ await load();
+ toast.success(successMessage);
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "保存失败");
+ } finally {
+ setSaving(false);
+ }
+ }
+
+ return { form, loading, saving, load, patchField, save };
+}
diff --git a/admin/src/index.css b/admin/src/index.css
index 6c37c44..c733234 100644
--- a/admin/src/index.css
+++ b/admin/src/index.css
@@ -287,20 +287,31 @@
}
}
-/* ---- Admin console shell (reference UI) ---- */
+/* ---- Admin console shell ---- */
.admin-app {
- --admin-bg: #f5f7fa;
+ --admin-bg: #eef1ef;
+ --admin-bg-subtle: #e4eae6;
--admin-card: #ffffff;
- --admin-text: #303133;
- --admin-muted: #909399;
- --admin-border: #ebeef5;
- --admin-accent: #67c23a;
- --admin-accent-soft: #f0f9eb;
- --admin-sidebar: #ffffff;
- --admin-sidebar-w: 220px;
+ --admin-text: #1a211c;
+ --admin-muted: #6b756e;
+ --admin-border: #dde4df;
+ --admin-forest: #1f5c48;
+ --admin-forest-deep: #163f33;
+ --admin-accent: #3d9a72;
+ --admin-accent-soft: rgba(61, 154, 114, 0.12);
+ --admin-accent-ring: rgba(31, 92, 72, 0.18);
+ --admin-sidebar: #121a16;
+ --admin-sidebar-border: rgba(255, 255, 255, 0.06);
+ --admin-sidebar-text: rgba(240, 245, 242, 0.72);
+ --admin-sidebar-muted: rgba(240, 245, 242, 0.42);
+ --admin-sidebar-w: 232px;
+ --admin-radius: 14px;
+ --admin-shadow: 0 1px 2px rgba(18, 26, 22, 0.04), 0 8px 24px rgba(18, 26, 22, 0.04);
display: flex;
min-height: 100vh;
- background: var(--admin-bg);
+ background:
+ radial-gradient(ellipse 90% 60% at 100% 0%, rgba(61, 154, 114, 0.06), transparent 55%),
+ var(--admin-bg);
color: var(--admin-text);
font-family: "Figtree", "PingFang SC", "Microsoft YaHei", sans-serif;
}
@@ -314,9 +325,12 @@
flex-shrink: 0;
display: flex;
flex-direction: column;
- background: var(--admin-sidebar);
- border-right: 1px solid var(--admin-border);
- transition: width 0.2s ease;
+ background:
+ linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 18%),
+ var(--admin-sidebar);
+ border-right: 1px solid var(--admin-sidebar-border);
+ transition: width 0.22s ease;
+ box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
}
.admin-brand {
@@ -325,70 +339,89 @@
gap: 0.75rem;
height: 64px;
padding: 0 1rem;
- border-bottom: 1px solid var(--admin-border);
+ border-bottom: 1px solid var(--admin-sidebar-border);
}
.admin-brand-mark {
- width: 36px;
- height: 36px;
- border-radius: 10px;
+ width: 38px;
+ height: 38px;
+ border-radius: 11px;
display: grid;
place-items: center;
- background: linear-gradient(145deg, #85ce61, #67c23a);
- color: #fff;
- font-size: 12px;
- font-weight: 700;
- letter-spacing: 0.02em;
+ background: linear-gradient(145deg, #4caf82 0%, var(--admin-forest) 100%);
+ color: #f4f1ea;
+ font-family: var(--font-display);
+ font-size: 11px;
+ font-weight: 800;
+ letter-spacing: 0.06em;
flex-shrink: 0;
+ box-shadow: 0 6px 16px rgba(31, 92, 72, 0.35);
}
.admin-brand-name {
- font-size: 14px;
- font-weight: 700;
- letter-spacing: 0.04em;
+ font-family: var(--font-display);
+ font-size: 13px;
+ font-weight: 800;
+ letter-spacing: 0.12em;
line-height: 1.2;
+ color: #f4f1ea;
}
.admin-brand-sub {
- font-size: 12px;
- color: var(--admin-muted);
+ font-size: 11px;
+ color: var(--admin-sidebar-muted);
+ letter-spacing: 0.08em;
}
.admin-nav {
display: flex;
flex-direction: column;
- gap: 4px;
- padding: 12px 10px;
+ gap: 2px;
+ padding: 14px 10px;
flex: 1;
overflow: auto;
}
+.admin-nav-group {
+ margin-bottom: 10px;
+}
+
+.admin-nav-group-label {
+ padding: 8px 12px 6px;
+ font-size: 10px;
+ font-weight: 600;
+ letter-spacing: 0.14em;
+ text-transform: uppercase;
+ color: var(--admin-sidebar-muted);
+}
+
.admin-nav-item {
display: flex;
align-items: center;
gap: 10px;
- min-height: 42px;
+ min-height: 40px;
padding: 0 12px;
border-radius: 10px;
- color: #606266;
+ color: var(--admin-sidebar-text);
text-decoration: none;
- font-size: 14px;
- transition: background 0.15s, color 0.15s;
+ font-size: 13px;
+ font-weight: 500;
+ transition: background 0.15s, color 0.15s, transform 0.12s;
}
.admin-nav-item:hover {
- background: #f5f7fa;
- color: var(--admin-text);
+ background: rgba(255, 255, 255, 0.06);
+ color: #f4f1ea;
}
.admin-nav-item.is-active {
- background: #303133;
- color: #fff;
+ background: var(--admin-accent-soft);
+ color: #e8f5ee;
+ box-shadow: inset 0 0 0 1px rgba(61, 154, 114, 0.28);
}
-.admin-nav-item.is-disabled {
- opacity: 0.45;
- cursor: not-allowed;
+.admin-nav-item.is-active svg {
+ color: #6fd4a8;
}
.admin-user-card {
@@ -398,8 +431,8 @@
margin: 10px;
padding: 10px;
border-radius: 12px;
- background: #f8fafc;
- border: 1px solid var(--admin-border);
+ background: rgba(255, 255, 255, 0.04);
+ border: 1px solid var(--admin-sidebar-border);
}
.admin-avatar {
@@ -408,8 +441,8 @@
border-radius: 999px;
display: grid;
place-items: center;
- background: var(--admin-accent-soft);
- color: var(--admin-accent);
+ background: rgba(61, 154, 114, 0.18);
+ color: #8fe0b8;
font-size: 13px;
font-weight: 700;
flex-shrink: 0;
@@ -423,188 +456,1605 @@
}
.admin-topbar {
- height: 56px;
+ height: 58px;
display: flex;
align-items: center;
justify-content: space-between;
- padding: 0 20px;
- background: #fff;
+ padding: 0 22px;
+ background: rgba(255, 255, 255, 0.82);
+ backdrop-filter: blur(12px);
border-bottom: 1px solid var(--admin-border);
+ position: sticky;
+ top: 0;
+ z-index: 20;
+}
+
+.admin-topbar-title {
+ font-size: 15px;
+ font-weight: 600;
+ color: var(--admin-text);
+ letter-spacing: -0.01em;
+}
+
+.admin-topbar-crumb {
+ font-size: 12px;
+ color: var(--admin-muted);
+ margin-top: 1px;
}
.admin-icon-btn {
width: 34px;
height: 34px;
border: 0;
- border-radius: 8px;
+ border-radius: 9px;
background: transparent;
- color: #606266;
+ color: var(--admin-muted);
display: grid;
place-items: center;
cursor: pointer;
+ transition: background 0.15s, color 0.15s;
}
.admin-icon-btn:hover {
- background: #f5f7fa;
- color: var(--admin-text);
+ background: var(--admin-accent-soft);
+ color: var(--admin-forest);
}
.admin-content {
flex: 1;
overflow: auto;
- padding: 20px 24px 32px;
+ padding: 14px 18px 20px;
+}
+
+.admin-page {
+ display: flex;
+ flex-direction: column;
+ gap: 14px;
+ width: 100%;
+ max-width: none;
+}
+
+.admin-page-header {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ justify-content: space-between;
+ gap: 10px;
+ margin: 0;
+}
+
+.admin-page-title {
+ display: none;
+}
+
+.admin-page-desc {
+ margin: 0;
+ font-size: 13px;
+ line-height: 1.45;
+ color: var(--admin-muted);
}
.admin-panel {
background: var(--admin-card);
border: 1px solid var(--admin-border);
- border-radius: 12px;
- padding: 18px 20px;
- box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
+ border-radius: var(--admin-radius);
+ padding: 14px 16px;
+ box-shadow: var(--admin-shadow);
+}
+
+.admin-section-header {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-start;
+ justify-content: space-between;
+ gap: 10px;
+ margin-bottom: 10px;
+}
+
+.admin-section-title {
+ margin: 0;
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--admin-text);
+}
+
+.admin-section-desc {
+ margin: 4px 0 0;
+ font-size: 12px;
+ color: var(--admin-muted);
+}
+
+.admin-section-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
}
.admin-stat-card {
position: relative;
overflow: hidden;
+ padding-top: 16px;
+ min-height: 96px;
+}
+
+.admin-stat-card::before {
+ content: "";
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ height: 3px;
+ background: linear-gradient(90deg, var(--admin-forest), var(--admin-accent));
+ opacity: 0.85;
+}
+
+.admin-stat-card.tone-info::before {
+ background: linear-gradient(90deg, #2563eb, #60a5fa);
+}
+
+.admin-stat-card.tone-warn::before {
+ background: linear-gradient(90deg, #d97706, #fbbf24);
+}
+
+.admin-stat-card.tone-success::before {
+ background: linear-gradient(90deg, var(--admin-forest), var(--admin-accent));
+}
+
+.admin-stat-label {
+ font-size: 13px;
+ color: var(--admin-muted);
+}
+
+.admin-stat-value {
+ margin-top: 6px;
+ font-family: var(--font-display);
+ font-size: 1.65rem;
+ font-weight: 700;
+ line-height: 1;
+ letter-spacing: -0.03em;
+ color: var(--admin-text);
+}
+
+.admin-stat-hint {
+ margin-top: 6px;
+ font-size: 11px;
+ color: #9aa39c;
}
.admin-stat-icon {
position: absolute;
- top: 16px;
+ top: 18px;
right: 16px;
- width: 40px;
- height: 40px;
- border-radius: 10px;
+ width: 42px;
+ height: 42px;
+ border-radius: 11px;
display: grid;
place-items: center;
background: var(--admin-accent-soft);
- color: var(--admin-accent);
+ color: var(--admin-forest);
+}
+
+.admin-stat-card.tone-info .admin-stat-icon {
+ background: rgba(37, 99, 235, 0.1);
+ color: #2563eb;
+}
+
+.admin-stat-card.tone-warn .admin-stat-icon {
+ background: rgba(217, 119, 6, 0.12);
+ color: #d97706;
}
.admin-status-pill {
display: inline-flex;
align-items: center;
gap: 8px;
- padding: 6px 12px;
+ padding: 5px 11px;
border-radius: 999px;
- font-size: 13px;
- font-weight: 500;
- background: #f4f4f5;
- color: #606266;
+ font-size: 12px;
+ font-weight: 600;
+ background: #f0f2f1;
+ color: var(--admin-muted);
}
.admin-status-pill.is-done {
- background: #f0f9eb;
- color: #67c23a;
+ background: rgba(61, 154, 114, 0.12);
+ color: var(--admin-forest);
}
+
.admin-status-pill.is-run {
- background: #ecf5ff;
- color: #409eff;
+ background: rgba(37, 99, 235, 0.1);
+ color: #2563eb;
}
+
.admin-status-pill.is-warn {
- background: #fdf6ec;
- color: #e6a23c;
+ background: rgba(217, 119, 6, 0.12);
+ color: #b45309;
}
+
.admin-status-pill.is-fail {
- background: #fef0f0;
- color: #f56c6c;
+ background: rgba(239, 68, 68, 0.1);
+ color: #dc2626;
}
-.admin-page-btn {
- min-width: 32px;
- height: 32px;
- padding: 0 8px;
- border: 1px solid transparent;
- border-radius: 8px;
+.admin-tab {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ min-height: 34px;
+ padding: 0 14px;
+ border-radius: 999px;
+ border: 1px solid var(--admin-border);
background: #fff;
- color: #606266;
+ color: var(--admin-muted);
font-size: 13px;
font-weight: 500;
cursor: pointer;
+ transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
+}
+
+.admin-tab:hover {
+ border-color: #c5d4cc;
+ color: var(--admin-text);
+}
+
+.admin-tab.is-active {
+ border-color: rgba(61, 154, 114, 0.45);
+ background: var(--admin-accent-soft);
+ color: var(--admin-forest);
+ box-shadow: 0 0 0 3px var(--admin-accent-ring);
+}
+
+.admin-btn {
display: inline-flex;
align-items: center;
justify-content: center;
- box-shadow: inset 0 0 0 1px #e4e7ed;
- transition: color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.1s;
+ gap: 6px;
+ min-height: 34px;
+ padding: 0 14px;
+ border-radius: 9px;
+ border: 1px solid transparent;
+ font-size: 13px;
+ font-weight: 600;
+ cursor: pointer;
+ transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
-.admin-page-btn:hover:not(:disabled) {
- color: #67c23a;
- box-shadow: inset 0 0 0 1px #c2e7b0;
- background: #f0f9eb;
+.admin-btn:active:not(:disabled) {
+ transform: translateY(1px);
}
-.admin-page-btn.is-active {
- background: linear-gradient(180deg, #85ce61, #67c23a);
- box-shadow: 0 4px 10px rgba(103, 194, 58, 0.28);
- color: #fff;
+.admin-btn:disabled {
+ opacity: 0.55;
+ cursor: not-allowed;
}
-.admin-page-btn:disabled {
- opacity: 0.4;
- cursor: not-allowed;
+.admin-btn-primary {
+ background: linear-gradient(180deg, #4caf82, var(--admin-forest));
+ color: #f7f5f0;
+ box-shadow: 0 4px 12px rgba(31, 92, 72, 0.28);
}
-.admin-table-wrap {
- overflow: auto;
- border-radius: 10px;
- border: 1px solid var(--admin-border);
+.admin-btn-primary:hover:not(:disabled) {
+ background: linear-gradient(180deg, #56b88b, var(--admin-forest-deep));
}
-.admin-table-wrap table {
- width: 100%;
- border-collapse: collapse;
- font-size: 13px;
+.admin-btn-secondary {
+ border-color: var(--admin-border);
+ background: #fff;
+ color: var(--admin-text);
}
-.admin-table-wrap th {
- text-align: left;
- padding: 12px 14px;
- background: #fafbfc;
- color: #909399;
- font-weight: 500;
- border-bottom: 1px solid var(--admin-border);
+.admin-btn-secondary:hover:not(:disabled) {
+ border-color: #c5d4cc;
+ background: #f8faf9;
}
-.admin-table-wrap td {
- padding: 12px 14px;
- border-bottom: 1px solid #f2f3f5;
- color: #303133;
+.admin-btn-danger {
+ border-color: rgba(239, 68, 68, 0.35);
+ background: rgba(239, 68, 68, 0.08);
+ color: #dc2626;
}
-.admin-table-wrap tr:last-child td {
- border-bottom: 0;
+.admin-btn-danger:hover:not(:disabled) {
+ background: rgba(239, 68, 68, 0.14);
}
-.admin-quick-btn {
+.admin-filter-bar {
display: flex;
- flex-direction: column;
- align-items: flex-start;
- gap: 8px;
+ flex-wrap: wrap;
+ align-items: flex-end;
+ gap: 12px;
padding: 14px;
- border-radius: 10px;
+ border-radius: 12px;
border: 1px solid var(--admin-border);
- background: #fafbfc;
- color: var(--admin-text);
- text-decoration: none;
+ background: #f8faf9;
+}
+
+.admin-field {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ min-width: 0;
+}
+
+.admin-field-label {
+ font-size: 11px;
+ font-weight: 600;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ color: var(--admin-muted);
+}
+
+.admin-input,
+.admin-select {
+ height: 36px;
+ min-width: 120px;
+ border-radius: 9px;
+ border: 1px solid #cfd8d2;
+ background: #fff;
+ padding: 0 10px;
font-size: 13px;
- transition: border-color 0.15s, background 0.15s;
+ color: var(--admin-text);
+ outline: none;
+ transition: border-color 0.15s, box-shadow 0.15s;
}
-.admin-quick-btn:hover {
- border-color: #c2e7b0;
- background: var(--admin-accent-soft);
+.admin-input:focus,
+.admin-select:focus {
+ border-color: var(--admin-accent);
+ box-shadow: 0 0 0 3px var(--admin-accent-ring);
}
-@media (max-width: 900px) {
- .admin-app {
- --admin-sidebar-w: 72px;
- }
- .admin-brand-name,
- .admin-brand-sub,
- .admin-nav-item span,
- .admin-user-card .min-w-0 {
- display: none;
+.admin-input-search-wrap {
+ position: relative;
+ flex: 1;
+ min-width: 200px;
+}
+
+.admin-input-search-wrap svg {
+ position: absolute;
+ left: 10px;
+ top: 50%;
+ transform: translateY(-50%);
+ color: #9aa39c;
+ pointer-events: none;
+}
+
+.admin-input-search-wrap .admin-input {
+ width: 100%;
+ padding-left: 32px;
+}
+
+.admin-select-wrap {
+ position: relative;
+ display: inline-flex;
+ min-width: 0;
+}
+
+.admin-select-wrap::after {
+ content: "";
+ position: absolute;
+ right: 12px;
+ top: 50%;
+ width: 0;
+ height: 0;
+ pointer-events: none;
+ border-left: 4px solid transparent;
+ border-right: 4px solid transparent;
+ border-top: 5px solid #909399;
+ transform: translateY(-35%);
+}
+
+.admin-select-wrap .admin-select {
+ width: 100%;
+ padding-right: 28px;
+ appearance: none;
+ cursor: pointer;
+}
+
+.admin-field-hint {
+ margin: 0;
+ font-size: 11px;
+ line-height: 1.5;
+ color: #909399;
+}
+
+.admin-filter-panel {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ padding: 14px;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #f8faf9;
+}
+
+.admin-filter-panel-main {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 12px;
+}
+
+.admin-filter-panel-trailing {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: #909399;
+}
+
+.admin-chip-filter {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 8px;
+ width: 100%;
+}
+
+.admin-chip-filter-label {
+ flex-shrink: 0;
+ font-size: 12px;
+ font-weight: 600;
+ color: #606266;
+}
+
+.admin-chip-filter-list {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+}
+
+.admin-chip {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ height: 28px;
+ padding: 0 10px;
+ border: 1px solid #dce3de;
+ border-radius: 999px;
+ background: #fff;
+ font-size: 12px;
+ color: #606266;
+ cursor: pointer;
+ transition: border-color 0.15s, background 0.15s, color 0.15s;
+}
+
+.admin-chip:hover {
+ border-color: rgba(61, 154, 114, 0.45);
+ color: var(--admin-forest);
+}
+
+.admin-chip.is-active {
+ border-color: var(--admin-accent);
+ background: var(--admin-accent-soft);
+ color: var(--admin-forest);
+ font-weight: 600;
+}
+
+.admin-chip-count {
+ min-width: 18px;
+ height: 18px;
+ padding: 0 5px;
+ border-radius: 999px;
+ background: rgba(0, 0, 0, 0.06);
+ font-size: 10px;
+ font-weight: 700;
+ line-height: 18px;
+ text-align: center;
+}
+
+.admin-chip.is-active .admin-chip-count {
+ background: rgba(61, 154, 114, 0.18);
+}
+
+.admin-modal {
+ gap: 0 !important;
+ padding: 0 !important;
+ overflow: hidden;
+}
+
+.admin-modal--md {
+ max-width: 420px !important;
+}
+
+.admin-modal--lg {
+ max-width: 640px !important;
+}
+
+.admin-modal--xl {
+ max-width: 960px !important;
+}
+
+.admin-modal--full {
+ max-width: min(1100px, calc(100vw - 32px)) !important;
+}
+
+.admin-modal-header {
+ padding: 18px 22px 14px !important;
+ border-bottom: 1px solid var(--admin-border);
+}
+
+.admin-modal-title {
+ font-size: 17px !important;
+}
+
+.admin-modal-subtitle {
+ margin: 4px 0 0;
+ font-size: 13px;
+ line-height: 1.5;
+ color: #909399;
+}
+
+.admin-modal-body {
+ padding: 18px 22px;
+ overflow-y: auto;
+}
+
+.admin-modal-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 10px;
+ padding: 14px 22px;
+ border-top: 1px solid var(--admin-border);
+ background: #fafbfa;
+}
+
+.admin-page-btn {
+ min-width: 32px;
+ height: 32px;
+ padding: 0 8px;
+ border: 1px solid transparent;
+ border-radius: 8px;
+ background: #fff;
+ color: var(--admin-muted);
+ font-size: 13px;
+ font-weight: 500;
+ cursor: pointer;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ box-shadow: inset 0 0 0 1px #d5ddd8;
+ transition: color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.1s;
+}
+
+.admin-page-btn:hover:not(:disabled) {
+ color: var(--admin-forest);
+ box-shadow: inset 0 0 0 1px rgba(61, 154, 114, 0.45);
+ background: var(--admin-accent-soft);
+}
+
+.admin-page-btn.is-active {
+ background: linear-gradient(180deg, #4caf82, var(--admin-forest));
+ box-shadow: 0 4px 10px rgba(31, 92, 72, 0.25);
+ color: #fff;
+}
+
+.admin-page-btn:disabled {
+ opacity: 0.4;
+ cursor: not-allowed;
+}
+
+.admin-table-wrap {
+ overflow: auto;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+}
+
+.admin-table-wrap table {
+ width: 100%;
+ border-collapse: collapse;
+ font-size: 13px;
+}
+
+.admin-table-wrap th {
+ text-align: left;
+ padding: 11px 14px;
+ background: #f5f8f6;
+ color: var(--admin-muted);
+ font-size: 11px;
+ font-weight: 600;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ border-bottom: 1px solid var(--admin-border);
+}
+
+.admin-table-wrap td {
+ padding: 12px 14px;
+ border-bottom: 1px solid #eef2ef;
+ color: var(--admin-text);
+}
+
+.admin-table-wrap tbody tr {
+ transition: background 0.12s;
+}
+
+.admin-table-wrap tbody tr:hover td {
+ background: #f8fbf9;
+}
+
+.admin-table-wrap tr:last-child td {
+ border-bottom: 0;
+}
+
+.admin-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 6px;
+ padding: 28px 16px;
+ text-align: center;
+ color: var(--admin-muted);
+}
+
+.admin-empty-icon {
+ width: 48px;
+ height: 48px;
+ border-radius: 14px;
+ display: grid;
+ place-items: center;
+ background: #f0f3f1;
+ color: #b0bab4;
+ font-size: 20px;
+}
+
+.admin-empty-title {
+ font-size: 14px;
+ font-weight: 600;
+ color: #4a524c;
+}
+
+.admin-empty-desc {
+ font-size: 12px;
+ color: var(--admin-muted);
+}
+
+.admin-quick-btn {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 8px;
+ padding: 14px;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #f8faf9;
+ color: var(--admin-text);
+ text-decoration: none;
+ font-size: 13px;
+ font-weight: 500;
+ transition: border-color 0.15s, background 0.15s, transform 0.12s, box-shadow 0.15s;
+}
+
+.admin-quick-btn:hover {
+ border-color: rgba(61, 154, 114, 0.4);
+ background: var(--admin-accent-soft);
+ box-shadow: 0 4px 14px rgba(31, 92, 72, 0.08);
+ transform: translateY(-1px);
+}
+
+.admin-quick-btn svg {
+ color: var(--admin-forest);
+}
+
+.admin-notice {
+ margin-top: 12px;
+ border-radius: 10px;
+ border: 1px solid var(--admin-border);
+ background: linear-gradient(135deg, #f8faf9 0%, #f0f5f2 100%);
+ padding: 12px 14px;
+}
+
+.admin-dashboard-top {
+ display: grid;
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ gap: 12px;
+}
+
+.admin-dashboard-body {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
+ gap: 12px;
+ align-items: stretch;
+}
+
+.admin-list-page {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ width: 100%;
+}
+
+@media (max-width: 1280px) {
+ .admin-dashboard-top {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+
+ .admin-dashboard-body {
+ grid-template-columns: 1fr;
+ }
+}
+
+@media (max-width: 640px) {
+ .admin-dashboard-top {
+ grid-template-columns: 1fr;
+ }
+}
+
+.admin-notice-title {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ font-size: 13px;
+ font-weight: 600;
+ color: var(--admin-text);
+}
+
+.admin-notice-body {
+ margin-top: 8px;
+ font-size: 13px;
+ line-height: 1.65;
+ color: var(--admin-muted);
+}
+
+.admin-link {
+ font-size: 12px;
+ font-weight: 600;
+ color: var(--admin-forest);
+ text-decoration: none;
+}
+
+.admin-link:hover {
+ text-decoration: underline;
+}
+
+.admin-pagination {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ border-radius: 12px;
+ background: #f5f8f6;
+ border: 1px solid var(--admin-border);
+ padding: 10px 12px;
+ font-size: 13px;
+ color: var(--admin-muted);
+}
+
+.admin-domain-card {
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #f8faf9;
+ padding: 14px 16px;
+ transition: border-color 0.15s, box-shadow 0.15s;
+}
+
+.admin-domain-card:hover {
+ border-color: rgba(61, 154, 114, 0.35);
+ box-shadow: 0 4px 16px rgba(31, 92, 72, 0.06);
+}
+
+/* ---- Model settings (VOZEB-inspired panels) ---- */
+.settings-page {
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+}
+
+.settings-readiness {
+ display: grid;
+ gap: 12px;
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
+}
+
+.settings-readiness-card {
+ border: 1px solid var(--admin-border);
+ border-radius: 10px;
+ background: #fafbfc;
+ padding: 12px 14px;
+}
+
+.settings-readiness-card.is-ready {
+ border-color: rgba(61, 154, 114, 0.35);
+ background: var(--admin-accent-soft);
+}
+
+.settings-panel {
+ overflow: hidden;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #fff;
+}
+
+.settings-panel-header {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-start;
+ justify-content: space-between;
+ gap: 12px;
+ border-bottom: 1px solid var(--admin-border);
+ padding: 16px 20px;
+}
+
+.settings-panel-title {
+ margin: 0;
+ font-size: 15px;
+ font-weight: 600;
+ color: #303133;
+}
+
+.settings-panel-desc {
+ margin: 6px 0 0;
+ font-size: 12px;
+ line-height: 1.5;
+ color: #909399;
+}
+
+.settings-panel-actions {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 8px;
+}
+
+.settings-panel-body {
+ padding: 16px 20px 20px;
+}
+
+.settings-surface {
+ border-radius: 10px;
+ border: 1px solid #ebeef5;
+ background: #fafbfc;
+ padding: 16px;
+}
+
+.settings-section-title {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 14px;
+ font-weight: 600;
+ color: #303133;
+}
+
+.settings-section-icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ border-radius: 8px;
+ background: #fff;
+ color: #606266;
+ border: 1px solid #ebeef5;
+}
+
+.settings-field-grid {
+ margin-top: 16px;
+ display: grid;
+ gap: 14px;
+ grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
+}
+
+.settings-field {
+ display: block;
+ min-width: 0;
+}
+
+.settings-field-label {
+ display: block;
+ margin-bottom: 6px;
+ font-size: 12px;
+ font-weight: 500;
+ color: #606266;
+}
+
+.settings-field-hint {
+ display: block;
+ margin-top: 4px;
+ font-size: 11px;
+ line-height: 1.4;
+ color: #c0c4cc;
+}
+
+.settings-input,
+.settings-select {
+ width: 100%;
+ height: 36px;
+ border-radius: 8px;
+ border: 1px solid #dcdfe6;
+ background: #fff;
+ padding: 0 10px;
+ font-size: 13px;
+ color: #303133;
+ outline: none;
+}
+
+.settings-input:focus,
+.settings-select:focus {
+ border-color: var(--admin-accent);
+ box-shadow: 0 0 0 2px var(--admin-accent-ring);
+}
+
+.settings-input.is-secret::placeholder {
+ color: #909399;
+}
+
+.settings-toggle-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+ border-radius: 8px;
+ border: 1px solid #ebeef5;
+ background: #fff;
+ padding: 10px 12px;
+}
+
+.settings-toggle-row strong {
+ display: block;
+ font-size: 13px;
+ color: #303133;
+}
+
+.settings-toggle-row span {
+ display: block;
+ margin-top: 2px;
+ font-size: 11px;
+ color: #909399;
+}
+
+/* ---- Template management (card grid + editor) ---- */
+.template-grid {
+ display: grid;
+ gap: 14px;
+ grid-template-columns: repeat(6, minmax(0, 1fr));
+}
+
+@media (max-width: 1600px) {
+ .template-grid {
+ grid-template-columns: repeat(5, minmax(0, 1fr));
+ }
+}
+
+@media (max-width: 1280px) {
+ .template-grid {
+ grid-template-columns: repeat(4, minmax(0, 1fr));
+ }
+}
+
+@media (max-width: 1024px) {
+ .template-grid {
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ }
+}
+
+.template-grid-loading,
+.template-grid-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 12px;
+ min-height: 220px;
+ border-radius: 12px;
+ border: 1px dashed var(--admin-border);
+ background: #fafbfc;
+ color: var(--admin-muted);
+ font-size: 14px;
+}
+
+.template-card {
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ border-radius: 14px;
+ border: 1px solid var(--admin-border);
+ background: #fff;
+ box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
+ transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
+}
+
+.template-card:hover {
+ border-color: rgba(61, 154, 114, 0.4);
+ box-shadow: 0 8px 24px rgba(31, 92, 72, 0.08);
+ transform: translateY(-1px);
+}
+
+.template-card--inactive {
+ opacity: 0.82;
+}
+
+.template-card-cover {
+ position: relative;
+ display: block;
+ width: 100%;
+ aspect-ratio: 16 / 10;
+ padding: 0;
+ border: none;
+ background: linear-gradient(135deg, #1f5c48 0%, #3d9a72 100%);
+ cursor: pointer;
+ overflow: hidden;
+}
+
+.template-card-cover-img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ transition: transform 0.25s ease;
+}
+
+.template-card:hover .template-card-cover-img {
+ transform: scale(1.03);
+}
+
+.template-card-cover-fallback {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 100%;
+ height: 100%;
+ background: linear-gradient(135deg, #2d6a4f 0%, #52b788 55%, #1b4332 100%);
+}
+
+.template-card-cover-gradient {
+ position: absolute;
+ inset: 0;
+ background: linear-gradient(to top, rgba(0, 0, 0, 0.55) 0%, transparent 52%);
+ pointer-events: none;
+}
+
+.template-card-cover-meta {
+ position: absolute;
+ left: 10px;
+ right: 10px;
+ bottom: 10px;
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 6px;
+ z-index: 1;
+}
+
+.template-card-sort {
+ font-size: 11px;
+ font-weight: 700;
+ color: rgba(255, 255, 255, 0.9);
+ background: rgba(0, 0, 0, 0.35);
+ border-radius: 6px;
+ padding: 2px 8px;
+}
+
+.template-card-badge {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 10px;
+ font-weight: 600;
+ border-radius: 999px;
+ padding: 2px 8px;
+}
+
+.template-card-badge--premium {
+ color: #7c4a03;
+ background: #fdf6ec;
+}
+
+.template-card-badge--off {
+ color: #606266;
+ background: rgba(255, 255, 255, 0.88);
+}
+
+.template-card-body {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ padding: 12px 14px 14px;
+}
+
+.template-card-head {
+ display: flex;
+ align-items: flex-start;
+ gap: 8px;
+}
+
+.template-card-title {
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--admin-text);
+ line-height: 1.35;
+}
+
+.template-card-id {
+ margin-top: 2px;
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ font-size: 11px;
+ color: var(--admin-muted);
+ word-break: break-all;
+}
+
+.template-card-actions {
+ display: flex;
+ gap: 4px;
+ opacity: 0;
+ transition: opacity 0.15s;
+}
+
+.template-card:hover .template-card-actions {
+ opacity: 1;
+}
+
+.template-card-icon-btn {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 30px;
+ height: 30px;
+ border: none;
+ border-radius: 8px;
+ background: #f5f7fa;
+ color: #606266;
+ cursor: pointer;
+ transition: background 0.15s, color 0.15s;
+}
+
+.template-card-icon-btn:hover {
+ background: var(--admin-accent-soft);
+ color: var(--admin-forest);
+}
+
+.template-card-icon-btn--danger:hover {
+ background: #fef0f0;
+ color: #f56c6c;
+}
+
+.template-card-desc {
+ font-size: 12px;
+ line-height: 1.55;
+ color: #606266;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+ min-height: 2.4em;
+}
+
+.template-card-desc--empty {
+ color: #c0c4cc;
+ font-style: italic;
+}
+
+.template-card-tags {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+}
+
+.template-card-tag {
+ font-size: 11px;
+ color: var(--admin-forest);
+ background: var(--admin-accent-soft);
+ border-radius: 6px;
+ padding: 2px 8px;
+}
+
+.template-card-tag--muted {
+ color: #909399;
+ background: #f5f7fa;
+}
+
+.template-card-foot {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ margin-top: 4px;
+ padding-top: 10px;
+ border-top: 1px solid #f0f2f5;
+}
+
+.template-card-toggle {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: #606266;
+}
+
+.template-editor-dialog {
+ gap: 0 !important;
+}
+
+.template-editor-header {
+ padding: 18px 22px 12px !important;
+ border-bottom: 1px solid var(--admin-border);
+}
+
+.template-editor-subtitle {
+ margin-top: 4px;
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ font-size: 12px;
+ color: var(--admin-muted);
+}
+
+.template-editor-layout {
+ display: grid;
+ grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
+ max-height: calc(92vh - 72px);
+}
+
+.template-editor-preview {
+ display: flex;
+ flex-direction: column;
+ gap: 14px;
+ padding: 16px;
+ border-right: 1px solid var(--admin-border);
+ background: #f8faf9;
+ overflow-y: auto;
+}
+
+.template-editor-preview-frame {
+ aspect-ratio: 16 / 10;
+ overflow: hidden;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #fff;
+}
+
+.template-editor-preview-img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.template-editor-preview-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ width: 100%;
+ height: 100%;
+ font-size: 12px;
+ color: #909399;
+ background: linear-gradient(145deg, #f5f7fa, #eef2f6);
+}
+
+.template-editor-preview-fields {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
+.template-editor-main {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+}
+
+.template-editor-tabs {
+ display: flex;
+ gap: 4px;
+ padding: 12px 16px 0;
+ border-bottom: 1px solid var(--admin-border);
+ background: #fff;
+}
+
+.template-editor-tab {
+ border: none;
+ background: transparent;
+ border-radius: 8px 8px 0 0;
+ padding: 8px 14px;
+ font-size: 13px;
+ font-weight: 500;
+ color: #909399;
+ cursor: pointer;
+ transition: color 0.15s, background 0.15s;
+}
+
+.template-editor-tab:hover {
+ color: #606266;
+ background: #f5f7fa;
+}
+
+.template-editor-tab.is-active {
+ color: var(--admin-forest);
+ background: var(--admin-accent-soft);
+}
+
+.template-editor-panel {
+ flex: 1;
+ overflow-y: auto;
+ padding: 16px 18px;
+}
+
+.template-editor-grid {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 14px;
+}
+
+.template-editor-grid .admin-field {
+ min-width: 0;
+}
+
+.template-editor-grid .template-editor-field--full {
+ grid-column: 1 / -1;
+}
+
+.template-editor-grid--prompts {
+ grid-template-columns: 1fr;
+}
+
+.template-editor-field {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.template-editor-field--full {
+ grid-column: 1 / -1;
+}
+
+.template-editor-publish {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+}
+
+.template-editor-publish-row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+ padding: 14px 16px;
+ border-radius: 12px;
+ border: 1px solid var(--admin-border);
+ background: #fafbfc;
+}
+
+.template-editor-publish-row strong {
+ display: block;
+ font-size: 14px;
+ color: #303133;
+}
+
+.template-editor-publish-row p {
+ margin-top: 4px;
+ font-size: 12px;
+ line-height: 1.5;
+ color: #909399;
+}
+
+.template-editor-footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: 10px;
+ padding: 12px 18px 16px;
+ border-top: 1px solid var(--admin-border);
+ background: #fff;
+}
+
+@media (max-width: 768px) {
+ .template-grid {
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ }
+
+ .template-editor-layout {
+ grid-template-columns: 1fr;
+ max-height: none;
+ }
+
+ .template-editor-preview {
+ border-right: none;
+ border-bottom: 1px solid var(--admin-border);
+ }
+
+ .template-editor-grid {
+ grid-template-columns: 1fr;
+ }
+
+ .template-card-actions {
+ opacity: 1;
+ }
+}
+
+@media (max-width: 900px) {
+ .admin-app {
+ --admin-sidebar-w: 72px;
+ }
+ .admin-brand-name,
+ .admin-brand-sub,
+ .admin-nav-group-label,
+ .admin-nav-item span,
+ .admin-user-card .min-w-0 {
+ display: none;
+ }
+}
+
+/* 任务详情弹窗 */
+.task-detail-modal.admin-modal--full {
+ max-width: min(960px, calc(100vw - 32px)) !important;
+}
+
+.task-detail-loading {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 10px;
+ min-height: 240px;
+ color: #909399;
+}
+
+.task-detail-body {
+ display: flex;
+ flex-direction: column;
+ max-height: calc(90vh - 140px);
+}
+
+.task-detail-tabs {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ padding: 12px 18px 0;
+ border-bottom: 1px solid var(--admin-border);
+ background: #fafbfa;
+}
+
+.task-detail-tab {
+ border: none;
+ background: transparent;
+ border-radius: 8px 8px 0 0;
+ padding: 8px 14px;
+ font-size: 13px;
+ color: #909399;
+ cursor: pointer;
+}
+
+.task-detail-tab:hover {
+ color: #606266;
+ background: #f5f7fa;
+}
+
+.task-detail-tab.is-active {
+ color: var(--admin-forest);
+ background: #fff;
+ font-weight: 600;
+ box-shadow: inset 0 -2px 0 var(--admin-accent);
+}
+
+.task-detail-panel {
+ flex: 1;
+ overflow-y: auto;
+ padding: 16px 18px 20px;
+}
+
+.task-detail-grid {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 14px;
+}
+
+.task-detail-section {
+ padding: 12px 14px;
+ border: 1px solid var(--admin-border);
+ border-radius: 10px;
+ background: #fff;
+}
+
+.task-detail-section--full {
+ grid-column: 1 / -1;
+}
+
+.task-detail-section h4 {
+ margin: 0 0 10px;
+ font-size: 12px;
+ font-weight: 700;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ color: #909399;
+}
+
+.task-detail-meta {
+ margin: 8px 0 0;
+ font-size: 12px;
+ color: #606266;
+}
+
+.task-detail-error {
+ margin: 10px 0 0;
+ padding: 10px;
+ border-radius: 8px;
+ background: #fef0f0;
+ color: #f56c6c;
+ font-size: 12px;
+ line-height: 1.5;
+ white-space: pre-wrap;
+ word-break: break-word;
+}
+
+.task-detail-dl {
+ display: grid;
+ gap: 8px;
+ margin: 0;
+}
+
+.task-detail-dl > div {
+ display: grid;
+ grid-template-columns: 110px 1fr;
+ gap: 8px;
+ align-items: start;
+}
+
+.task-detail-dl dt {
+ margin: 0;
+ font-size: 11px;
+ color: #909399;
+}
+
+.task-detail-dl dd {
+ margin: 0;
+ font-size: 13px;
+ color: #303133;
+}
+
+.task-detail-dl--inline {
+ grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
+}
+
+.task-detail-dl--inline > div {
+ grid-template-columns: 1fr;
+}
+
+.task-detail-json {
+ margin: 0;
+ max-height: 280px;
+ overflow: auto;
+ padding: 12px;
+ border-radius: 8px;
+ background: #1e1e1e;
+ color: #d4d4d4;
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ font-size: 11px;
+ line-height: 1.55;
+}
+
+.task-detail-json--compact {
+ max-height: 120px;
+ margin-top: 8px;
+}
+
+.task-detail-json-title {
+ margin: 0 0 8px;
+ font-size: 12px;
+ font-weight: 600;
+ color: #606266;
+}
+
+.task-detail-events {
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.task-detail-event {
+ padding: 10px 12px;
+ border: 1px solid var(--admin-border);
+ border-radius: 10px;
+ background: #fafbfa;
+}
+
+.task-detail-event-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+}
+
+@media (max-width: 768px) {
+ .task-detail-grid {
+ grid-template-columns: 1fr;
}
}
diff --git a/admin/src/lib/pagination.ts b/admin/src/lib/pagination.ts
index e61cdbe..5850d02 100644
--- a/admin/src/lib/pagination.ts
+++ b/admin/src/lib/pagination.ts
@@ -1,3 +1,6 @@
+/** 模板列表每页数量(卡片网格铺满) */
+export const TEMPLATE_PAGE_SIZE = 24;
+
/** Default page size for all admin list pages */
export const DEFAULT_PAGE_SIZE = 10;
diff --git a/admin/src/lib/statusLabels.ts b/admin/src/lib/statusLabels.ts
index cbcd81a..7a3ddf0 100644
--- a/admin/src/lib/statusLabels.ts
+++ b/admin/src/lib/statusLabels.ts
@@ -53,6 +53,26 @@ export const PAY_TYPE_LABELS: Record<string, string> = {
wxpay: "微信",
};
+/** Unified task platform status → Chinese */
+export const TASK_STATUS_LABELS: Record<string, string> = {
+ pending: "排队中",
+ leased: "已租约",
+ running: "执行中",
+ awaiting_poll: "等待轮询",
+ awaiting_review: "待审核",
+ cancel_requested: "取消中",
+ succeeded: "已成功",
+ failed: "失败",
+ cancelled: "已取消",
+};
+
+/** Task domain → Chinese */
+export const TASK_DOMAIN_LABELS: Record<string, string> = {
+ drama: "漫剧",
+ kepu: "科普",
+ tools: "工具",
+};
+
// Resolve project status display text
export function projectStatusLabel(status: string): string {
return PROJECT_STATUS_LABELS[status] ?? status;
@@ -83,6 +103,16 @@ export function payTypeLabel(payType: string): string {
return PAY_TYPE_LABELS[payType] ?? payType;
}
+// Resolve task status display text
+export function taskStatusLabel(status: string): string {
+ return TASK_STATUS_LABELS[status] ?? status;
+}
+
+// Resolve task domain display text
+export function taskDomainLabel(domain: string): string {
+ return TASK_DOMAIN_LABELS[domain] ?? domain;
+}
+
/** Filter options for project status select (value stays English for API) */
export const PROJECT_STATUS_OPTIONS: { value: string; label: string }[] = [
{ value: "", label: "全部状态" },
diff --git a/admin/src/pages/DashboardPage.tsx b/admin/src/pages/DashboardPage.tsx
index f3cd9e1..9b059fa 100644
--- a/admin/src/pages/DashboardPage.tsx
+++ b/admin/src/pages/DashboardPage.tsx
@@ -5,11 +5,15 @@ import {
Clapperboard,
Layers,
Receipt,
+ Settings,
Shapes,
Users,
Wallet,
} from "lucide-react";
import { toast } from "sonner";
+import { StatCard } from "@/components/admin/StatCard";
+import { PageSection } from "@/components/admin/PageSection";
+import { PageHeader } from "@/components/ui/page";
import { api, type AdminOrder, type AdminStats, type PageMeta } from "@/api/client";
import { fenToYuan } from "@/lib/utils";
import { orderStatusLabel, payTypeLabel, projectStatusLabel } from "@/lib/statusLabels";
@@ -26,19 +30,15 @@ function statusClass(status: string): string {
return "is-warn";
}
-// Dashboard matching reference ops console
+// Dashboard overview
export function DashboardPage() {
- /*
- * stats aggregate stats
- * orders recent orders
- */
const [stats, setStats] = useState<AdminStats | null>(null);
const [orders, setOrders] = useState<AdminOrder[]>([]);
useEffect(() => {
Promise.all([
api<AdminStats>("/api/admin/stats"),
- api<OrderRes>("/api/admin/orders?page=1&page_size=5"),
+ api<OrderRes>("/api/admin/orders?page=1&page_size=8"),
])
.then(([s, o]) => {
setStats(s);
@@ -52,69 +52,52 @@ export function DashboardPage() {
);
return (
- <div className="space-y-5">
- <div className="flex flex-wrap items-end justify-between gap-3">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">仪表盘</h2>
- <p className="mt-1 text-sm text-[#909399]">用户、订单与项目状态概览</p>
- </div>
- </div>
+ <div className="admin-page">
+ <PageHeader description="用户、订单与项目状态概览" />
- <div className="grid gap-4 md:grid-cols-3">
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <Users className="h-5 w-5" />
- </div>
- <div className="text-sm text-[#909399]">用户总数</div>
- <div className="mt-2 text-3xl font-semibold tracking-tight">{stats?.user_count ?? "—"}</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">总注册用户</div>
- </div>
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <Banknote className="h-5 w-5" />
- </div>
- <div className="text-sm text-[#909399]">累计已付金额</div>
- <div className="mt-2 text-3xl font-semibold tracking-tight">
- ¥{stats ? fenToYuan(stats.order_paid_total_fen) : "—"}
- </div>
- <div className="mt-1 text-xs text-[#c0c4cc]">历史累计付款</div>
- </div>
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <Wallet className="h-5 w-5" />
- </div>
- <div className="text-sm text-[#909399]">今日已付金额</div>
- <div className="mt-2 text-3xl font-semibold tracking-tight">
- ¥{stats ? fenToYuan(stats.order_paid_today_fen) : "—"}
+ <div className="admin-dashboard-top">
+ <StatCard label="用户总数" value={stats?.user_count ?? "—"} hint="总注册用户" icon={Users} />
+ <StatCard
+ label="累计已付"
+ value={stats ? `¥${fenToYuan(stats.order_paid_total_fen)}` : "—"}
+ hint="历史累计"
+ icon={Banknote}
+ tone="success"
+ />
+ <StatCard
+ label="今日已付"
+ value={stats ? `¥${fenToYuan(stats.order_paid_today_fen)}` : "—"}
+ hint="今日付款"
+ icon={Wallet}
+ tone="info"
+ />
+ <div className="admin-panel admin-stat-card tone-success">
+ <div className="admin-stat-label">项目状态</div>
+ <div className="mt-2 flex flex-wrap gap-1.5">
+ {statusEntries.length === 0 ? (
+ <span className="text-xs text-[var(--admin-muted)]">暂无数据</span>
+ ) : (
+ statusEntries.map(([status, count]) => (
+ <span key={status} className={`admin-status-pill !px-2 !py-1 !text-[11px] ${statusClass(status)}`}>
+ {projectStatusLabel(status)} {count}
+ </span>
+ ))
+ )}
</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">今日付款金额</div>
</div>
</div>
- <div className="admin-panel">
- <div className="mb-3 text-sm font-medium text-[#303133]">项目状态分布</div>
- <div className="flex flex-wrap gap-2">
- {statusEntries.length === 0 ? (
- <span className="text-sm text-[#909399]">暂无数据</span>
- ) : (
- statusEntries.map(([status, count]) => (
- <span key={status} className={`admin-status-pill ${statusClass(status)}`}>
- <span>{projectStatusLabel(status)}</span>
- <strong className="font-semibold">{count}</strong>
- </span>
- ))
- )}
- </div>
- </div>
-
- <div className="grid gap-4 xl:grid-cols-5">
- <div className="admin-panel xl:col-span-3">
- <div className="mb-3 flex items-center justify-between">
- <div className="text-sm font-medium">最近订单</div>
- <Link to="/orders" className="text-xs text-[#67c23a] hover:underline">
- 查看全部订单 →
+ <div className="admin-dashboard-body">
+ <PageSection
+ title="最近订单"
+ actions={
+ <Link to="/orders" className="admin-link">
+ 全部 →
</Link>
- </div>
+ }
+ bodyClassName="!pt-0"
+ className="min-h-0"
+ >
<div className="admin-table-wrap">
<table>
<thead>
@@ -130,7 +113,7 @@ export function DashboardPage() {
<tbody>
{orders.length === 0 ? (
<tr>
- <td colSpan={6} className="!text-center text-[#909399]">
+ <td colSpan={6} className="!text-center text-[var(--admin-muted)]">
暂无订单
</td>
</tr>
@@ -148,7 +131,7 @@ export function DashboardPage() {
{orderStatusLabel(o.status)}
</span>
</td>
- <td className="text-xs text-[#909399]">
+ <td className="text-xs text-[var(--admin-muted)]">
{new Date(o.created_at).toLocaleString()}
</td>
</tr>
@@ -157,42 +140,44 @@ export function DashboardPage() {
</tbody>
</table>
</div>
- </div>
+ </PageSection>
- <div className="admin-panel xl:col-span-2">
- <div className="mb-3 text-sm font-medium">快捷操作</div>
- <div className="grid grid-cols-2 gap-3">
- <Link to="/templates" className="admin-quick-btn">
- <Shapes className="h-4 w-4 text-[#67c23a]" />
- 模板管理
+ <PageSection title="快捷入口" bodyClassName="!pt-0">
+ <div className="grid grid-cols-2 gap-2">
+ <Link to="/templates" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Shapes className="h-4 w-4" />
+ 模板
+ </Link>
+ <Link to="/orders" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Receipt className="h-4 w-4" />
+ 订单
</Link>
- <Link to="/orders" className="admin-quick-btn">
- <Receipt className="h-4 w-4 text-[#67c23a]" />
- 充值记录
+ <Link to="/users" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Users className="h-4 w-4" />
+ 用户
</Link>
- <Link to="/users" className="admin-quick-btn">
- <Users className="h-4 w-4 text-[#67c23a]" />
- 用户列表
+ <Link to="/projects" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Clapperboard className="h-4 w-4" />
+ 项目
</Link>
- <Link to="/projects" className="admin-quick-btn">
- <Clapperboard className="h-4 w-4 text-[#67c23a]" />
- 项目管理
+ <Link to="/settings" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Settings className="h-4 w-4" />
+ 配置
</Link>
- <Link to="/queues" className="admin-quick-btn">
- <Layers className="h-4 w-4 text-[#67c23a]" />
- 队列任务
+ <Link to="/queues" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Layers className="h-4 w-4" />
+ 任务
</Link>
</div>
- <div className="mt-5 rounded-xl border border-[#ebeef5] bg-[#fafbfc] p-4">
- <div className="mb-2 flex items-center justify-between text-sm">
- <span className="font-medium">系统公告</span>
- <span className="text-xs text-[#c0c4cc]">今天</span>
+ <div className="admin-notice">
+ <div className="admin-notice-title">
+ <span>系统公告</span>
</div>
- <p className="text-sm leading-relaxed text-[#606266]">
- 欢迎使用 PRINTFILM 管理后台。可在此管理用户额度、审核作品与模板上下架。
+ <p className="admin-notice-body !text-xs">
+ 管理用户额度、审核作品与模板,并在任务中心监控统一任务平台。
</p>
</div>
- </div>
+ </PageSection>
</div>
</div>
);
diff --git a/admin/src/pages/DramaProjectsPage.tsx b/admin/src/pages/DramaProjectsPage.tsx
index 99b298e..1bf58d0 100644
--- a/admin/src/pages/DramaProjectsPage.tsx
+++ b/admin/src/pages/DramaProjectsPage.tsx
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { toast } from "sonner";
import { api, type PageMeta } from "@/api/client";
import { PaginationBar } from "@/components/PaginationBar";
-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
+import { PageHeader } from "@/components/ui/page";
type DramaProjectRow = {
id: number;
@@ -18,10 +18,6 @@ type ListRes = { items: DramaProjectRow[]; meta: PageMeta };
/** Admin table listing drama projects with pagination */
export function DramaProjectsPage() {
- /*
- * page current page
- * data list response
- */
const [page, setPage] = useState(1);
const [data, setData] = useState<ListRes | null>(null);
@@ -41,39 +37,38 @@ export function DramaProjectsPage() {
}, [page]);
return (
- <div className="space-y-4">
- <div>
- <h1 className="text-2xl font-semibold">漫剧项目</h1>
- <p className="text-sm text-muted-foreground">查看用户创建的漫剧项目</p>
- </div>
- <div className="rounded-lg border bg-white">
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>ID</TableHead>
- <TableHead>标题</TableHead>
- <TableHead>用户</TableHead>
- <TableHead>创建时间</TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {(data?.items || []).map((row) => (
- <TableRow key={row.id}>
- <TableCell>{row.id}</TableCell>
- <TableCell>{row.title}</TableCell>
- <TableCell>{row.user_email || row.user_id}</TableCell>
- <TableCell>{row.created_at ? String(row.created_at).slice(0, 19) : "-"}</TableCell>
- </TableRow>
+ <div className="admin-list-page">
+ <PageHeader description="查看用户创建的漫剧项目" />
+ <div className="admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>ID</th>
+ <th>标题</th>
+ <th>用户</th>
+ <th>创建时间</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(data?.items ?? []).map((row) => (
+ <tr key={row.id}>
+ <td>{row.id}</td>
+ <td>{row.title}</td>
+ <td>{row.user_email ?? row.user_id}</td>
+ <td className="text-xs text-[var(--admin-muted)]">
+ {row.created_at ? new Date(row.created_at).toLocaleString() : "—"}
+ </td>
+ </tr>
))}
- {!data?.items?.length ? (
- <TableRow>
- <TableCell colSpan={4} className="text-center text-muted-foreground">
- 暂无数据
- </TableCell>
- </TableRow>
+ {(data?.items.length ?? 0) === 0 ? (
+ <tr>
+ <td colSpan={4} className="!text-center text-[var(--admin-muted)]">
+ 暂无项目
+ </td>
+ </tr>
) : null}
- </TableBody>
- </Table>
+ </tbody>
+ </table>
</div>
{data?.meta ? (
<PaginationBar
diff --git a/admin/src/pages/OrdersPage.tsx b/admin/src/pages/OrdersPage.tsx
index 5440bcd..3e8ea49 100644
--- a/admin/src/pages/OrdersPage.tsx
+++ b/admin/src/pages/OrdersPage.tsx
@@ -9,6 +9,7 @@ import { Input } from "@/components/ui/input";
import { Select } from "@/components/ui/select";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
+import { PageHeader } from "@/components/ui/page";
import { fenToYuan } from "@/lib/utils";
import { ledgerKindLabel, orderStatusLabel, payTypeLabel } from "@/lib/statusLabels";
@@ -73,11 +74,8 @@ export function OrdersPage() {
}, [ledgerPage]);
return (
- <div className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">订单与流水</h2>
- <p className="mt-1 text-sm text-[#909399]">查看充值单与钱包流水</p>
- </div>
+ <div className="admin-list-page">
+ <PageHeader description="查看充值单与钱包流水" />
<Tabs value={tab} onValueChange={setTab}>
<TabsList>
<TabsTrigger value="orders">充值订单</TabsTrigger>
diff --git a/admin/src/pages/ProjectsPage.tsx b/admin/src/pages/ProjectsPage.tsx
index 9b52c03..f1c277d 100644
--- a/admin/src/pages/ProjectsPage.tsx
+++ b/admin/src/pages/ProjectsPage.tsx
@@ -9,6 +9,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/u
import { Input } from "@/components/ui/input";
import { Select } from "@/components/ui/select";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
+import { PageHeader } from "@/components/ui/page";
import { PROJECT_STATUS_OPTIONS, projectStatusLabel } from "@/lib/statusLabels";
type ListRes = { items: AdminProject[]; meta: PageMeta };
@@ -64,12 +65,9 @@ export function ProjectsPage() {
}
return (
- <div className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">项目管理</h2>
- <p className="mt-1 text-sm text-[#909399]">按状态筛选,查看失败原因与进度</p>
- </div>
- <div className="flex flex-wrap gap-2">
+ <div className="admin-list-page">
+ <PageHeader description="按状态筛选,查看失败原因与进度" />
+ <div className="admin-filter-bar">
<Select className="w-44" value={status} onChange={(e) => setStatus(e.target.value)}>
{PROJECT_STATUS_OPTIONS.map((opt) => (
<option key={opt.value || "all"} value={opt.value}>
diff --git a/admin/src/pages/QueuesPage.tsx b/admin/src/pages/QueuesPage.tsx
index e53c8ac..38f783b 100644
--- a/admin/src/pages/QueuesPage.tsx
+++ b/admin/src/pages/QueuesPage.tsx
@@ -1,434 +1,458 @@
import { useCallback, useEffect, useMemo, useState } from "react";
-import { Activity, Layers, Loader2, Minus, Plus, Power, RefreshCw, Server } from "lucide-react";
+import { Activity, Ban, Eye, Layers, Loader2, RefreshCw, Search } from "lucide-react";
import { toast } from "sonner";
-import { api, type AdminQueuesSnapshot, type AdminQueueTask } from "@/api/client";
+import { api, type AdminTaskListRes, type AdminTaskRow, type AdminTaskStats } from "@/api/client";
+import { StatCard } from "@/components/admin/StatCard";
+import { PageSection } from "@/components/admin/PageSection";
+import { TaskDetailDialog } from "@/components/tasks/TaskDetailDialog";
+import { PageHeader, Toolbar } from "@/components/ui/page";
+import { PaginationBar } from "@/components/PaginationBar";
import { cn } from "@/lib/utils";
+import { DEFAULT_PAGE_SIZE } from "@/lib/pagination";
+import { taskDomainLabel, taskStatusLabel } from "@/lib/statusLabels";
const REFRESH_MS = 15000;
-const LIGHT_QUERY = "?detail=0";
-const FULL_QUERY = "?detail=1";
+const TERMINAL_STATUSES = new Set(["succeeded", "failed", "cancelled"]);
// 任务状态 → 样式
-function stateClass(state: string): string {
- if (state === "active") return "is-run";
- if (state === "reserved") return "is-warn";
+function statusClass(status: string): string {
+ if (status === "running" || status === "leased") return "is-run";
+ if (status === "succeeded") return "is-done";
+ if (status === "failed") return "is-fail";
+ if (status === "cancelled" || status === "cancel_requested") return "is-warn";
return "is-warn";
}
-function stateLabel(state: string): string {
- if (state === "active") return "执行中";
- if (state === "reserved") return "已预取";
- return "排队中";
+function formatTime(value: string | null | undefined): string {
+ if (!value) return "—";
+ return new Date(value).toLocaleString();
}
-function formatTime(ts: number | null | undefined): string {
- if (!ts) return "—";
- return new Date(ts * 1000).toLocaleString();
+function scopeLabel(task: AdminTaskRow): string {
+ const parts: string[] = [];
+ if (task.drama_project_id) parts.push(`漫剧#${task.drama_project_id}`);
+ if (task.project_id) parts.push(`科普#${task.project_id}`);
+ if (task.episode_id) parts.push(`分集#${task.episode_id}`);
+ if (task.fragment_id) parts.push(`分镜#${task.fragment_id}`);
+ return parts.length ? parts.join(" · ") : "—";
}
-// 队列任务监控页
+function canCancel(task: AdminTaskRow): boolean {
+ return task.cancelable && !TERMINAL_STATUSES.has(task.status);
+}
+
+// 统一任务平台监控页
export function QueuesPage() {
/*
- * data 最新快照
+ * stats 平台聚合统计
+ * data 分页任务列表
* loading 首次加载
- * refreshing 手动/定时刷新
- * tab 当前任务列表视图
+ * refreshing 刷新中
+ * page / pageSize 分页
+ * q 搜索关键词
+ * domain / status 筛选
+ * viewTab 快捷视图
+ * cancelLoading 取消中的任务 id
*/
- const [data, setData] = useState<AdminQueuesSnapshot | null>(null);
+ const [stats, setStats] = useState<AdminTaskStats | null>(null);
+ const [data, setData] = useState<AdminTaskListRes | null>(null);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
- const [tab, setTab] = useState<"pending" | "active" | "reserved">("pending");
- const [actionLoading, setActionLoading] = useState<string | null>(null);
- const [boundsMin, setBoundsMin] = useState("1");
- const [boundsMax, setBoundsMax] = useState("3");
+ const [page, setPage] = useState(1);
+ const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE);
+ const [q, setQ] = useState("");
+ const [searchInput, setSearchInput] = useState("");
+ const [domain, setDomain] = useState("");
+ const [status, setStatus] = useState("");
+ const [viewTab, setViewTab] = useState<"all" | "active">("all");
+ const [cancelLoading, setCancelLoading] = useState<number | null>(null);
+ const [detailTaskId, setDetailTaskId] = useState<number | null>(null);
+ const [detailOpen, setDetailOpen] = useState(false);
- const control = data?.worker_control;
+ const loadStats = useCallback(async () => {
+ const res = await api<AdminTaskStats>("/api/admin/tasks/stats");
+ setStats(res);
+ }, []);
- useEffect(() => {
- if (!control) return;
- setBoundsMin(String(control.bounds_min));
- setBoundsMax(String(control.bounds_max));
- }, [control?.bounds_min, control?.bounds_max]);
+ const loadTasks = useCallback(
+ async (silent = false) => {
+ if (!silent) setRefreshing(true);
+ try {
+ const params = new URLSearchParams({
+ page: String(page),
+ page_size: String(pageSize),
+ });
+ if (domain) params.set("domain", domain);
+ if (status) params.set("status", status);
+ if (q.trim()) params.set("q", q.trim());
+ if (viewTab === "active" && !status) params.set("active_only", "true");
+ const res = await api<AdminTaskListRes>(`/api/admin/tasks?${params}`);
+ setData(res);
+ } catch (err) {
+ if (!silent) {
+ toast.error(err instanceof Error ? err.message : "加载任务失败");
+ }
+ } finally {
+ setLoading(false);
+ setRefreshing(false);
+ }
+ },
+ [domain, page, pageSize, q, status, viewTab],
+ );
- const load = useCallback(async (silent = false, full = false) => {
- if (!silent) setRefreshing(true);
- try {
- const snap = await api<AdminQueuesSnapshot>(
- `/api/admin/queues${full ? FULL_QUERY : LIGHT_QUERY}`,
- );
- setData(snap);
- } catch (err) {
- if (!silent) {
- toast.error(err instanceof Error ? err.message : "加载队列失败");
+ const refreshAll = useCallback(
+ async (silent = false) => {
+ if (!silent) setRefreshing(true);
+ try {
+ await Promise.all([loadStats(), loadTasks(true)]);
+ } catch (err) {
+ if (!silent) toast.error(err instanceof Error ? err.message : "刷新失败");
+ } finally {
+ setRefreshing(false);
+ setLoading(false);
}
- } finally {
- setLoading(false);
- setRefreshing(false);
- }
- }, []);
+ },
+ [loadStats, loadTasks],
+ );
+
+ useEffect(() => {
+ void refreshAll();
+ }, [page, pageSize, domain, status, q, viewTab, refreshAll]);
useEffect(() => {
- void load(false, true);
- const timer = window.setInterval(() => void load(true, false), REFRESH_MS);
+ const timer = window.setInterval(() => void refreshAll(true), REFRESH_MS);
return () => window.clearInterval(timer);
- }, [load]);
+ }, [refreshAll]);
- const runAction = useCallback(
- async (key: string, path: string, options?: RequestInit) => {
- setActionLoading(key);
+ const handleCancel = useCallback(
+ async (task: AdminTaskRow) => {
+ if (!canCancel(task)) return;
+ if (!window.confirm(`确定取消任务 #${task.id}(${task.task_type})?`)) return;
+ setCancelLoading(task.id);
try {
- await api(path, options);
- toast.success("操作已提交");
- await load(true, true);
+ await api(`/api/admin/tasks/${task.id}/cancel`, { method: "POST" });
+ toast.success("已提交取消请求");
+ await refreshAll(true);
} catch (err) {
- toast.error(err instanceof Error ? err.message : "操作失败");
+ toast.error(err instanceof Error ? err.message : "取消失败");
} finally {
- setActionLoading(null);
+ setCancelLoading(null);
}
},
- [load],
+ [refreshAll],
);
- const modeLabel = (mode: string | undefined) => {
- if (mode === "systemd") return "Systemd 托管";
- if (mode === "autoscale") return "Autoscale 动态进程";
- return "Celery";
- };
+ const domainOptions = useMemo(() => {
+ const fromStats = stats?.domains.map((d) => d.domain) ?? [];
+ return Array.from(new Set(fromStats));
+ }, [stats]);
- const tasks = useMemo(() => {
- if (!data) return [] as AdminQueueTask[];
- if (tab === "active") return data.active_tasks;
- if (tab === "reserved") return data.reserved_tasks;
- return data.pending_tasks;
- }, [data, tab]);
-
- const maxPending = useMemo(() => {
- if (!data?.queues.length) return 1;
- return Math.max(1, ...data.queues.map((q) => q.pending));
- }, [data]);
+ function openDetail(taskId: number) {
+ setDetailTaskId(taskId);
+ setDetailOpen(true);
+ }
return (
- <div className="space-y-5">
- <div className="flex flex-wrap items-end justify-between gap-3">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">队列任务</h2>
- <p className="mt-1 text-sm text-[#909399]">
- Celery 各队列排队与 Worker 执行状态 · 轻量刷新 {REFRESH_MS / 1000}s · 手动刷新拉全量明细
- </p>
- </div>
- <button
- type="button"
- className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4"
- onClick={() => void load(false, true)}
- disabled={refreshing}
- >
- {refreshing ? <Loader2 className="h-4 w-4 animate-spin" /> : <RefreshCw className="h-4 w-4" />}
- 刷新
- </button>
- </div>
+ <div className="admin-page">
+ <PageHeader
+ description={`统一任务平台 · 自动刷新 ${REFRESH_MS / 1000}s · 并发 ${stats?.scheduler_running_jobs ?? 0}/${stats?.max_concurrency ?? 0}`}
+ actions={
+ <button
+ type="button"
+ className="admin-btn admin-btn-secondary"
+ onClick={() => void refreshAll()}
+ disabled={refreshing}
+ >
+ {refreshing ? <Loader2 className="h-4 w-4 animate-spin" /> : <RefreshCw className="h-4 w-4" />}
+ 刷新
+ </button>
+ }
+ />
- {loading && !data ? (
- <div className="admin-panel flex items-center justify-center py-16 text-[#909399]">
+ {loading && !stats ? (
+ <div className="admin-panel flex items-center justify-center py-16 text-[var(--admin-muted)]">
<Loader2 className="mr-2 h-5 w-5 animate-spin" />
加载中…
</div>
) : (
<>
- <div className="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <Layers className="h-5 w-5" />
- </div>
- <div className="text-sm text-[#909399]">排队总数</div>
- <div className="mt-2 text-3xl font-semibold">{data?.total_pending ?? 0}</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">unacked {data?.unacked ?? 0}</div>
- </div>
- <div className="admin-panel admin-stat-card">
+ <div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
+ <StatCard
+ label="排队中"
+ value={stats?.pending_count ?? 0}
+ hint="含待调度 pending"
+ icon={Layers}
+ tone="warn"
+ />
+ <StatCard
+ label="进行中"
+ value={stats?.active_count ?? 0}
+ hint={`执行 ${stats?.running_count ?? 0} · 轮询 ${stats?.awaiting_poll_count ?? 0}`}
+ icon={Activity}
+ tone="info"
+ />
+ <StatCard
+ label="运行时槽位"
+ value={
+ <>
+ {stats?.scheduler_running_jobs ?? 0}
+ <span className="text-lg text-[var(--admin-muted)]"> / {stats?.max_concurrency ?? 0}</span>
+ </>
+ }
+ hint={`已租约 ${stats?.leased_count ?? 0}`}
+ icon={RefreshCw}
+ />
+ <div className="admin-panel admin-stat-card tone-success">
<div className="admin-stat-icon">
- <Activity className="h-5 w-5" />
+ <Ban className="h-5 w-5" />
</div>
- <div className="text-sm text-[#909399]">执行中</div>
- <div className="mt-2 text-3xl font-semibold">{data?.active_count ?? 0}</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">预取 {data?.reserved_count ?? 0}</div>
- </div>
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <Server className="h-5 w-5" />
- </div>
- <div className="text-sm text-[#909399]">Worker 在线</div>
- <div className="mt-2 text-3xl font-semibold">{data?.workers_online ?? 0}</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">
- Redis {data?.redis_ok ? "正常" : "异常"} · Celery {data?.use_celery ? "开" : "关"}
- </div>
- </div>
- <div className="admin-panel admin-stat-card">
- <div className="admin-stat-icon">
- <RefreshCw className="h-5 w-5" />
+ <div className="admin-stat-label">终态统计</div>
+ <div className="admin-stat-value !text-base !leading-relaxed">
+ 成功 {stats?.succeeded_count ?? 0} · 失败 {stats?.failed_count ?? 0} · 取消{" "}
+ {stats?.cancelled_count ?? 0}
</div>
- <div className="text-sm text-[#909399]">监听队列</div>
- <div className="mt-2 text-sm font-medium leading-snug">{data?.worker_queues ?? "—"}</div>
- <div className="mt-1 text-xs text-[#c0c4cc]">
- 更新 {data?.fetched_at ? new Date(data.fetched_at).toLocaleTimeString() : "—"}
+ <div className="admin-stat-hint">
+ 更新 {stats?.fetched_at ? new Date(stats.fetched_at).toLocaleTimeString() : "—"}
</div>
</div>
</div>
- <div className="admin-panel">
- <div className="mb-4 text-sm font-medium text-[#303133]">各队列积压</div>
- <div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
- {(data?.queues ?? []).map((q) => (
- <div key={q.name} className="rounded-xl border border-[#ebeef5] bg-[#fafbfc] p-4">
- <div className="flex items-center justify-between gap-2">
- <div>
- <div className="text-sm font-medium text-[#303133]">{q.label}</div>
- <div className="mt-0.5 font-mono text-xs text-[#909399]">{q.name}</div>
+ {(stats?.domains.length ?? 0) > 0 ? (
+ <PageSection title="各领域任务" bodyClassName="!pt-0">
+ <div className="grid gap-3 md:grid-cols-2 xl:grid-cols-4">
+ {stats?.domains.map((d) => (
+ <div key={d.domain} className="admin-domain-card">
+ <div className="flex items-center justify-between gap-2">
+ <div>
+ <div className="text-sm font-medium">{taskDomainLabel(d.domain)}</div>
+ <div className="mt-0.5 font-mono text-xs text-[var(--admin-muted)]">{d.domain}</div>
+ </div>
+ <span
+ className={cn(
+ "admin-status-pill",
+ d.pending + d.active > 0 ? "is-warn" : "is-done",
+ )}
+ >
+ {d.pending + d.active}
+ </span>
+ </div>
+ <div className="mt-2 text-xs text-[var(--admin-muted)]">
+ 排队 {d.pending} · 进行 {d.active} · 成功 {d.succeeded}
</div>
- <span
- className={cn(
- "admin-status-pill",
- q.pending > 20 ? "is-fail" : q.pending > 0 ? "is-warn" : "is-done",
- )}
- >
- {q.pending}
- </span>
- </div>
- <div className="mt-3 h-2 overflow-hidden rounded-full bg-[#ebeef5]">
- <div
- className="h-full rounded-full bg-[#67c23a] transition-all"
- style={{ width: `${Math.min(100, (q.pending / maxPending) * 100)}%` }}
- />
</div>
- </div>
- ))}
- </div>
- </div>
-
- {control ? (
- <div className="admin-panel">
- <div className="mb-4 flex flex-wrap items-center justify-between gap-3">
- <div>
- <div className="text-sm font-medium text-[#303133]">Worker 动态管理</div>
- <p className="mt-1 text-xs text-[#909399]">
- 模式:{modeLabel(control.mode)}
- {control.systemd_active ? " · systemd 运行中" : ""}
- {control.autoscale_running ? ` · autoscale pid ${control.autoscale_pid}` : ""}
- </p>
- </div>
- <span className="admin-status-pill is-run">
- 进程 {control.total_processes}
- {control.max_concurrency != null ? ` / 并发上限 ${control.max_concurrency}` : ""}
- </span>
- </div>
-
- <div className="flex flex-wrap gap-2">
- <button
- type="button"
- className="admin-quick-btn !inline-flex !w-auto items-center gap-1.5 px-3 py-2 text-sm"
- disabled={!control.can_pool_grow || actionLoading !== null}
- onClick={() => void runAction("grow", "/api/admin/workers/pool-grow?n=1", { method: "POST" })}
- >
- {actionLoading === "grow" ? <Loader2 className="h-4 w-4 animate-spin" /> : <Plus className="h-4 w-4" />}
- Pool +1
- </button>
- <button
- type="button"
- className="admin-quick-btn !inline-flex !w-auto items-center gap-1.5 px-3 py-2 text-sm"
- disabled={!control.can_pool_shrink || actionLoading !== null}
- onClick={() => void runAction("shrink", "/api/admin/workers/pool-shrink?n=1", { method: "POST" })}
- >
- {actionLoading === "shrink" ? <Loader2 className="h-4 w-4 animate-spin" /> : <Minus className="h-4 w-4" />}
- Pool -1
- </button>
- <button
- type="button"
- className="admin-quick-btn !inline-flex !w-auto items-center gap-1.5 px-3 py-2 text-sm"
- disabled={!control.can_restart || actionLoading !== null}
- onClick={() => {
- if (!window.confirm("确定重启 Celery Worker?执行中的任务会中断后由 Redis 重新投递。")) return;
- void runAction("restart", "/api/admin/workers/restart", { method: "POST" });
- }}
- >
- {actionLoading === "restart" ? <Loader2 className="h-4 w-4 animate-spin" /> : <Power className="h-4 w-4" />}
- 重启 Worker
- </button>
- </div>
- <p className="mt-2 text-xs text-[#909399]">
- Pool 扩缩仅对 prefork 进程池有效(线上 systemd worker);上限 {control.pool_max_limit}。solo 池请用下方 Autoscale。
- </p>
-
- <div className="mt-5 rounded-xl border border-[#ebeef5] bg-[#fafbfc] p-4">
- <div className="mb-3 text-sm font-medium text-[#303133]">Autoscale 自动扩缩(开发 / 备选)</div>
- <div className="flex flex-wrap items-end gap-3">
- <label className="text-xs text-[#606266]">
- 最小进程
- <input
- className="mt-1 block w-20 rounded-lg border border-[#dcdfe6] px-2 py-1.5 text-sm"
- value={boundsMin}
- onChange={(e) => setBoundsMin(e.target.value)}
- />
- </label>
- <label className="text-xs text-[#606266]">
- 最大进程
- <input
- className="mt-1 block w-20 rounded-lg border border-[#dcdfe6] px-2 py-1.5 text-sm"
- value={boundsMax}
- onChange={(e) => setBoundsMax(e.target.value)}
- />
- </label>
- <button
- type="button"
- className="rounded-lg border border-[#dcdfe6] bg-white px-3 py-2 text-xs hover:border-[#67c23a]"
- disabled={actionLoading !== null}
- onClick={() =>
- void runAction("bounds", "/api/admin/workers/autoscale", {
- method: "PATCH",
- body: JSON.stringify({
- min_workers: Number(boundsMin),
- max_workers: Number(boundsMax),
- }),
- })
- }
- >
- 保存边界
- </button>
- <button
- type="button"
- className="rounded-lg border border-[#67c23a] bg-[#f0f9eb] px-3 py-2 text-xs text-[#67c23a]"
- disabled={actionLoading !== null || control.autoscale_running}
- onClick={() => void runAction("autostart", "/api/admin/workers/autoscale/start", { method: "POST" })}
- >
- 启动 Autoscale
- </button>
- <button
- type="button"
- className="rounded-lg border border-[#f56c6c] bg-[#fef0f0] px-3 py-2 text-xs text-[#f56c6c]"
- disabled={actionLoading !== null || !control.autoscale_running}
- onClick={() => void runAction("autostop", "/api/admin/workers/autoscale/stop", { method: "POST" })}
- >
- 停止 Autoscale
- </button>
- </div>
- <p className="mt-2 text-xs text-[#909399]">
- 配置来源:{control.bounds_source === "redis" ? "Redis 覆盖" : "环境变量"} ·
- 当前 autoscale 子进程 {control.autoscale_workers} 个
- </p>
- </div>
- </div>
- ) : null}
-
- {data?.workers && data.workers.length > 0 ? (
- <div className="admin-panel">
- <div className="mb-3 text-sm font-medium text-[#303133]">Worker 进程</div>
- <div className="admin-table-wrap">
- <table>
- <thead>
- <tr>
- <th>Worker</th>
- <th>状态</th>
- <th>执行中</th>
- <th>Pool</th>
- </tr>
- </thead>
- <tbody>
- {data.workers.map((w) => (
- <tr key={w.name}>
- <td className="font-mono text-xs">{w.name}</td>
- <td>
- <span className="admin-status-pill is-done">{w.status}</span>
- </td>
- <td>{w.active_count}</td>
- <td className="text-xs text-[#909399]">{w.pool || "—"}</td>
- </tr>
- ))}
- </tbody>
- </table>
+ ))}
</div>
- </div>
+ </PageSection>
) : null}
- <div className="admin-panel">
- <div className="mb-3 flex flex-wrap items-center justify-between gap-3">
- <div className="text-sm font-medium text-[#303133]">任务明细</div>
+ <PageSection
+ title="任务列表"
+ actions={
<div className="flex flex-wrap gap-2">
{(
[
- ["pending", `排队中 (${data?.pending_tasks.length ?? 0})`],
- ["active", `执行中 (${data?.active_count ?? 0})`],
- ["reserved", `已预取 (${data?.reserved_count ?? 0})`],
+ ["active", `进行中 (${stats?.pending_count ?? 0}+${stats?.active_count ?? 0})`],
+ ["all", "全部"],
] as const
).map(([key, label]) => (
<button
key={key}
type="button"
- className={cn(
- "rounded-lg border px-3 py-1.5 text-xs transition-colors",
- tab === key
- ? "border-[#67c23a] bg-[#f0f9eb] text-[#67c23a]"
- : "border-[#ebeef5] bg-white text-[#606266] hover:border-[#dcdfe6]",
- )}
- onClick={() => setTab(key)}
+ className={cn("admin-tab !min-h-[30px] !px-3 !text-xs", viewTab === key && "is-active")}
+ onClick={() => {
+ setViewTab(key);
+ setPage(1);
+ if (key === "active") setStatus("");
+ }}
>
{label}
</button>
))}
</div>
- </div>
+ }
+ bodyClassName="space-y-4 !pt-0"
+ >
+ <Toolbar>
+ <label className="admin-field">
+ <span className="admin-field-label">领域</span>
+ <select
+ className="admin-select"
+ value={domain}
+ onChange={(e) => {
+ setDomain(e.target.value);
+ setPage(1);
+ }}
+ >
+ <option value="">全部</option>
+ {domainOptions.map((d) => (
+ <option key={d} value={d}>
+ {taskDomainLabel(d)}
+ </option>
+ ))}
+ </select>
+ </label>
+ <label className="admin-field">
+ <span className="admin-field-label">状态</span>
+ <select
+ className="admin-select"
+ value={status}
+ onChange={(e) => {
+ setStatus(e.target.value);
+ setPage(1);
+ if (e.target.value) setViewTab("all");
+ }}
+ >
+ <option value="">全部</option>
+ {Object.entries({
+ pending: "排队中",
+ leased: "已租约",
+ running: "执行中",
+ awaiting_poll: "等待轮询",
+ cancel_requested: "取消中",
+ succeeded: "已成功",
+ failed: "失败",
+ cancelled: "已取消",
+ }).map(([value, label]) => (
+ <option key={value} value={value}>
+ {label}
+ </option>
+ ))}
+ </select>
+ </label>
+ <form
+ className="flex min-w-[240px] flex-1 flex-wrap items-end gap-2"
+ onSubmit={(e) => {
+ e.preventDefault();
+ setQ(searchInput);
+ setPage(1);
+ }}
+ >
+ <label className="admin-field flex-1">
+ <span className="admin-field-label">搜索</span>
+ <div className="admin-input-search-wrap">
+ <Search className="h-4 w-4" />
+ <input
+ className="admin-input"
+ placeholder="任务类型 / 用户邮箱 / dedupe_key"
+ value={searchInput}
+ onChange={(e) => setSearchInput(e.target.value)}
+ />
+ </div>
+ </label>
+ <button type="submit" className="admin-btn admin-btn-primary">
+ 查询
+ </button>
+ </form>
+ </Toolbar>
+
<div className="admin-table-wrap">
<table>
<thead>
<tr>
- <th>队列</th>
- <th>任务</th>
- <th>参数 / ID</th>
+ <th>ID</th>
+ <th>领域 / 类型</th>
+ <th>用户</th>
+ <th>关联</th>
<th>状态</th>
- <th>Worker</th>
+ <th>进度</th>
<th>时间</th>
+ <th>操作</th>
</tr>
</thead>
<tbody>
- {tasks.length === 0 ? (
+ {(data?.items.length ?? 0) === 0 ? (
<tr>
- <td colSpan={6} className="!text-center text-[#909399]">
- 暂无{stateLabel(tab === "pending" ? "pending" : tab)}任务
+ <td colSpan={8}>
+ <div className="admin-empty !py-10">
+ <div className="admin-empty-title">暂无任务</div>
+ <div className="admin-empty-desc">切换到「全部」查看历史任务</div>
+ </div>
</td>
</tr>
) : (
- tasks.map((t) => (
- <tr key={`${t.state}-${t.task_id || t.args_repr}-${t.position ?? ""}`}>
+ data?.items.map((task) => (
+ <tr
+ key={task.id}
+ className="cursor-pointer hover:bg-[#f8faf9]"
+ onClick={() => openDetail(task.id)}
+ >
+ <td className="font-mono text-xs">#{task.id}</td>
<td>
- <div className="text-sm">{t.queue}</div>
- {tab === "pending" && t.position ? (
- <div className="text-xs text-[#c0c4cc]">#{t.position}</div>
- ) : null}
+ <div className="text-sm">{taskDomainLabel(task.domain)}</div>
+ <div className="font-mono text-[11px] text-[#909399]">{task.task_type}</div>
</td>
<td>
- <div className="text-sm">{t.label}</div>
- <div className="font-mono text-[11px] text-[#c0c4cc]">{t.task_name}</div>
+ <div className="text-xs">{task.user_email ?? `#${task.requested_by}`}</div>
</td>
- <td className="max-w-[240px] truncate font-mono text-xs" title={t.args_repr}>
- {t.args_repr || t.ref_id || "—"}
+ <td className="max-w-[180px] truncate text-xs text-[#909399]" title={scopeLabel(task)}>
+ {scopeLabel(task)}
</td>
<td>
- <span className={`admin-status-pill ${stateClass(t.state)}`}>
- {stateLabel(t.state)}
+ <span className={`admin-status-pill ${statusClass(task.status)}`}>
+ {taskStatusLabel(task.status)}
</span>
+ {task.error_message ? (
+ <div className="mt-1 max-w-[200px] truncate text-[11px] text-[#f56c6c]" title={task.error_message}>
+ {task.error_message}
+ </div>
+ ) : null}
+ </td>
+ <td className="text-xs">{task.progress_percent}%</td>
+ <td className="text-xs text-[#909399]">
+ <div>创建 {formatTime(task.created_at)}</div>
+ {task.started_at ? <div>开始 {formatTime(task.started_at)}</div> : null}
+ </td>
+ <td onClick={(e) => e.stopPropagation()}>
+ <div className="flex flex-wrap gap-1">
+ <button
+ type="button"
+ className="admin-btn admin-btn-secondary !min-h-[28px] !px-2 !text-xs"
+ onClick={() => openDetail(task.id)}
+ >
+ <Eye className="mr-1 inline h-3 w-3" />
+ 详情
+ </button>
+ {canCancel(task) ? (
+ <button
+ type="button"
+ className="admin-btn admin-btn-danger !min-h-[28px] !px-2 !text-xs"
+ disabled={cancelLoading === task.id}
+ onClick={() => void handleCancel(task)}
+ >
+ {cancelLoading === task.id ? "取消中…" : "取消"}
+ </button>
+ ) : null}
+ </div>
</td>
- <td className="font-mono text-xs text-[#909399]">{t.worker || "—"}</td>
- <td className="text-xs text-[#909399]">{formatTime(t.started_at)}</td>
</tr>
))
)}
</tbody>
</table>
</div>
- {tab === "pending" && (data?.total_pending ?? 0) > (data?.pending_tasks.length ?? 0) ? (
- <p className="mt-3 text-xs text-[#909399]">
- 仅展示各队列前 30 条排队任务,其余 {(data?.total_pending ?? 0) - (data?.pending_tasks.length ?? 0)} 条未列出。
- </p>
+
+ {data?.meta ? (
+ <PaginationBar
+ page={page}
+ pageSize={pageSize}
+ total={data.meta.total}
+ onPageChange={setPage}
+ onPageSizeChange={(size) => {
+ setPageSize(size);
+ setPage(1);
+ }}
+ />
) : null}
- </div>
+ </PageSection>
</>
)}
+
+ <TaskDetailDialog
+ taskId={detailTaskId}
+ open={detailOpen}
+ onOpenChange={setDetailOpen}
+ onCancelled={() => void refreshAll(true)}
+ />
</div>
);
}
diff --git a/admin/src/pages/SettingsPage.tsx b/admin/src/pages/SettingsPage.tsx
new file mode 100644
index 0000000..a4b6e97
--- /dev/null
+++ b/admin/src/pages/SettingsPage.tsx
@@ -0,0 +1,98 @@
+import { useState } from "react";
+import { Download } from "lucide-react";
+import { toast } from "sonner";
+import { api } from "@/api/client";
+import { AdminConfirmDialog } from "@/components/admin/AdminConfirmDialog";
+import { OssSettingsPanel } from "@/components/settings/OssSettingsPanel";
+import { PaymentSettingsPanel } from "@/components/settings/PaymentSettingsPanel";
+import { RoutingSettingsPanel } from "@/components/settings/RoutingSettingsPanel";
+import { RuntimeSettingsPanel } from "@/components/settings/RuntimeSettingsPanel";
+import { SiteSettingsPanel } from "@/components/settings/SiteSettingsPanel";
+import { PageHeader } from "@/components/ui/page";
+import { cn } from "@/lib/utils";
+
+type SettingsTab = "routing" | "runtime" | "oss" | "payment" | "site";
+
+type ImportEnvRes = {
+ imported_fields: string[];
+ skipped_secret_fields: string[];
+};
+
+const TABS: { id: SettingsTab; label: string }[] = [
+ { id: "routing", label: "模型路由" },
+ { id: "runtime", label: "运行参数" },
+ { id: "oss", label: "存储 OSS" },
+ { id: "payment", label: "支付计费" },
+ { id: "site", label: "站点工具" },
+];
+
+// 系统设置:模型、运行参数、OSS、支付、站点
+export function SettingsPage() {
+ const [tab, setTab] = useState<SettingsTab>("routing");
+ const [reloadKey, setReloadKey] = useState(0);
+ const [importOpen, setImportOpen] = useState(false);
+ const [importing, setImporting] = useState(false);
+
+ // 从服务器 .env 一键导入 flat 配置到 DB
+ async function handleImportEnv() {
+ setImporting(true);
+ try {
+ const res = await api<ImportEnvRes>("/api/admin/settings/models/import-env", { method: "POST" });
+ setReloadKey((k) => k + 1);
+ setImportOpen(false);
+ const skipped = res.skipped_secret_fields?.length ?? 0;
+ toast.success(
+ `已导入 ${res.imported_fields?.length ?? 0} 项${skipped ? `,${skipped} 个空密钥已跳过` : ""}`,
+ );
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "导入失败");
+ } finally {
+ setImporting(false);
+ }
+ }
+
+ return (
+ <div className="admin-page">
+ <PageHeader
+ description="渠道路由、运行参数、OSS / 易支付 / 计费与站点配置;密钥加密存库,留空保存不修改。"
+ actions={
+ <button
+ type="button"
+ className="admin-quick-btn !inline-flex !w-auto items-center gap-2 px-4 py-2.5"
+ onClick={() => setImportOpen(true)}
+ >
+ <Download className="h-4 w-4" />
+ 从 .env 导入
+ </button>
+ }
+ />
+ <div className="flex flex-wrap gap-2">
+ {TABS.map(({ id, label }) => (
+ <button
+ key={id}
+ type="button"
+ className={cn("admin-tab", tab === id && "is-active")}
+ onClick={() => setTab(id)}
+ >
+ {label}
+ </button>
+ ))}
+ </div>
+ {tab === "routing" ? <RoutingSettingsPanel key={reloadKey} /> : null}
+ {tab === "runtime" ? <RuntimeSettingsPanel key={reloadKey} /> : null}
+ {tab === "oss" ? <OssSettingsPanel key={reloadKey} /> : null}
+ {tab === "payment" ? <PaymentSettingsPanel key={reloadKey} /> : null}
+ {tab === "site" ? <SiteSettingsPanel key={reloadKey} /> : null}
+
+ <AdminConfirmDialog
+ open={importOpen}
+ title="从 .env 导入配置"
+ description="将服务器当前环境变量 / backend/.env 中的 OSS、支付、模型密钥、运行参数等写入数据库并立即生效。已有 DB 配置会被覆盖;.env 中为空的密钥字段会跳过(保留库内原值)。"
+ confirmLabel="开始导入"
+ loading={importing}
+ onOpenChange={setImportOpen}
+ onConfirm={() => void handleImportEnv()}
+ />
+ </div>
+ );
+}
diff --git a/admin/src/pages/TemplatesPage.tsx b/admin/src/pages/TemplatesPage.tsx
index aa6dbc7..b35bacf 100644
--- a/admin/src/pages/TemplatesPage.tsx
+++ b/admin/src/pages/TemplatesPage.tsx
@@ -1,38 +1,33 @@
-import { useEffect, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
+import { LayoutGrid, Loader2, Plus } from "lucide-react";
import { toast } from "sonner";
import { api, type AdminTemplate, type PageMeta } from "@/api/client";
+import { AdminChipFilter } from "@/components/admin/AdminChipFilter";
+import { AdminConfirmDialog } from "@/components/admin/AdminConfirmDialog";
+import { AdminFilterBar } from "@/components/admin/AdminFilterBar";
+import { AdminSearchInput } from "@/components/admin/AdminSearchInput";
+import { AdminSelect } from "@/components/admin/AdminSelect";
+import { TemplateCard } from "@/components/templates/TemplateCard";
+import {
+ TemplateEditorDialog,
+ type TemplateFormState,
+} from "@/components/templates/TemplateEditorDialog";
import { PaginationBar } from "@/components/PaginationBar";
-import { DEFAULT_PAGE_SIZE } from "@/lib/pagination";
+import { TEMPLATE_PAGE_SIZE } from "@/lib/pagination";
import { Button } from "@/components/ui/button";
-import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
-import { Input } from "@/components/ui/input";
-import { Label } from "@/components/ui/label";
-import { Switch } from "@/components/ui/switch";
-import { Textarea } from "@/components/ui/select";
-import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
+import { PageHeader } from "@/components/ui/page";
type ListRes = { items: AdminTemplate[]; meta: PageMeta };
+type MetaRes = { categories: string[] };
-type FormState = {
- id: string;
- name: string;
- description: string;
- category: string;
- preview_cover: string;
- style_prefix: string;
- character_prompt: string;
- extra_prompt: string;
- negative_prompt: string;
- default_ratio: string;
- shot_duration_min: number;
- shot_duration_max: number;
- llm_system_addon: string;
- sort_order: number;
- is_active: boolean;
- is_premium: boolean;
-};
+const STATUS_OPTIONS = [
+ { value: "", label: "全部状态" },
+ { value: "active", label: "已上架" },
+ { value: "inactive", label: "已下架" },
+ { value: "premium", label: "Premium" },
+];
-const emptyForm = (): FormState => ({
+const emptyForm = (): TemplateFormState => ({
id: "",
name: "",
description: "",
@@ -57,46 +52,97 @@ function seedreamText(cfg: Record<string, unknown> | undefined, key: string): st
return typeof value === "string" ? value : "";
}
-// Template CRUD with active / premium toggles
+// 模板管理:封面卡片网格 + 分类筛选 + 全局 UI 组件
export function TemplatesPage() {
- /*
- * page current page
- * data list response
- * open dialog visibility
- * editing existing template or null for create
- * form form fields
- * saving request in flight
- */
const [page, setPage] = useState(1);
const [data, setData] = useState<ListRes | null>(null);
+ const [categories, setCategories] = useState<string[]>([]);
+ const [loading, setLoading] = useState(true);
const [open, setOpen] = useState(false);
const [editing, setEditing] = useState<AdminTemplate | null>(null);
- const [form, setForm] = useState<FormState>(emptyForm());
+ const [form, setForm] = useState<TemplateFormState>(emptyForm());
const [saving, setSaving] = useState(false);
+ const [q, setQ] = useState("");
+ const [statusFilter, setStatusFilter] = useState("");
+ const [categoryFilter, setCategoryFilter] = useState("");
+ const [deleteTarget, setDeleteTarget] = useState<string | null>(null);
+ const [deleting, setDeleting] = useState(false);
- // Load templates
+ // 加载模板分页列表
async function load(nextPage = page) {
+ setLoading(true);
try {
- const params = new URLSearchParams({ page: String(nextPage), page_size: String(DEFAULT_PAGE_SIZE) });
+ const params = new URLSearchParams({
+ page: String(nextPage),
+ page_size: String(TEMPLATE_PAGE_SIZE),
+ });
setData(await api<ListRes>(`/api/admin/templates?${params}`));
} catch (err) {
toast.error(err instanceof Error ? err.message : "加载失败");
+ } finally {
+ setLoading(false);
}
}
+ // 加载全库分类标签
+ async function loadMeta() {
+ try {
+ const meta = await api<MetaRes>("/api/admin/templates/meta");
+ setCategories(meta.categories ?? []);
+ } catch {
+ /* 分类元数据失败不阻塞列表 */
+ }
+ }
+
+ useEffect(() => {
+ void loadMeta();
+ }, []);
+
useEffect(() => {
void load();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page]);
- // Open create dialog
+ const categoryOptions = useMemo(() => {
+ const items = data?.items ?? [];
+ const countFor = (cat: string) =>
+ items.filter((t) => (t.category || []).includes(cat)).length;
+ return [
+ { value: "", label: "全部分类", count: items.length },
+ ...categories.map((cat) => ({
+ value: cat,
+ label: cat,
+ count: countFor(cat),
+ })),
+ ];
+ }, [categories, data?.items]);
+
+ const filteredItems = useMemo(() => {
+ const items = data?.items ?? [];
+ const keyword = q.trim().toLowerCase();
+ return items.filter((t) => {
+ if (statusFilter === "active" && !t.is_active) return false;
+ if (statusFilter === "inactive" && t.is_active) return false;
+ if (statusFilter === "premium" && !t.is_premium) return false;
+ if (categoryFilter && !(t.category || []).includes(categoryFilter)) return false;
+ if (!keyword) return true;
+ return (
+ t.id.toLowerCase().includes(keyword) ||
+ t.name.toLowerCase().includes(keyword) ||
+ (t.description || "").toLowerCase().includes(keyword) ||
+ (t.category || []).some((c) => c.toLowerCase().includes(keyword))
+ );
+ });
+ }, [data?.items, q, statusFilter, categoryFilter]);
+
+ // 打开新建弹窗
function openCreate() {
setEditing(null);
setForm(emptyForm());
setOpen(true);
}
- // Open edit dialog
+ // 打开编辑弹窗
function openEdit(tpl: AdminTemplate) {
setEditing(tpl);
setForm({
@@ -120,7 +166,7 @@ export function TemplatesPage() {
setOpen(true);
}
- // Create or update template
+ // 创建或更新模板
async function save() {
setSaving(true);
try {
@@ -183,7 +229,7 @@ export function TemplatesPage() {
}
toast.success("已保存");
setOpen(false);
- await load();
+ await Promise.all([load(), loadMeta()]);
} catch (err) {
toast.error(err instanceof Error ? err.message : "保存失败");
} finally {
@@ -191,7 +237,7 @@ export function TemplatesPage() {
}
}
- // Toggle active / premium quickly
+ // 快捷切换上架 / Premium
async function quickPatch(id: string, body: Partial<AdminTemplate>) {
try {
await api(`/api/admin/templates/${id}`, { method: "PATCH", body: JSON.stringify(body) });
@@ -201,75 +247,90 @@ export function TemplatesPage() {
}
}
- // Delete template if unused
- async function remove(id: string) {
- if (!window.confirm(`确认删除模板 ${id}?`)) return;
+ // 确认删除模板
+ async function confirmDelete() {
+ if (!deleteTarget) return;
+ setDeleting(true);
try {
- await api(`/api/admin/templates/${id}`, { method: "DELETE" });
+ await api(`/api/admin/templates/${deleteTarget}`, { method: "DELETE" });
toast.success("已删除");
- await load();
+ setDeleteTarget(null);
+ await Promise.all([load(), loadMeta()]);
} catch (err) {
toast.error(err instanceof Error ? err.message : "删除失败");
+ } finally {
+ setDeleting(false);
}
}
return (
- <div className="space-y-4">
- <div className="flex items-start justify-between gap-3">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">模板管理</h2>
- <p className="mt-1 text-sm text-[#909399]">
- 风格 / 角色 / 额外提示词以本页为准;启动不再用代码覆盖。已创建项目若曾单独改过,需在分镜页恢复模板后才会跟随。
- </p>
+ <div className="admin-list-page">
+ <PageHeader
+ description="风格 / 角色 / 提示词以本页为准;已创建项目需在分镜页恢复模板后才会跟随。"
+ actions={
+ <Button onClick={openCreate} className="gap-2">
+ <Plus className="h-4 w-4" />
+ 新建模板
+ </Button>
+ }
+ />
+
+ <AdminFilterBar
+ trailing={
+ <>
+ <LayoutGrid className="h-4 w-4" />
+ {filteredItems.length} / {data?.meta.total ?? 0} 项
+ </>
+ }
+ >
+ <AdminSearchInput
+ className="min-w-[220px] flex-1 max-w-md"
+ placeholder="搜索名称 / ID / 描述 / 分类"
+ value={q}
+ onChange={setQ}
+ />
+ <AdminSelect
+ className="w-36"
+ value={statusFilter}
+ options={STATUS_OPTIONS}
+ onChange={setStatusFilter}
+ />
+ <AdminChipFilter
+ label="分类"
+ value={categoryFilter}
+ options={categoryOptions}
+ onChange={setCategoryFilter}
+ />
+ </AdminFilterBar>
+
+ {loading ? (
+ <div className="template-grid-loading">
+ <Loader2 className="h-6 w-6 animate-spin text-[#67c23a]" />
+ <span>加载模板…</span>
</div>
- <Button onClick={openCreate}>新建模板</Button>
- </div>
- <div className="rounded-lg border bg-background">
- <Table>
- <TableHeader>
- <TableRow>
- <TableHead>ID</TableHead>
- <TableHead>名称</TableHead>
- <TableHead>排序</TableHead>
- <TableHead>上架</TableHead>
- <TableHead>Premium</TableHead>
- <TableHead></TableHead>
- </TableRow>
- </TableHeader>
- <TableBody>
- {(data?.items ?? []).map((t) => (
- <TableRow key={t.id}>
- <TableCell className="font-mono text-xs">{t.id}</TableCell>
- <TableCell>{t.name}</TableCell>
- <TableCell>{t.sort_order}</TableCell>
- <TableCell>
- <Switch
- checked={t.is_active}
- onCheckedChange={(v) => void quickPatch(t.id, { is_active: v })}
- />
- </TableCell>
- <TableCell>
- <Switch
- checked={t.is_premium}
- onCheckedChange={(v) => void quickPatch(t.id, { is_premium: v })}
- />
- </TableCell>
- <TableCell>
- <div className="flex gap-1">
- <Button size="sm" variant="outline" onClick={() => openEdit(t)}>
- 编辑
- </Button>
- <Button size="sm" variant="ghost" onClick={() => void remove(t.id)}>
- 删除
- </Button>
- </div>
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </div>
- {data && (
+ ) : filteredItems.length === 0 ? (
+ <div className="template-grid-empty">
+ <p>暂无匹配的模板</p>
+ <Button variant="outline" size="sm" onClick={openCreate}>
+ 新建第一个模板
+ </Button>
+ </div>
+ ) : (
+ <div className="template-grid">
+ {filteredItems.map((t) => (
+ <TemplateCard
+ key={t.id}
+ template={t}
+ onEdit={openEdit}
+ onDelete={(id) => setDeleteTarget(id)}
+ onToggleActive={(id, v) => void quickPatch(id, { is_active: v })}
+ onTogglePremium={(id, v) => void quickPatch(id, { is_premium: v })}
+ />
+ ))}
+ </div>
+ )}
+
+ {data && data.meta.total > TEMPLATE_PAGE_SIZE && (
<PaginationBar
page={data.meta.page}
pageSize={data.meta.page_size}
@@ -278,129 +339,29 @@ export function TemplatesPage() {
/>
)}
- <Dialog open={open} onOpenChange={setOpen}>
- <DialogContent className="max-h-[90vh] max-w-2xl overflow-y-auto">
- <DialogHeader>
- <DialogTitle>{editing ? `编辑模板 · ${editing.id}` : "新建模板"}</DialogTitle>
- </DialogHeader>
- <div className="grid gap-3 sm:grid-cols-2">
- {!editing && (
- <div className="space-y-2 sm:col-span-2">
- <Label>ID</Label>
- <Input value={form.id} onChange={(e) => setForm((f) => ({ ...f, id: e.target.value }))} />
- </div>
- )}
- <div className="space-y-2 sm:col-span-2">
- <Label>名称</Label>
- <Input value={form.name} onChange={(e) => setForm((f) => ({ ...f, name: e.target.value }))} />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>描述</Label>
- <Textarea
- value={form.description}
- onChange={(e) => setForm((f) => ({ ...f, description: e.target.value }))}
- />
- </div>
- <div className="space-y-2">
- <Label>分类(逗号分隔)</Label>
- <Input
- value={form.category}
- onChange={(e) => setForm((f) => ({ ...f, category: e.target.value }))}
- />
- </div>
- <div className="space-y-2">
- <Label>封面 URL</Label>
- <Input
- value={form.preview_cover}
- onChange={(e) => setForm((f) => ({ ...f, preview_cover: e.target.value }))}
- />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>风格提示词</Label>
- <Textarea
- value={form.style_prefix}
- onChange={(e) => setForm((f) => ({ ...f, style_prefix: e.target.value }))}
- />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>角色提示词</Label>
- <Textarea
- value={form.character_prompt}
- onChange={(e) => setForm((f) => ({ ...f, character_prompt: e.target.value }))}
- />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>额外提示词</Label>
- <Textarea
- value={form.extra_prompt}
- onChange={(e) => setForm((f) => ({ ...f, extra_prompt: e.target.value }))}
- />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>LLM 附加说明</Label>
- <Textarea
- value={form.llm_system_addon}
- onChange={(e) => setForm((f) => ({ ...f, llm_system_addon: e.target.value }))}
- />
- </div>
- <div className="space-y-2 sm:col-span-2">
- <Label>负面提示词</Label>
- <Textarea
- value={form.negative_prompt}
- onChange={(e) => setForm((f) => ({ ...f, negative_prompt: e.target.value }))}
- />
- </div>
- <div className="space-y-2">
- <Label>画幅</Label>
- <Input
- value={form.default_ratio}
- onChange={(e) => setForm((f) => ({ ...f, default_ratio: e.target.value }))}
- />
- </div>
- <div className="space-y-2">
- <Label>排序</Label>
- <Input
- type="number"
- value={form.sort_order}
- onChange={(e) => setForm((f) => ({ ...f, sort_order: Number(e.target.value) }))}
- />
- </div>
- <div className="space-y-2">
- <Label>时长 min</Label>
- <Input
- type="number"
- value={form.shot_duration_min}
- onChange={(e) => setForm((f) => ({ ...f, shot_duration_min: Number(e.target.value) }))}
- />
- </div>
- <div className="space-y-2">
- <Label>时长 max</Label>
- <Input
- type="number"
- value={form.shot_duration_max}
- onChange={(e) => setForm((f) => ({ ...f, shot_duration_max: Number(e.target.value) }))}
- />
- </div>
- <div className="flex items-center justify-between sm:col-span-1">
- <Label>上架</Label>
- <Switch
- checked={form.is_active}
- onCheckedChange={(v) => setForm((f) => ({ ...f, is_active: v }))}
- />
- </div>
- <div className="flex items-center justify-between sm:col-span-1">
- <Label>Premium</Label>
- <Switch
- checked={form.is_premium}
- onCheckedChange={(v) => setForm((f) => ({ ...f, is_premium: v }))}
- />
- </div>
- </div>
- <Button className="mt-2 w-full" disabled={saving} onClick={() => void save()}>
- {saving ? "保存中…" : "保存"}
- </Button>
- </DialogContent>
- </Dialog>
+ <TemplateEditorDialog
+ open={open}
+ saving={saving}
+ editing={editing}
+ form={form}
+ categorySuggestions={categories}
+ onOpenChange={setOpen}
+ onChange={(patch) => setForm((prev) => ({ ...prev, ...patch }))}
+ onSave={() => void save()}
+ />
+
+ <AdminConfirmDialog
+ open={Boolean(deleteTarget)}
+ title="删除模板"
+ description={deleteTarget ? `确认删除模板「${deleteTarget}」?已被项目引用的模板无法删除。` : undefined}
+ confirmLabel="删除"
+ loading={deleting}
+ destructive
+ onOpenChange={(next) => {
+ if (!next) setDeleteTarget(null);
+ }}
+ onConfirm={() => void confirmDelete()}
+ />
</div>
);
}
diff --git a/admin/src/pages/UsersPage.tsx b/admin/src/pages/UsersPage.tsx
index 8123c7d..391f316 100644
--- a/admin/src/pages/UsersPage.tsx
+++ b/admin/src/pages/UsersPage.tsx
@@ -106,8 +106,8 @@ export function UsersPage() {
}
return (
- <div className="space-y-4">
- <PageHeader title="用户管理" description="搜索用户,调整套餐、余额与无限额度" />
+ <div className="admin-list-page">
+ <PageHeader description="搜索用户,调整套餐、余额与无限额度" />
<Toolbar>
<Input
diff --git a/admin/src/pages/WorksPage.tsx b/admin/src/pages/WorksPage.tsx
index 568ab80..df4b63e 100644
--- a/admin/src/pages/WorksPage.tsx
+++ b/admin/src/pages/WorksPage.tsx
@@ -7,6 +7,7 @@ import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Select } from "@/components/ui/select";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
+import { PageHeader } from "@/components/ui/page";
import { auditStatusLabel, visibilityLabel } from "@/lib/statusLabels";
type ListRes = { items: AdminWork[]; meta: PageMeta };
@@ -53,12 +54,9 @@ export function WorksPage() {
}
return (
- <div className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-[#303133]">作品审核</h2>
- <p className="mt-1 text-sm text-[#909399]">调整可见性与审核状态</p>
- </div>
- <div className="flex flex-wrap gap-2">
+ <div className="admin-list-page">
+ <PageHeader description="调整可见性与审核状态" />
+ <div className="admin-filter-bar">
<Select className="w-40" value={auditStatus} onChange={(e) => setAuditStatus(e.target.value)}>
<option value="">全部审核</option>
<option value="pending">待审核</option>
diff --git a/admin/vite.config.ts b/admin/vite.config.ts
index f04fb23..0688943 100644
--- a/admin/vite.config.ts
+++ b/admin/vite.config.ts
@@ -18,11 +18,11 @@ export default defineConfig({
port: 5174,
proxy: {
"/api": {
- target: "http://127.0.0.1:8001",
+ target: "http://127.0.0.1:8000",
changeOrigin: true,
},
"/static": {
- target: "http://127.0.0.1:8001",
+ target: "http://127.0.0.1:8000",
changeOrigin: true,
},
},