refactor: 拆分品牌业务类型与页面方案
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
This commit is contained in:
1 parent
f02e2cafbb
commit
0d9f4a7d6f
86 files changed
+4111
-1543
No files matched your search
@@ -0,0 +1,129 @@
|
||||
import { Alert, Button, Card, Col, Row, Space } from "antd";
|
||||
import { PlusOutlined } from "@ant-design/icons";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { adminMessage as message } from "../../components/AdminMessage.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
export function BrandsPage({ canCreate }: { canCreate: boolean }) {
|
||||
const navigate = useNavigate();
|
||||
const brands = useQuery({
|
||||
queryKey: ["admin-brand-memberships"],
|
||||
queryFn: () => client.listAdminBrands(),
|
||||
});
|
||||
const current = useQuery({
|
||||
queryKey: ["admin-shell-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
});
|
||||
const switchBrand = async (brandId: string) => {
|
||||
try {
|
||||
await client.switchAdminBrand(brandId);
|
||||
window.location.assign("/admin/overview");
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "品牌切换失败,请重试");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={brands.isLoading || current.isLoading}
|
||||
error={brands.error || current.error}
|
||||
onRetry={() => {
|
||||
void brands.refetch();
|
||||
void current.refetch();
|
||||
}}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="品牌管理"
|
||||
description="每个品牌拥有独立的业务类型、页面方案、内容与发布记录。"
|
||||
extra={
|
||||
canCreate ? (
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => navigate("/admin/brands/new")}
|
||||
>
|
||||
创建品牌
|
||||
</Button>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
<Alert
|
||||
className="admin-offset-bottom"
|
||||
type="info"
|
||||
showIcon
|
||||
message="切换品牌会进入对应品牌的工作区"
|
||||
description="品牌之间的业务内容、成员、发布记录和页面方案相互隔离。"
|
||||
/>
|
||||
{brands.data?.length ? (
|
||||
<Row gutter={[16, 16]} className="admin-equal-height">
|
||||
{brands.data.map((membership) => {
|
||||
const isCurrent = membership.brand.id === current.data?.id;
|
||||
return (
|
||||
<Col key={membership.brand.id} xs={24} lg={12}>
|
||||
<Card
|
||||
title={membership.brand.name}
|
||||
extra={
|
||||
<StatusTag
|
||||
tone={isCurrent ? "success" : "neutral"}
|
||||
label={
|
||||
isCurrent ? "当前品牌" : membership.role === "owner" ? "负责人" : "编辑"
|
||||
}
|
||||
/>
|
||||
}
|
||||
actions={[
|
||||
<Button
|
||||
key="switch"
|
||||
type={isCurrent ? "default" : "primary"}
|
||||
disabled={isCurrent}
|
||||
onClick={() => void switchBrand(membership.brand.id)}
|
||||
>
|
||||
{isCurrent ? "正在使用" : "进入此品牌"}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<Space direction="vertical" size={8}>
|
||||
<span className="admin-section-description">
|
||||
小程序地址标识:{membership.brand.slug}
|
||||
</span>
|
||||
{membership.role === "owner" ? (
|
||||
<span className="admin-section-description">
|
||||
你可以在该品牌中管理页面方案、成员和发布。
|
||||
</span>
|
||||
) : (
|
||||
<span className="admin-section-description">
|
||||
你在该品牌中的角色是内容编辑,不能管理页面方案或成员。
|
||||
</span>
|
||||
)}
|
||||
</Space>
|
||||
</Card>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
) : (
|
||||
<Card>
|
||||
<EmptyState
|
||||
title="还没有可管理的品牌"
|
||||
description={
|
||||
canCreate ? "创建第一个品牌后即可开始配置内容。" : "请联系品牌负责人邀请你加入。"
|
||||
}
|
||||
action={
|
||||
canCreate ? (
|
||||
<Button type="primary" onClick={() => navigate("/admin/brands/new")}>
|
||||
创建品牌
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { Alert, Button, Col, Form, Input, Radio, Row, Space } from "antd";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
BrandCreationOptionBusiness,
|
||||
BrandCreationOptionPageScheme,
|
||||
CreateBrandInput,
|
||||
} from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
function compatibleSchemes(
|
||||
schemes: BrandCreationOptionPageScheme[],
|
||||
businessType?: CreateBrandInput["businessType"],
|
||||
) {
|
||||
return businessType
|
||||
? schemes.filter((scheme) => scheme.supportedBusinessTypes.includes(businessType))
|
||||
: [];
|
||||
}
|
||||
|
||||
export function CreateBrandPage() {
|
||||
const navigate = useNavigate();
|
||||
const [form] = Form.useForm<CreateBrandInput>();
|
||||
const businessType = Form.useWatch("businessType", form);
|
||||
const options = useQuery({
|
||||
queryKey: ["admin-brand-creation-options"],
|
||||
queryFn: () => client.getAdminBrandCreationOptions(),
|
||||
});
|
||||
const create = useMutation({
|
||||
mutationFn: (values: CreateBrandInput) => client.createAdminBrand(values),
|
||||
onSuccess: () => {
|
||||
// 创建接口会切换品牌会话;完整导航确保所有查询重新绑定到新品牌。
|
||||
window.location.assign("/admin/overview");
|
||||
},
|
||||
});
|
||||
const schemes = compatibleSchemes(options.data?.pageSchemes ?? [], businessType);
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={options.isLoading}
|
||||
error={options.error}
|
||||
onRetry={() => void options.refetch()}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="创建品牌"
|
||||
description="先确定业务类型,再选择与该业务兼容的页面方案。业务类型创建后不可更改。"
|
||||
/>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={(values) => create.mutate(values)}
|
||||
onValuesChange={(changed: Partial<CreateBrandInput>) => {
|
||||
if (!changed.businessType) return;
|
||||
const nextSchemes = compatibleSchemes(
|
||||
options.data?.pageSchemes ?? [],
|
||||
changed.businessType,
|
||||
);
|
||||
const selected = form.getFieldValue("templatePackageVersionId") as unknown;
|
||||
if (!nextSchemes.some((scheme) => scheme.templatePackageVersionId === selected)) {
|
||||
form.setFieldValue("templatePackageVersionId", undefined);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="admin-stack">
|
||||
<AdminSection title="品牌身份" description="这些信息会展示给访客,之后仍可继续完善。">
|
||||
<Row gutter={16}>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Item
|
||||
name="name"
|
||||
label="品牌名称"
|
||||
rules={[{ required: true, message: "请输入品牌名称" }]}
|
||||
>
|
||||
<Input size="large" maxLength={80} placeholder="例如:林境建筑" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Item
|
||||
name="slug"
|
||||
label="小程序地址标识"
|
||||
help="用于生成和识别公开品牌地址,只能使用小写字母、数字和连字符。"
|
||||
rules={[
|
||||
{ required: true, message: "请输入小程序地址标识" },
|
||||
{
|
||||
pattern: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
|
||||
message: "只能使用小写字母、数字和连字符",
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input size="large" maxLength={80} placeholder="例如:linjing-architecture" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="业务类型"
|
||||
description="业务类型决定品牌需要填写哪些内容。不同业务类型的字段和能力不同,创建后不能修改。"
|
||||
>
|
||||
<Form.Item name="businessType" rules={[{ required: true, message: "请选择业务类型" }]}>
|
||||
<Radio.Group className="admin-stack">
|
||||
<Row gutter={[12, 12]}>
|
||||
{(options.data?.businesses ?? []).map((business: BrandCreationOptionBusiness) => (
|
||||
<Col key={business.key} xs={24} lg={8}>
|
||||
<Radio.Button value={business.key} className="admin-choice-card">
|
||||
<strong>{business.name}</strong>
|
||||
<span>{business.description}</span>
|
||||
</Radio.Button>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
{businessType ? (
|
||||
schemes.length ? null : (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="当前业务类型还没有可用的页面方案"
|
||||
description="请先联系平台管理员发布兼容的页面方案。"
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
<Alert type="info" showIcon message="选择业务类型后,将只显示兼容的页面方案" />
|
||||
)}
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="页面方案"
|
||||
description="页面方案决定页面结构、视觉和资源位。版本可在创建后继续升级或切换。"
|
||||
>
|
||||
{schemes.length ? (
|
||||
<Form.Item
|
||||
name="templatePackageVersionId"
|
||||
rules={[{ required: true, message: "请选择页面方案" }]}
|
||||
>
|
||||
<Radio.Group className="admin-stack">
|
||||
<Space direction="vertical" size={12} className="admin-full-width">
|
||||
{schemes.map((scheme) => (
|
||||
<Radio.Button
|
||||
key={scheme.templatePackageVersionId}
|
||||
value={scheme.templatePackageVersionId}
|
||||
className="admin-choice-card admin-choice-card--wide"
|
||||
>
|
||||
<span className="admin-row-line">
|
||||
<strong>{scheme.name}</strong>
|
||||
<StatusTag
|
||||
tone={scheme.isLatestForPackage ? "success" : "neutral"}
|
||||
label={
|
||||
scheme.isLatestForPackage
|
||||
? `最新版 ${scheme.version}`
|
||||
: `版本 ${scheme.version}`
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
<span>{scheme.description}</span>
|
||||
</Radio.Button>
|
||||
))}
|
||||
</Space>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
) : (
|
||||
<EmptyState
|
||||
title={businessType ? "没有兼容的页面方案" : "先选择业务类型"}
|
||||
description={
|
||||
businessType
|
||||
? "平台尚未发布适配该业务类型的页面方案。"
|
||||
: "选择业务类型后,这里会列出可用的页面结构和视觉方案。"
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</AdminSection>
|
||||
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="创建品牌不会自动导入示例内容"
|
||||
description="新品牌会从空白内容开始,避免把示例品牌、案例或联系方式误当成真实信息发布。"
|
||||
/>
|
||||
<MutationError error={create.error} />
|
||||
<Space>
|
||||
<Button onClick={() => navigate("/admin/brands")}>取消</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
size="large"
|
||||
loading={create.isPending}
|
||||
disabled={!businessType || schemes.length === 0}
|
||||
>
|
||||
创建并进入品牌
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
</Form>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user