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
@@ -1,4 +1,4 @@
|
||||
import { Alert, Button, Col, Form, Input, Row, Select, Segmented, message } from "antd";
|
||||
import { Alert, Button, Col, Form, Input, Row, Segmented, message } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
@@ -36,10 +36,6 @@ export function BrandPage() {
|
||||
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: () => {
|
||||
@@ -60,7 +56,12 @@ export function BrandPage() {
|
||||
? `先让访客理解你是谁、服务谁,以及为什么值得信任。${template.data.description}`
|
||||
: "先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||
}
|
||||
extra={<StatusTag tone="info" label={template.data?.name ?? "当前模板"} />}
|
||||
extra={
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={workspace.data?.templateContent?.displayName ?? "当前页面方案"}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<div className="brand-page__toolbar">
|
||||
<Segmented
|
||||
@@ -169,25 +170,20 @@ export function BrandPage() {
|
||||
<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 label="当前页面方案">
|
||||
<div>
|
||||
<strong>{workspace.data?.templateContent?.displayName ?? "尚未安装"}</strong>
|
||||
<p className="admin-section-description">
|
||||
页面方案的版本、升级和资源位由品牌负责人统一维护。
|
||||
</p>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
<Col xs={24} md={12}>
|
||||
@@ -223,7 +219,7 @@ export function BrandPage() {
|
||||
className="brand-page__template-note"
|
||||
type="info"
|
||||
showIcon
|
||||
message={`当前使用:${template.data.name}`}
|
||||
message={`当前页面方案:${workspace.data?.templateContent?.displayName ?? template.data.name}`}
|
||||
description={`适用场景:${template.data.serviceCategories.join("、") || "通用品牌展示"}`}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
@@ -311,12 +311,12 @@ export function PresentationEditor({
|
||||
</div>
|
||||
{templateContent ? <StatusTag tone="info" label={templateContent.displayName} /> : null}
|
||||
</div>
|
||||
{loading ? <Alert type="info" showIcon message="正在读取当前模板的编辑项目" /> : null}
|
||||
{loading ? <Alert type="info" showIcon message="正在读取当前页面方案的编辑项目" /> : null}
|
||||
{error ? (
|
||||
<Alert type="warning" showIcon message="模板编辑项目读取失败,请刷新后重试。" />
|
||||
<Alert type="warning" showIcon message="页面方案编辑项目读取失败,请刷新后重试。" />
|
||||
) : null}
|
||||
{!loading && !error && !templateContent ? (
|
||||
<Alert type="warning" showIcon message="当前模板暂未提供可编辑的页面内容。" />
|
||||
<Alert type="warning" showIcon message="当前页面方案暂未提供可编辑的页面内容。" />
|
||||
) : null}
|
||||
{templateContent ? (
|
||||
<>
|
||||
|
||||
@@ -46,8 +46,8 @@ export function useBrandPresentationSections(
|
||||
return [
|
||||
...[...new Set(declaredTemplateFields.map((field) => field.page ?? "home"))].map((page) => ({
|
||||
key: `template-data:${page}`,
|
||||
title: "模板专属内容",
|
||||
description: "这些字段由当前小程序模板定义,保存后发布才会对外展示。",
|
||||
title: "页面方案专属内容",
|
||||
description: "这些字段由当前页面方案定义,保存后发布才会对外展示。",
|
||||
page,
|
||||
target: "brand" as const,
|
||||
fields: declaredTemplateFields.filter((field) => (field.page ?? "home") === page),
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export function CapabilitiesPage() {
|
||||
<QueryState loading={query.isLoading} error={query.error} onRetry={() => void query.refetch()}>
|
||||
<AdminPageHeader
|
||||
title="能力插件"
|
||||
description="以经营者视角调整模板能力的开关与展示设置;保存后进入草稿,发布后生效。"
|
||||
description="以经营者视角调整当前页面方案提供的业务能力;保存后进入草稿,发布后生效。"
|
||||
/>
|
||||
{query.data?.length ? (
|
||||
<Row gutter={[16, 16]} className="admin-equal-height">
|
||||
@@ -29,9 +29,9 @@ export function CapabilitiesPage() {
|
||||
<Card>
|
||||
<EmptyState
|
||||
icon={<AppstoreOutlined />}
|
||||
title="当前模板没有可配置能力"
|
||||
description="能力的开关由品牌当前使用的行业模板决定;更换行业模板不在本版本范围内。"
|
||||
action={<Button onClick={() => navigate("/admin/publication")}>查看模板与发布</Button>}
|
||||
title="当前页面方案没有可配置能力"
|
||||
description="能力由品牌当前使用的业务类型和页面方案决定。"
|
||||
action={<Button onClick={() => navigate("/admin/page-scheme")}>查看页面方案</Button>}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
@@ -8,12 +8,12 @@ import { CapabilityStatusControl, CapabilityStatusTag } from "./CapabilityStatus
|
||||
|
||||
const sourceLabels = {
|
||||
brand: "品牌覆盖",
|
||||
template: "模板默认",
|
||||
template: "方案默认",
|
||||
} as const;
|
||||
|
||||
const disablePolicyLabels = {
|
||||
allowed: "该能力允许停用,保存后进入草稿。",
|
||||
disabled: "该能力为模板必需项,保存后进入草稿。",
|
||||
disabled: "该能力为页面方案必需项,保存后进入草稿。",
|
||||
} as const;
|
||||
|
||||
const updatedTimeFormatter = new Intl.DateTimeFormat("zh-CN", {
|
||||
@@ -143,7 +143,7 @@ export function CapabilityCard({ capability }: { capability: AdminCapability })
|
||||
) : null}
|
||||
<Typography.Text type="secondary">
|
||||
{capability.source === "template"
|
||||
? "当前使用模板默认设置;修改后保存会创建品牌覆盖。"
|
||||
? "当前使用页面方案默认设置;修改后保存会创建品牌覆盖。"
|
||||
: "当前已创建品牌覆盖;修改后保存会更新草稿。"}
|
||||
{capability.updatedAt
|
||||
? ` 最近更新:${updatedTimeFormatter.format(new Date(capability.updatedAt))}`
|
||||
|
||||
@@ -213,7 +213,7 @@ export function InquiriesPage() {
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title={`动态咨询提交${submissions.data ? `(${submissions.data.length})` : ""}`}
|
||||
description="按模板表单提交的咨询记录,字段随表单配置变化。"
|
||||
description="按咨询表单提交的记录,字段随表单配置变化。"
|
||||
extra={
|
||||
<Button onClick={() => void submissions.refetch()} loading={submissions.isFetching}>
|
||||
刷新提交记录
|
||||
@@ -248,7 +248,7 @@ export function InquiriesPage() {
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无动态咨询提交"
|
||||
description="按模板表单提交的咨询会汇总在这里。"
|
||||
description="按咨询表单提交的内容会汇总在这里。"
|
||||
/>
|
||||
),
|
||||
}}
|
||||
|
||||
@@ -90,7 +90,7 @@ export function OverviewPage() {
|
||||
<p className="admin-brand-tagline">{brand?.tagline || "还没有设置一句话定位"}</p>
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={`当前模板:${workspace?.templateContent?.displayName ?? "尚未安装模板"}`}
|
||||
label={`当前页面方案:${workspace?.templateContent?.displayName ?? "尚未安装页面方案"}`}
|
||||
/>
|
||||
</Card>
|
||||
<Row gutter={[16, 16]}>
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Alert, Button, Card, Collapse, Descriptions, Empty, List, Modal, Space, Tag } from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
import { adminMessage as message } from "../../components/AdminMessage.js";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
export function PageSchemePage() {
|
||||
const queryClient = useQueryClient();
|
||||
const [selectedVersionId, setSelectedVersionId] = useState<string>();
|
||||
const [samplePreview, setSamplePreview] = useState<Awaited<
|
||||
ReturnType<typeof client.previewAdminSampleContent>
|
||||
> | null>(null);
|
||||
const workspace = useQuery({
|
||||
queryKey: ["page-scheme-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const options = useQuery({
|
||||
queryKey: ["admin-page-scheme-options"],
|
||||
queryFn: () => client.getAdminPageSchemeOptions(),
|
||||
});
|
||||
const upgradePreview = useQuery({
|
||||
queryKey: ["page-scheme-upgrade-preview"],
|
||||
queryFn: () => client.getAdminTemplateUpgradePreview(),
|
||||
});
|
||||
const installation = workspace.data?.installations[0];
|
||||
const currentVersionId = installation?.templatePackageVersionId;
|
||||
const currentScheme = options.data?.pageSchemes.find(
|
||||
(scheme) => scheme.templatePackageVersionId === currentVersionId,
|
||||
);
|
||||
const business = options.data?.business;
|
||||
const compatibleSchemes = options.data?.pageSchemes ?? [];
|
||||
|
||||
useEffect(() => {
|
||||
if (currentVersionId) setSelectedVersionId(currentVersionId);
|
||||
}, [currentVersionId]);
|
||||
|
||||
const refresh = () => {
|
||||
for (const queryKey of [
|
||||
"page-scheme-workspace",
|
||||
"page-scheme-upgrade-preview",
|
||||
"admin-workspace",
|
||||
"admin-preview-workspace",
|
||||
"admin-overview-workspace",
|
||||
"publication-workspace",
|
||||
"publication-readiness",
|
||||
]) {
|
||||
void queryClient.invalidateQueries({ queryKey: [queryKey] });
|
||||
}
|
||||
};
|
||||
|
||||
const selectVersion = useMutation({
|
||||
mutationFn: (templatePackageVersionId: string) =>
|
||||
client.selectAdminTemplateVersion({
|
||||
templatePackageVersionId,
|
||||
expectedCurrentPackageVersionId: currentVersionId ?? null,
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("页面方案版本已切换");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const upgrade = useMutation({
|
||||
mutationFn: async () => {
|
||||
const preview = upgradePreview.data;
|
||||
if (
|
||||
!preview?.canUpgrade ||
|
||||
!preview.targetPackageVersionId ||
|
||||
!preview.targetContentChecksum
|
||||
) {
|
||||
throw new Error("当前没有可升级的页面方案版本,请刷新后重试");
|
||||
}
|
||||
return client.upgradeAdminTemplate({
|
||||
templatePackageVersionId: preview.targetPackageVersionId,
|
||||
expectedContentChecksum: preview.targetContentChecksum,
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
expectedCurrentPackageVersionId: preview.currentPackageVersionId,
|
||||
confirm: true,
|
||||
preservedBindings: preview.conflicts.map(({ key, binding }) => ({
|
||||
key,
|
||||
binding,
|
||||
action: "preserve",
|
||||
})),
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("页面方案已升级,现有内容已全部保留");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollback = useMutation({
|
||||
mutationFn: () => {
|
||||
const preview = upgradePreview.data;
|
||||
if (!preview?.canRollback) throw new Error("当前没有可恢复的上一版配置基线");
|
||||
return client.rollbackAdminTemplate({
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
confirm: true,
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
message.success("已恢复上一版页面方案配置基线");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const previewSample = useMutation({
|
||||
mutationFn: () =>
|
||||
client.previewAdminSampleContent({
|
||||
...(currentVersionId ? { templatePackageVersionId: currentVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
}),
|
||||
onSuccess: (data) => setSamplePreview(data),
|
||||
});
|
||||
const importSample = useMutation({
|
||||
mutationFn: () =>
|
||||
client.importAdminSampleContent({
|
||||
...(currentVersionId ? { templatePackageVersionId: currentVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("示例内容已按缺失项导入,现有内容未被覆盖");
|
||||
setSamplePreview(null);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
|
||||
const confirmSelect = (templatePackageVersionId: string) => {
|
||||
const target = compatibleSchemes.find(
|
||||
(scheme) => scheme.templatePackageVersionId === templatePackageVersionId,
|
||||
);
|
||||
Modal.confirm({
|
||||
title: "切换页面方案版本",
|
||||
content: target
|
||||
? `将当前品牌切换到「${target.name}」版本 ${target.version}。现有品牌内容会保留。`
|
||||
: "将切换当前品牌使用的页面方案版本。现有品牌内容会保留。",
|
||||
okText: "确认切换",
|
||||
cancelText: "取消",
|
||||
onOk: () => selectVersion.mutateAsync(templatePackageVersionId),
|
||||
});
|
||||
};
|
||||
const confirmUpgrade = () => {
|
||||
const preview = upgradePreview.data;
|
||||
Modal.confirm({
|
||||
title: "升级页面方案",
|
||||
content:
|
||||
preview && preview.conflicts.length
|
||||
? `将升级到版本 ${preview.latestVersion},并全部保留 ${preview.conflicts.length} 项现有内容。`
|
||||
: `将升级到版本 ${preview?.latestVersion ?? "最新版"},现有品牌内容会保留。`,
|
||||
okText: "确认升级",
|
||||
cancelText: "取消",
|
||||
onOk: () => upgrade.mutateAsync(),
|
||||
});
|
||||
};
|
||||
const confirmRollback = () => {
|
||||
Modal.confirm({
|
||||
title: "恢复上一版配置基线",
|
||||
content: "此操作只恢复上一版页面方案配置,不会删除品牌内容、业务提供项或咨询记录。",
|
||||
okText: "确认恢复",
|
||||
cancelText: "取消",
|
||||
onOk: () => rollback.mutateAsync(),
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<QueryState
|
||||
loading={workspace.isLoading || options.isLoading || upgradePreview.isLoading}
|
||||
error={workspace.error || options.error || upgradePreview.error}
|
||||
onRetry={() => {
|
||||
void workspace.refetch();
|
||||
void options.refetch();
|
||||
void upgradePreview.refetch();
|
||||
}}
|
||||
>
|
||||
<AdminPageHeader
|
||||
title="页面方案"
|
||||
description="页面方案决定小程序有哪些页面、页面结构、视觉和资源位。它可以独立于内容发布进行升级或版本切换。"
|
||||
/>
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="当前方案"
|
||||
description="业务类型创建后固定;页面方案和版本可以继续调整。"
|
||||
>
|
||||
<Descriptions column={{ xs: 1, md: 2 }} bordered>
|
||||
<Descriptions.Item label="业务类型">{business?.name ?? "未识别"}</Descriptions.Item>
|
||||
<Descriptions.Item label="页面方案">
|
||||
{currentScheme?.name ?? workspace.data?.templateContent?.displayName ?? "尚未安装"}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="当前状态">
|
||||
<StatusTag
|
||||
tone={installation ? "info" : "neutral"}
|
||||
label={
|
||||
installation ? `正在使用版本 ${installation.templateVersion}` : "尚未安装页面方案"
|
||||
}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{business?.description ? (
|
||||
<p className="admin-section-description admin-offset-top">{business.description}</p>
|
||||
) : null}
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="升级预览"
|
||||
description="升级前先查看页面、模块、资源和绑定的变化;冲突项默认保留现有内容。"
|
||||
>
|
||||
<Card>
|
||||
{upgradePreview.data?.canUpgrade ? (
|
||||
<Space direction="vertical" size={12} className="admin-full-width">
|
||||
<div className="admin-row-line">
|
||||
<strong>可升级到版本 {upgradePreview.data.latestVersion}</strong>
|
||||
<Tag color="blue">建议先预览</Tag>
|
||||
</div>
|
||||
<Descriptions column={{ xs: 1, md: 2 }} size="small">
|
||||
<Descriptions.Item label="新增页面">
|
||||
{upgradePreview.data.changes.pages.added.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="变更页面">
|
||||
{upgradePreview.data.changes.pages.changed.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="新增字段绑定">
|
||||
{upgradePreview.data.changes.templateBindings.added.length}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="需要保留的冲突">
|
||||
{upgradePreview.data.conflicts.length}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
{upgradePreview.data.conflicts.length ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`发现 ${upgradePreview.data.conflicts.length} 项自定义内容与新版布局存在差异`}
|
||||
description="升级时会全部保留现有内容,不会逐项覆盖。请确认后再执行升级。"
|
||||
/>
|
||||
) : (
|
||||
<Alert type="success" showIcon message="未发现内容绑定冲突" />
|
||||
)}
|
||||
<Button type="primary" onClick={confirmUpgrade} loading={upgrade.isPending}>
|
||||
升级到 {upgradePreview.data.latestVersion}
|
||||
</Button>
|
||||
</Space>
|
||||
) : (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description="当前已是可用的最新页面方案版本,暂无可升级版本。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={upgrade.error} />
|
||||
</Card>
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="选择版本"
|
||||
description="可切换到同一业务类型下的其他已发布版本。切换会保留品牌内容。"
|
||||
>
|
||||
<List
|
||||
dataSource={compatibleSchemes}
|
||||
locale={{ emptyText: "没有可切换的页面方案版本" }}
|
||||
renderItem={(scheme) => {
|
||||
const isCurrent = scheme.templatePackageVersionId === currentVersionId;
|
||||
return (
|
||||
<List.Item
|
||||
actions={[
|
||||
<Button
|
||||
key="select"
|
||||
type={isCurrent ? "default" : "primary"}
|
||||
disabled={isCurrent}
|
||||
loading={
|
||||
selectVersion.isPending &&
|
||||
selectedVersionId === scheme.templatePackageVersionId
|
||||
}
|
||||
onClick={() => {
|
||||
setSelectedVersionId(scheme.templatePackageVersionId);
|
||||
confirmSelect(scheme.templatePackageVersionId);
|
||||
}}
|
||||
>
|
||||
{isCurrent ? "当前版本" : "切换到此版本"}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<List.Item.Meta
|
||||
title={
|
||||
<Space>
|
||||
<span>{scheme.name}</span>
|
||||
<Tag color={scheme.isLatestForPackage ? "green" : "default"}>
|
||||
{scheme.isLatestForPackage ? "最新版" : `版本 ${scheme.version}`}
|
||||
</Tag>
|
||||
</Space>
|
||||
}
|
||||
description={`${scheme.description} · 版本 ${scheme.version}`}
|
||||
/>
|
||||
</List.Item>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<MutationError error={selectVersion.error} />
|
||||
</AdminSection>
|
||||
|
||||
<AdminSection
|
||||
title="配置恢复"
|
||||
description="恢复上一版页面方案配置基线,仅用于升级后出现配置问题时回退。"
|
||||
>
|
||||
<Button danger onClick={confirmRollback} disabled={!upgradePreview.data?.canRollback}>
|
||||
恢复上一版配置
|
||||
</Button>
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
|
||||
<Collapse
|
||||
items={[
|
||||
{
|
||||
key: "sample-content",
|
||||
label: "高级:导入示例内容",
|
||||
children: (
|
||||
<Space direction="vertical" size={12} className="admin-full-width">
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message="此操作会写入当前品牌内容"
|
||||
description="仅导入当前缺失的内容,不会覆盖已有品牌资料。创建品牌时不会自动执行。"
|
||||
/>
|
||||
<Space>
|
||||
<Button
|
||||
onClick={() => previewSample.mutate()}
|
||||
loading={previewSample.isPending}
|
||||
>
|
||||
预览将导入的内容
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
danger
|
||||
disabled={!samplePreview}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate()}
|
||||
>
|
||||
确认导入缺失内容
|
||||
</Button>
|
||||
</Space>
|
||||
<MutationError error={previewSample.error || importSample.error} />
|
||||
{samplePreview ? (
|
||||
<Descriptions bordered size="small" column={{ xs: 1, md: 2 }}>
|
||||
<Descriptions.Item label="品牌资料">
|
||||
{samplePreview.counts.brandConfig}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="业务提供项">
|
||||
{samplePreview.counts.offerings}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="信任内容">
|
||||
{samplePreview.counts.trustContent}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="字段">
|
||||
{samplePreview.counts.fields}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="咨询表单">
|
||||
{samplePreview.counts.inquiryForms}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="是否已导入">
|
||||
{samplePreview.alreadyImported ? "是" : "否"}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +1,11 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
Divider,
|
||||
Input,
|
||||
Popconfirm,
|
||||
Modal,
|
||||
Form,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
Tabs,
|
||||
Typography,
|
||||
} from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { Alert, Button, Divider, Form, Input, Modal, Space, Tabs, Typography } from "antd";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { ErrorNote, MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag, statusLabel } from "../../components/StatusTag.js";
|
||||
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||
import { MiniAppSettingsTab, type MiniAppSettingsValues } from "./MiniAppSettingsTab.js";
|
||||
@@ -30,34 +15,28 @@ import { usePublicationMutations } from "./use-publication-mutations.js";
|
||||
const destinations: Record<string, string> = {
|
||||
brand: "/admin/brand",
|
||||
positioning: "/admin/brand",
|
||||
template: "/admin/publication",
|
||||
visual: "/admin/publication",
|
||||
template: "/admin/page-scheme",
|
||||
visual: "/admin/page-scheme",
|
||||
offerings: "/admin/services",
|
||||
forms: "/admin/workspace",
|
||||
trust: "/admin/trust",
|
||||
};
|
||||
|
||||
export function PublicationPage({ canManageTemplate }: { canManageTemplate: boolean }) {
|
||||
export function PublicationPage() {
|
||||
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 [preservedBindings, setPreservedBindings] = useState<Record<string, boolean>>({});
|
||||
const [note, setNote] = useState("");
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<MiniAppSettingsValues>();
|
||||
const queries = usePublicationQueries(miniAppSettingsForm);
|
||||
const {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
@@ -66,11 +45,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
for (const key of [
|
||||
"publication-brand",
|
||||
"publication-workspace",
|
||||
"publication-sample",
|
||||
"publication-readiness",
|
||||
"publication-template-preview",
|
||||
"publication-releases",
|
||||
"publication-miniapp-releases",
|
||||
"publication-miniapp-settings",
|
||||
"admin-shell-brand",
|
||||
"admin-workspace",
|
||||
"public-runtime-workspace",
|
||||
@@ -80,18 +58,11 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
};
|
||||
const mutations = usePublicationMutations({
|
||||
refresh,
|
||||
currentTemplatePackageVersionId: workspace.data?.installations[0]?.templatePackageVersionId,
|
||||
onInstallClose: () => setIndustryTarget(null),
|
||||
onPublishClose: () => setConfirmAction(null),
|
||||
onNoteClear: () => setNote(""),
|
||||
onRollbackClose: () => setRollbackVersion(null),
|
||||
});
|
||||
const {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
@@ -100,18 +71,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
uploadMiniAppRelease,
|
||||
updateMiniAppStatus,
|
||||
} = mutations;
|
||||
const industryKey =
|
||||
workspace.data?.installations[0]?.templateKey ??
|
||||
workspace.data?.brand?.templateKey ??
|
||||
brand.data?.templateKey ??
|
||||
null;
|
||||
const selectablePackageVersions = (queries.packages.data?.items ?? []).filter(
|
||||
(item) =>
|
||||
item.status === "published" &&
|
||||
typeof industryKey === "string" &&
|
||||
item.manifestSummary?.supportedIndustryTemplates.includes(industryKey),
|
||||
);
|
||||
const visualKey = workspace.data?.installations[0]?.visualTemplateKey ?? null;
|
||||
const currentRelease = releases.data?.find((item) => item.status === "published");
|
||||
const publishedHistory = (releases.data ?? []).filter(
|
||||
(item) => item.status === "published" || item.status === "superseded",
|
||||
@@ -123,12 +82,12 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
isEnabled: boolean;
|
||||
}>;
|
||||
|
||||
const contentTab = null;
|
||||
return (
|
||||
<QueryState loading={loading} error={error} onRetry={retry}>
|
||||
<AdminPageHeader
|
||||
title="配置与发布"
|
||||
description="编辑内容不会立即影响小程序;确认后统一发布当前品牌。"
|
||||
title="内容与发布"
|
||||
description="检查当前草稿并发布品牌内容;页面方案与内容发布互不混用。"
|
||||
extra={<Button onClick={() => navigate("/admin/page-scheme")}>管理页面方案</Button>}
|
||||
/>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
@@ -137,418 +96,175 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
{
|
||||
key: "content",
|
||||
label: "内容发布",
|
||||
children: contentTab,
|
||||
children: (
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="发布前检查"
|
||||
description="请先处理未完成的检查项,再发布当前草稿。发布不会自动修改页面方案。"
|
||||
>
|
||||
{draftOfferings.length || draftForms.length ? (
|
||||
<p className="admin-section-description">
|
||||
当前草稿包含 {draftOfferings.length} 个启用中的业务提供项和{" "}
|
||||
{draftForms.length} 个咨询表单。
|
||||
</p>
|
||||
) : null}
|
||||
<ul className="admin-list">
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<li key={check.key} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={check.passed ? "success" : "warning"}
|
||||
label={check.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{check.label}</span>
|
||||
{!check.passed && check.help ? (
|
||||
<span className="admin-row-meta">{check.help}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{!check.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() =>
|
||||
navigate(
|
||||
check.destination ?? destinations[check.key] ?? "/admin/overview",
|
||||
)
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<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 className="admin-divider" />
|
||||
<h3 className="admin-section-title">发布记录</h3>
|
||||
{releases.data?.length ? (
|
||||
<ul className="admin-list admin-offset-top-xs">
|
||||
{releases.data.map((item) => (
|
||||
<li key={item.id} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">v{item.version}</span>
|
||||
<StatusTag
|
||||
tone={item.status === "published" ? "success" : "neutral"}
|
||||
label={statusLabel(item.status)}
|
||||
/>
|
||||
<span className="admin-row-meta">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
{item.note ? (
|
||||
<span className="admin-row-meta">{item.note}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{item.status === "superseded" && publishedHistory.length > 1 ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => setRollbackVersion(item.version)}
|
||||
>
|
||||
恢复此版本
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无发布记录"
|
||||
description="完成检查并发布后,这里会保留每个版本的记录。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "miniapp",
|
||||
label: "小程序发布",
|
||||
children: (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序代码发布"
|
||||
description="使用微信官方工具上传代码;审核与发布状态需按微信平台结果人工确认。"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已配置上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传凭据" />
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{miniAppReleases.data?.length ? (
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) =>
|
||||
updateMiniAppStatus.mutate({ id: task.id, status })
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无小程序发布任务"
|
||||
description="先发布品牌内容,再上传当前版本到微信。"
|
||||
/>
|
||||
)}
|
||||
</AdminSection>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{ key: "miniapp", label: "小程序发布", children: null },
|
||||
{
|
||||
key: "settings",
|
||||
label: "小程序配置",
|
||||
children:
|
||||
activeTab === "settings" ? (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
onSave={(values) => saveMiniAppSettings.mutate(values)}
|
||||
/>
|
||||
) : null,
|
||||
children: (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
onSave={(values) => saveMiniAppSettings.mutate(values)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
{activeTab === "content" && (
|
||||
<div className="admin-stack">
|
||||
<AdminSection
|
||||
title="选择表达方式"
|
||||
description="行业模板决定内容结构,视觉模板决定小程序的排版风格。"
|
||||
>
|
||||
<Space wrap>
|
||||
<Select
|
||||
aria-label="行业模板"
|
||||
className="admin-field-w-xl"
|
||||
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="视觉模板"
|
||||
className="admin-field-w-xl"
|
||||
value={visualKey}
|
||||
disabled={!canManageTemplate}
|
||||
loading={selectVisual.isPending}
|
||||
options={selectablePackageVersions.map((item) => ({
|
||||
value: item.id,
|
||||
label: `${item.displayName} · ${item.version}`,
|
||||
}))}
|
||||
onChange={(versionId) => selectVisual.mutate(versionId)}
|
||||
/>
|
||||
</Space>
|
||||
{industryKey ? (
|
||||
<div className="admin-offset-top-sm">
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone="neutral"
|
||||
label={`当前版本 ${templatePreview.data?.currentVersion ?? "加载中"}`}
|
||||
/>
|
||||
<StatusTag
|
||||
tone="info"
|
||||
label={`最新版本 ${templatePreview.data?.latestVersion ?? "加载中"}`}
|
||||
/>
|
||||
{templatePreview.data?.canUpgrade ? (
|
||||
<Popconfirm
|
||||
title="确认升级到已发布模板包?"
|
||||
description={`新增 binding ${templatePreview.data.changes.templateBindings.added.length} 项;冲突值需逐项确认保留。升级不会删除字段或业务内容。`}
|
||||
okText="确认升级"
|
||||
cancelText="取消"
|
||||
onConfirm={() => {
|
||||
const preview = templatePreview.data;
|
||||
if (!preview?.targetPackageVersionId || !preview.targetContentChecksum)
|
||||
return;
|
||||
if (
|
||||
!preview.conflicts.every(
|
||||
(item) => preservedBindings[`${item.key}:${item.binding}`],
|
||||
)
|
||||
)
|
||||
return;
|
||||
upgradeTemplate.mutate({
|
||||
templatePackageVersionId: preview.targetPackageVersionId,
|
||||
expectedContentChecksum: preview.targetContentChecksum,
|
||||
expectedCurrentVersion: preview.currentVersion,
|
||||
expectedCurrentPackageVersionId: preview.currentPackageVersionId,
|
||||
confirm: true,
|
||||
preservedBindings: preview.conflicts.map(({ key, binding }) => ({
|
||||
key,
|
||||
binding,
|
||||
action: "preserve" as const,
|
||||
})),
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
disabled={
|
||||
!canManageTemplate ||
|
||||
!templatePreview.data?.targetPackageVersionId ||
|
||||
!templatePreview.data.conflicts.every(
|
||||
(item) => preservedBindings[`${item.key}:${item.binding}`],
|
||||
)
|
||||
}
|
||||
loading={upgradeTemplate.isPending}
|
||||
>
|
||||
升级模板
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
) : (
|
||||
<StatusTag tone="success" label="已是最新版本" />
|
||||
)}
|
||||
{templatePreview.data?.canRollback ? (
|
||||
<Popconfirm
|
||||
title="确认恢复上一版模板配置基线?"
|
||||
description="不会删除品牌字段、业务内容、历史发布或客户咨询记录。"
|
||||
okText="确认回滚"
|
||||
cancelText="取消"
|
||||
onConfirm={() => {
|
||||
const currentVersion = templatePreview.data?.currentVersion;
|
||||
if (!currentVersion) return;
|
||||
rollbackTemplate.mutate({
|
||||
expectedCurrentVersion: currentVersion,
|
||||
confirm: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
disabled={!canManageTemplate}
|
||||
loading={rollbackTemplate.isPending}
|
||||
>
|
||||
回滚到上一版
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
) : null}
|
||||
</Space>
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
行业模板随品牌身份固定。升级目标为当前视觉模板最新已发布包,并按包版本与 checksum
|
||||
锁定预览;新增字段会补入,改动冲突和已移除字段不会覆盖或删除。回滚仅恢复配置基线,不删除品牌字段、内容或历史发布。
|
||||
</p>
|
||||
{templatePreview.data?.conflicts.length ? (
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`请逐项确认保留 ${templatePreview.data.conflicts.length} 个现有品牌配置值`}
|
||||
description={
|
||||
<Space direction="vertical">
|
||||
{templatePreview.data.conflicts.map((item) => {
|
||||
const key = `${item.key}:${item.binding}`;
|
||||
return (
|
||||
<Checkbox
|
||||
key={key}
|
||||
checked={Boolean(preservedBindings[key])}
|
||||
onChange={(event) =>
|
||||
setPreservedBindings((current) => ({
|
||||
...current,
|
||||
[key]: event.target.checked,
|
||||
}))
|
||||
}
|
||||
>
|
||||
保留 {item.binding}({item.reason})
|
||||
</Checkbox>
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{templatePreview.data ? (
|
||||
<div className="admin-section-description admin-offset-top-sm">
|
||||
页面入口变更:新增 {templatePreview.data.changes.pages.added.length}、变更{" "}
|
||||
{templatePreview.data.changes.pages.changed.length}、移除{" "}
|
||||
{templatePreview.data.changes.pages.removed.length};资源槽位变更:新增{" "}
|
||||
{templatePreview.data.changes.assets.slots.added.length}、变更{" "}
|
||||
{templatePreview.data.changes.assets.slots.changed.length}、移除{" "}
|
||||
{templatePreview.data.changes.assets.slots.removed.length};
|
||||
{templatePreview.data.changes.assets.files.available
|
||||
? `包内文件变更:新增 ${templatePreview.data.changes.assets.files.added?.length ?? 0}、变更 ${templatePreview.data.changes.assets.files.changed?.length ?? 0}、移除 ${templatePreview.data.changes.assets.files.removed?.length ?? 0}`
|
||||
: templatePreview.data.changes.assets.files.reason}
|
||||
。模块与 renderer 由已部署的平台视觉模板管理,此次包升级不会替换 renderer。
|
||||
</div>
|
||||
) : null}
|
||||
<MutationError
|
||||
error={templatePreview.error || upgradeTemplate.error || rollbackTemplate.error}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<MutationError error={install.error || selectVisual.error} />
|
||||
<Divider className="admin-divider" />
|
||||
<Space wrap>
|
||||
<Typography.Text>示例内容</Typography.Text>
|
||||
{sample.isLoading && <Spin size="small" />}
|
||||
{sample.data && (
|
||||
<StatusTag
|
||||
tone={sample.data.alreadyImported ? "success" : "info"}
|
||||
label={sample.data.alreadyImported ? "已导入" : "可导入"}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
disabled={!canManageTemplate || !sample.data || sample.data.alreadyImported}
|
||||
loading={importSample.isPending}
|
||||
onClick={() => importSample.mutate(sample.data?.source.templatePackageVersionId)}
|
||||
>
|
||||
导入示例内容
|
||||
</Button>
|
||||
{sample.isError && <Button onClick={() => void sample.refetch()}>重试</Button>}
|
||||
</Space>
|
||||
{sample.isError && (
|
||||
<div className="admin-offset-top-sm">
|
||||
<ErrorNote error={sample.error} onRetry={() => void sample.refetch()} />
|
||||
</div>
|
||||
)}
|
||||
{sample.data && !sample.data.alreadyImported && (
|
||||
<p className="admin-section-description admin-offset-top-sm">
|
||||
来源:{sample.data.source.packageKey}@{sample.data.source.version}
|
||||
(checksum {(sample.data.source.contentChecksum ?? "").slice(0, 12)})
|
||||
。将向草稿添加{" "}
|
||||
{Object.entries(sample.data.counts)
|
||||
.map(([key, count]) => `${key} ${count} 项`)
|
||||
.join("、")}
|
||||
;同时补齐当前模板缺失的页面初始配置,保留已有配置和已启用表单。发布前请替换示例文案和图片。
|
||||
</p>
|
||||
)}
|
||||
<MutationError error={importSample.error} />
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="核对草稿内容"
|
||||
description="此处核对的是待发布内容,不是小程序视觉预览。"
|
||||
>
|
||||
<ul className="admin-list">
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">{brand.data?.name || "未命名品牌"}</span>
|
||||
<span className="admin-row-meta">
|
||||
{brand.data?.tagline || "尚未填写品牌定位"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用业务项</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftOfferings.map((item) => item.name).join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">已启用咨询表单</span>
|
||||
<span className="admin-row-meta">
|
||||
{draftForms
|
||||
.filter((item) => item.isEnabled)
|
||||
.map((item) => item.name)
|
||||
.join("、") || "无"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<Button onClick={() => navigate("/admin/brand")}>编辑小程序页面</Button>
|
||||
<Button onClick={() => navigate("/admin/services")}>编辑业务展示和详情</Button>
|
||||
<Button onClick={() => navigate("/admin/trust")}>编辑信任证明</Button>
|
||||
</Space>
|
||||
</AdminSection>
|
||||
<AdminSection
|
||||
title="检查并发布"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<StatusTag
|
||||
tone={currentRelease ? "success" : "neutral"}
|
||||
label={currentRelease ? `已发布 v${currentRelease.version}` : "尚未发布"}
|
||||
/>
|
||||
<Button onClick={() => void readiness.refetch()}>重新检查</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<ul className="admin-list">
|
||||
{(readiness.data?.checks ?? []).map((check) => (
|
||||
<li key={check.key} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<StatusTag
|
||||
tone={check.passed ? "success" : "warning"}
|
||||
label={check.passed ? "已完成" : "待完善"}
|
||||
/>
|
||||
<span className="admin-row-title">{check.label}</span>
|
||||
{!check.passed && check.help ? (
|
||||
<span className="admin-row-meta">{check.help}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{!check.passed ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() =>
|
||||
navigate(check.destination ?? destinations[check.key] ?? "/admin/overview")
|
||||
}
|
||||
>
|
||||
去处理
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<Space wrap className="admin-offset-top">
|
||||
<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 className="admin-divider" />
|
||||
<h3 className="admin-section-title">发布记录</h3>
|
||||
{releases.data?.length ? (
|
||||
<ul className="admin-list admin-offset-top-xs">
|
||||
{releases.data.map((item) => (
|
||||
<li key={item.id} className="admin-row">
|
||||
<div className="admin-row-main">
|
||||
<div className="admin-row-line">
|
||||
<span className="admin-row-title">v{item.version}</span>
|
||||
<StatusTag
|
||||
tone={item.status === "published" ? "success" : "neutral"}
|
||||
label={statusLabel(item.status)}
|
||||
/>
|
||||
<span className="admin-row-meta">
|
||||
{new Date(item.createdAt).toLocaleString("zh-CN")}
|
||||
</span>
|
||||
{item.note ? <span className="admin-row-meta">{item.note}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
{item.status === "superseded" && publishedHistory.length > 1 ? (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => setRollbackVersion(item.version)}
|
||||
>
|
||||
恢复此版本
|
||||
</Button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无发布记录"
|
||||
description="完成检查并发布后,这里会保留每个版本的记录。"
|
||||
/>
|
||||
)}
|
||||
<MutationError error={rollback.error} />
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === "miniapp" && (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
title="小程序代码发布"
|
||||
description="使用微信官方工具上传代码;审核与发布状态需按微信平台结果人工确认。"
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
disabled={!currentRelease}
|
||||
loading={uploadLatestMiniAppRelease.isPending}
|
||||
onClick={() => uploadLatestMiniAppRelease.mutate()}
|
||||
>
|
||||
上传当前版本到微信
|
||||
</Button>
|
||||
{miniAppSettings.data?.hasStoredCredentials ? (
|
||||
<StatusTag tone="success" label="已配置上传凭据" />
|
||||
) : (
|
||||
<StatusTag tone="warning" label="未配置上传凭据" />
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{miniAppReleases.data?.length ? (
|
||||
<div className="admin-stack admin-stack-tight">
|
||||
{miniAppReleases.data.map((task) => (
|
||||
<MiniAppReleaseCard
|
||||
key={task.id}
|
||||
task={task}
|
||||
uploading={uploadMiniAppRelease.isPending}
|
||||
onUpload={() => uploadMiniAppRelease.mutate(task.id)}
|
||||
onStatusChange={(status) => updateMiniAppStatus.mutate({ id: task.id, status })}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState
|
||||
compact
|
||||
title="暂无小程序发布任务"
|
||||
description="先发布品牌内容,再上传当前版本到微信。"
|
||||
/>
|
||||
)}
|
||||
</AdminSection>
|
||||
</div>
|
||||
)}
|
||||
<Modal
|
||||
title={confirmAction === "revoke" ? "确认撤回品牌" : "确认发布品牌"}
|
||||
open={confirmAction !== null}
|
||||
@@ -584,23 +300,6 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
>
|
||||
将 v{rollbackVersion} 重新发布为新版本;当前草稿不会被覆盖。
|
||||
</Modal>
|
||||
<Modal
|
||||
title="确认安装行业模板"
|
||||
open={industryTarget !== null}
|
||||
onCancel={() => setIndustryTarget(null)}
|
||||
okButtonProps={{ disabled: !templatePreview.data?.targetPackageVersionId }}
|
||||
onOk={() =>
|
||||
industryTarget &&
|
||||
templatePreview.data?.targetPackageVersionId &&
|
||||
install.mutate({
|
||||
key: industryTarget,
|
||||
versionId: templatePreview.data.targetPackageVersionId,
|
||||
})
|
||||
}
|
||||
confirmLoading={install.isPending}
|
||||
>
|
||||
模板会更新当前品牌的草稿结构,不会立即改变已发布的小程序。请安装后核对业务内容与视觉模板。
|
||||
</Modal>
|
||||
</QueryState>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { message } from "antd";
|
||||
import type { BrandTemplateKey } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
interface MutationOptions {
|
||||
refresh: () => void;
|
||||
currentTemplatePackageVersionId: string | null | undefined;
|
||||
onInstallClose: () => void;
|
||||
onPublishClose: () => void;
|
||||
onNoteClear: () => void;
|
||||
onRollbackClose: () => void;
|
||||
@@ -16,83 +13,11 @@ interface MutationOptions {
|
||||
|
||||
export function usePublicationMutations({
|
||||
refresh,
|
||||
onInstallClose,
|
||||
onPublishClose,
|
||||
onNoteClear,
|
||||
onRollbackClose,
|
||||
currentTemplatePackageVersionId,
|
||||
}: MutationOptions) {
|
||||
const queryClient = useQueryClient();
|
||||
const install = useMutation({
|
||||
mutationFn: ({ key, versionId }: { key: BrandTemplateKey; versionId: string }) =>
|
||||
client.installAdminTemplate(key, versionId),
|
||||
onSuccess: () => {
|
||||
onInstallClose();
|
||||
message.success("行业模板已安装");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const upgradeTemplate = useMutation({
|
||||
mutationFn: (input: {
|
||||
templatePackageVersionId: string;
|
||||
expectedContentChecksum: string;
|
||||
expectedCurrentVersion: string;
|
||||
expectedCurrentPackageVersionId: string | null;
|
||||
confirm: true;
|
||||
preservedBindings: Array<{ key: string; binding: string; action: "preserve" }>;
|
||||
}) => client.upgradeAdminTemplate(input),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板已升级,现有内容未被覆盖");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const rollbackTemplate = useMutation({
|
||||
mutationFn: (input: { expectedCurrentVersion: string; confirm: true }) =>
|
||||
client.rollbackAdminTemplate(input),
|
||||
onSuccess: () => {
|
||||
message.success("行业模板配置基线已回滚");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const selectVisual = useMutation({
|
||||
mutationFn: (templatePackageVersionId: string) =>
|
||||
client.selectAdminTemplateVersion({
|
||||
templatePackageVersionId,
|
||||
...(currentTemplatePackageVersionId !== undefined
|
||||
? { expectedCurrentPackageVersionId: currentTemplatePackageVersionId }
|
||||
: {}),
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: () => {
|
||||
message.success("模板版本已切换");
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const importSample = useMutation<
|
||||
Awaited<ReturnType<typeof client.importAdminSampleContent>>,
|
||||
Error,
|
||||
string | undefined
|
||||
>({
|
||||
mutationFn: (templatePackageVersionId) =>
|
||||
client.importAdminSampleContent({
|
||||
...(templatePackageVersionId ? { templatePackageVersionId } : {}),
|
||||
strategy: "missing_only",
|
||||
confirm: true,
|
||||
}),
|
||||
onSuccess: ({ counts, alreadyImported }) => {
|
||||
if (alreadyImported) {
|
||||
message.info("该模板包版本的示例内容已导入,未重复创建");
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
message.success(
|
||||
counts.inquiryForms
|
||||
? "示例内容和客户咨询表单已导入草稿"
|
||||
: "示例内容已导入草稿,现有客户咨询表单已保留",
|
||||
);
|
||||
refresh();
|
||||
},
|
||||
});
|
||||
const publish = useMutation({
|
||||
mutationFn: (note: string) => client.publishAdminRelease(note || undefined),
|
||||
onSuccess: () => {
|
||||
@@ -163,11 +88,6 @@ export function usePublicationMutations({
|
||||
});
|
||||
|
||||
return {
|
||||
install,
|
||||
upgradeTemplate,
|
||||
rollbackTemplate,
|
||||
selectVisual,
|
||||
importSample,
|
||||
publish,
|
||||
revoke,
|
||||
rollback,
|
||||
|
||||
@@ -20,25 +20,6 @@ export function usePublicationQueries(
|
||||
queryKey: ["publication-workspace"],
|
||||
queryFn: () => client.getAdminWorkspace(),
|
||||
});
|
||||
const catalog = useQuery<Awaited<ReturnType<typeof client.listPublicTemplates>>>({
|
||||
queryKey: ["publication-catalog"],
|
||||
queryFn: () => client.listPublicTemplates(),
|
||||
});
|
||||
const packages = useQuery<Awaited<ReturnType<typeof client.listAdminTemplatePackages>>>({
|
||||
queryKey: ["publication-template-packages"],
|
||||
queryFn: () => client.listAdminTemplatePackages({ page: 1, pageSize: 100 }),
|
||||
});
|
||||
const sample = useQuery<Awaited<ReturnType<typeof client.previewAdminSampleContent>>>({
|
||||
queryKey: ["publication-sample", workspace.data?.installations[0]?.templatePackageVersionId],
|
||||
queryFn: () =>
|
||||
client.previewAdminSampleContent({
|
||||
...(workspace.data?.installations[0]?.templatePackageVersionId
|
||||
? { templatePackageVersionId: workspace.data.installations[0].templatePackageVersionId }
|
||||
: {}),
|
||||
strategy: "missing_only",
|
||||
}),
|
||||
enabled: Boolean(workspace.data),
|
||||
});
|
||||
const readiness = useQuery<Awaited<ReturnType<typeof client.getAdminReleaseReadiness>>>({
|
||||
queryKey: ["publication-readiness"],
|
||||
queryFn: () => client.getAdminReleaseReadiness(),
|
||||
@@ -55,12 +36,6 @@ export function usePublicationQueries(
|
||||
queryKey: ["publication-miniapp-settings"],
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
const templatePreview = useQuery<
|
||||
Awaited<ReturnType<typeof client.getAdminTemplateUpgradePreview>>
|
||||
>({
|
||||
queryKey: ["publication-template-preview"],
|
||||
queryFn: () => client.getAdminTemplateUpgradePreview(),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
@@ -82,31 +57,15 @@ export function usePublicationQueries(
|
||||
return () => clearInterval(timer);
|
||||
}, [miniAppReleases]);
|
||||
|
||||
const loading = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].some((query) => query.isLoading);
|
||||
const error = [
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
].find((query) => query.isError)?.error;
|
||||
const loading = [brand, workspace, readiness, releases, miniAppReleases, miniAppSettings].some(
|
||||
(query) => query.isLoading,
|
||||
);
|
||||
const error = [brand, workspace, readiness, releases, miniAppReleases, miniAppSettings].find(
|
||||
(query) => query.isError,
|
||||
)?.error;
|
||||
const retry = () => {
|
||||
void brand.refetch();
|
||||
void workspace.refetch();
|
||||
void catalog.refetch();
|
||||
void packages.refetch();
|
||||
void readiness.refetch();
|
||||
void releases.refetch();
|
||||
void miniAppReleases.refetch();
|
||||
@@ -116,14 +75,10 @@ export function usePublicationQueries(
|
||||
return {
|
||||
brand,
|
||||
workspace,
|
||||
catalog,
|
||||
packages,
|
||||
sample,
|
||||
readiness,
|
||||
releases,
|
||||
miniAppReleases,
|
||||
miniAppSettings,
|
||||
templatePreview,
|
||||
loading,
|
||||
error,
|
||||
retry,
|
||||
|
||||
@@ -20,7 +20,7 @@ export function useOfferingEditor(templateFields: TemplateAdminField[]) {
|
||||
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||
() => ({
|
||||
key: "offering",
|
||||
title: "模板内容",
|
||||
title: "页面方案内容",
|
||||
description: "",
|
||||
page: "detail",
|
||||
target: "offering",
|
||||
|
||||
@@ -66,7 +66,7 @@ export function TrustContentPage() {
|
||||
}
|
||||
/>
|
||||
<AdminSection
|
||||
title="当前模板需要配置的内容"
|
||||
title="当前页面方案需要配置的内容"
|
||||
description="标记为「发布必填」的项目需要填写完整后,才能发布小程序。"
|
||||
>
|
||||
<TrustRequirementsList
|
||||
|
||||
@@ -137,7 +137,7 @@ function sharesMeaningfulOverlap(label: string, token: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 列表按模板声明的类型顺序排列,与「当前模板需要配置的内容」保持一致。
|
||||
// 列表按页面方案声明的类型顺序排列,与「当前页面方案需要配置的内容」保持一致。
|
||||
export function sortTrustContentByTypeOrder(
|
||||
items: TrustContent[],
|
||||
availableTypes: TrustTypeOption[],
|
||||
|
||||
Reference in new issue
Block a user