feat: 打通业务与页面编辑入口

This commit is contained in:
que01 committed 2026-10-10 17:08:19 +08:00
1 parent d0ef25cfb3
commit 20eb160abf
3 files changed
+29 -2

No files matched your search

@@ -14,6 +14,7 @@ import {
} from "antd"; } from "antd";
import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import type { import type {
Offering, Offering,
TemplateAdminField, TemplateAdminField,
@@ -41,6 +42,7 @@ export interface RecordContentEditorProps {
context: "visual" | "services"; context: "visual" | "services";
onDraft?: (values: PresentationValues) => void; onDraft?: (values: PresentationValues) => void;
onSaved?: () => void; onSaved?: () => void;
visualSelection?: { targetKey: string; page: string };
} }
function renderField(field: TemplateAdminField) { function renderField(field: TemplateAdminField) {
@@ -103,7 +105,9 @@ export function RecordContentEditor({
context, context,
onDraft, onDraft,
onSaved, onSaved,
visualSelection,
}: RecordContentEditorProps) { }: RecordContentEditorProps) {
const navigate = useNavigate();
const [form] = Form.useForm<PresentationValues>(); const [form] = Form.useForm<PresentationValues>();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const recordName = "name" in record ? record.name : record.title; const recordName = "name" in record ? record.name : record.title;
@@ -183,9 +187,26 @@ export function RecordContentEditor({
</div> </div>
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}> <Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
<MutationError error={save.error} /> <MutationError error={save.error} />
<Space wrap>
<Button type="primary" htmlType="submit" loading={save.isPending}> <Button type="primary" htmlType="submit" loading={save.isPending}>
保存此项内容 保存此项内容
</Button> </Button>
{source === "offering" ? (
<Button
htmlType="button"
onClick={() =>
navigate("/admin/brand", {
state: {
targetKey: visualSelection?.targetKey ?? "linjing-editorial.offerings.item",
recordId: record.id,
},
})
}
>
在小程序页面编辑
</Button>
) : null}
</Space>
</Space> </Space>
</Form> </Form>
); );
+5 -1
View File
@@ -14,17 +14,20 @@ import {
} from "antd"; } from "antd";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useState } from "react"; import { useState } from "react";
import { Link } from "react-router-dom"; import { Link, useLocation } from "react-router-dom";
import type { BrandProfile } from "@personal-brand/api-client"; import type { BrandProfile } from "@personal-brand/api-client";
import { createApiClient } from "../../lib/api.js"; import { createApiClient } from "../../lib/api.js";
import { AdminPageHeader } from "../../components/AdminPageHeader.js"; import { AdminPageHeader } from "../../components/AdminPageHeader.js";
import { ImageUrlField } from "../../components/ImageUrlField.js"; import { ImageUrlField } from "../../components/ImageUrlField.js";
import { MutationError, QueryState } from "../../components/QueryState.js"; import { MutationError, QueryState } from "../../components/QueryState.js";
import { PresentationEditor } from "./PresentationEditor.js"; import { PresentationEditor } from "./PresentationEditor.js";
import type { PreviewSelection } from "./preview-selection.js";
import "./BrandPage.css"; import "./BrandPage.css";
import { useEditorDraft } from "./use-editor-draft.js"; import { useEditorDraft } from "./use-editor-draft.js";
export function BrandPage() { export function BrandPage() {
const location = useLocation();
const initialSelection = location.state as PreviewSelection | undefined;
const [panel, setPanel] = useState("pages"); const [panel, setPanel] = useState("pages");
const [dirty, setDirty] = useState(false); const [dirty, setDirty] = useState(false);
useEditorDraft(dirty); useEditorDraft(dirty);
@@ -236,6 +239,7 @@ export function BrandPage() {
brand={brand.data} brand={brand.data}
loading={workspace.isLoading} loading={workspace.isLoading}
error={workspace.error} error={workspace.error}
{...(initialSelection ? { initialSelection } : {})}
/> />
</div> </div>
</> </>
@@ -59,6 +59,7 @@ interface PresentationEditorProps {
brand: BrandProfile; brand: BrandProfile;
loading?: boolean; loading?: boolean;
error?: unknown; error?: unknown;
initialSelection?: PreviewSelection;
} }
function trustSection( function trustSection(
@@ -174,13 +175,14 @@ export function PresentationEditor({
brand, brand,
loading, loading,
error, error,
initialSelection,
}: PresentationEditorProps) { }: PresentationEditorProps) {
const [form] = Form.useForm<PresentationValues>(); const [form] = Form.useForm<PresentationValues>();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const navigate = useNavigate(); const navigate = useNavigate();
const breakpoints = Grid.useBreakpoint(); const breakpoints = Grid.useBreakpoint();
const [activePage, setActivePage] = useState<string>(); const [activePage, setActivePage] = useState<string>();
const [selection, setSelection] = useState<PreviewSelection>(); const [selection, setSelection] = useState<PreviewSelection | undefined>(initialSelection);
const [detailOfferingId, setDetailOfferingId] = useState<string>(); const [detailOfferingId, setDetailOfferingId] = useState<string>();
const [recordDraft, setRecordDraft] = useState<{ const [recordDraft, setRecordDraft] = useState<{
source: "offering" | "trust"; source: "offering" | "trust";