feat: 新增 Taro 模板双端运行与独立 Web 预览

This commit is contained in:
que01 committed 2026-10-08 15:28:26 +08:00
1 parent f4061a24bd
commit 7e8fc01fba
48 files changed
+11576 -12

No files matched your search

+8
View File
@@ -11,3 +11,11 @@ coverage/
.DS_Store
apps/miniapp/miniprogram_npm/
apps/miniapp/project.private.config.json
.worktrees/
apps/taro/src/assets/
apps/taro/test-results/
apps/taro/playwright-report/
**/.swc/
+2
View File
@@ -4,3 +4,5 @@ dist
.next
prototype
pnpm-lock.yaml
.codex-tasks/**/raw/
+5
View File
@@ -0,0 +1,5 @@
# 构建时确定模板,品牌可在 Web 中通过 ?brand=linjing-doors 选择。
TEMPLATE_KEY=acheng-campus-food
BRAND_SLUG=default-brand
API_BASE_URL=http://localhost:3001
PREVIEW_PORT=3002
+59
View File
@@ -0,0 +1,59 @@
# Taro 模板双端工程
本目录在独立迁移分支提供 Web 和微信小程序共用的 React 页面。后台、Prisma 和发布 API 不变;当前原生模板构建仍保留。
## 启动 Web
在仓库根目录执行:
```sh
pnpm install
pnpm --filter @personal-brand/types build
pnpm --filter @personal-brand/taro dev:h5
```
默认餐饮模板、default-brand、API http://localhost:3001,Web http://localhost:3002。
林境模板:
```sh
TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5
```
API 地址通过 `API_BASE_URL` 设置,品牌通过 `BRAND_SLUG` 设置。H5 也可在地址查询参数使用 `?brand=linjing-doors`,但必须与构建模板匹配。环境变量通过命令环境传入;`.env.example` 是参数说明,不自动加载真实密钥。
## 构建
```sh
pnpm --filter @personal-brand/taro build:h5
pnpm --filter @personal-brand/taro build:weapp
TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5
TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp
```
输出 `apps/taro/dist/<templateKey>/h5` 和 `weapp`。微信开发者工具导入对应 weapp 目录;正式登录需在项目配置里设置与 API 相匹配的 AppID,配置请求合法域名。默认 touristappid 仅用于浏览,不含密钥。
页面结构和样式以 React 原型为参考,当前原生小程序用于校对字段、结构化来源、认证与提交行为。模板实现位于各 package 的 `taro/`;公共请求、表单、记录和状态位于此目录。新模板须提供 manifest、Taro 实现和验收用例,不新增全局 seed。
## 使用边界
Web 支持真实已发布内容、导航、餐品搜索/分类、咨询表单填写和校验。未接入 Web 身份登录,因此没有微信会话时不会提交,不生成假咨询或伪造成功。微信小程序采用 Taro.login 和原 customer/session/wechat 接口。令牌按品牌隔离;请求失败保留表单输入,401 清理会话。
Web 与小程序来自同一套源码,H5 排版检查不等同微信原生验收。原生微信登录、拨号、剪贴板及真机排版须在微信环境最终核验。
## 验证
```sh
pnpm --filter @personal-brand/taro typecheck
pnpm --filter @personal-brand/taro lint
pnpm --filter @personal-brand/taro test
pnpm --filter @personal-brand/taro test:browser
```
浏览器测试需要先启动 API 和餐饮 H5 预览。`PREVIEW_URL` 指定预览地址,`CHROMIUM_PATH` 指定本机 Chromium;测试只读取开发库,模拟错误响应用于失败路径,不写入真实数据。
## 回滚与切换
所有工作在 feat/taro-template-preview 独立 worktree。用户确认前不合并、不切换主工作区、不修改开发数据库或原 dist/miniapp。确认后另行切换默认构建;旧 template:dev 始终可用。
Taro 4.3 官方依赖树含部分旧依赖 deprecation 和 punycode 提示,跟进负责人为框架维护者;本项目固定版本并检查双端产物。Admin React 19 与 Taro React 18 在各 workspace 依赖边界独立,避免跨端插件 peer mismatch。
+67
View File
@@ -0,0 +1,67 @@
import { defineConfig } from "@tarojs/cli";
import path from "node:path";
import fs from "node:fs";
const root = path.resolve(__dirname, "../../..");
const key = process.env.TEMPLATE_KEY || "acheng-campus-food";
const templates = fs
.readdirSync(path.join(root, "packages"))
.filter(
(directory) =>
directory.startsWith("template-") &&
fs.existsSync(path.join(root, "packages", directory, "taro/index.tsx")) &&
fs.existsSync(path.join(root, "packages", directory, "template.json")),
)
.map((directory) => directory.slice("template-".length));
if (!templates.includes(key)) throw new Error(`Unsupported Taro template: ${key}`);
const template = path.join(root, "packages", `template-${key}`);
const manifest = JSON.parse(fs.readFileSync(path.join(template, "template.json"), "utf8")) as {
packageKey: string;
defaultBrandSlug?: string;
};
if (manifest.packageKey !== key) throw new Error(`Template key mismatch: ${key}`);
const brand = process.env.BRAND_SLUG || manifest.defaultBrandSlug || "default-brand";
fs.cpSync(path.join(template, "miniapp/assets"), path.resolve(__dirname, "../src/assets"), {
recursive: true,
});
export default defineConfig({
projectName: "personal-brand-taro",
date: "2026-10-08",
designWidth: 750,
deviceRatio: { 750: 1 },
sourceRoot: "src",
outputRoot: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
framework: "react",
compiler: { type: "vite" },
plugins: [],
alias: { "@template": path.join(template, "taro") },
defineConstants: {
TEMPLATE_KEY: JSON.stringify(key),
BRAND_SLUG: JSON.stringify(brand),
API_BASE_URL: JSON.stringify(process.env.API_BASE_URL || "http://localhost:3001"),
TEMPLATE_MANIFEST: JSON.stringify(manifest),
},
copy: {
options: {},
patterns: [
...(process.env.TARO_ENV === "weapp"
? [
{
from: path.resolve(__dirname, "../project.config.json"),
to: `dist/${key}/weapp/project.config.json`,
},
]
: []),
{
from: path.join(template, "miniapp/assets"),
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
},
],
},
mini: {},
h5: {
publicPath: "/",
router: { mode: "hash" },
devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) },
},
});
+39
View File
@@ -0,0 +1,39 @@
{
"name": "@personal-brand/taro",
"private": true,
"scripts": {
"dev:h5": "taro build --type h5 --watch",
"build:h5": "taro build --type h5",
"build:weapp": "taro build --type weapp",
"typecheck": "tsc --noEmit",
"lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config packages/template-acheng-campus-food/taro packages/template-linjing-editorial/taro",
"test": "node --experimental-strip-types --test test/*.test.mjs",
"test:browser": "playwright test"
},
"dependencies": {
"@personal-brand/types": "workspace:*",
"@tarojs/components": "4.3.0",
"@tarojs/helper": "4.3.0",
"@tarojs/plugin-framework-react": "4.3.0",
"@tarojs/plugin-platform-h5": "4.3.0",
"@tarojs/plugin-platform-weapp": "4.3.0",
"@tarojs/react": "4.3.0",
"@tarojs/runtime": "4.3.0",
"@tarojs/shared": "4.3.0",
"@tarojs/taro": "4.3.0",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@tarojs/cli": "4.3.0",
"@tarojs/vite-runner": "4.3.0",
"@types/react": "18.3.18",
"@types/react-dom": "18.3.5",
"@vitejs/plugin-react": "4.7.0",
"vite": "4.5.14",
"@types/node": "^22.10.0",
"@babel/plugin-proposal-decorators": "^7.25.9",
"@babel/plugin-transform-class-properties": "^7.25.9",
"@playwright/test": "1.58.2"
}
}
+18
View File
@@ -0,0 +1,18 @@
import { defineConfig } from "@playwright/test";
export default defineConfig({
testDir: "./test/browser",
timeout: 30000,
use: {
baseURL: process.env.PREVIEW_URL || "http://localhost:3002",
viewport: { width: 375, height: 812 },
screenshot: "only-on-failure",
launchOptions: {
executablePath:
process.env.CHROMIUM_PATH ||
"/home/que01/.cache/ms-playwright/chromium-1228/chrome-linux64/chrome",
args: ["--no-sandbox"],
},
},
reporter: [["list"]],
outputDir: "../../.codex-tasks/taro-migration/raw/browser",
});
+7
View File
@@ -0,0 +1,7 @@
{
"appid": "touristappid",
"projectname": "personal-brand-taro-preview",
"compileType": "miniprogram",
"setting": { "es6": false, "minified": true, "urlCheck": true },
"description": "独立迁移分支的 Taro 小程序产物;正式登录需配置实际 AppID。"
}
+35
View File
@@ -0,0 +1,35 @@
const routes: Record<string, string> = {
home: "pages/home/index",
offerings: "pages/offerings/index",
service: "pages/service/index",
profile: "pages/profile/index",
inquiry: "pages/inquiry/index",
};
export default defineAppConfig({
pages: [
"pages/home/index",
"pages/offerings/index",
"pages/service/index",
"pages/profile/index",
"pages/inquiry/index",
"pages/detail/index",
"pages/success/index",
"pages/records/index",
],
window: {
navigationBarTitleText: TEMPLATE_MANIFEST.displayName,
navigationBarBackgroundColor: "#ffffff",
navigationBarTextStyle: "black",
},
tabBar: {
color: "#8b8178",
selectedColor: "#3b2118",
backgroundColor: "#ffffff",
list: TEMPLATE_MANIFEST.navigation.map((tab) => ({
pagePath: routes[tab.page],
text: tab.label,
iconPath: tab.iconPath,
selectedIconPath: tab.selectedIconPath,
})),
},
});
+55
View File
@@ -0,0 +1,55 @@
page {
background: #fafaf9;
}
body {
margin: 0;
}
view,
text,
image,
input,
textarea,
button {
box-sizing: border-box;
}
button::after {
border: 0;
}
image {
display: block;
}
.runtime-state {
min-height: 70vh;
padding: 80px 32px;
color: #78716c;
font-size: 28px;
text-align: center;
}
.runtime-state button {
margin-top: 24px;
}
.preview-context {
padding: 12px 32px;
color: #78716c;
background: #fff;
border-bottom: 1px solid #eee;
font-size: 22px;
}
@media (min-width: 600px) {
body {
max-width: 430px;
margin: 0 auto;
background: #e7e5e4;
}
#app {
min-height: 100vh;
background: #fafaf9;
}
}
/* postcss-pxtransform disable */
@media (min-width: 600px) {
html {
font-size: 22.933333px !important;
}
}
/* postcss-pxtransform enable */
+6
View File
@@ -0,0 +1,6 @@
import type { PropsWithChildren } from "react";
import { WorkspaceProvider } from "./runtime/workspace";
import "./app.css";
export default function App({ children }: PropsWithChildren) {
return <WorkspaceProvider>{children}</WorkspaceProvider>;
}
+206
View File
@@ -0,0 +1,206 @@
import { useEffect, useRef, useState } from "react";
import {
View,
Text,
Button,
Input,
Textarea,
Picker,
Checkbox,
CheckboxGroup,
Label,
} from "@tarojs/components";
import Taro, { useDidShow, useRouter } from "@tarojs/taro";
import type { RuntimeWorkspace, RuntimeInquiryForm } from "@personal-brand/types";
import { missingField, visibleFields, presentation } from "../runtime/content";
import type { Values } from "../runtime/content";
import { ensureSession, request, brandSlug } from "../runtime/api";
import { takeQuery, navigate } from "../runtime/navigation";
import "./forms.css";
export function Inquiry({ workspace }: { workspace: RuntimeWorkspace }) {
const router = useRouter();
const [offeringId, setOfferingId] = useState(router.params.offeringId || "");
const form: RuntimeInquiryForm | undefined =
workspace.inquiryForms.find((form) => offeringId && form.targetId === offeringId) ||
workspace.inquiryForms.find((form) => form.target === "brand");
const [values, setValues] = useState<Values>({});
const [error, setError] = useState("");
const [sending, setSending] = useState(false);
const busy = useRef(false);
const p = presentation(workspace, "inquiry");
const food = TEMPLATE_KEY === "acheng-campus-food";
useDidShow(() => {
const query = takeQuery("inquiry");
if (query.offeringId) setOfferingId(query.offeringId);
});
useEffect(() => {
setValues({});
setError("");
}, [form?.key]);
const setValue = (key: string, value: string | string[]) =>
setValues((current) => ({ ...current, [key]: value }));
async function submit() {
if (busy.current) return;
if (!form) {
setError("咨询表单暂不可用,请稍后重试");
return;
}
const missing = missingField(form.fields, values);
if (missing) {
setError("请填写" + missing.label);
return;
}
busy.current = true;
setSending(true);
setError("");
try {
await ensureSession();
const valid = Object.fromEntries(
visibleFields(form.fields, values)
.filter((field) => values[field.key] !== undefined)
.map((field) => [field.key, values[field.key]]),
);
const result = await request<{ id: string }>("/customer/inquiry-submissions", {
method: "POST",
customer: true,
data: { formId: form.key, values: valid },
});
Taro.setStorageSync(`latestInquiry:${brandSlug()}`, result);
navigate("success");
} catch (error) {
setError(error instanceof Error ? error.message : "提交失败,请重试");
} finally {
setSending(false);
busy.current = false;
}
}
return (
<View className={`inquiry-page ${food ? "food-inquiry" : "editorial-inquiry"}`}>
<View className="form-intro">
<Text className="eyebrow">{p.eyebrow}</Text>
<Text className="form-title">{p.title || "提交咨询"}</Text>
<Text className="form-subtitle">{p.subtitle}</Text>
</View>
{!form ? (
<View className="form-error">尚未配置可用的咨询表单</View>
) : (
<View className="inquiry-form">
<View className="field-grid">
{visibleFields(form.fields, values).map((field) => {
const options = field.options || [];
const value = values[field.key];
const stringValue = typeof value === "string" ? value : "";
const chips =
food && field.key === "type" && ["select", "radio"].includes(field.type);
return (
<View
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
key={field.key}
>
<Text className="field-label">
{field.label}
{field.required && <Text className="required"> *</Text>}
</Text>
{chips ? (
<View className="option-grid">
{options.map((option) => (
<Button
className={value === option.value ? "choice selected" : "choice"}
key={option.value}
onClick={() => setValue(field.key, option.value)}
>
{option.label}
</Button>
))}
</View>
) : field.type === "checkbox" ? (
<CheckboxGroup onChange={(event) => setValue(field.key, event.detail.value)}>
<View className="checkbox-options">
{options.map((option) => (
<Label className="checkbox-option" key={option.value}>
<Checkbox
value={option.value}
checked={Array.isArray(value) && value.includes(option.value)}
/>
<Text>{option.label}</Text>
</Label>
))}
</View>
</CheckboxGroup>
) : ["select", "radio"].includes(field.type) ? (
<Picker
mode="selector"
range={options.map((option) => option.label)}
value={Math.max(
0,
options.findIndex((option) => option.value === stringValue),
)}
onChange={(event) => {
const option = options[Number(event.detail.value)];
if (option) setValue(field.key, option.value);
}}
>
<View className="field-input picker-input">
{options.find((option) => option.value === stringValue)?.label || "请选择"}
<Text>⌄</Text>
</View>
</Picker>
) : field.type === "date" ? (
<Picker
mode="date"
value={stringValue}
onChange={(event) => setValue(field.key, event.detail.value)}
>
<View className="field-input picker-input">
{stringValue || "请选择日期"}
<Text>⌄</Text>
</View>
</Picker>
) : field.type === "textarea" ? (
<Textarea
className="field-input field-textarea"
value={stringValue}
placeholder={"请填写" + field.label}
onInput={(event) => setValue(field.key, event.detail.value)}
maxlength={2000}
/>
) : (
<Input
className="field-input"
type={
field.type === "number"
? "number"
: field.type === "tel"
? "number"
: "text"
}
value={stringValue}
placeholder={"请填写" + field.label}
onInput={(event) => setValue(field.key, event.detail.value)}
/>
)}
</View>
);
})}
</View>
{error && (
<View className="form-error" role="alert">
{error}
</View>
)}
<Button
className="submit-button"
disabled={sending}
loading={sending}
onClick={() => void submit()}
>
{p.submitLabel || "提交需求"}
</Button>
</View>
)}
<View className="history-link" onClick={() => navigate("records")}>
查看我的咨询记录 ›
</View>
</View>
);
}
+33
View File
@@ -0,0 +1,33 @@
import { View, Button } from "@tarojs/components";
import { useRouter } from "@tarojs/taro";
import { TemplatePage } from "@template";
import { useWorkspace } from "../runtime/workspace";
import type { PageKey } from "../runtime/navigation";
import { Inquiry } from "./Inquiry";
import { Records } from "./Records";
import { Success } from "./Success";
export function Page({ page }: { page: PageKey }) {
const { workspace, error, loading, reload } = useWorkspace();
const router = useRouter();
if (loading) return <View className="runtime-state">正在加载…</View>;
if (error || !workspace)
return (
<View className="runtime-state">
{error || "暂时无法加载"}
<Button onClick={reload}>重试</Button>
</View>
);
const children =
page === "inquiry" ? (
<Inquiry workspace={workspace} />
) : page === "records" ? (
<Records workspace={workspace} />
) : page === "success" ? (
<Success workspace={workspace} />
) : null;
return (
<TemplatePage workspace={workspace} page={page} offeringId={router.params.id}>
{children}
</TemplatePage>
);
}
+130
View File
@@ -0,0 +1,130 @@
import { useCallback, useState } from "react";
import { View, Text, Button } from "@tarojs/components";
import { useDidShow } from "@tarojs/taro";
import type { RuntimeWorkspace } from "@personal-brand/types";
import { ensureSession, hasSession, request } from "../runtime/api";
import { navigate } from "../runtime/navigation";
import { presentation } from "../runtime/content";
import "./forms.css";
type RecordItem = {
id: string;
status: string;
createdAt: string;
replyNote?: string;
inquiryForm?: { name: string };
offering?: { name: string };
fieldsSnapshot?: { key: string; label: string; options?: { label: string; value: string }[] }[];
values: Record<string, string | string[]>;
statusHistory?: { toStatus: string; createdAt: string }[];
};
const labels: Record<string, string> = {
new: "待处理",
reviewing: "沟通中",
replied: "已回复",
qualified: "已确认",
converted: "已转化",
closed: "已关闭",
};
export function Records({ workspace }: { workspace: RuntimeWorkspace }) {
const [records, setRecords] = useState<RecordItem[]>([]);
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [authenticated, setAuthenticated] = useState(hasSession());
const p = presentation(workspace, "records");
const load = useCallback(() => {
if (!hasSession()) {
setAuthenticated(false);
setRecords([]);
return;
}
setLoading(true);
setError("");
void request<RecordItem[]>("/customer/inquiry-submissions", { customer: true })
.then(setRecords)
.catch((error: unknown) => {
setError(error instanceof Error ? error.message : "加载失败");
setAuthenticated(hasSession());
})
.finally(() => setLoading(false));
}, []);
useDidShow(load);
return (
<View className="records-page">
<Text className="form-title">{p.title || "我的咨询记录"}</Text>
<Button onClick={() => navigate("inquiry")}>{p.createAction || "新增咨询"}</Button>
{loading ? (
<View className="runtime-state">正在加载…</View>
) : error ? (
<View className="form-error">
{error}
<Button onClick={load}>重试</Button>
</View>
) : !authenticated ? (
<View className="records-empty">
<Text>登录后查看你的咨询及处理进度</Text>
{process.env.TARO_ENV === "weapp" ? (
<Button
onClick={() =>
void ensureSession()
.then(() => {
setAuthenticated(true);
load();
})
.catch((error: unknown) =>
setError(error instanceof Error ? error.message : "登录失败"),
)
}
>
微信登录
</Button>
) : (
<Text className="form-subtitle">
请在微信小程序内登录查看。Web 预览不显示其他用户的记录。
</Text>
)}
</View>
) : !records.length ? (
<View className="records-empty">
<Text>{p.emptyTitle || "还没有咨询记录"}</Text>
<Text className="form-subtitle">{p.emptyDescription}</Text>
<Button onClick={() => navigate("inquiry")}>{p.emptyAction || "开始咨询"}</Button>
</View>
) : (
records.map((item) => (
<View className="record-card" key={item.id}>
<View className="record-head">
<Text>{item.inquiryForm?.name || "品牌咨询"}</Text>
<Text className="record-status">{labels[item.status] || item.status}</Text>
</View>
{item.offering && <Text className="form-subtitle">{item.offering.name}</Text>}
<Text className="record-date">{new Date(item.createdAt).toLocaleString("zh-CN")}</Text>
{(item.fieldsSnapshot || [])
.filter((field) => item.values[field.key] !== undefined)
.map((field) => {
const raw = item.values[field.key];
const value = (Array.isArray(raw) ? raw : [raw])
.map(
(value) =>
field.options?.find((option) => option.value === value)?.label || value,
)
.join("、");
return (
<View className="record-value" key={field.key}>
<Text>{field.label}</Text>
<Text>{value}</Text>
</View>
);
})}
{item.replyNote && <View className="reply-note">主理人回复:{item.replyNote}</View>}
{item.statusHistory?.map((entry, index) => (
<View className="record-history" key={index}>
{labels[entry.toStatus] || entry.toStatus} ·{" "}
{new Date(entry.createdAt).toLocaleString("zh-CN")}
</View>
))}
</View>
))
)}
</View>
);
}
+28
View File
@@ -0,0 +1,28 @@
import { View, Text, Button } from "@tarojs/components";
import Taro from "@tarojs/taro";
import type { RuntimeWorkspace } from "@personal-brand/types";
import { presentation, object, text } from "../runtime/content";
import { brandSlug } from "../runtime/api";
import { navigate } from "../runtime/navigation";
export function Success({ workspace }: { workspace: RuntimeWorkspace }) {
const p = presentation(workspace, "success");
const result = object(Taro.getStorageSync<unknown>(`latestInquiry:${brandSlug()}`));
if (!text(result.id))
return (
<View className="runtime-state">
尚未提交咨询<Button onClick={() => navigate("inquiry")}>填写需求</Button>
</View>
);
return (
<View className="success-page">
<Text className="success-symbol">✓</Text>
<Text className="eyebrow">{p.eyebrow}</Text>
<Text className="form-title">{p.title || "已收到你的需求"}</Text>
<Text className="form-subtitle">{p.intro}</Text>
<Button className="submit-button" onClick={() => navigate("records")}>
{p.recordsAction || "查看咨询记录"}
</Button>
<Button onClick={() => navigate("home")}>{p.homeAction || "返回首页"}</Button>
</View>
);
}
+205
View File
@@ -0,0 +1,205 @@
.inquiry-page,
.records-page,
.success-page {
padding: 32px;
min-height: 100vh;
background: #fafaf9;
color: #292524;
}
.form-intro {
margin: 16px 0 32px;
}
.eyebrow {
display: block;
color: #c2410c;
font-size: 20px;
letter-spacing: 3px;
}
.form-title {
display: block;
font-size: 36px;
font-weight: 700;
line-height: 1.4;
margin-top: 12px;
}
.form-subtitle {
display: block;
font-size: 24px;
line-height: 1.7;
color: #78716c;
margin-top: 12px;
}
.inquiry-form {
background: #fff;
padding: 32px;
border: 1px solid #f5f5f4;
border-radius: 36px;
}
.field-grid {
display: flex;
flex-wrap: wrap;
gap: 24px 20px;
}
.form-field {
width: 100%;
min-width: 0;
}
.half-field {
width: calc(50% - 10px);
}
.field-label {
display: block;
margin-bottom: 12px;
font-size: 24px;
font-weight: 600;
}
.required {
color: #ea580c;
}
.field-input {
display: block;
width: 100%;
height: 84px;
padding: 20px;
border: 1px solid #e7e5e4;
border-radius: 24px;
background: #fafaf9;
font-size: 24px;
}
.field-textarea {
height: 180px;
}
.picker-input {
display: flex;
align-items: center;
justify-content: space-between;
}
.option-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.choice {
margin: 0;
padding: 12px 8px;
line-height: 1.6;
background: #fafaf9;
border: 1px solid #e7e5e4;
border-radius: 24px;
font-size: 24px;
}
.choice.selected {
background: #fff7ed;
border-color: #fb923c;
color: #c2410c;
}
.checkbox-options {
display: flex;
flex-direction: column;
gap: 16px;
}
.checkbox-option {
display: flex;
align-items: center;
font-size: 24px;
}
.submit-button {
margin: 32px 0 0;
background: #f97316;
color: #fff;
border-radius: 24px;
font-size: 28px;
}
.form-error {
margin: 24px 0;
padding: 20px;
background: #fff1f2;
color: #be123c;
font-size: 24px;
line-height: 1.6;
border-radius: 16px;
}
.history-link {
text-align: center;
color: #78716c;
font-size: 24px;
margin-top: 28px;
}
.record-card {
margin-top: 24px;
padding: 28px;
background: #fff;
border-radius: 28px;
}
.record-head {
display: flex;
justify-content: space-between;
gap: 12px;
font-weight: 700;
font-size: 26px;
}
.record-status {
color: #c2410c;
font-size: 22px;
}
.record-date,
.record-history {
display: block;
color: #78716c;
font-size: 22px;
margin-top: 16px;
}
.record-value {
display: flex;
justify-content: space-between;
gap: 20px;
padding-top: 16px;
font-size: 24px;
}
.record-value text:last-child {
white-space: pre-wrap;
text-align: right;
}
.reply-note {
margin-top: 20px;
padding: 20px;
background: #fffbeb;
font-size: 24px;
line-height: 1.6;
}
.records-empty {
text-align: center;
padding: 80px 16px;
font-size: 28px;
}
.records-empty button {
margin-top: 24px;
}
.success-page {
text-align: center;
padding-top: 120px;
}
.success-symbol {
display: block;
color: #16a34a;
font-size: 80px;
margin-bottom: 24px;
}
.success-page button {
margin-top: 28px;
}
.editorial-inquiry .submit-button,
.editorial-forms .submit-button {
background: #202221;
}
.editorial-inquiry,
.editorial-forms .records-page,
.editorial-forms .success-page {
background: #f7f5f1;
}
.editorial-inquiry .eyebrow {
color: #8a6846;
}
.editorial-inquiry .form-title {
font-family: serif;
}
+18
View File
@@ -0,0 +1,18 @@
declare const TEMPLATE_KEY: string;
declare const BRAND_SLUG: string;
declare const API_BASE_URL: string;
declare const TEMPLATE_MANIFEST: {
packageKey: string;
displayName: string;
navigation: {
key: string;
label: string;
page: string;
iconPath: string;
selectedIconPath: string;
}[];
};
declare module "*.css";
declare module "@template" {
export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro";
}
+16
View File
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width,initial-scale=1,maximum-scale=1,viewport-fit=cover"
/>
<title>品牌模板预览</title>
</head>
<body>
<div id="app"></div>
<!-- prettier-ignore -->
<script><%= htmlWebpackPlugin.options.script %></script>
</body>
</html>
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="detail" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="home" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="inquiry" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="offerings" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="profile" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="records" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="service" />;
}
+4
View File
@@ -0,0 +1,4 @@
import { Page } from "../../components/Page";
export default function Screen() {
return <Page page="success" />;
}
+56
View File
@@ -0,0 +1,56 @@
import Taro from "@tarojs/taro";
import type { RuntimeWorkspace } from "@personal-brand/types";
export function brandSlug() {
if (process.env.TARO_ENV === "h5") {
const search = new URLSearchParams(window.location.search);
return search.get("brand") || BRAND_SLUG;
}
return BRAND_SLUG;
}
export const tokenKey = () => `customerToken:${brandSlug()}`;
export function hasSession() {
return Boolean(Taro.getStorageSync<string>(tokenKey()));
}
export async function request<T>(
path: string,
options: { method?: "GET" | "POST"; data?: unknown; customer?: boolean } = {},
): Promise<T> {
const context = path.startsWith("/public/") || path.startsWith("/customer/session/wechat");
const query = context
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
: "";
const response = await Taro.request<T & { error?: { message?: string; requestId?: string } }>({
url: API_BASE_URL.replace(/\/$/, "") + path + query,
method: options.method || "GET",
data: options.data,
header: {
accept: "application/json",
...(options.customer
? { Authorization: `Bearer ${Taro.getStorageSync<string>(tokenKey()) || ""}` }
: {}),
},
});
if (response.statusCode < 200 || response.statusCode >= 300) {
if (options.customer && response.statusCode === 401) Taro.removeStorageSync(tokenKey());
throw new Error(response.data?.error?.message || `请求失败(${response.statusCode})`);
}
return response.data;
}
export async function loadWorkspace() {
const data = await request<RuntimeWorkspace>("/public/workspace");
if (data.publication?.status !== "published") throw new Error("品牌尚未发布");
if (data.brand.visualTemplateKey !== TEMPLATE_KEY)
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");
return data;
}
export async function ensureSession() {
if (hasSession()) return;
if (process.env.TARO_ENV === "h5")
throw new Error("请在微信小程序中登录后提交;Web 预览可填写表单,尚未接入 Web 登录。");
const login = await Taro.login();
const session = await request<{ token: string }>("/customer/session/wechat", {
method: "POST",
data: { code: login.code },
});
Taro.setStorageSync(tokenKey(), session.token);
}
+90
View File
@@ -0,0 +1,90 @@
import type {
RuntimeOffering,
RuntimeWorkspace,
RuntimeTrustItem,
RuntimeInquiryField,
} from "@personal-brand/types";
export type Presentation = Record<string, string>;
export function text(value: unknown): string {
return typeof value === "string" ? value : "";
}
export function object(value: unknown): Record<string, unknown> {
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
}
export function rows(value: unknown): Record<string, string>[] {
return Array.isArray(value)
? value
.filter(
(item): item is Record<string, string> =>
Boolean(item) && typeof item === "object" && !Array.isArray(item),
)
.map((item) =>
Object.fromEntries(Object.entries(item).map(([key, value]) => [key, text(value)])),
)
: [];
}
export function brandText(workspace: RuntimeWorkspace, key: string) {
return text(workspace.brand[key]);
}
export function presentation(workspace: RuntimeWorkspace, page: string): Presentation {
return object(object(workspace.brand.visualPresentation)[page]) as Presentation;
}
export function slot(workspace: RuntimeWorkspace, type: string): RuntimeTrustItem | undefined {
const items = workspace.trustItems.filter((item) => item.type === type);
return items.find((item) => Object.keys(item.config).length > 0) || items[0];
}
export type Offering = RuntimeOffering & {
image: string;
desc: string;
priceRange: string;
category: string;
area: string;
series: string;
keywords: string[];
details: RuntimeOffering["presentation"]["details"];
};
export function offering(item: RuntimeOffering): Offering {
return {
...item,
image: item.presentation.heroImage || item.coverUrl || "",
desc: item.summary || "",
priceRange: item.priceText || "沟通报价",
category: item.presentation.categoryLabel,
area: text(item.presentation.area),
series: text(item.presentation.series),
keywords: item.presentation.keywords,
details: item.presentation.details,
};
}
export type Values = Record<string, string | string[]>;
export function visibleFields(fields: RuntimeInquiryField[], values: Values) {
return fields.filter((field) =>
(field.visibleWhen || []).every((rule) => {
const value = values[rule.field];
switch (rule.operator) {
case "exists":
return Array.isArray(value) ? value.length > 0 : Boolean(value);
case "equals":
return value === rule.value;
case "not-equals":
return value !== rule.value;
case "in":
return (
Array.isArray(rule.value) && typeof value === "string" && rule.value.includes(value)
);
}
}),
);
}
export function missingField(fields: RuntimeInquiryField[], values: Values) {
return visibleFields(fields, values).find(
(field) =>
field.required &&
(!values[field.key] ||
(Array.isArray(values[field.key])
? values[field.key].length === 0
: !(values[field.key] as string).trim())),
);
}
+30
View File
@@ -0,0 +1,30 @@
import Taro from "@tarojs/taro";
export const routes = {
home: "/pages/home/index",
offerings: "/pages/offerings/index",
service: "/pages/service/index",
profile: "/pages/profile/index",
inquiry: "/pages/inquiry/index",
detail: "/pages/detail/index",
success: "/pages/success/index",
records: "/pages/records/index",
};
export type PageKey = keyof typeof routes;
export function navigate(page: PageKey, params: Record<string, string> = {}) {
const isTab = TEMPLATE_MANIFEST.navigation.some((tab) => tab.page === page);
if (isTab) {
Taro.setStorageSync(`routeQuery:${page}`, params);
void Taro.switchTab({ url: routes[page] });
} else {
const query = Object.entries(params)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join("&");
void Taro.navigateTo({ url: routes[page] + (query ? "?" + query : "") });
}
}
export function takeQuery(page: PageKey): Record<string, string> {
const key = `routeQuery:${page}`;
const value = Taro.getStorageSync<Record<string, string>>(key) || {};
Taro.removeStorageSync(key);
return value;
}
+8
View File
@@ -0,0 +1,8 @@
import type { RuntimeWorkspace } from "@personal-brand/types";
import type { PageKey } from "./navigation";
export type TemplateProps = {
workspace: RuntimeWorkspace;
page: PageKey;
children?: React.ReactNode;
offeringId?: string;
};
+30
View File
@@ -0,0 +1,30 @@
import { createContext, useCallback, useContext, useEffect, useState } from "react";
import type { PropsWithChildren } from "react";
import type { RuntimeWorkspace } from "@personal-brand/types";
import { loadWorkspace } from "./api";
const Context = createContext<{
workspace?: RuntimeWorkspace;
error: string;
loading: boolean;
reload: () => void;
}>({ error: "", loading: true, reload() {} });
export function WorkspaceProvider({ children }: PropsWithChildren) {
const [workspace, setWorkspace] = useState<RuntimeWorkspace>();
const [error, setError] = useState("");
const [loading, setLoading] = useState(true);
const reload = useCallback(() => {
setLoading(true);
setError("");
void loadWorkspace()
.then(setWorkspace)
.catch((error: unknown) =>
setError(error instanceof Error ? error.message : "加载失败,请重试"),
)
.finally(() => setLoading(false));
}, []);
useEffect(reload, [reload]);
return (
<Context.Provider value={{ workspace, error, loading, reload }}>{children}</Context.Provider>
);
}
export const useWorkspace = () => useContext(Context);
+81
View File
@@ -0,0 +1,81 @@
import { test, expect } from "@playwright/test";
test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await page.goto("/");
await expect(page.locator(".food-home .name")).toContainText("阿成");
const widths = await page.locator(".scene").evaluate((element) => ({
image: element.getBoundingClientRect().width,
parent: element.parentElement!.getBoundingClientRect().width,
}));
expect(Math.abs(widths.image - widths.parent)).toBeLessThan(2);
await page.getByText("出摊服务", { exact: true }).click();
await expect(page.locator(".schedule")).toHaveCount(2);
await expect(page.locator(".delivery-item")).toHaveCount(2);
await expect(page.locator(".step")).toHaveCount(4);
await page.screenshot({
path: "../../.codex-tasks/taro-migration/raw/food-service.png",
fullPage: true,
});
await page.getByText("主理人", { exact: true }).click();
await expect(page.locator(".standard")).toHaveCount(3);
await expect(page.locator(".case-row")).toHaveCount(3);
await expect(page.locator(".commitment")).toHaveCount(2);
await page.screenshot({
path: "../../.codex-tasks/taro-migration/raw/food-profile.png",
fullPage: true,
});
expect(errors).toEqual([]);
});
test("餐品搜索、详情和咨询目标传递", async ({ page }) => {
await page.goto("/#/pages/offerings/index");
await expect(page.locator(".offering-card").first()).toBeVisible();
await page.locator("input").fill("不存在的餐品名称");
await expect(page.getByText("没有找到相关餐品,换个词试试")).toBeVisible();
await page.locator("input").fill("");
const name = await page.locator(".dish-name").first().textContent();
await page.locator(".offering-card").first().click();
await expect(page.locator(".hero-copy")).toContainText(name!);
await page.locator(".bar taro-button-core").click();
await expect(page.locator(".inquiry-form")).toBeVisible();
await expect(page.locator(".half-field")).toHaveCount(4);
});
test("失败和未登录不清空表单,不伪造提交成功", async ({ page }) => {
await page.goto("/#/pages/inquiry/index");
await expect(page.locator(".inquiry-form")).toBeVisible();
await page.locator(".submit-button").click();
await expect(page.locator(".form-error")).toContainText("请填写");
const input = page.locator("input:not([type=hidden])").last();
await input.fill("13800138000");
await page.locator(".submit-button").click();
await expect(input).toHaveValue("13800138000");
await expect(page).not.toHaveURL(/success/);
});
test("加载失败提供重试", async ({ page }) => {
await page.route("**/public/workspace**", (route) =>
route.fulfill({
status: 503,
contentType: "application/json",
body: JSON.stringify({ error: { message: "测试服务暂不可用" } }),
}),
);
await page.goto("/");
await expect(page.getByText("测试服务暂不可用")).toBeVisible();
await expect(page.getByText("重试")).toBeVisible();
});
test("林境模板使用真实品牌数据与独立路由", async ({ page }) => {
const errors: string[] = [];
page.on("pageerror", (error) => errors.push(error.message));
await page.goto("http://localhost:3003/");
await expect(page.locator(".founder-name")).toContainText("林");
await expect(page.locator(".stat-value")).toHaveCount(4);
await page.getByText("主理人与我", { exact: true }).click();
await expect(page.locator(".editorial-profile .founder")).toBeVisible();
await expect(page.locator(".trust-card").first()).toBeVisible();
await page.screenshot({
path: "../../.codex-tasks/taro-migration/raw/linjing-profile.png",
fullPage: true,
});
expect(errors).toEqual([]);
});
+24
View File
@@ -0,0 +1,24 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
const root = path.resolve(import.meta.dirname, "../../..");
for (const key of ["acheng-campus-food", "linjing-editorial"])
test(`${key} 两端产物有真实入口及模板导航`, () => {
const manifest = JSON.parse(
fs.readFileSync(path.join(root, `packages/template-${key}/template.json`)),
);
const base = path.join(root, `apps/taro/dist/${key}`);
const config = JSON.parse(fs.readFileSync(path.join(base, "weapp/app.json")));
assert.equal(config.pages.length, 8);
assert.deepEqual(
config.tabBar.list.map((item) => item.text),
manifest.navigation.map((item) => item.label),
);
for (const page of config.pages)
for (const ext of ["js", "wxml", "json"])
assert.ok(fs.existsSync(path.join(base, "weapp", `${page}.${ext}`)), `${page}.${ext}`);
assert.ok(fs.readFileSync(path.join(base, "h5/index.html"), "utf8").includes('type="module"'));
assert.ok(fs.existsSync(path.join(base, "weapp/project.config.json")));
assert.ok(fs.readFileSync(path.join(base, "weapp/common.wxss"), "utf8").length > 1000);
});
+44
View File
@@ -0,0 +1,44 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { missingField, visibleFields, slot, offering } from "../src/runtime/content.ts";
test("条件字段与空数组校验使用实际显示字段", () => {
const fields = [
{ key: "type", type: "select", label: "类型", required: true },
{
key: "choices",
type: "checkbox",
label: "选项",
required: true,
visibleWhen: [{ field: "type", operator: "equals", value: "group" }],
},
];
assert.equal(visibleFields(fields, { type: "daily" }).length, 1);
assert.equal(missingField(fields, { type: "group", choices: [] }).key, "choices");
assert.equal(missingField(fields, { type: "group", choices: ["a"] }), undefined);
});
test("结构化来源优先,详情使用公开投影", () => {
const item = slot(
{
trustItems: [
{ type: "credential", config: {}, content: "old" },
{ type: "credential", config: { standards: [] }, content: "edited" },
],
},
"credential",
);
assert.equal(item.content, "edited");
const data = offering({
id: "a",
summary: "摘要",
coverUrl: "cover",
priceText: "报价",
presentation: {
categoryLabel: "套餐",
heroImage: "hero",
keywords: [],
details: { background: "实际餐品说明" },
},
});
assert.equal(data.image, "hero");
assert.equal(data.details.background, "实际餐品说明");
});
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noEmit": true,
"types": ["node", "@tarojs/taro"],
"baseUrl": "."
},
"include": [
"src",
"config",
"../../packages/template-*/taro",
"playwright.config.ts",
"test/browser"
]
}
+23
View File
@@ -0,0 +1,23 @@
# 0019 Taro 模板双端运行时
## Context
原生 WXML/WXSS 难以在浏览器预览,自建转换器需要重复实现组件、事件和 API。客户提供的 React 原型应通过统一页面源码输出 Web 与微信小程序。
## Decision
新增 apps/taro,使用固定版本 Taro 4.3、React 18 与 Vite 4 编译器,支持 H5 和 weapp。React 18 是 Taro 当前官方插件 peer contract,独立于 Admin React 19。复用 Public Workspace 类型和模板 package manifest、图片与视觉槽位,不建立第二套后台或数据库,不维护手写 WXML 解释器。
页面实现按模板放入 package/taro,通用请求、登录、表单和记录在 apps/taro 中。模板选项在构建时校验,manifest 驱动 tab 名称和路由。H5 仅访问已发布数据;微信登录使用 Taro.login,H5 无微信身份时明确不能提交,不创建假用户或模拟成功。API 地址和品牌来自构建环境,允许 H5 以查询参数选择品牌,令牌按品牌隔离。
## Alternatives
kbone 适合 Web 运行于小程序,但引入 DOM 适配成本;uni-app 需要 Vue 重写现有 React 原型;自建模拟器持续承担不必要的兼容责任。
## Consequences
一次迁移页面和构建链路,后续同一份 React/CSS 输出两端。原生微信能力和排版仍需微信环境验收,H5 不被称作原生模拟器。TDesign 原生组件不直接用于 H5,基础表单改用 Taro 双端组件。
## Migration Plan
在 feat/taro-template-preview 和独立 worktree 完成两模板全部页面及双端构建,旧原生模板和编译器继续可用。用户确认前不切换当前分支、不替换当前 API、不改数据库、不覆盖旧 dist 产物。迁移分支以独立 preview 端口提供验收。确认后再决定默认构建切换,旧实现作为回滚基线。
+31
View File
@@ -0,0 +1,31 @@
# Taro 迁移分支验收
分支:`feat/taro-template-preview`。基线:`f4061a2`。主工作区保持 `feat/template-runtime-platform`,用户确认前不合并或切换。
## 已交付
- Taro 4.3 + React 18 共用 React/CSS 构建 Web 和微信小程序;Admin 的 React 19 独立保留。
- 餐饮:首页、餐品分类搜索、详情、出摊、主理人、咨询、成功、记录。视觉综合原 React 原型和当前小程序,数据使用同一份已发布 Public Workspace。
- 林境:首页、作品列表/详情、主理人、咨询、成功、记录。
- 模板自动发现 package 的 manifest 与 taro 实现,不新增全局 seed,不修改数据库。
- 真实表单选择、条件字段、选项 label/value、checkbox、必填校验、失败保留输入、微信登录、品牌隔离、401 清理及历史字段快照显示。
- 独立 H5 预览端口:餐饮 http://localhost:3002,林境 http://localhost:3003。
## 验证
- 两模板 H5/weapp 共 4 个 production build 通过,weapp 包含工程配置、页面与共用样式。
- Playwright 5/5:真实 API、图片容器宽度、日程/配送/流程槽位、主理人资质/案例/承诺、餐品搜索与详情到咨询、失败保留输入、错误重试、林境路由。
- 纯函数与产物契约 4/4;API integration 39/39 使用独立 schema;旧原生模板完整检查通过。
- 全量 typecheck 10/10、lint 8/8、格式检查、Admin production build 通过。
运行命令和输出路径见 [Taro README](../apps/taro/README.md)。预览是 Taro 的真实 H5 构建,不使用 WXML 转 HTML 脚本。
## 验证边界
Web 未接入微信身份登录,没有已有会话时仅支持填写与校验,明确提示在微信小程序提交,不伪造成功。默认小程序 AppID 为 touristappid,正式登录需配置实际 AppID 和合法域名。未取得本机微信 IDE 原生截图,不能把 H5 验收称为真机或像素一致验收。
现有远程图片继续使用后台实际 URL;远端不可用时不会替换成虚构素材。Taro 官方依赖的 deprecation/punycode 提示由框架维护者后续升级跟进;Admin 既有 676 kB chunk 提示由前端维护者跟进拆包。当前构建与测试通过。
## 切换
先由用户浏览新分支预览并确认,之后才切换主工作区或合并。旧 `template:dev` 和原生产配置继续作为回滚基线。
+2
View File
@@ -13,6 +13,8 @@ export default tseslint.config(
"apps/api/test/**/*.cjs",
"apps/admin/test/**/*.test.mjs",
"packages/types/test/**/*.test.mjs",
"apps/taro/test/**/*.test.mjs",
"apps/taro/src/assets/**",
"apps/miniapp/pages/**/*.js",
"apps/miniapp/app.js",
"apps/admin/vite.config.ts",
+5 -1
View File
@@ -23,7 +23,11 @@
"template:check": "pnpm validate:templates && pnpm test:template-compiler && pnpm --filter @personal-brand/miniapp test:visual-fixture",
"validate:template-release": "node scripts/validate-template-release.cjs",
"test:template-compiler": "pnpm --filter @personal-brand/template-compiler test",
"clean": "turbo run clean && rimraf node_modules .turbo"
"clean": "turbo run clean && rimraf node_modules .turbo",
"preview:food": "pnpm --filter @personal-brand/taro dev:h5",
"preview:linjing": "TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5",
"build:taro:food": "pnpm --filter @personal-brand/taro build:h5 && pnpm --filter @personal-brand/taro build:weapp",
"build:taro:linjing": "TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5 && TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
@@ -7,6 +7,19 @@
"template.json",
"miniapp",
"fixtures",
"README.md"
]
"README.md",
"taro"
],
"dependencies": {
"@tarojs/components": "4.3.0",
"@tarojs/taro": "4.3.0",
"react": "18.3.1",
"@personal-brand/types": "workspace:*",
"@tarojs/plugin-platform-weapp": "4.3.0",
"@tarojs/plugin-platform-h5": "4.3.0",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/react": "18.3.18"
}
}
@@ -0,0 +1,511 @@
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/${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">
<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 onClick={() => navigate("inquiry")}>咨询 / 预订</Button>
<Button className="muted" onClick={() => navigate("offerings")}>
查看餐品
</Button>
</View>
</View>
<View className="scene-wrap">
<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">
<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>
<Text className="heading manifesto-heading">{p.manifestoTitle}</Text>
{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">
<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 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">
<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>
);
}
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">{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">
<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">
<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">
<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>
);
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,4 @@
{
"extends": "../../apps/taro/tsconfig.json",
"include": ["taro"]
}
@@ -6,6 +6,19 @@
"files": [
"template.json",
"miniapp",
"README.md"
]
"README.md",
"taro"
],
"dependencies": {
"@tarojs/components": "4.3.0",
"@tarojs/taro": "4.3.0",
"react": "18.3.1",
"@personal-brand/types": "workspace:*",
"@tarojs/plugin-platform-weapp": "4.3.0",
"@tarojs/plugin-platform-h5": "4.3.0",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/react": "18.3.18"
}
}
@@ -0,0 +1,338 @@
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">
<View className="page">
<View className="founder-card">
{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" 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">
<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">
<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">
<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">
<View className="profile">
<View className="founder-card">
<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">
<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">
<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">
<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>
);
}
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">{children}</View>;
}
@@ -0,0 +1,707 @@
.editorial-home .page {
background: #f7f5f1;
color: #252525;
padding-bottom: 30px;
}
.editorial-home .founder-card {
position: relative;
display: flex;
gap: 20px;
align-items: flex-start;
margin: 32px 40px 20px;
padding: 28px;
border: 1px solid #e6ded5;
border-radius: 28px;
background: #fff;
}
.editorial-home .avatar {
width: 112px;
height: 112px;
flex: 0 0 112px;
border: 4px solid #d9c8b2;
border-radius: 50%;
}
.editorial-home .founder-copy {
min-width: 0;
padding-right: 78px;
}
.editorial-home .founder-name,
.editorial-home .founder-title,
.editorial-home .quote,
.editorial-home .eyebrow,
.editorial-home .hero-title,
.editorial-home .hero-slogan,
.editorial-home .section-title,
.editorial-home .body,
.editorial-home .stat-value,
.editorial-home .stat-label,
.editorial-home .stat-sub,
.editorial-home .pillar-title,
.editorial-home .pillar-desc,
.editorial-home .work-category,
.editorial-home .work-name,
.editorial-home .work-desc,
.editorial-home .flow-eyebrow,
.editorial-home .flow-title,
.editorial-home .flow-step,
.editorial-home .flow-name,
.editorial-home .flow-desc {
display: block;
}
.editorial-home .founder-name {
font: 30px serif;
}
.editorial-home .founder-title {
margin-top: 6px;
color: #77736b;
font-size: 20px;
}
.editorial-home .quote {
margin-top: 14px;
font: 21px serif;
}
.editorial-home .badge {
position: absolute;
top: 24px;
right: 20px;
padding: 8px 12px;
border-radius: 20px;
background: #f3ede6;
color: #8a6846;
font-size: 18px;
}
.editorial-home .hero {
position: relative;
height: 400px;
margin: 0 40px 42px;
overflow: hidden;
border-radius: 28px;
}
.editorial-home .hero-image {
width: 100%;
height: 100%;
}
.editorial-home .hero-shade {
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(20, 22, 21, 0.1), rgba(20, 22, 21, 0.82));
}
.editorial-home .hero-copy {
position: absolute;
right: 28px;
bottom: 28px;
left: 28px;
color: #fff;
}
.editorial-home .eyebrow {
margin-bottom: 14px;
color: #d9c8b2;
font-size: 18px;
letter-spacing: 3px;
}
.editorial-home .dark {
color: #8a6846;
}
.editorial-home .hero-title,
.editorial-home .section-title {
font: 34px serif;
}
.editorial-home .hero-slogan {
margin-top: 10px;
font-size: 21px;
}
.editorial-home .hero-button {
position: absolute;
right: 0;
bottom: 0;
padding: 12px 16px;
border: 1px solid rgba(255, 255, 255, 0.3);
color: #d9c8b2;
font-size: 19px;
}
.editorial-home .intro,
.editorial-home .section {
padding: 0 40px 48px;
}
.editorial-home .body {
color: #77736b;
font-size: 24px;
line-height: 1.8;
}
.editorial-home .stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-top: 22px;
}
.editorial-home .stats view {
padding: 22px;
border: 1px solid #e6ded5;
border-radius: 20px;
background: #fff;
}
.editorial-home .stat-value {
color: #8a6846;
font: 38px serif;
}
.editorial-home .stat-label {
margin-top: 4px;
font-size: 22px;
font-weight: 600;
}
.editorial-home .stat-sub {
margin-top: 6px;
color: #77736b;
font-size: 18px;
line-height: 1.5;
}
.editorial-home .trust {
padding: 42px 40px;
background: #202221;
color: #fff;
}
.editorial-home .light {
color: #fff;
}
.editorial-home .pillar {
margin-top: 24px;
}
.editorial-home .pillar-title {
color: #fff;
font: 28px serif;
}
.editorial-home .pillar-desc {
margin-top: 8px;
color: #c6c2ba;
font-size: 22px;
line-height: 1.65;
}
.editorial-home .section-head {
display: flex;
align-items: end;
justify-content: space-between;
margin-bottom: 22px;
}
.editorial-home .more {
color: #8a6846;
font-size: 21px;
}
.editorial-home .work-card {
margin-bottom: 24px;
overflow: hidden;
border: 1px solid #e6ded5;
border-radius: 28px;
background: #fff;
}
.editorial-home .work-card image {
width: 100%;
height: 300px;
}
.editorial-home .work-info {
padding: 24px;
}
.editorial-home .work-category {
color: #8a6846;
font-size: 19px;
}
.editorial-home .work-name {
margin: 10px 0;
font: 28px serif;
}
.editorial-home .work-desc {
color: #77736b;
font-size: 22px;
line-height: 1.6;
}
.editorial-home .flow {
margin: 0 40px 42px;
padding: 30px 24px;
border: 1px solid #e6ded5;
border-radius: 20px;
background: #efece6;
text-align: center;
}
.editorial-home .flow-eyebrow {
color: #8a6846;
font-size: 18px;
letter-spacing: 2px;
}
.editorial-home .flow-title {
margin-top: 6px;
font: 30px serif;
}
.editorial-home .flow-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-top: 24px;
text-align: left;
}
.editorial-home .flow-item {
padding: 18px;
border: 1px solid #e6ded5;
border-radius: 14px;
background: #fff;
}
.editorial-home .flow-step {
color: #8a6846;
font-size: 18px;
font-weight: 700;
}
.editorial-home .flow-name {
margin-top: 5px;
font-size: 21px;
font-weight: 600;
}
.editorial-home .flow-desc {
margin-top: 6px;
color: #77736b;
font-size: 17px;
line-height: 1.5;
}
.editorial-profile .profile {
min-height: 100vh;
padding: 0;
background: #f7f5f1;
color: #252525;
}
.editorial-profile .founder-card {
margin: 18px 28px 0;
padding: 34px 30px;
border-radius: 20px;
background: #202221;
color: #fff;
box-shadow: 0 12px 34px rgba(32, 34, 33, 0.12);
}
.editorial-profile .identity {
display: flex;
align-items: center;
gap: 22px;
}
.editorial-profile .avatar {
width: 92px;
height: 92px;
border: 2px solid #8a6846;
border-radius: 50%;
background: #343736;
}
.editorial-profile .founder,
.editorial-profile .role,
.editorial-profile .label,
.editorial-profile .value,
.editorial-profile .address-value,
.editorial-profile .entry-copy text,
.editorial-profile .entry-count text,
.editorial-profile .note-title,
.editorial-profile .note text,
.editorial-profile .warranty text {
display: block;
}
.editorial-profile .founder {
font: 34px serif;
}
.editorial-profile .role {
margin-top: 8px;
color: #d9c8b2;
font-size: 22px;
}
.editorial-profile .contact-lines {
margin-top: 24px;
border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.editorial-profile .contact-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding-top: 18px;
margin-top: 18px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
font-size: 22px;
}
.editorial-profile .contact-line:first-child {
border-top: 0;
margin-top: 0;
}
.editorial-profile .label {
flex: 0 0 auto;
color: rgba(255, 255, 255, 0.52);
}
.editorial-profile .contact-action {
display: flex;
min-width: 0;
align-items: center;
gap: 12px;
}
.editorial-profile .value {
color: #fff;
font-family: monospace;
white-space: nowrap;
}
.editorial-profile .accent {
color: #d9c8b2;
}
.editorial-profile .contact-action button {
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
min-width: 86px;
height: 46px;
margin: 0;
padding: 0 12px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.1);
color: #d9c8b2;
font-size: 20px;
line-height: 46px;
}
.editorial-profile .address {
align-items: flex-start;
}
.editorial-profile .address-value {
max-width: 410px;
color: rgba(255, 255, 255, 0.82);
line-height: 1.55;
text-align: right;
}
.editorial-profile .records-card,
.editorial-profile .info-card {
margin: 20px 28px 0;
border: 1px solid #e6ded5;
border-radius: 18px;
background: #fff;
box-shadow: 0 10px 30px -12px rgba(32, 34, 33, 0.08);
}
.editorial-profile .records-card {
display: flex;
align-items: center;
gap: 18px;
padding: 26px;
}
.editorial-profile .entry-icon {
display: flex;
align-items: center;
justify-content: center;
width: 66px;
height: 66px;
border-radius: 12px;
background: rgba(138, 104, 70, 0.1);
color: #8a6846;
}
.editorial-profile .entry-copy {
flex: 1;
min-width: 0;
}
.editorial-profile .entry-copy text:first-child {
color: #202221;
font-size: 25px;
font-weight: 600;
}
.editorial-profile .entry-copy text:last-child {
margin-top: 7px;
color: #77736b;
font-size: 20px;
line-height: 1.4;
}
.editorial-profile .entry-count {
display: flex;
align-items: center;
gap: 4px;
flex: 0 0 auto;
color: #8a6846;
font-size: 20px;
}
.editorial-profile .info-card {
padding: 28px;
}
.editorial-profile .card-title {
display: flex;
align-items: center;
gap: 12px;
color: #202221;
font-size: 26px;
font-weight: 700;
}
.editorial-profile .card-title t-icon {
color: #8a6846;
}
.editorial-profile .note {
margin-top: 18px;
padding: 20px;
border: 1px solid #e6ded5;
border-radius: 12px;
background: #f7f5f1;
color: #57534e;
font-size: 23px;
line-height: 1.7;
}
.editorial-profile .note-title {
margin-bottom: 5px;
color: #202221;
font-size: 23px;
font-weight: 700;
}
.editorial-profile .warranty {
display: flex;
gap: 10px;
margin-top: 16px;
color: #77736b;
font-size: 23px;
line-height: 1.65;
}
.editorial-profile .trust-card > text {
display: block;
color: #57534e;
font-size: 23px;
line-height: 1.65;
}
.editorial-profile .trust-card .trust-summary {
margin-bottom: 8px;
color: #202221;
font-weight: 600;
}
.editorial-profile .dot {
flex: 0 0 auto;
color: #8a6846;
}
/* 页面样式由林境模板组件提供。 */
.editorial-detail .detail {
background: #f7f5f1;
min-height: 100vh;
color: #252525;
padding-bottom: 150px;
}
.editorial-detail .hero {
width: 100%;
height: 600px;
display: block;
}
.editorial-detail .hero-wrap {
position: relative;
height: 520px;
overflow: hidden;
background: #202221;
}
.editorial-detail .hero-wrap .hero {
height: 100%;
}
.editorial-detail .hero-shade {
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.78));
}
.editorial-detail .hero-copy {
position: absolute;
right: 40px;
bottom: 32px;
left: 40px;
color: #fff;
}
.editorial-detail .hero-copy text {
display: block;
}
.editorial-detail .hero-copy text:first-child {
color: #d9c8b2;
font-size: 20px;
}
.editorial-detail .hero-copy text:nth-child(2) {
margin-top: 12px;
font: 38px serif;
}
.editorial-detail .hero-copy text:last-child {
margin-top: 8px;
color: rgba(255, 255, 255, 0.72);
font-size: 23px;
}
.editorial-detail .content {
padding: 42px 40px;
}
.editorial-detail .price-card {
display: flex;
justify-content: space-between;
gap: 24px;
padding: 26px;
border: 1px solid #e6ded5;
border-radius: 16px;
background: #fff;
}
.editorial-detail .price-card view:last-child {
text-align: right;
}
.editorial-detail .price-card text {
display: block;
}
.editorial-detail .price-card text:first-child {
color: #77736b;
font-size: 20px;
}
.editorial-detail .price-card text:last-child {
margin-top: 8px;
color: #8a6846;
font: 25px serif;
}
.editorial-detail .detail-section {
margin-top: 38px;
}
.editorial-detail .section-title {
display: block;
padding-left: 16px;
border-left: 5px solid #8a6846;
color: #202221;
font: 27px serif;
}
.editorial-detail .body {
display: block;
margin-top: 16px;
padding: 24px;
border: 1px solid #e6ded5;
border-radius: 14px;
background: #fff;
color: #252525;
font-size: 23px;
line-height: 1.8;
}
.editorial-detail .warm {
background: #efece6;
}
.editorial-detail .craft {
display: flex;
gap: 18px;
margin-top: 14px;
padding: 20px;
border: 1px solid #e6ded5;
border-radius: 12px;
background: #fff;
color: #252525;
font-size: 22px;
line-height: 1.65;
}
.editorial-detail .craft text:first-child {
flex: 0 0 auto;
color: #8a6846;
font-family: monospace;
font-weight: 700;
}
.editorial-detail .materials {
margin-top: 16px;
overflow: hidden;
border: 1px solid #e6ded5;
border-radius: 12px;
background: #fff;
}
.editorial-detail .materials view {
display: flex;
justify-content: space-between;
gap: 24px;
padding: 20px;
color: #252525;
font-size: 21px;
line-height: 1.5;
}
.editorial-detail .materials view + view {
border-top: 1px solid #e6ded5;
}
.editorial-detail .materials text:first-child {
flex: 0 0 auto;
color: #77736b;
}
.editorial-detail .materials text:last-child {
text-align: right;
}
.editorial-detail .category {
font-size: 21px;
color: #8a6846;
}
.editorial-detail .title {
display: block;
font: 46px serif;
line-height: 1.35;
margin: 18px 0 8px;
}
.editorial-detail .series {
display: block;
color: #77736b;
font-size: 26px;
}
.editorial-detail .price {
display: block;
color: #8a6846;
font-size: 30px;
margin-top: 26px;
}
.editorial-detail .desc {
display: block;
margin-top: 30px;
color: #77736b;
font-size: 27px;
line-height: 1.9;
}
.editorial-detail .chips {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin: 30px 0;
}
.editorial-detail .chips text {
border: 1px solid #c9b7a0;
color: #8a6846;
padding: 10px 18px;
font-size: 22px;
}
.editorial-detail .bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 22px 32px;
background: #f7f5f1;
}
.editorial-detail .bar button {
background: #252827;
color: #fff;
border-radius: 0;
}
.editorial-detail .bar text {
display: block;
margin-top: 10px;
color: #77736b;
text-align: center;
font-size: 19px;
}
.editorial-list .work-card {
margin-top: 32px;
background: #fff;
}
.editorial-list .work-card image {
width: 100%;
height: 420px;
}
.editorial-list .work-info {
padding: 28px;
}
.editorial-list .work-name {
display: block;
font-size: 32px;
font-family: serif;
}
.editorial-list .work-category,
.editorial-list .work-desc,
.editorial-list .work-price,
.editorial-list .more,
.editorial-list .subtitle {
display: block;
margin-top: 12px;
font-size: 24px;
color: #8a6846;
}
.editorial-profile .profile {
padding-bottom: 48px;
}
.editorial-profile .trust-card > text {
white-space: pre-wrap;
}
@@ -0,0 +1,4 @@
{
"extends": "../../apps/taro/tsconfig.json",
"include": ["taro"]
}
+7322 -7
View File
File diff suppressed because it is too large. Load diff