Files
persionalBrand/packages/template-linjing-editorial/taro/index.tsx
T

355 lines
14 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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,
offering,
presentation,
slot,
text,
rows,
} from "../../../apps/taro/src/runtime/content";
import "./style.css";
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
const b = workspace.brand;
const p = presentation(workspace, "home");
const hero = object(b.homeHero);
const credential = slot(workspace, "credential");
const t = workspace.trustPresentation;
return (
<View className="editorial-home" data-editor-target="linjing-editorial.home.home">
<View className="page">
<View className="founder-card" data-editor-target="editorial.home.identity">
{text(b.avatarUrl) && (
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
)}
<View className="founder-copy">
<Text className="founder-name">{text(b.founder)}</Text>
<Text className="founder-title">{text(b.title)}</Text>
<Text className="quote">“{text(b.description)}”</Text>
</View>
{p.founderBadge && <Text className="badge">{p.founderBadge}</Text>}
</View>
<View
className="hero"
data-editor-target="editorial.home.hero"
onClick={() => navigate("offerings")}
>
<Image className="hero-image" src={text(b.heroImage)} mode="aspectFill" />
<View className="hero-shade" />
<View className="hero-copy">
<Text className="eyebrow">{text(hero.eyebrow) || text(b.tagline)}</Text>
<Text className="hero-title">{text(hero.title) || text(b.name)}</Text>
<Text className="hero-slogan">
{text(hero.slogan) ||
text(workspace.templateData.designPhilosophy) ||
text(b.description)}
</Text>
<Text className="hero-button">{text(hero.cta) || "查看作品"}</Text>
</View>
</View>
<View className="intro" data-editor-target="editorial.home.proof">
<Text className="eyebrow dark">{p.proofEyebrow}</Text>
<Text className="section-title">{p.proofTitle}</Text>
<Text className="body">{credential?.content}</Text>
<View className="stats">
{t.stats?.map((item, index) => (
<View key={index}>
<Text className="stat-value">{item.value}</Text>
<Text className="stat-label">{item.label}</Text>
<Text className="stat-sub">{item.sub}</Text>
</View>
))}
</View>
</View>
<View className="trust" data-editor-target="editorial.home.manifesto">
<Text className="eyebrow">{p.manifestoEyebrow}</Text>
<Text className="section-title light">{p.manifestoTitle}</Text>
{t.pillars?.map((item, index) => (
<View className="pillar" key={index}>
<Text className="pillar-title">{item.title}</Text>
<Text className="pillar-desc">{item.desc}</Text>
</View>
))}
</View>
<View className="section">
<View className="section-head" data-editor-target="editorial.home.works">
<View>
<Text className="eyebrow dark">{p.worksEyebrow}</Text>
<Text className="section-title">{p.worksTitle}</Text>
</View>
<Text className="more" onClick={() => navigate("offerings")}>
{p.worksAction}
</Text>
</View>
{workspace.offerings.map(offering).map((item) => (
<View
className="work-card"
key={item.id}
onClick={() => navigate("detail", { id: item.id })}
>
<Image src={item.image} mode="aspectFill" />
<View className="work-info">
<Text className="work-category">
{item.category} · {item.area}
</Text>
<Text className="work-name">{item.name}</Text>
<Text className="work-desc">
{[item.series, ...item.keywords.slice(0, 2)].filter(Boolean).join(" · ")}
</Text>
</View>
</View>
))}
</View>
<View className="flow">
<Text className="flow-eyebrow">{p.flowEyebrow}</Text>
<Text className="flow-title">{p.flowTitle}</Text>
<View className="flow-grid">
{t.serviceFlow?.map((step, index) => (
<View className="flow-item" key={index}>
<Text className="flow-step">{step.step}</Text>
<Text className="flow-name">{step.name}</Text>
<Text className="flow-desc">{step.desc}</Text>
</View>
))}
</View>
</View>
</View>
</View>
);
}
function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
const b = workspace.brand;
const p = presentation(workspace, "profile");
const config = object(b.profilePresentation);
return (
<View
className="editorial-profile"
data-editor-target="linjing-editorial.profile.profileDetails"
>
<View className="profile">
<View className="founder-card" data-editor-target="linjing-editorial.profile.identity">
<View className="identity">
{text(b.avatarUrl) && (
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
)}
<View>
<Text className="founder">{text(b.founder)}</Text>
<Text className="role">{text(b.title)}</Text>
</View>
</View>
<View className="contact-lines">
{text(b.contactPhone) && (
<View className="contact-line">
<Text className="label">{p.phoneLabel || "电话"}</Text>
<View className="contact-action">
<Text className="value">{text(b.contactPhone)}</Text>
<Button
onClick={() => void Taro.makePhoneCall({ phoneNumber: text(b.contactPhone) })}
>
{p.callAction || "呼叫"}
</Button>
</View>
</View>
)}
{text(b.contactWechat) && (
<View className="contact-line">
<Text className="label">{p.wechatLabel || "微信"}</Text>
<View className="contact-action">
<Text className="value accent">{text(b.contactWechat)}</Text>
<Button
onClick={() => void Taro.setClipboardData({ data: text(b.contactWechat) })}
>
{p.copyAction || "复制"}
</Button>
</View>
</View>
)}
{text(b.address) && (
<View className="contact-line address">
<Text className="label">{p.addressLabel || "地址"}</Text>
<Text className="address-value">{text(b.address)}</Text>
</View>
)}
</View>
</View>
<View className="records-card" onClick={() => navigate("records")}>
<View className="entry-copy">
<Text>{p.recordsTitle || "我的咨询记录"}</Text>
<Text>{p.recordsSubtitle}</Text>
</View>
<Text>查看 ›</Text>
</View>
{rows(config.coverage).length > 0 && (
<View className="info-card">
<View className="card-title">{p.coverageTitle}</View>
{rows(config.coverage).map((item, index) => (
<View className="note" key={index}>
<Text className="note-title">{item.title}</Text>
<Text>{item.content}</Text>
</View>
))}
</View>
)}
{Array.isArray(config.warranty) && config.warranty.length > 0 && (
<View className="info-card">
<View className="card-title">{p.warrantyTitle}</View>
{config.warranty.map((item, index) => (
<View className="warranty" key={index}>
<Text className="dot">•</Text>
<Text>{text(item)}</Text>
</View>
))}
</View>
)}
{workspace.trustItems.map((item) => (
<View className="info-card trust-card" key={item.id}>
<View className="card-title">{item.title}</View>
{item.summary && <Text className="trust-summary">{item.summary}</Text>}
<Text>{item.content}</Text>
</View>
))}
</View>
</View>
);
}
function List({ workspace }: { workspace: RuntimeWorkspace }) {
const p = presentation(workspace, "offerings");
return (
<View className="editorial-list" data-editor-target="linjing-editorial.offerings.cases">
<View className="page">
<Text className="eyebrow">{p.eyebrow}</Text>
<Text className="section-title">{p.title || "作品与服务"}</Text>
<Text className="subtitle">{p.subtitle}</Text>
{workspace.offerings.map(offering).map((item) => (
<View
className="work-card"
key={item.id}
onClick={() => navigate("detail", { id: item.id })}
>
<Image src={item.image} mode="aspectFill" />
<View className="work-info">
<Text className="work-category">
{item.category} · {item.area}
</Text>
<Text className="work-name">{item.name}</Text>
<Text className="work-desc">{item.desc}</Text>
<Text className="work-price">{item.priceRange}</Text>
<Text className="more">{p.detailAction || "了解详情 →"}</Text>
</View>
</View>
))}
<Text className="subtitle">{p.closingText}</Text>
{p.closingAction && <Button onClick={() => navigate("inquiry")}>{p.closingAction}</Button>}
</View>
</View>
);
}
function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string }) {
const found = workspace.offerings.find((item) => item.id === id);
if (!found)
return (
<View className="runtime-state">
未找到该作品<Button onClick={() => navigate("offerings")}>查看作品</Button>
</View>
);
const item = offering(found);
const p = presentation(workspace, "detail");
return (
<View className="editorial-detail" data-editor-target="linjing-editorial.detail.projectDetail">
<View className="detail">
<View className="hero-wrap">
<Image
className="hero"
src={text(item.presentation.detailHero) || item.image}
mode="aspectFill"
/>
<View className="hero-shade" />
<View className="hero-copy">
<Text>
{item.category} · {item.area}
</Text>
<Text>{item.name}</Text>
<Text>{item.series}</Text>
</View>
</View>
<View className="content" data-editor-target="linjing-editorial.detail.detailCopy">
<View className="price-card">
<View>
<Text>{p.priceLabel}</Text>
<Text>{item.priceRange}</Text>
</View>
<View>
<Text>{p.spaceLabel}</Text>
<Text>{text(item.presentation.spaceType)}</Text>
</View>
</View>
<View className="detail-section">
<Text className="section-title">{p.backgroundTitle}</Text>
<Text className="body">{item.details.background || item.desc}</Text>
</View>
{item.details.designConcept && (
<View className="detail-section">
<Text className="section-title">{p.conceptTitle}</Text>
<Text className="body warm">{item.details.designConcept}</Text>
</View>
)}
{item.details.crafts.length > 0 && (
<View className="detail-section">
<Text className="section-title">{p.craftsTitle}</Text>
{item.details.crafts.map((craft, index) => (
<View className="craft" key={index}>
<Text>0{index + 1}</Text>
<Text>{craft}</Text>
</View>
))}
</View>
)}
{item.details.materialsList.length > 0 && (
<View className="detail-section">
<Text className="section-title">{p.materialsTitle}</Text>
<View className="materials">
{item.details.materialsList.map((material, index) => (
<View key={index}>
<Text>{material.name}</Text>
<Text>{material.spec}</Text>
</View>
))}
</View>
</View>
)}
<View className="chips">
{item.keywords.map((word, index) => (
<Text key={index}>{word}</Text>
))}
</View>
</View>
<View className="bar">
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
{p.inquiryAction}
</Button>
<Text>{p.inquiryHint}</Text>
</View>
</View>
</View>
);
}
const formTargets: Record<string, string> = {
inquiry: "linjing-editorial.inquiry.consultation",
success: "linjing-editorial.success.successCopy",
records: "linjing-editorial.records.recordsCopy",
};
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
if (page === "home") return <Home workspace={workspace} />;
if (page === "offerings") return <List workspace={workspace} />;
if (page === "profile" || page === "service") return <Profile workspace={workspace} />;
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
return (
<View className="editorial-forms" data-editor-target={formTargets[page]}>
{children}
</View>
);
}