统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
437 lines
17 KiB
TypeScript
437 lines
17 KiB
TypeScript
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);
|
||
const identity = object(config.identity);
|
||
const founderStatus = text(identity.status);
|
||
const founderExperience = text(identity.experience);
|
||
const b = workspace.brand;
|
||
return (
|
||
<View className="atelier-page">
|
||
<View className="atelier-founder" data-editor-target="atelier.home.identity">
|
||
{text(b.avatarUrl) ? (
|
||
<Image src={text(b.avatarUrl)} mode="aspectFill" />
|
||
) : (
|
||
<View className="atelier-monogram">{(text(b.founder) || "·").slice(0, 1)}</View>
|
||
)}
|
||
<View>
|
||
<Text className="atelier-founder-name">{text(b.founder) || "待补充主理人"}</Text>
|
||
<Text className="atelier-founder-role">
|
||
{[text(b.title), founderExperience].filter(Boolean).join(" · ")}
|
||
</Text>
|
||
<View className="atelier-tagrow">
|
||
{founderStatus && <Text className="atelier-tag atelier-tag-live">{founderStatus}</Text>}
|
||
{rows(identity.tags).map((item, index) => (
|
||
<Text className="atelier-tag" key={index}>
|
||
{item.title}
|
||
</Text>
|
||
))}
|
||
</View>
|
||
</View>
|
||
</View>
|
||
<View className="atelier-hair" />
|
||
<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.length ? (
|
||
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 className="runtime-state">
|
||
案例内容正在整理中
|
||
<InquiryAction workspace={workspace} label={p.primaryAction} />
|
||
</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>
|
||
<InquiryAction workspace={workspace} label={p.ctaAction} />
|
||
</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" data-editor-target="atelier.profile.records">
|
||
<Text className="atelier-card-title">{p.recordsTitle}</Text>
|
||
<Text className="atelier-body">{p.recordsDescription}</Text>
|
||
<Button className="atelier-records" onClick={() => navigate("records")}>
|
||
{p.recordsAction}
|
||
</Button>
|
||
</View>
|
||
<View className="atelier-card" 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>
|
||
</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 atelier-detail-facts">
|
||
<View className="atelier-detail-row">
|
||
<Text
|
||
className="atelier-detail-label"
|
||
data-editor-target="atelier-solopreneur.detail.detailCopy"
|
||
>
|
||
{p.priceLabel}
|
||
</Text>
|
||
<Text className="atelier-detail-value">{item.priceRange}</Text>
|
||
</View>
|
||
<View className="atelier-detail-row">
|
||
<Text
|
||
className="atelier-detail-label"
|
||
data-editor-target="atelier-solopreneur.detail.detailCopy"
|
||
>
|
||
{p.spaceLabel}
|
||
</Text>
|
||
<Text className="atelier-detail-value">{text(item.presentation.spaceType)}</Text>
|
||
</View>
|
||
<View className="atelier-detail-meta">
|
||
{[item.category, item.area, item.series].filter(Boolean).map((value, index) => (
|
||
<Text className="atelier-tag" key={index}>
|
||
{value}
|
||
</Text>
|
||
))}
|
||
</View>
|
||
<Text className="atelier-caption atelier-detail-keywords">
|
||
{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>
|
||
);
|
||
}
|