refactor: 整理品牌配置与小程序编辑工作区
This commit is contained in:
1 parent
849ae5df05
commit
a2932b1134
13 files changed
+416
-63
No files matched your search
@@ -0,0 +1,60 @@
|
||||
.brand-page__content {
|
||||
max-width: 960px;
|
||||
}
|
||||
|
||||
.brand-page__settings {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.brand-settings-section {
|
||||
padding: 24px 0;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.brand-settings-section:first-child {
|
||||
padding-top: 8px;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.brand-settings-section__header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-typography {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-typography + .ant-typography {
|
||||
display: block;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.brand-page__template-note {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
.brand-page__content {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.brand-page__template-note {
|
||||
position: static;
|
||||
margin-top: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.brand-settings-section__header {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.brand-settings-section__header .ant-tag {
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,16 @@
|
||||
import { Button, Card, Col, Form, Input, Row, Select, Space, Tag, Typography, message } from "antd";
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
@@ -6,6 +18,7 @@ import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { PresentationEditor } from "./PresentationEditor.js";
|
||||
import "./BrandPage.css";
|
||||
|
||||
export function BrandPage() {
|
||||
const client = createApiClient();
|
||||
@@ -38,21 +51,31 @@ export function BrandPage() {
|
||||
<>
|
||||
<AdminPageHeader
|
||||
title="品牌资料"
|
||||
description="先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||
description={
|
||||
template.data?.description
|
||||
? `先让访客理解你是谁、服务谁,以及为什么值得信任。${template.data.description}`
|
||||
: "先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||
}
|
||||
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
||||
/>
|
||||
<Row gutter={[24, 24]} align="top">
|
||||
<Col xs={24} xl={16}>
|
||||
<div className="brand-page__content">
|
||||
<div className="brand-page__settings">
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={brand.data}
|
||||
onFinish={(values) => save.mutate(values)}
|
||||
>
|
||||
<Card
|
||||
title="我是谁"
|
||||
extra={<Typography.Text type="secondary">公开展示</Typography.Text>}
|
||||
>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-identity-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div>
|
||||
<Typography.Title id="brand-identity-title" level={4}>
|
||||
我是谁
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">公开展示的品牌身份和定位。</Typography.Text>
|
||||
</div>
|
||||
<Tag>品牌基础信息</Tag>
|
||||
</div>
|
||||
<Form.Item
|
||||
name="name"
|
||||
label="品牌名称"
|
||||
@@ -77,8 +100,18 @@ export function BrandPage() {
|
||||
placeholder="让第一次认识你的人快速建立基本信任。"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Card>
|
||||
<Card title="如何联系与合作" style={{ marginTop: 24 }}>
|
||||
</section>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-contact-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div>
|
||||
<Typography.Title id="brand-contact-title" level={4}>
|
||||
如何联系与合作
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">
|
||||
让访客知道联系渠道、服务范围和响应预期。
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
<Row gutter={16}>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Item name="hours" label="可联系时间">
|
||||
@@ -108,8 +141,18 @@ export function BrandPage() {
|
||||
>
|
||||
<Input.TextArea rows={3} placeholder="例如:收到咨询后 1 个工作日内回复。" />
|
||||
</Form.Item>
|
||||
</Card>
|
||||
<Card title="模板与品牌视觉" style={{ marginTop: 24 }}>
|
||||
</section>
|
||||
<section className="brand-settings-section" aria-labelledby="brand-visual-title">
|
||||
<div className="brand-settings-section__header">
|
||||
<div>
|
||||
<Typography.Title id="brand-visual-title" level={4}>
|
||||
模板与品牌视觉
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">
|
||||
模板负责业务表达,品牌信息仍由你统一维护。
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
<Form.Item
|
||||
name="templateKey"
|
||||
label="业务表达模板"
|
||||
@@ -139,7 +182,7 @@ export function BrandPage() {
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</section>
|
||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||
<MutationError error={save.error} />
|
||||
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
|
||||
@@ -147,26 +190,25 @@ export function BrandPage() {
|
||||
</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
<PresentationEditor
|
||||
templateContent={workspace.data?.templateContent}
|
||||
previewWorkspace={previewWorkspace.data}
|
||||
config={brand.data.config}
|
||||
brand={brand.data}
|
||||
loading={workspace.isLoading}
|
||||
error={workspace.error}
|
||||
</div>
|
||||
{template.data ? (
|
||||
<Alert
|
||||
className="brand-page__template-note"
|
||||
type="info"
|
||||
showIcon
|
||||
message={`当前使用:${template.data.name}`}
|
||||
description={`适用场景:${template.data.serviceCategories.join("、") || "通用品牌展示"}`}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} xl={8}>
|
||||
{template.data && (
|
||||
<Card title="模板说明" style={{ marginTop: 24 }}>
|
||||
<Typography.Paragraph>{template.data.description}</Typography.Paragraph>
|
||||
<Typography.Text type="secondary">
|
||||
服务分类:{template.data.serviceCategories.join("、")}
|
||||
</Typography.Text>
|
||||
</Card>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
) : null}
|
||||
</div>
|
||||
<PresentationEditor
|
||||
templateContent={workspace.data?.templateContent}
|
||||
previewWorkspace={previewWorkspace.data}
|
||||
config={brand.data.config}
|
||||
brand={brand.data}
|
||||
loading={workspace.isLoading}
|
||||
error={workspace.error}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</QueryState>
|
||||
|
||||
@@ -133,3 +133,12 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.component-template-preview__tools[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.component-template-preview-shell:has(.component-template-preview__tools[hidden])
|
||||
.component-template-preview {
|
||||
height: 100%;
|
||||
}
|
||||
@@ -129,7 +129,11 @@ export function ComponentTemplatePreview({
|
||||
return <Alert type="warning" showIcon message="此模板尚无组件预览,请使用页面预览" />;
|
||||
return (
|
||||
<div className="component-template-preview-shell">
|
||||
<div className="component-template-preview__tools" aria-label="预览操作模式">
|
||||
<div
|
||||
className="component-template-preview__tools"
|
||||
aria-label="预览操作模式"
|
||||
hidden={!targets.length}
|
||||
>
|
||||
<button type="button" aria-pressed={mode === "edit"} onClick={() => setMode("edit")}>
|
||||
点选编辑
|
||||
</button>
|
||||
@@ -144,13 +148,13 @@ export function ComponentTemplatePreview({
|
||||
data-active-record-id={selection?.recordId}
|
||||
data-editor-mode={mode}
|
||||
onPointerMoveCapture={(event) => {
|
||||
if (mode !== "edit") return;
|
||||
if (mode !== "edit" || !targets.length) return;
|
||||
const next = targetFor(event.target instanceof Element ? event.target : null);
|
||||
if (next !== hovered) setHovered(next);
|
||||
}}
|
||||
onPointerLeave={() => setHovered(null)}
|
||||
onClickCapture={(event) => {
|
||||
if (mode !== "edit") return;
|
||||
if (mode !== "edit" || !targets.length) return;
|
||||
const canvas = root.current?.querySelector(".component-template-preview__canvas");
|
||||
if (!event.target || !(event.target instanceof Node) || !canvas?.contains(event.target))
|
||||
return;
|
||||
|
||||
@@ -16,7 +16,7 @@ export function InquiryPreviewEditor({
|
||||
fieldKey: string;
|
||||
onDraft: (fields: RuntimeInquiryForm["fields"]) => void;
|
||||
}) {
|
||||
const [form] = Form.useForm();
|
||||
const [form] = Form.useForm<Record<string, unknown>>();
|
||||
const cache = useQueryClient();
|
||||
const query = useQuery({
|
||||
queryKey: ["admin-inquiry-forms"],
|
||||
@@ -25,12 +25,10 @@ export function InquiryPreviewEditor({
|
||||
const record = query.data?.find((item) => item.id === runtime.key);
|
||||
const field = runtime.fields.find((item) => item.key === fieldKey);
|
||||
useEffect(() => {
|
||||
if (field) form.setFieldsValue(field);
|
||||
if (field) form.setFieldsValue({ ...field });
|
||||
}, [fieldKey, runtime.key, form]);
|
||||
const update = (values: Record<string, unknown>) =>
|
||||
runtime.fields.map((item) =>
|
||||
item.key === fieldKey ? ({ ...item, ...values } as typeof item) : item,
|
||||
);
|
||||
runtime.fields.map((item) => (item.key === fieldKey ? { ...item, ...values } : item));
|
||||
const save = useMutation({
|
||||
mutationFn: async (values: Record<string, unknown>) => {
|
||||
if (!record || !field) throw new Error("表单已不存在,请刷新后重试");
|
||||
@@ -71,7 +69,7 @@ export function InquiryPreviewEditor({
|
||||
);
|
||||
if (!field) return <Alert type="warning" message="字段已不存在" />;
|
||||
return (
|
||||
<Form
|
||||
<Form<Record<string, unknown>>
|
||||
form={form}
|
||||
layout="vertical"
|
||||
initialValues={field}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
.presentation-editor {
|
||||
margin-top: 40px;
|
||||
padding-top: 28px;
|
||||
border-top: 1px solid #e8e8e8;
|
||||
}
|
||||
|
||||
.presentation-editor__header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.presentation-editor__header .ant-typography {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.presentation-editor__header .ant-typography + .ant-typography {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.presentation-editor > .ant-space {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
margin-bottom: 24px !important;
|
||||
padding: 6px;
|
||||
border: 1px solid #e8e8e8;
|
||||
border-radius: 10px;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.presentation-editor__header {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.presentation-editor__header .ant-tag {
|
||||
display: inline-block;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.presentation-editor__workspace {
|
||||
margin: 0 !important;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.presentation-editor__preview {
|
||||
padding: 20px !important;
|
||||
background: #f8fafc;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.presentation-editor__inspector {
|
||||
padding: 24px !important;
|
||||
min-width: 0;
|
||||
border-left: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.presentation-editor__preview .template-preview {
|
||||
height: 680px;
|
||||
min-height: 0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.presentation-editor__regions .ant-btn {
|
||||
height: auto;
|
||||
padding: 5px 10px;
|
||||
font-size: 12px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.presentation-editor__empty {
|
||||
padding: 56px 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.presentation-editor__inspector .ant-form-item {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
.presentation-editor__inspector {
|
||||
border-left: 0;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 575px) {
|
||||
.presentation-editor__preview,
|
||||
.presentation-editor__inspector {
|
||||
padding: 12px !important;
|
||||
}
|
||||
.presentation-editor__preview .template-preview {
|
||||
height: 600px;
|
||||
}
|
||||
.presentation-editor__navigation {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Col,
|
||||
Form,
|
||||
@@ -50,6 +49,7 @@ import {
|
||||
readPresentationValue,
|
||||
type PresentationValues,
|
||||
} from "./presentation-bindings.js";
|
||||
import "./PresentationEditor.css";
|
||||
|
||||
interface PresentationEditorProps {
|
||||
templateContent: AdminTemplateContent | null | undefined;
|
||||
@@ -239,11 +239,7 @@ export function PresentationEditor({
|
||||
const visibleTargets = useMemo<PreviewTarget[]>(
|
||||
() =>
|
||||
[...(templateContent?.admin.sections ?? []), ...recordSections]
|
||||
.filter(
|
||||
(section) =>
|
||||
section.page === selectedPage &&
|
||||
!(selectedPage === "detail" && section.target === "brand"),
|
||||
)
|
||||
.filter((section) => section.page === selectedPage && selectedPage !== "detail")
|
||||
.flatMap((section) =>
|
||||
(section.previewTargets ?? []).map((target) => ({
|
||||
...target,
|
||||
@@ -536,15 +532,18 @@ export function PresentationEditor({
|
||||
: draftWorkspace?.offerings[0]?.id;
|
||||
|
||||
return (
|
||||
<Card
|
||||
title="小程序页面配置"
|
||||
extra={templateContent ? <Tag color="blue">{templateContent.displayName}</Tag> : null}
|
||||
style={{ marginTop: 32 }}
|
||||
styles={{ body: { minHeight: breakpoints.md ? 760 : 620 } }}
|
||||
>
|
||||
<Typography.Paragraph type="secondary">
|
||||
按小程序页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
|
||||
</Typography.Paragraph>
|
||||
<section className="presentation-editor" aria-labelledby="presentation-editor-title">
|
||||
<div className="presentation-editor__header">
|
||||
<div>
|
||||
<Typography.Title id="presentation-editor-title" level={3}>
|
||||
小程序页面配置
|
||||
</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
按页面查找内容。这里修改的是草稿,发布后访客才会看到更新。
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
{templateContent ? <Tag color="blue">{templateContent.displayName}</Tag> : null}
|
||||
</div>
|
||||
{loading ? <Alert type="info" showIcon message="正在读取当前模板的编辑项目" /> : null}
|
||||
{error ? (
|
||||
<Alert type="warning" showIcon message="模板编辑项目读取失败,请刷新后重试。" />
|
||||
@@ -554,7 +553,7 @@ export function PresentationEditor({
|
||||
) : null}
|
||||
{templateContent ? (
|
||||
<>
|
||||
<Space wrap style={{ marginBottom: 24 }}>
|
||||
<Space className="presentation-editor__navigation" wrap>
|
||||
{breakpoints.xs ? (
|
||||
<Select
|
||||
aria-label="选择小程序页面"
|
||||
@@ -571,8 +570,8 @@ export function PresentationEditor({
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
<Row gutter={[24, 24]} align="top">
|
||||
<Col xs={24} xl={12}>
|
||||
<Row className="presentation-editor__workspace" gutter={[24, 24]} align="top">
|
||||
<Col className="presentation-editor__preview" xs={24} lg={12}>
|
||||
<Typography.Title level={5}>页面预览</Typography.Title>
|
||||
{selectedPage === "detail" && draftWorkspace?.offerings.length ? (
|
||||
<Select
|
||||
@@ -602,7 +601,7 @@ export function PresentationEditor({
|
||||
onTargetSelected={handleTargetSelected}
|
||||
/>
|
||||
{visibleTargets.length ? (
|
||||
<Space wrap style={{ marginTop: 16 }}>
|
||||
<Space className="presentation-editor__regions" wrap style={{ marginTop: 16 }}>
|
||||
{visibleTargets.map((target) => (
|
||||
<Button
|
||||
key={target.key}
|
||||
@@ -630,7 +629,7 @@ export function PresentationEditor({
|
||||
</Space>
|
||||
) : null}
|
||||
</Col>
|
||||
<Col xs={24} xl={12}>
|
||||
<Col className="presentation-editor__inspector" xs={24} lg={12}>
|
||||
<Typography.Title level={5}>
|
||||
{selectedTarget?.label ?? pageTitle(selectedPage ?? "home")}
|
||||
</Typography.Title>
|
||||
@@ -751,6 +750,13 @@ export function PresentationEditor({
|
||||
: {})}
|
||||
/>
|
||||
)
|
||||
) : !selectedTarget ? (
|
||||
<div className="presentation-editor__empty">
|
||||
<Typography.Title level={5}>选择要编辑的区域</Typography.Title>
|
||||
<Typography.Paragraph type="secondary">
|
||||
点击预览中的内容,或使用区域列表,查看并修改对应字段。
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
) : (
|
||||
<Form
|
||||
form={form}
|
||||
@@ -863,7 +869,7 @@ export function PresentationEditor({
|
||||
</Row>
|
||||
</>
|
||||
) : null}
|
||||
</Card>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user