feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -0,0 +1,382 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Divider,
|
||||
Empty,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
const destinations: Record<string, string> = {
|
||||
brand: "/admin/brand",
|
||||
positioning: "/admin/brand",
|
||||
template: "/admin/publication",
|
||||
visual: "/admin/publication",
|
||||
offerings: "/admin/services",
|
||||
forms: "/admin/workspace",
|
||||
trust: "/admin/trust",
|
||||
};
|
||||
|
||||
export function PublicationPage({ canManageTemplate }: { canManageTemplate: boolean }) {
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
const [industryTarget, setIndustryTarget] = useState<BrandTemplateKey | null>(null);
|
||||
const [confirmAction, setConfirmAction] = useState<"publish" | "revoke" | null>(null);
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [note, setNote] = useState("");
|
||||
const brand = useQuery({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
});
|
||||
const workspace = useQuery({
|
||||
queryKey: ["publication-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const catalog = useQuery({
|
||||
queryKey: ["publication-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const sample = useQuery({
|
||||
queryKey: ["publication-sample"],
|
||||
queryFn: () => client.previewAdminSampleContent(),
|
||||
enabled: Boolean(workspace.data),
|
||||
});
|
||||
const readiness = useQuery({
|
||||
queryKey: ["publication-readiness"],
|
||||
queryFn: () => client.getAdminReleaseReadiness(),
|
||||
});
|
||||
const releases = useQuery({
|
||||
queryKey: ["publication-releases"],
|
||||
queryFn: () => client.listAdminReleases(),
|
||||
});
|
||||
const refresh = () => {
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
"publication-workspace",
|
||||
"publication-sample",
|
||||
"publication-readiness",
|
||||
"publication-releases",
|
||||
"admin-shell-brand",
|
||||
"admin-workspace",
|
||||
"public-runtime-workspace",
|
||||
]) {
|
||||
void queryClient.invalidateQueries({ queryKey: [key] });
|
||||
}
|
||||
};
|
||||
const install = useMutation({
|
||||
mutationFn: (key: BrandTemplateKey) => client.installAdminTemplate(key),
|
||||
onSuccess: () => {
|
||||
setIndustryTarget(null);
|
||||
message.success("行业模板已安装");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const selectVisual = useMutation({
|
||||
mutationFn: (key: string) =>
|
||||
client.updateAdminBrand({
|
||||
config: { ...(brand.data?.config ?? {}), visualTemplateKey: key },
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("视觉模板已保存到草稿");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const importSample = useMutation({
|
||||
mutationFn: () => client.importAdminSampleContent(),
|
||||
onSuccess: () => {
|
||||
message.success("示例内容已导入草稿");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const publish = useMutation({
|
||||
mutationFn: () => client.publishAdminRelease(note.trim() || undefined),
|
||||
onSuccess: () => {
|
||||
setConfirmAction(null);
|
||||
setNote("");
|
||||
message.success("品牌已发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const revoke = useMutation({
|
||||
mutationFn: () => client.revokeAdminRelease(),
|
||||
onSuccess: () => {
|
||||
setConfirmAction(null);
|
||||
message.success("品牌已撤回,小程序将显示未发布状态");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: (version: number) => client.rollbackAdminRelease(version),
|
||||
onSuccess: () => {
|
||||
setRollbackVersion(null);
|
||||
message.success("历史版本已重新发布");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const loading = [brand, workspace, catalog, readiness, releases].some((query) => query.isLoading);
|
||||
const error = [brand, workspace, catalog, readiness, releases].find(
|
||||
(query) => query.isError,
|
||||
)?.error;
|
||||
const retry = () => {
|
||||
void brand.refetch();
|
||||
void workspace.refetch();
|
||||
void catalog.refetch();
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
};
|
||||
const industryKey =
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
workspace.data?.brand?.templateKey ??
|
||||
brand.data?.templateKey ??
|
||||
"personal";
|
||||
const visuals = (catalog.data?.visuals ?? []).filter((item) =>
|
||||
item.supportedIndustryTemplates.includes(industryKey),
|
||||
);
|
||||
const visualKey =
|
||||
typeof brand.data?.config?.visualTemplateKey === "string"
|
||||
? brand.data.config.visualTemplateKey
|
||||
: "linjing-editorial";
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
);
|
||||
const draftOfferings = workspace.data?.offerings.filter((item) => item.isEnabled) ?? [];
|
||||
const draftForms = (workspace.data?.forms ?? []) as Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
isEnabled: boolean;
|
||||
}>;
|
||||
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
<AdminPageHeader
|
||||
title="配置与发布"
|
||||
description="编辑内容不会立即影响小程序;确认后统一发布当前品牌。"
|
||||
/>
|
||||
<Space direction="vertical" size={24} style={{ width: "100%" }}>
|
||||
<section>
|
||||
<Typography.Title level={4}>1. 选择表达方式</Typography.Title>
|
||||
<Space wrap>
|
||||
<Select
|
||||
aria-label="行业模板"
|
||||
style={{ width: 220 }}
|
||||
value={industryKey}
|
||||
disabled={!canManageTemplate || Boolean(workspace.data?.installations.length)}
|
||||
options={(catalog.data?.industries ?? []).map((item) => ({
|
||||
value: item.key,
|
||||
label: item.name,
|
||||
}))}
|
||||
onChange={(key: BrandTemplateKey) => setIndustryTarget(key)}
|
||||
/>
|
||||
<Select
|
||||
aria-label="视觉模板"
|
||||
style={{ width: 220 }}
|
||||
value={visualKey}
|
||||
disabled={!canManageTemplate}
|
||||
loading={selectVisual.isPending}
|
||||
options={visuals.map((item) => ({ value: item.key, label: item.name }))}
|
||||
onChange={(key) => selectVisual.mutate(key)}
|
||||
/>
|
||||
{canManageTemplate && (
|
||||
<Button onClick={() => navigate("/admin/workspace")}>高级模板设置</Button>
|
||||
)}
|
||||
</Space>
|
||||
{workspace.data?.installations.length ? (
|
||||
<Typography.Paragraph type="secondary" style={{ marginTop: 8 }}>
|
||||
当前品牌已安装主模板。模板版本与升级在高级设置中管理。
|
||||
</Typography.Paragraph>
|
||||
) : null}
|
||||
<MutationError error={install.error || selectVisual.error} />
|
||||
<Divider />
|
||||
<Space wrap>
|
||||
<Typography.Text>示例内容</Typography.Text>
|
||||
{sample.isLoading && <Spin size="small" />}
|
||||
{sample.data && (
|
||||
<Tag color={sample.data.alreadyImported ? "green" : "blue"}>
|
||||
{sample.data.alreadyImported ? "已导入" : "可导入"}
|
||||
</Tag>
|
||||
)}
|
||||
<Button
|
||||
disabled={!canManageTemplate || !sample.data || sample.data.alreadyImported}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate()}
|
||||
>
|
||||
导入示例内容
|
||||
</Button>
|
||||
{sample.isError && <Button onClick={() => void sample.refetch()}>重试</Button>}
|
||||
</Space>
|
||||
{sample.isError && (
|
||||
<Alert
|
||||
type="error"
|
||||
message={sample.error instanceof Error ? sample.error.message : "示例内容加载失败"}
|
||||
showIcon
|
||||
style={{ marginTop: 8 }}
|
||||
/>
|
||||
)}
|
||||
{sample.data && !sample.data.alreadyImported && (
|
||||
<Typography.Paragraph type="secondary" style={{ marginTop: 8 }}>
|
||||
将向草稿添加{" "}
|
||||
{Object.entries(sample.data.counts)
|
||||
.map(([key, count]) => `${key} ${count} 项`)
|
||||
.join("、")}
|
||||
;发布前请替换示例文案和图片。
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
<MutationError error={importSample.error} />
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Typography.Title level={4}>2. 核对草稿内容</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
此处核对的是待发布内容,不是小程序视觉预览。
|
||||
</Typography.Paragraph>
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<Typography.Text strong>{brand.data?.name || "未命名品牌"}</Typography.Text>
|
||||
<Typography.Text>{brand.data?.tagline || "尚未填写品牌定位"}</Typography.Text>
|
||||
<Typography.Text>
|
||||
已启用业务项:{draftOfferings.map((item) => item.name).join("、") || "无"}
|
||||
</Typography.Text>
|
||||
<Typography.Text>
|
||||
已启用咨询表单:
|
||||
{draftForms
|
||||
.filter((item) => item.isEnabled)
|
||||
.map((item) => item.name)
|
||||
.join("、") || "无"}
|
||||
</Typography.Text>
|
||||
<Space wrap>
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑品牌</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务项</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任内容</Button>
|
||||
</Space>
|
||||
</Space>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Typography.Title level={4}>3. 检查并发布</Typography.Title>
|
||||
<Space wrap style={{ marginBottom: 12 }}>
|
||||
<Tag color={currentRelease ? "green" : "default"}>
|
||||
{currentRelease ? `已发布 v${currentRelease.version}` : "尚未发布"}
|
||||
</Tag>
|
||||
<Button onClick={() => void readiness.refetch()}>重新检查</Button>
|
||||
</Space>
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<Space key={check.key}>
|
||||
<Tag color={check.passed ? "success" : "warning"}>
|
||||
{check.passed ? "已完成" : "待完善"}
|
||||
</Tag>
|
||||
<Typography.Text>{check.label}</Typography.Text>
|
||||
{!check.passed && (
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => navigate(destinations[check.key] ?? "/admin/overview")}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
))}
|
||||
</Space>
|
||||
<Space wrap style={{ marginTop: 16 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!readiness.data?.ready}
|
||||
onClick={() => setConfirmAction("publish")}
|
||||
>
|
||||
发布当前草稿
|
||||
</Button>
|
||||
{currentRelease && (
|
||||
<Button danger onClick={() => setConfirmAction("revoke")}>
|
||||
撤回当前版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
<MutationError error={publish.error || revoke.error} />
|
||||
<Divider />
|
||||
<Typography.Title level={5}>发布记录</Typography.Title>
|
||||
{releases.data?.length ? (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
{releases.data.map((item) => (
|
||||
<Space key={item.id} wrap>
|
||||
<Typography.Text>v{item.version}</Typography.Text>
|
||||
<Tag color={item.status === "published" ? "green" : "default"}>{item.status}</Tag>
|
||||
<Typography.Text type="secondary">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</Typography.Text>
|
||||
{item.note && <Typography.Text>{item.note}</Typography.Text>}
|
||||
{item.status === "superseded" && publishedHistory.length > 1 && (
|
||||
<Button size="small" onClick={() => setRollbackVersion(item.version)}>
|
||||
恢复此版本
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
))}
|
||||
</Space>
|
||||
) : (
|
||||
<Empty description="暂无发布记录" />
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</section>
|
||||
</Space>
|
||||
<Modal
|
||||
title={confirmAction === "revoke" ? "确认撤回品牌" : "确认发布品牌"}
|
||||
open={confirmAction !== null}
|
||||
onCancel={() => setConfirmAction(null)}
|
||||
onOk={() => (confirmAction === "revoke" ? revoke.mutate() : publish.mutate())}
|
||||
confirmLoading={publish.isPending || revoke.isPending}
|
||||
okText={confirmAction === "revoke" ? "确认撤回" : "确认发布"}
|
||||
okButtonProps={{ danger: confirmAction === "revoke" }}
|
||||
>
|
||||
{confirmAction === "revoke" ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
message="撤回后,小程序将显示品牌尚未发布,新的咨询和预约会停止受理。"
|
||||
/>
|
||||
) : (
|
||||
<Space direction="vertical" style={{ width: "100%" }}>
|
||||
<Typography.Text>当前草稿将成为品牌新的公开版本。</Typography.Text>
|
||||
<Input
|
||||
value={note}
|
||||
onChange={(event) => setNote(event.target.value)}
|
||||
placeholder="发布备注(可选)"
|
||||
maxLength={200}
|
||||
/>
|
||||
</Space>
|
||||
)}
|
||||
</Modal>
|
||||
<Modal
|
||||
title="确认恢复历史版本"
|
||||
open={rollbackVersion !== null}
|
||||
onCancel={() => setRollbackVersion(null)}
|
||||
onOk={() => rollbackVersion !== null && rollback.mutate(rollbackVersion)}
|
||||
confirmLoading={rollback.isPending}
|
||||
>
|
||||
将 v{rollbackVersion} 重新发布为新版本;当前草稿不会被覆盖。
|
||||
</Modal>
|
||||
<Modal
|
||||
title="确认安装行业模板"
|
||||
open={industryTarget !== null}
|
||||
onCancel={() => setIndustryTarget(null)}
|
||||
onOk={() => industryTarget && install.mutate(industryTarget)}
|
||||
confirmLoading={install.isPending}
|
||||
>
|
||||
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
||||
</Modal>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user