Skip to content

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

feat(admin): show usage costs, project detail drawers, and usage tab deep-link

yi29ef51a8e682
diff --git a/admin/src/api/client.ts b/admin/src/api/client.ts
index b9b3b55..211a4db 100644
--- a/admin/src/api/client.ts
+++ b/admin/src/api/client.ts
@@ -62,11 +62,78 @@ export async function loginAsAdmin(email: string, password: string): Promise<Adm
return me;
}
+export type AdminUsageBucket = {
+ key: string;
+ calls: number;
+ charge_fen: number;
+};
+
+export type AdminDailyUsage = {
+ date: string;
+ calls: number;
+ charge_fen: number;
+};
+
+export type AdminTopUser = {
+ user_id: number;
+ email?: string | null;
+ calls: number;
+ charge_fen: number;
+};
+
+export type AdminProjectUsage = {
+ charge_fen: number;
+ cost_fen: number;
+ tokens: number;
+ calls: number;
+ image_gens: number;
+ video_gens: number;
+ llm_calls: number;
+ tts_gens?: number;
+};
+
+export type AdminTaskBrief = {
+ id: number;
+ domain: string;
+ task_type: string;
+ status: string;
+ progress_percent: number;
+ billing_charged_fen: number;
+ billing_estimate_fen: number;
+ error_message?: string | null;
+ created_at?: string | null;
+ finished_at?: string | null;
+};
+
+export type AdminShotBrief = {
+ id: number;
+ shot_no: number;
+ status: string;
+ has_image: boolean;
+ has_video: boolean;
+ has_audio: boolean;
+ duration: number;
+};
+
export type AdminStats = {
user_count: number;
order_paid_total_fen: number;
order_paid_today_fen: number;
project_status_counts: Record<string, number>;
+ drama_project_count?: number;
+ usage_calls_today?: number;
+ usage_calls_month?: number;
+ usage_calls_total?: number;
+ usage_charge_today_fen?: number;
+ usage_charge_month_fen?: number;
+ usage_charge_total_fen?: number;
+ usage_cost_today_fen?: number;
+ usage_cost_month_fen?: number;
+ usage_cost_total_fen?: number;
+ usage_by_capability?: AdminUsageBucket[];
+ usage_by_domain?: AdminUsageBucket[];
+ daily_usage?: AdminDailyUsage[];
+ top_users_by_charge?: AdminTopUser[];
};
export type AdminUserRow = {
@@ -125,11 +192,42 @@ export type AdminProject = {
created_at: string;
updated_at: string;
shot_count: number;
+ charge_fen?: number;
source_type?: string;
source_text?: string;
resolution_mode?: string;
output_ratio?: string;
voice_id?: string;
+ usage?: AdminProjectUsage;
+ shots?: AdminShotBrief[];
+ recent_tasks?: AdminTaskBrief[];
+};
+
+export type AdminDramaProject = {
+ id: number;
+ user_id: number;
+ user_email?: string | null;
+ title: string;
+ description?: string | null;
+ created_at?: string | null;
+ updated_at?: string | null;
+ episode_count?: number;
+ asset_count?: number;
+ fragment_count?: number;
+ charge_fen?: number;
+ summary_status?: string | null;
+ assets_seed_status?: string | null;
+ episode_content_status?: string | null;
+ usage?: AdminProjectUsage;
+ episodes?: { id: number; name: string; fragment_count: number; fragment_plan_status?: string | null }[];
+ assets?: {
+ id: number;
+ type: string;
+ name?: string | null;
+ has_cover: boolean;
+ generation_status?: string | null;
+ }[];
+ recent_tasks?: AdminTaskBrief[];
};
export type AdminWork = {
diff --git a/admin/src/components/layout/AdminLayout.tsx b/admin/src/components/layout/AdminLayout.tsx
index d06eb4f..3be767a 100644
--- a/admin/src/components/layout/AdminLayout.tsx
+++ b/admin/src/components/layout/AdminLayout.tsx
@@ -82,7 +82,7 @@ const navGroups: NavGroup[] = [
{ to: "/orders", label: "订单流水", icon: Receipt },
- { to: "/projects", label: "项目管理", icon: Clapperboard },
+ { to: "/projects", label: "科普项目", icon: Clapperboard },
{ to: "/drama-projects", label: "漫剧项目", icon: Film },
@@ -126,7 +126,7 @@ const titles: Record<string, string> = {
"/orders": "订单流水",
- "/projects": "项目管理",
+ "/projects": "科普项目",
"/drama-projects": "漫剧项目",
diff --git a/admin/src/index.css b/admin/src/index.css
index c733234..4b82bff 100644
--- a/admin/src/index.css
+++ b/admin/src/index.css
@@ -1147,7 +1147,7 @@
.admin-dashboard-top {
display: grid;
- grid-template-columns: repeat(4, minmax(0, 1fr));
+ grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
}
diff --git a/admin/src/pages/DashboardPage.tsx b/admin/src/pages/DashboardPage.tsx
index 9b059fa..20f320a 100644
--- a/admin/src/pages/DashboardPage.tsx
+++ b/admin/src/pages/DashboardPage.tsx
@@ -1,14 +1,17 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import {
+ Activity,
Banknote,
Clapperboard,
+ Film,
Layers,
Receipt,
Settings,
Shapes,
Users,
Wallet,
+ Zap,
} from "lucide-react";
import { toast } from "sonner";
import { StatCard } from "@/components/admin/StatCard";
@@ -16,10 +19,18 @@ 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";
+import { orderStatusLabel, payTypeLabel, projectStatusLabel, taskDomainLabel } from "@/lib/statusLabels";
type OrderRes = { items: AdminOrder[]; meta: PageMeta };
+const CAPABILITY_LABELS: Record<string, string> = {
+ llm: "LLM 文本",
+ image: "生图",
+ video: "视频",
+ tts: "配音",
+ unknown: "其他",
+};
+
// Map project status to pill style
function statusClass(status: string): string {
if (status === "DONE") return "is-done";
@@ -30,7 +41,11 @@ function statusClass(status: string): string {
return "is-warn";
}
-// Dashboard overview
+function capabilityLabel(key: string): string {
+ return CAPABILITY_LABELS[key] ?? key;
+}
+
+// Dashboard overview with usage / cost / rankings
export function DashboardPage() {
const [stats, setStats] = useState<AdminStats | null>(null);
const [orders, setOrders] = useState<AdminOrder[]>([]);
@@ -50,29 +65,57 @@ export function DashboardPage() {
const statusEntries = Object.entries(stats?.project_status_counts ?? {}).sort(
(a, b) => b[1] - a[1],
);
+ const daily = stats?.daily_usage ?? [];
+ const byCapability = stats?.usage_by_capability ?? [];
+ const byDomain = stats?.usage_by_domain ?? [];
+ const topUsers = stats?.top_users_by_charge ?? [];
return (
<div className="admin-page">
- <PageHeader description="用户、订单与项目状态概览" />
+ <PageHeader description="用户、充值、AI 调用与费用概览" />
<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="历史累计"
+ hint="历史充值"
icon={Banknote}
tone="success"
/>
<StatCard
label="今日已付"
value={stats ? `¥${fenToYuan(stats.order_paid_today_fen)}` : "—"}
- hint="今日付款"
+ hint="今日充值"
icon={Wallet}
tone="info"
/>
+ <StatCard
+ label="本月 AI 扣费"
+ value={stats ? `¥${fenToYuan(stats.usage_charge_month_fen ?? 0)}` : "—"}
+ hint={`今日 ¥${fenToYuan(stats?.usage_charge_today_fen ?? 0)}`}
+ icon={Zap}
+ tone="warn"
+ />
+ <StatCard
+ label="本月上游成本"
+ value={stats ? `¥${fenToYuan(stats.usage_cost_month_fen ?? 0)}` : "—"}
+ hint={`今日 ¥${fenToYuan(stats?.usage_cost_today_fen ?? 0)} · 累计 ¥${fenToYuan(stats?.usage_cost_total_fen ?? 0)}`}
+ icon={Banknote}
+ tone="info"
+ />
+ <StatCard
+ label="今日调用"
+ value={stats?.usage_calls_today ?? "—"}
+ hint={`本月 ${stats?.usage_calls_month ?? 0} · 累计 ${stats?.usage_calls_total ?? 0}`}
+ icon={Activity}
+ tone="info"
+ />
<div className="admin-panel admin-stat-card tone-success">
- <div className="admin-stat-label">项目状态</div>
+ <div className="admin-stat-label">科普项目状态</div>
+ <div className="mt-1 text-xs text-[var(--admin-muted)]">
+ 漫剧项目 {stats?.drama_project_count ?? 0} 部
+ </div>
<div className="mt-2 flex flex-wrap gap-1.5">
{statusEntries.length === 0 ? (
<span className="text-xs text-[var(--admin-muted)]">暂无数据</span>
@@ -88,6 +131,145 @@ export function DashboardPage() {
</div>
<div className="admin-dashboard-body">
+ <PageSection title="近 7 日调用与扣费" bodyClassName="!pt-0" className="min-h-0">
+ <div className="admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>日期</th>
+ <th>调用次数</th>
+ <th>扣费</th>
+ </tr>
+ </thead>
+ <tbody>
+ {daily.length === 0 ? (
+ <tr>
+ <td colSpan={3} className="!text-center text-[var(--admin-muted)]">
+ 暂无用量
+ </td>
+ </tr>
+ ) : (
+ daily.map((d) => (
+ <tr key={d.date}>
+ <td className="font-mono text-xs">{d.date}</td>
+ <td>{d.calls}</td>
+ <td>¥{fenToYuan(d.charge_fen)}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </PageSection>
+
+ <PageSection title="能力 / 领域分布(本月)" bodyClassName="!pt-0">
+ <div className="mb-3 text-xs font-medium text-[var(--admin-muted)]">按能力</div>
+ <div className="admin-table-wrap mb-4">
+ <table>
+ <thead>
+ <tr>
+ <th>能力</th>
+ <th>调用</th>
+ <th>扣费</th>
+ </tr>
+ </thead>
+ <tbody>
+ {byCapability.length === 0 ? (
+ <tr>
+ <td colSpan={3} className="!text-center text-[var(--admin-muted)]">
+ 暂无
+ </td>
+ </tr>
+ ) : (
+ byCapability.map((b) => (
+ <tr key={b.key}>
+ <td>{capabilityLabel(b.key)}</td>
+ <td>{b.calls}</td>
+ <td>¥{fenToYuan(b.charge_fen)}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ <div className="mb-2 text-xs font-medium text-[var(--admin-muted)]">按领域</div>
+ <div className="admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>领域</th>
+ <th>调用</th>
+ <th>扣费</th>
+ </tr>
+ </thead>
+ <tbody>
+ {byDomain.length === 0 ? (
+ <tr>
+ <td colSpan={3} className="!text-center text-[var(--admin-muted)]">
+ 暂无
+ </td>
+ </tr>
+ ) : (
+ byDomain.map((b) => (
+ <tr key={b.key}>
+ <td>{taskDomainLabel(b.key)}</td>
+ <td>{b.calls}</td>
+ <td>¥{fenToYuan(b.charge_fen)}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </PageSection>
+ </div>
+
+ <div className="admin-dashboard-body mt-4">
+ <PageSection
+ title="用户消费排行(近 30 日)"
+ actions={
+ <Link to="/orders?tab=usage" className="admin-link">
+ 用量明细 →
+ </Link>
+ }
+ bodyClassName="!pt-0"
+ className="min-h-0"
+ >
+ <div className="admin-table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>#</th>
+ <th>用户</th>
+ <th>调用</th>
+ <th>扣费</th>
+ </tr>
+ </thead>
+ <tbody>
+ {topUsers.length === 0 ? (
+ <tr>
+ <td colSpan={4} className="!text-center text-[var(--admin-muted)]">
+ 暂无排行
+ </td>
+ </tr>
+ ) : (
+ topUsers.map((u, idx) => (
+ <tr key={u.user_id}>
+ <td>{idx + 1}</td>
+ <td>
+ <div className="text-sm">{u.email ?? u.user_id}</div>
+ <div className="font-mono text-[11px] text-[var(--admin-muted)]">ID {u.user_id}</div>
+ </td>
+ <td>{u.calls}</td>
+ <td>¥{fenToYuan(u.charge_fen)}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </PageSection>
+
<PageSection
title="最近订单"
actions={
@@ -141,16 +323,18 @@ export function DashboardPage() {
</table>
</div>
</PageSection>
+ </div>
+ <div className="mt-4">
<PageSection title="快捷入口" bodyClassName="!pt-0">
- <div className="grid grid-cols-2 gap-2">
+ <div className="grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-6">
<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">
+ <Link to="/orders?tab=usage" className="admin-quick-btn !flex-row !items-center !py-2.5">
<Receipt className="h-4 w-4" />
- 订单
+ 订单/用量
</Link>
<Link to="/users" className="admin-quick-btn !flex-row !items-center !py-2.5">
<Users className="h-4 w-4" />
@@ -158,24 +342,20 @@ export function DashboardPage() {
</Link>
<Link to="/projects" className="admin-quick-btn !flex-row !items-center !py-2.5">
<Clapperboard className="h-4 w-4" />
- 项目
+ 科普
</Link>
- <Link to="/settings" className="admin-quick-btn !flex-row !items-center !py-2.5">
- <Settings className="h-4 w-4" />
- 配置
+ <Link to="/drama-projects" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Film className="h-4 w-4" />
+ 漫剧
</Link>
<Link to="/queues" className="admin-quick-btn !flex-row !items-center !py-2.5">
<Layers className="h-4 w-4" />
任务
</Link>
- </div>
- <div className="admin-notice">
- <div className="admin-notice-title">
- <span>系统公告</span>
- </div>
- <p className="admin-notice-body !text-xs">
- 管理用户额度、审核作品与模板,并在任务中心监控统一任务平台。
- </p>
+ <Link to="/settings" className="admin-quick-btn !flex-row !items-center !py-2.5">
+ <Settings className="h-4 w-4" />
+ 配置
+ </Link>
</div>
</PageSection>
</div>
diff --git a/admin/src/pages/DramaProjectsPage.tsx b/admin/src/pages/DramaProjectsPage.tsx
index 1bf58d0..7d20e4a 100644
--- a/admin/src/pages/DramaProjectsPage.tsx
+++ b/admin/src/pages/DramaProjectsPage.tsx
@@ -1,30 +1,31 @@
import { useEffect, useState } from "react";
+import { Link } from "react-router-dom";
import { toast } from "sonner";
-import { api, type PageMeta } from "@/api/client";
+import { api, type AdminDramaProject, type PageMeta } from "@/api/client";
import { PaginationBar } from "@/components/PaginationBar";
+import { DEFAULT_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 { PageHeader } from "@/components/ui/page";
+import { taskStatusLabel, taskTypeLabel } from "@/lib/statusLabels";
+import { fenToYuan } from "@/lib/utils";
-type DramaProjectRow = {
- id: number;
- user_id: number;
- user_email?: string | null;
- title: string;
- description?: string | null;
- created_at?: string | null;
- updated_at?: string | null;
-};
+type ListRes = { items: AdminDramaProject[]; meta: PageMeta };
-type ListRes = { items: DramaProjectRow[]; meta: PageMeta };
-
-/** Admin table listing drama projects with pagination */
+/** Admin drama projects with filters and detail dialog */
export function DramaProjectsPage() {
const [page, setPage] = useState(1);
+ const [q, setQ] = useState("");
+ const [userId, setUserId] = useState("");
const [data, setData] = useState<ListRes | null>(null);
+ const [detail, setDetail] = useState<AdminDramaProject | null>(null);
- // Load drama projects
async function load(nextPage = page) {
try {
- const params = new URLSearchParams({ page: String(nextPage), page_size: "20" });
+ const params = new URLSearchParams({ page: String(nextPage), page_size: String(DEFAULT_PAGE_SIZE) });
+ if (q.trim()) params.set("q", q.trim());
+ if (userId.trim()) params.set("user_id", userId.trim());
setData(await api<ListRes>(`/api/admin/drama-projects?${params}`));
} catch (err) {
toast.error(err instanceof Error ? err.message : "加载失败");
@@ -36,9 +37,42 @@ export function DramaProjectsPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page]);
+ async function openDetail(id: number) {
+ try {
+ setDetail(await api<AdminDramaProject>(`/api/admin/drama-projects/${id}`));
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : "加载详情失败");
+ }
+ }
+
+ const usage = detail?.usage;
+
return (
<div className="admin-list-page">
- <PageHeader description="查看用户创建的漫剧项目" />
+ <PageHeader description="漫剧项目:集数、资产、生产状态、费用与关联任务" />
+ <div className="admin-filter-bar">
+ <Input
+ className="max-w-xs"
+ placeholder="标题 / 描述"
+ value={q}
+ onChange={(e) => setQ(e.target.value)}
+ />
+ <Input
+ className="w-32"
+ placeholder="用户 ID"
+ value={userId}
+ onChange={(e) => setUserId(e.target.value)}
+ />
+ <Button
+ variant="secondary"
+ onClick={() => {
+ setPage(1);
+ void load(1);
+ }}
+ >
+ 筛选
+ </Button>
+ </div>
<div className="admin-table-wrap">
<table>
<thead>
@@ -46,23 +80,37 @@ export function DramaProjectsPage() {
<th>ID</th>
<th>标题</th>
<th>用户</th>
+ <th>集数</th>
+ <th>资产</th>
+ <th>费用</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 className="max-w-[200px] truncate">{row.title}</td>
<td>{row.user_email ?? row.user_id}</td>
+ <td>{row.episode_count ?? 0}</td>
+ <td>{row.asset_count ?? 0}</td>
+ <td>¥{fenToYuan(row.charge_fen ?? 0)}</td>
+ <td className="text-xs text-[var(--admin-muted)]">{row.summary_status || "—"}</td>
<td className="text-xs text-[var(--admin-muted)]">
{row.created_at ? new Date(row.created_at).toLocaleString() : "—"}
</td>
+ <td>
+ <Button size="sm" variant="outline" onClick={() => void openDetail(row.id)}>
+ 详情
+ </Button>
+ </td>
</tr>
))}
{(data?.items.length ?? 0) === 0 ? (
<tr>
- <td colSpan={4} className="!text-center text-[var(--admin-muted)]">
+ <td colSpan={9} className="!text-center text-[var(--admin-muted)]">
暂无项目
</td>
</tr>
@@ -78,6 +126,179 @@ export function DramaProjectsPage() {
onPageChange={setPage}
/>
) : null}
+
+ <Dialog open={!!detail} onOpenChange={(open) => !open && setDetail(null)}>
+ <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">
+ <DialogHeader>
+ <DialogTitle>
+ 漫剧 #{detail?.id} · {detail?.title}
+ </DialogTitle>
+ </DialogHeader>
+ {detail && (
+ <div className="space-y-4 text-sm">
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">基本信息</div>
+ <div>用户:{detail.user_email ?? detail.user_id}</div>
+ <div>{detail.description || "无描述"}</div>
+ <div className="flex flex-wrap gap-2 text-xs">
+ <span className="rounded border px-2 py-0.5">摘要 {detail.summary_status || "—"}</span>
+ <span className="rounded border px-2 py-0.5">
+ 分集 {detail.episode_content_status || "—"}
+ </span>
+ <span className="rounded border px-2 py-0.5">
+ 资产抽取 {detail.assets_seed_status || "—"}
+ </span>
+ <span className="rounded border px-2 py-0.5">集 {detail.episode_count ?? 0}</span>
+ <span className="rounded border px-2 py-0.5">资产 {detail.asset_count ?? 0}</span>
+ <span className="rounded border px-2 py-0.5">分镜 {detail.fragment_count ?? 0}</span>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">费用汇总</div>
+ <div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">扣费</div>
+ <div>¥{fenToYuan(usage?.charge_fen ?? detail.charge_fen ?? 0)}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">成本</div>
+ <div>¥{fenToYuan(usage?.cost_fen ?? 0)}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">调用</div>
+ <div>{usage?.calls ?? 0}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">图/视/LLM/TTS</div>
+ <div>
+ {usage?.image_gens ?? 0}/{usage?.video_gens ?? 0}/{usage?.llm_calls ?? 0}/
+ {usage?.tts_gens ?? 0}
+ </div>
+ </div>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">
+ 集列表({(detail.episodes ?? []).length})
+ </div>
+ <div className="max-h-36 overflow-auto rounded border">
+ <table className="w-full text-xs">
+ <thead>
+ <tr className="border-b bg-muted/40 text-left">
+ <th className="p-2">ID</th>
+ <th className="p-2">名称</th>
+ <th className="p-2">分镜数</th>
+ <th className="p-2">分镜状态</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(detail.episodes ?? []).length === 0 ? (
+ <tr>
+ <td colSpan={4} className="p-2 text-center text-muted-foreground">
+ 暂无集
+ </td>
+ </tr>
+ ) : (
+ (detail.episodes ?? []).map((ep) => (
+ <tr key={ep.id} className="border-b">
+ <td className="p-2">{ep.id}</td>
+ <td className="p-2">{ep.name}</td>
+ <td className="p-2">{ep.fragment_count}</td>
+ <td className="p-2">{ep.fragment_plan_status || "—"}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">
+ 资产摘要({(detail.assets ?? []).length})
+ </div>
+ <div className="max-h-36 overflow-auto rounded border">
+ <table className="w-full text-xs">
+ <thead>
+ <tr className="border-b bg-muted/40 text-left">
+ <th className="p-2">ID</th>
+ <th className="p-2">类型</th>
+ <th className="p-2">名称</th>
+ <th className="p-2">封面</th>
+ <th className="p-2">生成</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(detail.assets ?? []).length === 0 ? (
+ <tr>
+ <td colSpan={5} className="p-2 text-center text-muted-foreground">
+ 暂无资产
+ </td>
+ </tr>
+ ) : (
+ (detail.assets ?? []).map((a) => (
+ <tr key={a.id} className="border-b">
+ <td className="p-2">{a.id}</td>
+ <td className="p-2">{a.type}</td>
+ <td className="max-w-[120px] truncate p-2">{a.name || "—"}</td>
+ <td className="p-2">{a.has_cover ? "有" : "—"}</td>
+ <td className="p-2">{a.generation_status || "—"}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="flex items-center justify-between">
+ <div className="text-xs font-medium text-muted-foreground">
+ 关联任务(最近 {(detail.recent_tasks ?? []).length})
+ </div>
+ <Link to="/queues" className="text-xs text-primary">
+ 任务中心 →
+ </Link>
+ </div>
+ <div className="max-h-48 overflow-auto rounded border">
+ <table className="w-full text-xs">
+ <thead>
+ <tr className="border-b bg-muted/40 text-left">
+ <th className="p-2">ID</th>
+ <th className="p-2">类型</th>
+ <th className="p-2">状态</th>
+ <th className="p-2">已扣 / 预估</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(detail.recent_tasks ?? []).length === 0 ? (
+ <tr>
+ <td colSpan={4} className="p-2 text-center text-muted-foreground">
+ 暂无任务
+ </td>
+ </tr>
+ ) : (
+ (detail.recent_tasks ?? []).map((t) => (
+ <tr key={t.id} className="border-b">
+ <td className="p-2 font-mono">{t.id}</td>
+ <td className="p-2">{taskTypeLabel(t.task_type)}</td>
+ <td className="p-2">{taskStatusLabel(t.status)}</td>
+ <td className="p-2">
+ ¥{fenToYuan(t.billing_charged_fen)} / ¥{fenToYuan(t.billing_estimate_fen)}
+ </td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </section>
+ </div>
+ )}
+ </DialogContent>
+ </Dialog>
</div>
);
}
diff --git a/admin/src/pages/OrdersPage.tsx b/admin/src/pages/OrdersPage.tsx
index bb6696b..c76566e 100644
--- a/admin/src/pages/OrdersPage.tsx
+++ b/admin/src/pages/OrdersPage.tsx
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
+import { useSearchParams } from "react-router-dom";
import { toast } from "sonner";
import { api, type AdminLedger, type AdminOrder, type AdminUsageEventListRes, type PageMeta } from "@/api/client";
import { PaginationBar } from "@/components/PaginationBar";
@@ -16,6 +17,12 @@ import { ledgerKindLabel, orderStatusLabel, payTypeLabel, taskDomainLabel } from
type OrderRes = { items: AdminOrder[]; meta: PageMeta };
type LedgerRes = { items: AdminLedger[]; meta: PageMeta };
+const ORDER_TABS = new Set(["orders", "ledger", "usage"]);
+
+function tabFromSearch(raw: string | null): string {
+ return raw && ORDER_TABS.has(raw) ? raw : "orders";
+}
+
// Orders and wallet ledger tabs
export function OrdersPage() {
/*
@@ -29,7 +36,8 @@ export function OrdersPage() {
* orders order list
* ledger ledger list
*/
- const [tab, setTab] = useState("orders");
+ const [searchParams, setSearchParams] = useSearchParams();
+ const [tab, setTab] = useState(() => tabFromSearch(searchParams.get("tab")));
const [orderStatus, setOrderStatus] = useState("");
const [orderUserId, setOrderUserId] = useState("");
const [ledgerKind, setLedgerKind] = useState("");
@@ -90,6 +98,11 @@ export function OrdersPage() {
}
}
+ useEffect(() => {
+ const next = tabFromSearch(searchParams.get("tab"));
+ setTab((prev) => (prev === next ? prev : next));
+ }, [searchParams]);
+
useEffect(() => {
void loadOrders();
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -105,10 +118,18 @@ export function OrdersPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [usagePage]);
+ function onTabChange(next: string) {
+ setTab(next);
+ const params = new URLSearchParams(searchParams);
+ if (next === "orders") params.delete("tab");
+ else params.set("tab", next);
+ setSearchParams(params, { replace: true });
+ }
+
return (
<div className="admin-list-page">
<PageHeader description="查看充值单、钱包流水与 AI 用量明细" />
- <Tabs value={tab} onValueChange={setTab}>
+ <Tabs value={tab} onValueChange={onTabChange}>
<TabsList>
<TabsTrigger value="orders">充值订单</TabsTrigger>
<TabsTrigger value="ledger">钱包流水</TabsTrigger>
diff --git a/admin/src/pages/ProjectsPage.tsx b/admin/src/pages/ProjectsPage.tsx
index f1c277d..6fa8d67 100644
--- a/admin/src/pages/ProjectsPage.tsx
+++ b/admin/src/pages/ProjectsPage.tsx
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
+import { Link } from "react-router-dom";
import { toast } from "sonner";
import { api, type AdminProject, type PageMeta } from "@/api/client";
import { PaginationBar } from "@/components/PaginationBar";
@@ -10,7 +11,8 @@ 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";
+import { PROJECT_STATUS_OPTIONS, projectStatusLabel, taskStatusLabel, taskTypeLabel } from "@/lib/statusLabels";
+import { fenToYuan } from "@/lib/utils";
type ListRes = { items: AdminProject[]; meta: PageMeta };
@@ -23,22 +25,14 @@ function statusBadgeVariant(status: string): "destructive" | "success" | "warnin
return "info";
}
-// Project list and failure detail
+// 科普项目列表与详情(镜头 / 任务 / 费用)
export function ProjectsPage() {
- /*
- * q title/error search
- * status status filter
- * page current page
- * data list response
- * detail selected project detail
- */
const [q, setQ] = useState("");
const [status, setStatus] = useState("");
const [page, setPage] = useState(1);
const [data, setData] = useState<ListRes | null>(null);
const [detail, setDetail] = useState<AdminProject | null>(null);
- // Load projects
async function load(nextPage = page) {
try {
const params = new URLSearchParams({ page: String(nextPage), page_size: String(DEFAULT_PAGE_SIZE) });
@@ -55,7 +49,6 @@ export function ProjectsPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [page]);
- // Fetch project detail for triage
async function openDetail(id: number) {
try {
setDetail(await api<AdminProject>(`/api/admin/projects/${id}`));
@@ -64,9 +57,11 @@ export function ProjectsPage() {
}
}
+ const usage = detail?.usage;
+
return (
<div className="admin-list-page">
- <PageHeader description="按状态筛选,查看失败原因与进度" />
+ <PageHeader description="科普管线项目:状态、镜头、关联任务与费用" />
<div className="admin-filter-bar">
<Select className="w-44" value={status} onChange={(e) => setStatus(e.target.value)}>
{PROJECT_STATUS_OPTIONS.map((opt) => (
@@ -101,6 +96,7 @@ export function ProjectsPage() {
<TableHead>状态</TableHead>
<TableHead>进度</TableHead>
<TableHead>镜头</TableHead>
+ <TableHead>费用</TableHead>
<TableHead>错误</TableHead>
<TableHead></TableHead>
</TableRow>
@@ -116,6 +112,7 @@ export function ProjectsPage() {
</TableCell>
<TableCell>{p.progress}%</TableCell>
<TableCell>{p.shot_count}</TableCell>
+ <TableCell>¥{fenToYuan(p.charge_fen ?? 0)}</TableCell>
<TableCell className="max-w-[220px] truncate text-xs text-red-600">
{p.error_msg || "—"}
</TableCell>
@@ -139,29 +136,143 @@ export function ProjectsPage() {
)}
<Dialog open={!!detail} onOpenChange={(open) => !open && setDetail(null)}>
- <DialogContent className="max-w-2xl">
+ <DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto">
<DialogHeader>
<DialogTitle>
- 项目 #{detail?.id} · {detail?.title}
+ 科普项目 #{detail?.id} · {detail?.title}
</DialogTitle>
</DialogHeader>
{detail && (
- <div className="space-y-2 text-sm">
- <div>用户:{detail.user_email ?? detail.user_id}</div>
- <div>
- 状态:{projectStatusLabel(detail.status)} · 进度 {detail.progress}% · 镜头 {detail.shot_count}
- </div>
- <div>模板:{detail.template_id}</div>
- <div>管线:{detail.pipeline_mode}</div>
- <div>成片:{detail.final_video_url || "—"}</div>
- <div className="rounded-md bg-muted p-3 text-xs whitespace-pre-wrap">
- {detail.error_msg || "无错误信息"}
- </div>
- {detail.source_text && (
- <div className="max-h-40 overflow-auto rounded-md border p-3 text-xs whitespace-pre-wrap">
- {detail.source_text}
+ <div className="space-y-4 text-sm">
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">基本信息</div>
+ <div>用户:{detail.user_email ?? detail.user_id}</div>
+ <div>
+ 状态:{projectStatusLabel(detail.status)} · 进度 {detail.progress}% · 镜头{" "}
+ {detail.shot_count}
+ </div>
+ <div>模板:{detail.template_id}</div>
+ <div>管线:{detail.pipeline_mode}</div>
+ <div>成片:{detail.final_video_url || "—"}</div>
+ <div className="rounded-md bg-muted p-3 text-xs whitespace-pre-wrap">
+ {detail.error_msg || "无错误信息"}
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">费用汇总</div>
+ <div className="grid grid-cols-2 gap-2 sm:grid-cols-4">
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">扣费</div>
+ <div>¥{fenToYuan(usage?.charge_fen ?? detail.charge_fen ?? 0)}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">成本</div>
+ <div>¥{fenToYuan(usage?.cost_fen ?? 0)}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">调用</div>
+ <div>{usage?.calls ?? 0}</div>
+ </div>
+ <div className="rounded border p-2">
+ <div className="text-[11px] text-muted-foreground">图/视/LLM/TTS</div>
+ <div>
+ {usage?.image_gens ?? 0}/{usage?.video_gens ?? 0}/{usage?.llm_calls ?? 0}/
+ {usage?.tts_gens ?? 0}
+ </div>
+ </div>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="text-xs font-medium text-muted-foreground">
+ 镜头({(detail.shots ?? []).length})
</div>
- )}
+ <div className="max-h-40 overflow-auto rounded border">
+ <table className="w-full text-xs">
+ <thead>
+ <tr className="border-b bg-muted/40 text-left">
+ <th className="p-2">#</th>
+ <th className="p-2">状态</th>
+ <th className="p-2">图</th>
+ <th className="p-2">视频</th>
+ <th className="p-2">音频</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(detail.shots ?? []).length === 0 ? (
+ <tr>
+ <td colSpan={5} className="p-2 text-center text-muted-foreground">
+ 暂无镜头
+ </td>
+ </tr>
+ ) : (
+ (detail.shots ?? []).map((s) => (
+ <tr key={s.id} className="border-b">
+ <td className="p-2">{s.shot_no}</td>
+ <td className="p-2">{s.status}</td>
+ <td className="p-2">{s.has_image ? "有" : "—"}</td>
+ <td className="p-2">{s.has_video ? "有" : "—"}</td>
+ <td className="p-2">{s.has_audio ? "有" : "—"}</td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </section>
+
+ <section className="space-y-1">
+ <div className="flex items-center justify-between">
+ <div className="text-xs font-medium text-muted-foreground">
+ 关联任务(最近 {(detail.recent_tasks ?? []).length})
+ </div>
+ <Link to="/queues" className="text-xs text-primary">
+ 任务中心 →
+ </Link>
+ </div>
+ <div className="max-h-48 overflow-auto rounded border">
+ <table className="w-full text-xs">
+ <thead>
+ <tr className="border-b bg-muted/40 text-left">
+ <th className="p-2">ID</th>
+ <th className="p-2">类型</th>
+ <th className="p-2">状态</th>
+ <th className="p-2">已扣 / 预估</th>
+ </tr>
+ </thead>
+ <tbody>
+ {(detail.recent_tasks ?? []).length === 0 ? (
+ <tr>
+ <td colSpan={4} className="p-2 text-center text-muted-foreground">
+ 暂无任务
+ </td>
+ </tr>
+ ) : (
+ (detail.recent_tasks ?? []).map((t) => (
+ <tr key={t.id} className="border-b">
+ <td className="p-2 font-mono">{t.id}</td>
+ <td className="p-2">{taskTypeLabel(t.task_type)}</td>
+ <td className="p-2">{taskStatusLabel(t.status)}</td>
+ <td className="p-2">
+ ¥{fenToYuan(t.billing_charged_fen)} / ¥{fenToYuan(t.billing_estimate_fen)}
+ </td>
+ </tr>
+ ))
+ )}
+ </tbody>
+ </table>
+ </div>
+ </section>
+
+ {detail.source_text ? (
+ <section>
+ <div className="mb-1 text-xs font-medium text-muted-foreground">源文本</div>
+ <div className="max-h-32 overflow-auto rounded-md border p-3 text-xs whitespace-pre-wrap">
+ {detail.source_text}
+ </div>
+ </section>
+ ) : null}
</div>
)}
</DialogContent>