Files
persionalBrand/apps/admin/src/features/brand/BrandPage.tsx
T
que01 2f26828f09 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。
2026-10-14 10:54:05 +08:00

247 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Alert, Button, Col, Form, Input, Row, Select, Segmented, message } from "antd";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { Link, useLocation } from "react-router-dom";
import type { BrandProfile } from "@personal-brand/api-client";
import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { ImageUrlField } from "../../components/ImageUrlField.js";
import { MutationError, QueryState } from "../../components/QueryState.js";
import { StatusTag } from "../../components/StatusTag.js";
import { PresentationEditor } from "./PresentationEditor.js";
import type { PreviewSelection } from "./preview-selection.js";
import "./BrandPage.css";
import { useEditorDraft } from "./use-editor-draft.js";
export function BrandPage() {
const location = useLocation();
const initialSelection = location.state as PreviewSelection | undefined;
const [panel, setPanel] = useState("pages");
const [dirty, setDirty] = useState(false);
useEditorDraft(dirty);
const client = createApiClient();
const queryClient = useQueryClient();
const [form] = Form.useForm<BrandProfile>();
const brand = useQuery({ queryKey: ["admin-brand"], queryFn: () => client.getAdminBrand() });
const workspace = useQuery({
queryKey: ["admin-workspace"],
queryFn: () => client.getAdminWorkspace(),
});
const previewWorkspace = useQuery({
queryKey: ["admin-preview-workspace"],
queryFn: () => client.getAdminPreviewWorkspace(),
});
const template = useQuery({
queryKey: ["template", brand.data?.templateKey],
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
enabled: Boolean(brand.data?.templateKey),
});
const templateCatalog = useQuery({
queryKey: ["template-catalog"],
queryFn: () => client.listPublicTemplates(),
});
const save = useMutation({
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
onSuccess: () => {
setDirty(false);
message.success("品牌表达已保存");
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
},
});
return (
<QueryState loading={brand.isLoading} error={brand.error} onRetry={() => void brand.refetch()}>
{!brand.data ? null : (
<>
<AdminPageHeader
title="小程序工作台"
description={
template.data?.description
? `先让访客理解你是谁、服务谁,以及为什么值得信任。${template.data.description}`
: "先让访客理解你是谁、服务谁,以及为什么值得信任。"
}
extra={<StatusTag tone="info" label={template.data?.name ?? "当前模板"} />}
/>
<div className="brand-page__toolbar">
<Segmented
aria-label="工作台视图"
value={panel}
onChange={(value) => setPanel(String(value))}
options={[
{ value: "pages", label: "页面编辑" },
{ value: "brand", label: "品牌资料" },
]}
/>
<div className="brand-page__toolbar-actions">
<StatusTag
tone={dirty ? "warning" : "neutral"}
label={dirty ? "品牌资料有未保存修改" : "草稿工作区"}
/>
<Link to="/admin/publication">检查与发布 →</Link>
</div>
</div>
<div className="brand-page__content" hidden={panel !== "brand"}>
<div className="brand-page__settings">
<Form
form={form}
layout="vertical"
initialValues={brand.data}
onValuesChange={() => setDirty(true)}
onFinish={(values) => save.mutate(values)}
>
<section className="brand-settings-section" aria-labelledby="brand-identity-title">
<div className="admin-section-head">
<div>
<h2 id="brand-identity-title" className="admin-section-title">
我是谁
</h2>
<p className="admin-section-description">公开展示的品牌身份和定位。</p>
</div>
<StatusTag tone="neutral" label="品牌基础信息" />
</div>
<Form.Item
name="name"
label="品牌名称"
help="可以是个人姓名、工作室名称或品牌名。"
rules={[{ required: true, message: "请输入品牌名称" }]}
>
<Input size="large" placeholder="例如:品牌主理人|品牌顾问" />
</Form.Item>
<Form.Item
name="tagline"
label="一句话定位"
help="用一句话说明你为谁提供什么价值。"
rules={[{ required: true, message: "请输入一句话定位" }]}
>
<Input size="large" placeholder="例如:帮助独立创作者建立可信的个人品牌" />
</Form.Item>
<Form.Item name="description" label="品牌简介" help="介绍背景、方法和合作风格。">
<Input.TextArea
rows={5}
showCount
maxLength={500}
placeholder="让第一次认识你的人快速建立基本信任。"
/>
</Form.Item>
</section>
<section className="brand-settings-section" aria-labelledby="brand-contact-title">
<div className="admin-section-head">
<div>
<h2 id="brand-contact-title" className="admin-section-title">
如何联系与合作
</h2>
<p className="admin-section-description">
让访客知道联系渠道、服务范围和响应预期。
</p>
</div>
</div>
<Row gutter={16}>
<Col xs={24} md={12}>
<Form.Item name="hours" label="可联系时间">
<Input placeholder="例如:工作日 10:00–18:00" />
</Form.Item>
</Col>
<Col xs={24} md={12}>
<Form.Item name="address" label="所在位置">
<Input placeholder="城市或服务范围" />
</Form.Item>
</Col>
<Col xs={24} md={12}>
<Form.Item name="contactPhone" label="联系电话">
<Input />
</Form.Item>
</Col>
<Col xs={24} md={12}>
<Form.Item name="contactWechat" label="微信号">
<Input />
</Form.Item>
</Col>
</Row>
<Form.Item
name="deliveryNote"
label="合作预期"
help="说明响应时间、合作方式或重要边界。"
>
<Input.TextArea rows={3} placeholder="例如:收到咨询后 1 个工作日内回复。" />
</Form.Item>
</section>
<section className="brand-settings-section" aria-labelledby="brand-visual-title">
<div className="admin-section-head">
<div>
<h2 id="brand-visual-title" className="admin-section-title">
模板与品牌视觉
</h2>
<p className="admin-section-description">
模板负责业务表达,品牌信息仍由你统一维护。
</p>
</div>
</div>
<Form.Item
name="templateKey"
label="业务表达模板"
help="模板只改变业务表达,不改变个人品牌主线。"
>
<Select
disabled
options={(templateCatalog.data?.industries ?? []).map((item) => ({
value: item.key,
label: item.name,
}))}
/>
</Form.Item>
<Row gutter={16}>
<Col xs={24} md={12}>
<Form.Item
name="avatarUrl"
label="头像图片地址"
help="点击上传或粘贴一张可公开访问的图片地址。"
>
<ImageUrlField scope="brand" />
</Form.Item>
</Col>
<Col xs={24} md={12}>
<Form.Item
name="coverUrl"
label="品牌封面图片地址"
help="点击上传,或粘贴一张横向图片地址。"
>
<ImageUrlField scope="brand" />
</Form.Item>
</Col>
</Row>
</section>
<div className="admin-actions admin-offset-top-lg">
<MutationError error={save.error} />
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
保存品牌表达
</Button>
</div>
</Form>
</div>
{template.data ? (
<Alert
className="brand-page__template-note"
type="info"
showIcon
message={`当前使用:${template.data.name}`}
description={`适用场景:${template.data.serviceCategories.join("、") || "通用品牌展示"}`}
/>
) : null}
</div>
<div hidden={panel !== "pages"}>
<PresentationEditor
templateContent={workspace.data?.templateContent}
previewWorkspace={previewWorkspace.data}
config={brand.data.config}
brand={brand.data}
loading={workspace.isLoading}
error={workspace.error}
{...(initialSelection ? { initialSelection } : {})}
/>
</div>
</>
)}
</QueryState>
);
}