feat: 新增独立工坊宣传模板及配置导入验证
This commit is contained in:
1 parent
bf4bbf81c7
commit
04e42b3a80
43 files changed
+5726
-13
No files matched your search
@@ -0,0 +1,395 @@
|
||||
import { useState, cloneElement, isValidElement, type ReactNode } from "react";
|
||||
import { View, Text, Image, Button } from "@tarojs/components";
|
||||
import Taro from "@tarojs/taro";
|
||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||
import type { TemplateProps } from "../../../apps/taro/src/runtime/template";
|
||||
import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
||||
import { object, rows, text, presentation, offering } from "../../../apps/taro/src/runtime/content";
|
||||
import { inquiryPluginState } from "../../../apps/taro/src/runtime/plugins";
|
||||
import "./style.css";
|
||||
|
||||
type Props = { workspace: RuntimeWorkspace };
|
||||
function InquiryAction({ workspace, label }: Props & { label: string }) {
|
||||
const state = inquiryPluginState(workspace);
|
||||
return (
|
||||
<Button disabled={!state.enabled} onClick={() => navigate("inquiry")}>
|
||||
{state.enabled ? label : state.disabledHint || "咨询暂不可用"}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
function Home({ workspace }: Props) {
|
||||
const p = presentation(workspace, "home");
|
||||
const config = object(workspace.brand.atelier);
|
||||
return (
|
||||
<View className="atelier-page">
|
||||
<View className="atelier-intro" data-editor-target="atelier.home.intro">
|
||||
<Text className="atelier-eyebrow">{p.eyebrow}</Text>
|
||||
<Text className="atelier-title">{p.title}</Text>
|
||||
<Text className="atelier-body">{p.subtitle}</Text>
|
||||
<View className="atelier-actions">
|
||||
<InquiryAction workspace={workspace} label={p.primaryAction} />
|
||||
<Button className="atelier-secondary" onClick={() => navigate("offerings")}>
|
||||
{p.secondaryAction}
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
<View className="atelier-badges" data-editor-target="atelier.home.badges">
|
||||
{rows(config.badges).map((item, index) => (
|
||||
<Text key={index}>✓ {item.title}</Text>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.home.featuresHeading">
|
||||
<Text>{p.featuresTitle}</Text>
|
||||
<Text>{p.featuresEnglish}</Text>
|
||||
</View>
|
||||
<View className="atelier-stack" data-editor-target="atelier.home.features">
|
||||
{rows(config.features).map((item, index) => (
|
||||
<View className="atelier-card" key={index}>
|
||||
<View className="atelier-card-top">
|
||||
<Text className="atelier-number">{String(index + 1).padStart(2, "0")}</Text>
|
||||
<Text className="atelier-tag">{item.tag}</Text>
|
||||
</View>
|
||||
<Text className="atelier-card-title">{item.title}</Text>
|
||||
<Text className="atelier-body">{item.description}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.home.casesHeading">
|
||||
<View>
|
||||
<Text>{p.casesTitle}</Text>
|
||||
<Text className="atelier-caption">{p.casesSubtitle}</Text>
|
||||
</View>
|
||||
<Text>{p.caseAction}</Text>
|
||||
</View>
|
||||
<View className="atelier-cases">
|
||||
{workspace.offerings.map((item) => (
|
||||
<View
|
||||
className="atelier-case"
|
||||
key={item.id}
|
||||
data-editor-target="atelier.home.case"
|
||||
data-editor-record-id={item.id}
|
||||
onClick={() => navigate("detail", { id: item.id })}
|
||||
>
|
||||
{item.coverUrl ? (
|
||||
<Image src={item.coverUrl} mode="aspectFill" />
|
||||
) : (
|
||||
<View className="atelier-case-placeholder">
|
||||
<Text>↗</Text>
|
||||
</View>
|
||||
)}
|
||||
<View className="atelier-case-copy">
|
||||
<Text className="atelier-card-title">{item.name}</Text>
|
||||
<Text className="atelier-caption">{item.summary}</Text>
|
||||
<Text className="atelier-case-arrow">→</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.home.audienceHeading">
|
||||
<Text>{p.audienceTitle}</Text>
|
||||
<Text>{p.audienceEnglish}</Text>
|
||||
</View>
|
||||
<View className="atelier-audiences" data-editor-target="atelier.home.audiences">
|
||||
{rows(config.audiences).map((item, index) => (
|
||||
<View className="atelier-audience" key={index}>
|
||||
<Text className="atelier-symbol">{item.symbol}</Text>
|
||||
<Text>{item.title}</Text>
|
||||
<Text className="atelier-caption">{item.description}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-cta" data-editor-target="atelier.home.cta">
|
||||
<View>
|
||||
<Text className="atelier-card-title">{p.ctaTitle}</Text>
|
||||
<Text className="atelier-caption">{p.ctaSubtitle}</Text>
|
||||
</View>
|
||||
<Button onClick={() => navigate("profile")}>{p.ctaAction}</Button>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
function Services({ workspace }: Props) {
|
||||
const p = presentation(workspace, "offerings");
|
||||
const config = object(workspace.brand.atelier);
|
||||
return (
|
||||
<View className="atelier-page">
|
||||
<View className="atelier-intro" data-editor-target="atelier.offerings.intro">
|
||||
<Text className="atelier-eyebrow">{p.eyebrow}</Text>
|
||||
<Text className="atelier-title">{p.title}</Text>
|
||||
<Text className="atelier-body">{p.subtitle}</Text>
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.offerings.deliverablesHeading">
|
||||
<Text>{p.deliverablesTitle}</Text>
|
||||
<Text>{p.deliverablesEnglish}</Text>
|
||||
</View>
|
||||
<View className="atelier-stack" data-editor-target="atelier.offerings.deliverables">
|
||||
{rows(config.deliverables).map((item, index) => (
|
||||
<View className="atelier-card atelier-deliverable" key={index}>
|
||||
<Text className="atelier-number">{String(index + 1).padStart(2, "0")}</Text>
|
||||
<View>
|
||||
<View className="atelier-card-top">
|
||||
<Text className="atelier-card-title">{item.title}</Text>
|
||||
<Text className="atelier-tag">{item.tag}</Text>
|
||||
</View>
|
||||
<Text className="atelier-body">{item.description}</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.offerings.processHeading">
|
||||
<Text>{p.processTitle}</Text>
|
||||
<Text>{p.processEnglish}</Text>
|
||||
</View>
|
||||
<View className="atelier-process" data-editor-target="atelier.offerings.process">
|
||||
{rows(config.process).map((item, index) => (
|
||||
<View className="atelier-step" key={index}>
|
||||
<Text className="atelier-step-dot">{index + 1}</Text>
|
||||
<View>
|
||||
<Text className="atelier-card-title">{item.title}</Text>
|
||||
<Text className="atelier-body">{item.description}</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-heading" data-editor-target="atelier.offerings.proofHeading">
|
||||
<Text>{p.proofTitle}</Text>
|
||||
<Text>{p.proofEnglish}</Text>
|
||||
</View>
|
||||
<View className="atelier-proof" data-editor-target="atelier.offerings.proofs">
|
||||
{rows(config.proofs).map((item, index) => (
|
||||
<View className="atelier-proof-item" key={index}>
|
||||
<Text>◇</Text>
|
||||
<View>
|
||||
<Text className="atelier-card-title">{item.title}</Text>
|
||||
<Text className="atelier-body">{item.description}</Text>
|
||||
</View>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
{workspace.trustItems.map((item) => (
|
||||
<View
|
||||
className="atelier-card atelier-trust"
|
||||
key={item.id}
|
||||
data-editor-target={`trust:${item.type}`}
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<Text className="atelier-card-title">{item.title}</Text>
|
||||
<Text className="atelier-caption">{item.summary}</Text>
|
||||
<Text className="atelier-body">{item.content}</Text>
|
||||
</View>
|
||||
))}
|
||||
<View className="atelier-cta atelier-cta-large" data-editor-target="atelier.offerings.cta">
|
||||
<Text className="atelier-card-title">{p.ctaTitle}</Text>
|
||||
<Text className="atelier-body">{p.ctaSubtitle}</Text>
|
||||
<InquiryAction workspace={workspace} label={p.ctaAction} />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
function Profile({ workspace }: Props) {
|
||||
const [opened, setOpened] = useState<number | null>(null);
|
||||
const b = workspace.brand;
|
||||
const p = presentation(workspace, "profile");
|
||||
const config = object(b.atelier);
|
||||
async function copyWechat() {
|
||||
try {
|
||||
await Taro.setClipboardData({ data: text(b.contactWechat) });
|
||||
} catch {
|
||||
void Taro.showToast({ title: "复制失败,请重试", icon: "none" });
|
||||
}
|
||||
}
|
||||
return (
|
||||
<View className="atelier-page">
|
||||
<View className="atelier-intro" data-editor-target="atelier.profile.intro">
|
||||
<Text className="atelier-eyebrow">{p.eyebrow}</Text>
|
||||
<Text className="atelier-title">{p.title}</Text>
|
||||
<Text className="atelier-body">{p.subtitle}</Text>
|
||||
</View>
|
||||
<View className="atelier-card">
|
||||
<View data-editor-target="atelier.profile.identity">
|
||||
<View className="atelier-identity">
|
||||
{text(b.avatarUrl) && <Image src={text(b.avatarUrl)} mode="aspectFill" />}
|
||||
<View>
|
||||
<Text className="atelier-card-title">{text(b.founder)}</Text>
|
||||
<Text className="atelier-caption">{text(b.title)}</Text>
|
||||
</View>
|
||||
</View>
|
||||
<Text className="atelier-body atelier-bio">{text(b.description)}</Text>
|
||||
</View>
|
||||
<View data-editor-target="atelier.profile.contact">
|
||||
<InquiryAction workspace={workspace} label={`${p.inquiryAction} ${p.timeHint}`} />
|
||||
<View className="atelier-wechat">
|
||||
<View>
|
||||
<Text className="atelier-caption">{p.wechatLabel}</Text>
|
||||
<Text>{text(b.contactWechat) || p.contactHint}</Text>
|
||||
</View>
|
||||
<Button
|
||||
className="atelier-copy"
|
||||
disabled={!text(b.contactWechat)}
|
||||
onClick={() => void copyWechat()}
|
||||
>
|
||||
{p.copyAction}
|
||||
</Button>
|
||||
</View>
|
||||
<Text className="atelier-contact-note">✓ {p.promise}</Text>
|
||||
<Button className="atelier-records" onClick={() => navigate("records")}>
|
||||
{p.recordsAction}
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
<View className="atelier-faq-heading" data-editor-target="atelier.profile.faqHeading">
|
||||
<Text className="atelier-title">{p.faqTitle}</Text>
|
||||
<Text className="atelier-body">{p.faqSubtitle}</Text>
|
||||
</View>
|
||||
<View className="atelier-stack" data-editor-target="atelier.profile.faqs">
|
||||
{rows(config.faqs).map((item, index) => (
|
||||
<View className="atelier-card atelier-faq" key={index}>
|
||||
<Button
|
||||
className="atelier-question"
|
||||
onClick={() => setOpened(opened === index ? null : index)}
|
||||
aria-expanded={opened === index}
|
||||
>
|
||||
<Text className="atelier-number">{String(index + 1).padStart(2, "0")}</Text>
|
||||
<Text>{item.title}</Text>
|
||||
<Text>{opened === index ? "−" : "+"}</Text>
|
||||
</Button>
|
||||
{opened === index && (
|
||||
<Text className="atelier-body atelier-answer">{item.description}</Text>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<View className="atelier-footer" data-editor-target="atelier.profile.footer">
|
||||
<Text>{p.footerQuote}</Text>
|
||||
<Text className="atelier-caption">{p.footerNote}</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
function Detail({ workspace, id }: Props & { id?: string }) {
|
||||
const found = workspace.offerings.find((item) => item.id === id);
|
||||
const p = presentation(workspace, "detail");
|
||||
if (!found)
|
||||
return (
|
||||
<View className="runtime-state">
|
||||
未找到该案例<Button onClick={() => navigate("home")}>返回首页</Button>
|
||||
</View>
|
||||
);
|
||||
const item = offering(found);
|
||||
return (
|
||||
<View className="atelier-page">
|
||||
<View
|
||||
data-editor-target="atelier-solopreneur.detail.projectDetail"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
{item.image && (
|
||||
<Image className="atelier-detail-image" src={item.image} mode="aspectFill" />
|
||||
)}
|
||||
<Text className="atelier-title">{item.name}</Text>
|
||||
<Text className="atelier-body">{item.desc}</Text>
|
||||
</View>
|
||||
<View
|
||||
data-editor-target="atelier-solopreneur.detail.projectDetail"
|
||||
data-editor-record-id={item.id}
|
||||
>
|
||||
<View className="atelier-card">
|
||||
<Text>
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">{p.priceLabel}</Text>:
|
||||
{item.priceRange}
|
||||
</Text>
|
||||
<Text>
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">{p.spaceLabel}</Text>:
|
||||
{text(item.presentation.spaceType)}
|
||||
</Text>
|
||||
<Text>
|
||||
{item.category} {item.area} {item.series}
|
||||
</Text>
|
||||
<Text>{item.keywords.join(" · ")}</Text>
|
||||
</View>
|
||||
<Text className="atelier-heading">
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">
|
||||
{p.backgroundTitle}
|
||||
</Text>
|
||||
</Text>
|
||||
<Text className="atelier-body">{item.details.background}</Text>
|
||||
<Text className="atelier-heading">
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">{p.conceptTitle}</Text>
|
||||
</Text>
|
||||
<Text className="atelier-body">{item.details.designConcept}</Text>
|
||||
<Text className="atelier-heading">
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">{p.craftsTitle}</Text>
|
||||
</Text>
|
||||
{item.details.crafts.map((line, index) => (
|
||||
<Text className="atelier-body" key={index}>
|
||||
{line}
|
||||
</Text>
|
||||
))}
|
||||
<Text className="atelier-heading">
|
||||
<Text data-editor-target="atelier-solopreneur.detail.detailCopy">{p.materialsTitle}</Text>
|
||||
</Text>
|
||||
{item.details.materialsList.map((row, index) => (
|
||||
<Text className="atelier-body" key={index}>
|
||||
{row.name} {row.spec}
|
||||
</Text>
|
||||
))}
|
||||
</View>
|
||||
<View
|
||||
className="atelier-detail-action"
|
||||
data-editor-target="atelier-solopreneur.detail.action"
|
||||
>
|
||||
<InquiryAction workspace={workspace} label={p.inquiryAction} />
|
||||
<Text className="atelier-caption">{p.inquiryHint}</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
const formTargets: Record<string, string> = {
|
||||
inquiry: "atelier.inquiry.intro",
|
||||
success: "atelier.success.copy",
|
||||
records: "atelier.records.copy",
|
||||
};
|
||||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||||
if (page === "home")
|
||||
return (
|
||||
<View className="atelier">
|
||||
<Home workspace={workspace} />
|
||||
</View>
|
||||
);
|
||||
if (page === "offerings" || page === "service")
|
||||
return (
|
||||
<View className="atelier">
|
||||
<Services workspace={workspace} />
|
||||
</View>
|
||||
);
|
||||
if (page === "profile")
|
||||
return (
|
||||
<View className="atelier">
|
||||
<Profile workspace={workspace} />
|
||||
</View>
|
||||
);
|
||||
if (page === "detail")
|
||||
return (
|
||||
<View className="atelier">
|
||||
<Detail workspace={workspace} id={offeringId} />
|
||||
</View>
|
||||
);
|
||||
const p = presentation(workspace, "inquiry");
|
||||
const privacy = (
|
||||
<View className="atelier-privacy" data-editor-target="atelier.inquiry.privacy">
|
||||
<Text data-editor-target="atelier.inquiry.intro">{p.note}</Text>
|
||||
<Text className="atelier-card-title">{p.privacyTitle}</Text>
|
||||
<Text className="atelier-body">{p.privacyNote}</Text>
|
||||
<Text className="atelier-caption">{p.followupHint}</Text>
|
||||
</View>
|
||||
);
|
||||
const content =
|
||||
page === "inquiry" &&
|
||||
isValidElement<{ choiceStyle?: string; beforeSubmit?: ReactNode }>(children)
|
||||
? cloneElement(children, { choiceStyle: "chips", beforeSubmit: privacy })
|
||||
: children;
|
||||
return (
|
||||
<View className="atelier atelier-forms">
|
||||
<View data-editor-target={formTargets[page]}>{content}</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user