feat: 统一 Admin 后台设计语言

用中性灰底 + 单一强调色重做后台视觉,并集中到一套令牌:

- 新增 apps/admin/src/lib/theme.ts,通过 ConfigProvider 注入主题令牌
- 新增 apps/admin/src/styles/admin.css 与 AdminSection、MetricCard、StatusTag 组件
- 侧栏改白底浅色并补图标,顶栏改 56px 白底,内容区最大宽 1200px
- 全部页面接入状态标签,antd 原生彩色 Tag 与内联色值清零
- 登录与改密页、加载态骨架屏、错误提示条统一
- brand 页两个 Tab 统一为白卡片容器,消除双标题与宽度不一致

设计规范见 apps/admin/design.md。
This commit is contained in:
que01 committed 2026-10-14 10:54:05 +08:00
1 parent bb94d80e13
commit 2f26828f09
34 files changed
+2159 -922

No files matched your search

+4 -14
View File
@@ -1,4 +1,3 @@
import { Space, Typography } from "antd";
import type { ReactNode } from "react";
export function AdminPageHeader({
@@ -11,21 +10,12 @@ export function AdminPageHeader({
extra?: ReactNode;
}) {
return (
<Space
align="start"
style={{ width: "100%", justifyContent: "space-between", marginBottom: 24 }}
>
<header className="admin-page-header">
<div>
<Typography.Title level={2} style={{ margin: 0 }}>
{title}
</Typography.Title>
{description && (
<Typography.Paragraph type="secondary" style={{ margin: "8px 0 0" }}>
{description}
</Typography.Paragraph>
)}
<h1 className="admin-page-header-title">{title}</h1>
{description ? <p className="admin-page-header-description">{description}</p> : null}
</div>
{extra}
</Space>
</header>
);
}
@@ -0,0 +1,28 @@
import type { ReactNode } from "react";
export function AdminSection({
title,
description,
extra,
children,
}: {
title?: ReactNode;
description?: ReactNode;
extra?: ReactNode;
children: ReactNode;
}) {
return (
<section className="admin-section">
{title ? (
<div className="admin-section-head">
<div>
<h2 className="admin-section-title">{title}</h2>
{description ? <p className="admin-section-description">{description}</p> : null}
</div>
{extra}
</div>
) : null}
{children}
</section>
);
}
+5 -21
View File
@@ -1,5 +1,5 @@
import { CloudUploadOutlined, DeleteOutlined, PictureOutlined } from "@ant-design/icons";
import { Alert, Button, Image, Popconfirm, Space, Spin, Upload, message } from "antd";
import { Alert, Button, Image, Popconfirm, Spin, Upload, message } from "antd";
import { useEffect, useMemo, useState } from "react";
import { createApiClient } from "../lib/api.js";
@@ -71,7 +71,7 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
}
return (
<Space direction="vertical" size={4} style={{ width: "100%" }}>
<div className="admin-field-stack-xs admin-block">
{storageStatus !== "ok" ? (
<Alert
type={storageStatus === "loading" ? "info" : "warning"}
@@ -86,33 +86,17 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
/>
) : null}
{imageUrl ? (
<div
style={{
position: "relative",
width: "100%",
minHeight: 140,
borderRadius: 8,
overflow: "hidden",
border: "1px solid #d9d9d9",
background: "#f5f5f5",
}}
>
<div className="admin-media-preview">
<Image
src={imageUrl}
alt={placeholder ?? "图片预览"}
width="100%"
height={180}
preview
style={{ objectFit: "cover" }}
fallback="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
/>
<Popconfirm title="移除这张图片?" onConfirm={() => onChange?.("")}>
<Button
danger
size="small"
icon={<DeleteOutlined />}
style={{ position: "absolute", top: 8, right: 8 }}
>
<Button danger size="small" icon={<DeleteOutlined />} className="admin-thumb-remove">
移除
</Button>
</Popconfirm>
@@ -150,6 +134,6 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
</Button>
) : null}
<input {...(id ? { id } : {})} type="hidden" value={imageUrl} />
</Space>
</div>
);
}
+25
View File
@@ -0,0 +1,25 @@
import { Card } from "antd";
import type { ReactNode } from "react";
export function MetricCard({
label,
value,
suffix,
extra,
}: {
label: ReactNode;
value: ReactNode;
suffix?: ReactNode;
extra?: ReactNode;
}) {
return (
<Card>
<div className="admin-metric-label">{label}</div>
<div className="admin-metric-value">
{value}
{suffix ? <span className="admin-metric-suffix">{suffix}</span> : null}
</div>
{extra}
</Card>
);
}
+46 -28
View File
@@ -1,6 +1,10 @@
import { Alert, Button, Card, Empty, Result, Spin } from "antd";
import { Button, Card, Empty, Skeleton } from "antd";
import type { ReactNode } from "react";
function errorMessage(error: unknown, fallback: string) {
return error instanceof Error ? error.message : fallback;
}
export function QueryState({
loading,
error,
@@ -12,36 +16,50 @@ export function QueryState({
onRetry?: () => void;
children?: ReactNode;
}) {
if (loading)
return (
<Card>
<Spin />
</Card>
);
if (error) {
return (
<Result
status="error"
title="内容加载失败"
subTitle={error instanceof Error ? error.message : "请检查 API 服务后重试"}
extra={onRetry ? <Button onClick={onRetry}>重新加载</Button> : undefined}
/>
);
}
if (loading) return <LoadingStack />;
if (error) return <ErrorNote error={error} onRetry={onRetry} />;
return <>{children}</>;
}
export function LoadingStack({ rows = 3 }: { rows?: number }) {
return (
<div className="admin-loading-stack">
<Card>
<Skeleton active paragraph={{ rows: 2 }} title={false} />
</Card>
{Array.from({ length: rows }).map((_, index) => (
<Card key={index}>
<Skeleton active paragraph={{ rows: 1 }} title={false} />
</Card>
))}
</div>
);
}
export function ErrorNote({
error,
onRetry,
}: {
error?: unknown;
onRetry?: (() => void) | undefined;
}) {
if (!error) return null;
return (
<div className="admin-error-note" role="alert">
<span>{errorMessage(error, "操作失败,请重试")}</span>
{onRetry ? (
<Button type="link" size="small" onClick={onRetry}>
重试
</Button>
) : null}
</div>
);
}
export function MutationError({ error }: { error?: unknown }) {
return <ErrorNote error={error} />;
}
export function EmptyState({ description }: { description: string }) {
return <Empty description={description} image={Empty.PRESENTED_IMAGE_SIMPLE} />;
}
export function MutationError({ error }: { error?: unknown }) {
if (!error) return null;
return (
<Alert
type="error"
showIcon
message={error instanceof Error ? error.message : "操作失败,请重试"}
/>
);
}
@@ -71,7 +71,7 @@ export function RecordContentEditor({
initialValues={initialValues}
onValuesChange={handleValuesChange}
onFinish={submit}
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
className="admin-form-column"
>
<Alert
type="info"
@@ -89,10 +89,10 @@ export function RecordContentEditor({
/>
{save.isPending ? <Typography.Text type="secondary">正在保存内容…</Typography.Text> : null}
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
<div style={{ flex: 1 }}>
<div className="admin-flex-1">
<RecordContentFields section={section} />
</div>
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
<div className="admin-actions admin-offset-top-lg">
<MutationError error={save.error} />
<Space wrap>
<Button type="primary" htmlType="submit" loading={save.isPending}>
@@ -114,7 +114,7 @@ export function RecordContentEditor({
</Button>
) : null}
</Space>
</Space>
</div>
</Form>
);
}
+67
View File
@@ -0,0 +1,67 @@
export type StatusTone = "success" | "warning" | "error" | "info" | "neutral";
const TONE_BY_STATUS: Record<string, StatusTone> = {
published: "success",
approved: "success",
completed: "success",
active: "success",
enabled: "success",
building: "info",
built: "neutral",
uploaded: "info",
pending: "neutral",
draft: "neutral",
superseded: "neutral",
disabled: "neutral",
review: "warning",
reviewing: "warning",
under_review: "warning",
processing: "warning",
rejected: "error",
failed: "error",
error: "error",
};
const LABELS: Record<string, string> = {
published: "已发布",
approved: "已通过",
completed: "已完成",
active: "已启用",
enabled: "已公开",
building: "构建中",
built: "待上传",
uploaded: "已上传微信",
pending: "待处理",
draft: "草稿",
superseded: "已过期",
disabled: "已停用",
review: "审核中",
reviewing: "审核中",
under_review: "审核中",
processing: "处理中",
rejected: "已拒绝",
failed: "失败",
error: "异常",
};
export function statusLabel(status: string | null | undefined, fallback = "未知"): string {
if (!status) return fallback;
return LABELS[status] ?? status;
}
export function StatusTag({
status,
label,
tone,
}: {
status?: string | null;
label?: string;
tone?: StatusTone;
}) {
const resolvedTone = tone ?? (status ? TONE_BY_STATUS[status] : undefined) ?? "neutral";
return (
<span className="admin-status-tag" data-tone={resolvedTone}>
{label ?? statusLabel(status)}
</span>
);
}
@@ -51,7 +51,7 @@ export function TemplateFieldRenderer({
value={typeof value === "number" ? value : null}
onChange={(input) => onChange?.(input ?? undefined)}
min={0}
style={{ width: "100%" }}
className="admin-block"
placeholder={field.placeholder}
/>
);
@@ -28,7 +28,7 @@ export function TemplateListField({
]}
>
{(rows, { add, remove, move }, { errors }) => (
<Space direction="vertical" size={12} style={{ width: "100%" }}>
<div className="admin-stack admin-stack-tight">
{rows.length === 0 ? (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
@@ -135,7 +135,7 @@ export function TemplateListField({
<Button block icon={<PlusOutlined />} onClick={() => add()}>
新增{field.label}
</Button>
</Space>
</div>
)}
</Form.List>
</Form.Item>