528 lines
21 KiB
TypeScript
528 lines
21 KiB
TypeScript
import { useState } from "react";
|
||
import { View, Text, Image, Button, Input } from "@tarojs/components";
|
||
import Taro from "@tarojs/taro";
|
||
import type { TemplateProps } from "../../../apps/taro/src/runtime/template";
|
||
import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
||
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||
import "./style.css";
|
||
const asset = (name: string) =>
|
||
`/assets/${PREVIEW_ALL_TEMPLATES ? "acheng-campus-food/" : ""}${name}`;
|
||
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||
const brand = workspace.brand;
|
||
const p = presentation(workspace, "home");
|
||
const list = workspace.offerings.map(offering).slice(0, 2);
|
||
return (
|
||
<View className="food-home">
|
||
<View className="page">
|
||
<View className="brand-card">
|
||
<View className="identity">
|
||
{text(brand.avatarUrl) && <Image src={text(brand.avatarUrl)} mode="aspectFill" />}
|
||
<View>
|
||
<Text className="name">{text(brand.founder)}</Text>
|
||
<Text className="title">{text(brand.title)}</Text>
|
||
<Text className="slogan">“{text(brand.description)}”</Text>
|
||
</View>
|
||
</View>
|
||
<View className="notice" data-editor-target="food.home.location">
|
||
<Text className="notice-title">{p.stallTitle || "服务地点"}</Text>
|
||
<Text>{text(brand.address)}</Text>
|
||
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
||
</View>
|
||
<View className="actions">
|
||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||
咨询 / 预订
|
||
</Button>
|
||
<Button className="home-action muted" onClick={() => navigate("offerings")}>
|
||
查看餐品
|
||
</Button>
|
||
</View>
|
||
</View>
|
||
<View className="scene-wrap" data-editor-target="food.home.hero">
|
||
<View className="section-head">
|
||
<Text className="eyebrow">{text(brand.name)}</Text>
|
||
</View>
|
||
{text(brand.heroImage) && (
|
||
<Image
|
||
className="scene"
|
||
src={text(brand.heroImage)}
|
||
mode="aspectFill"
|
||
onClick={() => navigate("service")}
|
||
/>
|
||
)}
|
||
</View>
|
||
<View className="section-head" data-editor-target="food.home.offerings-heading">
|
||
<View>
|
||
<Text className="eyebrow">{p.worksEyebrow || "餐品与服务"}</Text>
|
||
<Text className="heading">{p.worksTitle || "可选餐品"}</Text>
|
||
</View>
|
||
<Text className="more" onClick={() => navigate("offerings")}>
|
||
查看全部 ›
|
||
</Text>
|
||
</View>
|
||
<View className="dish-grid">
|
||
{list.map((item) => (
|
||
<View
|
||
className="dish"
|
||
key={item.id}
|
||
onClick={() => navigate("detail", { id: item.id })}
|
||
>
|
||
<Image src={item.image} mode="aspectFill" />
|
||
<View className="dish-copy">
|
||
<Text className="dish-name">{item.name}</Text>
|
||
<Text className="dish-sub">{item.desc}</Text>
|
||
<Text className="price">{item.priceRange}</Text>
|
||
</View>
|
||
</View>
|
||
))}
|
||
</View>
|
||
<View data-editor-target="food.home.promise-heading">
|
||
<Text className="heading manifesto-heading">{p.manifestoTitle}</Text>
|
||
</View>
|
||
{workspace.trustItems
|
||
.filter((item) => ["promise", "case"].includes(item.type))
|
||
.map((item) => (
|
||
<View className="promise" key={item.id}>
|
||
<Text className="eyebrow light">{item.title}</Text>
|
||
{item.summary && <Text className="promise-title">{item.summary}</Text>}
|
||
<Text className="quote">{item.content}</Text>
|
||
</View>
|
||
))}
|
||
</View>
|
||
</View>
|
||
);
|
||
}
|
||
function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
||
const schedule = slot(workspace, "schedule");
|
||
const c = slot(workspace, "coverage");
|
||
const process = slot(workspace, "process");
|
||
const p = presentation(workspace, "service");
|
||
const config = schedule?.config || {};
|
||
const scheduleRows = [
|
||
{
|
||
title: text(config.weekdayLabel),
|
||
detail: text(config.weekdayDetail),
|
||
hours: text(config.weekdayHours),
|
||
tag: text(config.weekdayTag),
|
||
tone: "orange",
|
||
},
|
||
{
|
||
title: text(config.weekendLabel),
|
||
detail: text(config.weekendDetail),
|
||
hours: text(config.weekendHours),
|
||
tag: text(config.weekendTag),
|
||
tone: "blue",
|
||
},
|
||
].filter((row) => row.title && row.detail);
|
||
const steps = rows(process?.config.steps).filter((step) => step.title && step.detail);
|
||
return (
|
||
<View className="food-service" data-editor-target="acheng-campus-food.service.service">
|
||
<View className="page service-page">
|
||
{schedule && scheduleRows.length > 0 && (
|
||
<View className="service-card schedule-card">
|
||
<View className="card-head">
|
||
<View className="head-title">
|
||
<Image className="icon" src={asset("service/clock.png")} />
|
||
<Text>{schedule.title}</Text>
|
||
</View>
|
||
{text(config.status) && <Text className="status-pill">{text(config.status)}</Text>}
|
||
</View>
|
||
{scheduleRows.map((row) => (
|
||
<View
|
||
key={row.tone}
|
||
className={`schedule ${row.tone === "blue" ? "schedule-weekend" : "schedule-primary"}`}
|
||
>
|
||
<View className="schedule-row-head">
|
||
<View className="schedule-title">
|
||
<Text className={`dot ${row.tone}`} />
|
||
<Text>{row.title}</Text>
|
||
</View>
|
||
{row.tag && (
|
||
<Text
|
||
className={`schedule-tag ${row.tone === "blue" ? "blue-tag" : "orange-tag"}`}
|
||
>
|
||
{row.tag}
|
||
</Text>
|
||
)}
|
||
</View>
|
||
<Text className="schedule-line">{row.detail}</Text>
|
||
{row.hours && <Text className="schedule-muted">{row.hours}</Text>}
|
||
</View>
|
||
))}
|
||
</View>
|
||
)}
|
||
{c && text(c.config.pickupDetail) && text(c.config.deliveryDetail) && (
|
||
<View className="service-card coverage-card">
|
||
<View className="simple-title">
|
||
<Image className="icon" src={asset("service/bike.png")} />
|
||
<Text>{c.title}</Text>
|
||
</View>
|
||
<View className="delivery-grid">
|
||
{["pickup", "delivery"].map((key) => (
|
||
<View className="delivery-item" key={key}>
|
||
<View className="delivery-title">
|
||
<Image
|
||
className="small-icon"
|
||
src={asset(
|
||
key === "pickup" ? "service/footprints.png" : "service/bike-blue.png",
|
||
)}
|
||
/>
|
||
<Text>{text(c.config[key + "Title"])}</Text>
|
||
</View>
|
||
<Text>{text(c.config[key + "Detail"])}</Text>
|
||
</View>
|
||
))}
|
||
</View>
|
||
</View>
|
||
)}
|
||
{process && steps.length > 0 && (
|
||
<View className="service-card process-card">
|
||
<View className="simple-title">
|
||
<Image className="icon" src={asset("service/list.png")} />
|
||
<Text>{process.title}</Text>
|
||
</View>
|
||
{text(process.config.intro) && (
|
||
<Text className="card-sub">{text(process.config.intro)}</Text>
|
||
)}
|
||
<View className="steps">
|
||
{steps.map((step, index) => (
|
||
<View className="step" key={index}>
|
||
<Text className="step-no">{index + 1}</Text>
|
||
<View>
|
||
<Text className="step-title">{step.title}</Text>
|
||
<Text>{step.detail}</Text>
|
||
</View>
|
||
</View>
|
||
))}
|
||
</View>
|
||
<View className="process-foot">
|
||
<View>
|
||
<Text>{text(process.config.minimumNote)}</Text>
|
||
{text(process.config.minimumNote) && text(process.config.refundNote) && (
|
||
<Text className="divider">|</Text>
|
||
)}
|
||
<Text>{text(process.config.refundNote)}</Text>
|
||
</View>
|
||
<Button className="process-action" onClick={() => navigate("inquiry")}>
|
||
{p.processAction || "立即咨询"} →
|
||
</Button>
|
||
</View>
|
||
</View>
|
||
)}
|
||
{!scheduleRows.length && !c && !steps.length && (
|
||
<View className="empty-state">出摊服务信息正在完善中</View>
|
||
)}
|
||
</View>
|
||
</View>
|
||
);
|
||
}
|
||
function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
||
const brand = workspace.brand;
|
||
const p = presentation(workspace, "profile");
|
||
const credentials = workspace.trustItems.filter((item) => item.type === "credential");
|
||
return (
|
||
<View className="food-profile" data-editor-target="acheng-campus-food.profile.identity">
|
||
<View className="page">
|
||
<View className="profile-card">
|
||
<View className="portrait">
|
||
{text(brand.avatarUrl) && <Image src={text(brand.avatarUrl)} mode="aspectFill" />}
|
||
<View className="identity">
|
||
{p.badge && <Text className="badge">{p.badge}</Text>}
|
||
<Text className="name">{text(brand.founder) || text(brand.name)}</Text>
|
||
{text(brand.title) && <Text className="title">{text(brand.title)}</Text>}
|
||
</View>
|
||
</View>
|
||
<View className="story">
|
||
{p.storyLead && <Text className="story-lead">{p.storyLead}</Text>}
|
||
{text(brand.description) && <Text className="bio">{text(brand.description)}</Text>}
|
||
{credentials.map((item) =>
|
||
rows(item.config.standards).length ? (
|
||
<View className="standards" key={item.id}>
|
||
{rows(item.config.standards).map((standard, index) => (
|
||
<View className="standard" key={index}>
|
||
<Image
|
||
className="standard-icon"
|
||
src={asset(
|
||
`owner/${["file-check", "shield-check", "sparkles"][index % 3]}.png`,
|
||
)}
|
||
/>
|
||
<Text className="standard-title">{standard.title}</Text>
|
||
<Text className="standard-detail">{standard.detail}</Text>
|
||
</View>
|
||
))}
|
||
</View>
|
||
) : (
|
||
<View className="credential-copy" key={item.id}>
|
||
<Text className="credential-title">{item.title}</Text>
|
||
{item.summary && <Text className="bio">{item.summary}</Text>}
|
||
<Text className="bio">{item.content}</Text>
|
||
</View>
|
||
),
|
||
)}
|
||
</View>
|
||
</View>
|
||
{workspace.trustItems
|
||
.filter((item) => item.type === "case")
|
||
.map((item) => (
|
||
<View className="case-card" key={item.id}>
|
||
<View className="section-heading">
|
||
<Image className="heading-icon" src={asset("owner/handshake.png")} />
|
||
<Text>{item.title}</Text>
|
||
</View>
|
||
{item.summary && <Text className="summary">{item.summary}</Text>}
|
||
{rows(item.config.entries).length ? (
|
||
<View className="case-list">
|
||
{rows(item.config.entries).map((entry, index) => (
|
||
<View className={`case-row tone-${index % 3}`} key={index}>
|
||
<View className="case-badge">{entry.badge}</View>
|
||
<View className="case-copy">
|
||
<Text className="case-title">{entry.title}</Text>
|
||
<Text className="case-detail">{entry.detail}</Text>
|
||
</View>
|
||
{entry.result && <Text className="case-result">{entry.result}</Text>}
|
||
</View>
|
||
))}
|
||
</View>
|
||
) : (
|
||
<Text className="content">{item.content}</Text>
|
||
)}
|
||
</View>
|
||
))}
|
||
{workspace.trustItems
|
||
.filter((item) => item.type === "promise")
|
||
.map((item) => (
|
||
<View className="promise-card" key={item.id}>
|
||
<View className="section-heading">
|
||
<Image className="promise-icon" src={asset("owner/clock.png")} />
|
||
<Text>{item.title}</Text>
|
||
</View>
|
||
{item.summary && <Text className="summary">{item.summary}</Text>}
|
||
{rows(item.config.commitments).length ? (
|
||
<View className="commitment-list">
|
||
{rows(item.config.commitments).map((entry, index) => (
|
||
<View className="commitment" key={index}>
|
||
<View className="dot" />
|
||
<View className="commitment-copy">
|
||
<Text className="commitment-label">{entry.label}:</Text>
|
||
<Text>{entry.detail}</Text>
|
||
{entry.highlight && <Text className="highlight">{entry.highlight}</Text>}
|
||
</View>
|
||
</View>
|
||
))}
|
||
</View>
|
||
) : (
|
||
<Text className="content">{item.content}</Text>
|
||
)}
|
||
</View>
|
||
))}
|
||
<View className="utilities">
|
||
<View className="contact-actions">
|
||
{text(brand.contactPhone) && (
|
||
<Button
|
||
onClick={() => void Taro.makePhoneCall({ phoneNumber: text(brand.contactPhone) })}
|
||
>
|
||
电话联系
|
||
</Button>
|
||
)}
|
||
{text(brand.contactWechat) && (
|
||
<Button
|
||
onClick={() => void Taro.setClipboardData({ data: text(brand.contactWechat) })}
|
||
>
|
||
复制微信
|
||
</Button>
|
||
)}
|
||
</View>
|
||
<View className="records-entry" onClick={() => navigate("records")}>
|
||
<Text>{p.recordsTitle || "我的咨询记录"}</Text>
|
||
<Text>查看记录 ›</Text>
|
||
</View>
|
||
</View>
|
||
</View>
|
||
</View>
|
||
);
|
||
}
|
||
const formTargets: Record<string, string> = {
|
||
inquiry: "acheng-campus-food.inquiry.booking",
|
||
success: "acheng-campus-food.success.successCopy",
|
||
records: "acheng-campus-food.records.recordsCopy",
|
||
};
|
||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||
if (page === "home") return <Home workspace={workspace} />;
|
||
if (page === "service") return <Service workspace={workspace} />;
|
||
if (page === "profile") return <Profile workspace={workspace} />;
|
||
if (page === "offerings") return <OfferingList workspace={workspace} />;
|
||
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
||
return (
|
||
<View className="food-forms" data-editor-target={formTargets[page]}>
|
||
{children}
|
||
</View>
|
||
);
|
||
}
|
||
function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||
const p = presentation(workspace, "offerings");
|
||
const [category, setCategory] = useState("all");
|
||
const [query, setQuery] = useState("");
|
||
const list = workspace.offerings.map(offering);
|
||
const categories = [...new Set(list.map((item) => item.category).filter(Boolean))];
|
||
const filtered = list.filter(
|
||
(item) =>
|
||
(category === "all" || item.category === category) &&
|
||
[item.name, item.desc, ...item.keywords]
|
||
.join(" ")
|
||
.toLowerCase()
|
||
.includes(query.trim().toLowerCase()),
|
||
);
|
||
return (
|
||
<View className="food-list" data-editor-target="acheng-campus-food.offerings.menu">
|
||
<View className="page">
|
||
<View className="filters">
|
||
<Button
|
||
className={category === "all" ? "filter active" : "filter"}
|
||
onClick={() => setCategory("all")}
|
||
>
|
||
全部餐品({list.length})
|
||
</Button>
|
||
{categories.map((value) => (
|
||
<Button
|
||
key={value}
|
||
className={category === value ? "filter active" : "filter"}
|
||
onClick={() => setCategory(value)}
|
||
>
|
||
{value}
|
||
</Button>
|
||
))}
|
||
</View>
|
||
<View className="menu-head">
|
||
<Text className="menu-title">{p.title || "套餐餐品"}</Text>
|
||
{p.subtitle && <Text className="subtitle">{p.subtitle}</Text>}
|
||
<Input
|
||
className="search-input"
|
||
value={query}
|
||
placeholder="搜索餐品"
|
||
onInput={(event) => setQuery(event.detail.value)}
|
||
/>
|
||
{p.menuTip && <View className="menu-tip">{p.menuTip}</View>}
|
||
</View>
|
||
<View className="menu-list">
|
||
{filtered.length ? (
|
||
filtered.map((item) => (
|
||
<View
|
||
className="offering-card"
|
||
key={item.id}
|
||
onClick={() => navigate("detail", { id: item.id })}
|
||
>
|
||
<View className="dish-media">
|
||
<Image src={item.image} mode="aspectFill" />
|
||
<Text className="dish-tag">{item.category}</Text>
|
||
</View>
|
||
<View className="offering-copy">
|
||
<Text className="dish-name">{item.name}</Text>
|
||
<Text className="subtitle">{item.desc}</Text>
|
||
<View className="dish-bottom">
|
||
<Text className="price">{item.priceRange}</Text>
|
||
<Text className="more">{p.detailAction || "查看详情 ›"}</Text>
|
||
</View>
|
||
</View>
|
||
</View>
|
||
))
|
||
) : (
|
||
<View className="empty-state">没有找到相关餐品,换个词试试</View>
|
||
)}
|
||
</View>
|
||
<Button className="menu-cta" onClick={() => navigate("inquiry")}>
|
||
咨询 / 预订
|
||
</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="food-detail" data-editor-target="acheng-campus-food.detail.dishDetail">
|
||
<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="acheng-campus-food.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((key, index) => (
|
||
<Text key={index}>{key}</Text>
|
||
))}
|
||
</View>
|
||
</View>
|
||
<View className="bar">
|
||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||
{p.inquiryAction || "咨询 / 提前预订"}
|
||
</Button>
|
||
<Text>{p.inquiryHint}</Text>
|
||
</View>
|
||
</View>
|
||
</View>
|
||
);
|
||
}
|