refactor: 重构模板叠加式编译产物
This commit is contained in:
1 parent
c46297b13b
commit
25d1fe983c
93 files changed
+855
-2452
No files matched your search
@@ -0,0 +1,23 @@
|
||||
# 模板构建时叠加平台
|
||||
|
||||
## 目标
|
||||
|
||||
将 `template:dev` 收敛为运行时层、能力包、模板包三层叠加编译,产出可直接被微信开发者工具打开的完整小程序。运行时不携带任何行业或具体模板代码,新增行业模板只需新增模板包。
|
||||
|
||||
## 范围
|
||||
|
||||
- 运行时壳清理与品牌构建参数注入。
|
||||
- `template-contract` manifest 契约及 compiler 冲突校验。
|
||||
- `capability-booking` 小程序页面迁移。
|
||||
- 阿成、林境模板页面和资产包化。
|
||||
- 编译产物校验、第二行业 fixture、文档与门禁。
|
||||
|
||||
## 不在范围
|
||||
|
||||
- 后端 Booking capability 化。
|
||||
- 后台视觉模板切换、历史和回滚。
|
||||
- 微信第三方平台、`ext.json` 和订单通知。
|
||||
|
||||
## 验收
|
||||
|
||||
阿成和林境模板均可独立编译;产物页面、组件、`require`、tab 图标、品牌参数均通过自动校验;运行时目录不含模板专属代码;`pnpm check`、模板校验和 compiler 测试通过。
|
||||
@@ -0,0 +1,26 @@
|
||||
# 执行记录
|
||||
|
||||
## 当前状态
|
||||
|
||||
本轮从既有未提交改动继续。叠加式 compiler 已可将 runtime、capability、template 编译成独立产物;`booking` 页面已迁入 capability 包;runtime 模板页面、模板组件和 tab 资产已移除。
|
||||
|
||||
## 已验证
|
||||
|
||||
- `acheng-campus-food` 编译成功。
|
||||
- `linjing-editorial` 编译成功。
|
||||
- compiler 已支持解析 `miniprogram_npm` 中的 TDesign 组件引用。
|
||||
- 顶层 `templates/` 镜像已删除,模板目录校验统一读取 `packages/template-*`。
|
||||
- `pnpm lint`、`pnpm typecheck`、模板 compiler 测试、模板契约测试和 miniapp fixture 均通过。
|
||||
|
||||
## 待办
|
||||
|
||||
- 更新 template catalog。
|
||||
- 修正并扩展 compiler 测试和 fixture。
|
||||
- 完成 runtime/template grep、typecheck、format、miniapp fixture 门禁。
|
||||
- 补齐 ADR、README 和新增模板说明。
|
||||
- `pnpm format:check` 全仓仍会报告已有 `.claude/settings.local.json`,该文件不属于本任务且未修改。
|
||||
|
||||
## 失败记录
|
||||
|
||||
- 初次编译因 `capability-booking/miniapp` 缺失而失败,已迁移页面解决。
|
||||
- 初次林境编译因 runtime tab 资产和模板资产冲突而失败,已将 tab 资产归属模板并清理 runtime。
|
||||
@@ -0,0 +1,6 @@
|
||||
id,title,status,depends_on,validation,notes
|
||||
1,完成叠加式契约与编译器,DONE,,pnpm test:template-compiler,阿成和林境编译及错误场景测试通过
|
||||
2,清理运行时模板代码与资源,DONE,1,rg -n 'acheng|linjing|pageRenderer|templateKey ===' apps/miniapp,运行时生产目录无模板专属代码
|
||||
3,迁移 booking 能力包,DONE,1,node packages/template-compiler/src/cli.mjs --template acheng-campus-food,
|
||||
4,完善两个模板包页面与资产,DONE,1;2,node packages/template-compiler/src/cli.mjs --template linjing-editorial,林境页面和 tab 资源已迁移并编译通过
|
||||
5,补齐测试、演练模板和文档,IN_PROGRESS,1;2;3;4,pnpm check,编译器测试、模板校验、fixture、lint、typecheck 通过;format 全仓受既有 settings 文件阻塞
|
||||
|
@@ -12,6 +12,9 @@ packages/types # 共享类型
|
||||
packages/api-client
|
||||
packages/validation
|
||||
packages/config
|
||||
packages/template-compiler # 构建时叠加 runtime、capability、template
|
||||
packages/template-<key> # 独立行业 / 视觉模板包
|
||||
packages/capability-<key> # 可选业务流程能力包
|
||||
prisma/
|
||||
docs/
|
||||
prototype/
|
||||
@@ -29,6 +32,17 @@ pnpm install
|
||||
pnpm check
|
||||
```
|
||||
|
||||
## 生成小程序模板
|
||||
|
||||
`apps/miniapp` 是运行时壳,不能直接作为完整小程序打开。使用模板编译器生成产物:
|
||||
|
||||
```bash
|
||||
pnpm template:dev acheng-campus-food --brand default-brand
|
||||
pnpm template:dev linjing-editorial --brand linjing-doors
|
||||
```
|
||||
|
||||
产物位于 `dist/miniapp/<brand>/`,可直接用微信开发者工具打开。生产构建需额外提供 `--appid`、`--api https://...` 和 `--env prod`。
|
||||
|
||||
## 本地数据库
|
||||
|
||||
在有 Docker 的机器上执行:
|
||||
|
||||
@@ -279,10 +279,7 @@ export class PublicWorkspaceController {
|
||||
templatePackageManifest?.navigation.map((tab) => ({
|
||||
key: tab.key,
|
||||
label: tab.label,
|
||||
page:
|
||||
templatePackageManifest.entrypoints[
|
||||
tab.page as keyof typeof templatePackageManifest.entrypoints
|
||||
] ?? tab.page,
|
||||
page: templatePackageManifest.entrypoints[tab.page] ?? tab.page,
|
||||
})) ?? [],
|
||||
},
|
||||
modules: runtimeModules,
|
||||
|
||||
+9
-4
@@ -1,11 +1,16 @@
|
||||
const DEFAULT_API_BASE_URL = "http://localhost:3001";
|
||||
const DEFAULT_BRAND_SLUG = "default-brand";
|
||||
const runtimeConfig = require("./runtime-config");
|
||||
|
||||
// 仅开发构建允许用本地 storage 覆盖 API 地址和品牌,便于局域网真机调试。
|
||||
function devOverride(key) {
|
||||
return runtimeConfig.env === "dev" ? wx.getStorageSync(key) : "";
|
||||
}
|
||||
|
||||
App({
|
||||
onLaunch() {
|
||||
this.globalData = {
|
||||
apiBaseUrl: wx.getStorageSync("apiBaseUrl") || DEFAULT_API_BASE_URL,
|
||||
brandSlug: wx.getStorageSync("brandSlug") || DEFAULT_BRAND_SLUG,
|
||||
apiBaseUrl: devOverride("apiBaseUrl") || runtimeConfig.apiBaseUrl,
|
||||
brandSlug: devOverride("brandSlug") || runtimeConfig.brandSlug,
|
||||
templateKey: runtimeConfig.templateKey,
|
||||
brand: {},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/services/index",
|
||||
"pages/stall-service/index",
|
||||
"pages/booking/index",
|
||||
"pages/bookings/index",
|
||||
"pages/offering/detail",
|
||||
"pages/inquiry/index",
|
||||
"pages/inquiry-success/index",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1022 B |
Binary file not shown.
|
Before Width: | Height: | Size: 794 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 769 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 913 B |
@@ -1,33 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
active: { type: String, value: "home" },
|
||||
navigation: { type: Array, value: [] },
|
||||
},
|
||||
data: {
|
||||
tabs: [],
|
||||
},
|
||||
methods: {
|
||||
navigate(e) {
|
||||
const tab = e.currentTarget.dataset.tab;
|
||||
if (!tab || tab.key === this.data.active) return;
|
||||
wx.navigateTo({ url: tab.page });
|
||||
},
|
||||
},
|
||||
observers: {
|
||||
navigation(navigation) {
|
||||
this.setData({
|
||||
tabs: Array.isArray(navigation)
|
||||
? navigation.map((item) => ({
|
||||
...item,
|
||||
page: item.page && item.page.startsWith("/") ? item.page : `/${item.page || ""}`,
|
||||
}))
|
||||
: [],
|
||||
});
|
||||
},
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
this.setData({ tabs: this.data.navigation || [] });
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
{ "component": true }
|
||||
@@ -1 +0,0 @@
|
||||
<view class="runtime-tab-bar"><view wx:for="{{tabs}}" wx:key="key" class="tab {{active === item.key ? 'active' : ''}}" data-tab="{{item}}" bindtap="navigate"><text class="icon">{{item.key === 'home' ? '⌂' : item.key === 'dishes' ? '♨' : item.key === 'service' ? '⌖' : item.key === 'owner' ? '♙' : item.key === 'booking' ? '✉' : '◈'}}</text><text>{{item.label}}</text></view></view>
|
||||
@@ -1,32 +0,0 @@
|
||||
.runtime-tab-bar {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
padding: 10rpx 6rpx calc(10rpx + env(safe-area-inset-bottom));
|
||||
border-top: 1rpx solid #eee5dc;
|
||||
background: rgba(255, 255, 255, 0.97);
|
||||
box-shadow: 0 -8rpx 24rpx rgba(48, 32, 20, 0.08);
|
||||
}
|
||||
.tab {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4rpx;
|
||||
color: #9a8d83;
|
||||
font-size: 19rpx;
|
||||
}
|
||||
.icon {
|
||||
height: 34rpx;
|
||||
font-size: 31rpx;
|
||||
line-height: 34rpx;
|
||||
}
|
||||
.tab.active {
|
||||
color: #e87532;
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
brand: { type: Object, value: {} },
|
||||
presentation: { type: Object, value: {} },
|
||||
trustContent: { type: Object, value: {} },
|
||||
offerings: { type: Array, value: [] },
|
||||
},
|
||||
methods: {
|
||||
openOffering(e) {
|
||||
this.triggerEvent("select", { id: e.currentTarget.dataset.id });
|
||||
},
|
||||
openInquiry() {
|
||||
this.triggerEvent("inquiry");
|
||||
},
|
||||
openOfferings() {
|
||||
this.triggerEvent("offerings");
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
{ "component": true }
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view class="brand-card"><view class="identity"><image src="{{brand.avatarUrl}}" mode="aspectFill"/><view><text class="name">{{brand.founder}}</text><text class="title">{{brand.title}}</text><text class="slogan">“{{brand.slogan}}”</text></view></view><view class="notice"><text class="notice-title">{{presentation.stallTitle || '今日出摊点'}}</text><text>{{brand.studioAddress || brand.address}}</text><text class="notice-time">{{presentation.stallTime || '今日营业中'}}</text></view><view class="actions"><button bindtap="openInquiry">预约 / 定制</button><button class="muted" bindtap="openOfferings">今日菜单</button></view></view><view class="section-head"><view><text class="eyebrow">{{presentation.worksEyebrow || '本周学生票选招牌'}}</text><text class="heading">{{presentation.worksTitle || '现做现吃,认真管饱'}}</text></view><text class="more" bindtap="openOfferings">全部餐品 ›</text></view><view class="dish-grid"><view wx:for="{{offerings}}" wx:key="id" class="dish" data-id="{{item.id}}" bindtap="openOffering"><image src="{{item.image}}" mode="aspectFill"/><view class="dish-copy"><text class="dish-name">{{item.name}}</text><text class="dish-sub">{{item.desc}}</text><text class="price">{{item.priceRange}}</text></view></view></view><view class="promise"><text class="eyebrow light">{{presentation.manifestoEyebrow || '阿成的开档底线'}}</text><text class="promise-title">{{presentation.manifestoTitle || '真材实料,当天现做'}}</text><view wx:for="{{trustContent.pillars}}" wx:key="title" class="promise-item"><text>✓</text><text>{{item.title}}</text></view></view></view>
|
||||
@@ -1,177 +0,0 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 20rpx 28rpx 48rpx;
|
||||
background: #fff8f0;
|
||||
color: #29231f;
|
||||
}
|
||||
.brand-card {
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #f2d9c6;
|
||||
border-radius: 28rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 12rpx 30rpx rgba(145, 75, 33, 0.08);
|
||||
}
|
||||
.identity {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
align-items: center;
|
||||
}
|
||||
.identity image {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border: 4rpx solid #ffd9bb;
|
||||
border-radius: 50%;
|
||||
background: #fff1e5;
|
||||
}
|
||||
.name,
|
||||
.title,
|
||||
.slogan,
|
||||
.notice-title,
|
||||
.notice text,
|
||||
.eyebrow,
|
||||
.heading,
|
||||
.more,
|
||||
.dish-name,
|
||||
.dish-sub,
|
||||
.price,
|
||||
.promise-title,
|
||||
.promise-item text {
|
||||
display: block;
|
||||
}
|
||||
.name {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.title {
|
||||
margin-top: 6rpx;
|
||||
color: #a2613b;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.slogan {
|
||||
margin-top: 10rpx;
|
||||
color: #7a6a60;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.notice {
|
||||
position: relative;
|
||||
margin-top: 24rpx;
|
||||
padding: 20rpx;
|
||||
border: 1rpx solid #f8d7b4;
|
||||
border-radius: 20rpx;
|
||||
background: #fff7df;
|
||||
color: #6b4a35;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.notice-title {
|
||||
font-weight: 700;
|
||||
color: #4f3020;
|
||||
}
|
||||
.notice-time {
|
||||
position: absolute;
|
||||
right: 18rpx;
|
||||
top: 18rpx;
|
||||
color: #c65c28;
|
||||
font-size: 19rpx;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
.actions button {
|
||||
flex: 1;
|
||||
height: 76rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #e87532;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
line-height: 76rpx;
|
||||
}
|
||||
.actions .muted {
|
||||
background: #fff0e5;
|
||||
color: #b85e2c;
|
||||
}
|
||||
.section-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: end;
|
||||
margin: 34rpx 4rpx 18rpx;
|
||||
}
|
||||
.eyebrow {
|
||||
color: #d2652b;
|
||||
font-size: 19rpx;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
.heading {
|
||||
margin-top: 8rpx;
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.more {
|
||||
color: #d2652b;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.dish-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16rpx;
|
||||
}
|
||||
.dish {
|
||||
overflow: hidden;
|
||||
border: 1rpx solid #f2e2d6;
|
||||
border-radius: 22rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.dish image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 220rpx;
|
||||
background: #f3e7de;
|
||||
}
|
||||
.dish-copy {
|
||||
padding: 18rpx;
|
||||
}
|
||||
.dish-name {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.dish-sub {
|
||||
margin-top: 6rpx;
|
||||
color: #8c7b70;
|
||||
font-size: 19rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.price {
|
||||
margin-top: 14rpx;
|
||||
color: #dc6429;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.promise {
|
||||
margin-top: 28rpx;
|
||||
padding: 28rpx;
|
||||
border-radius: 24rpx;
|
||||
background: #3b2118;
|
||||
color: #fff;
|
||||
}
|
||||
.light {
|
||||
color: #ffc79f;
|
||||
}
|
||||
.promise-title {
|
||||
margin-top: 8rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.promise-item {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
margin-top: 18rpx;
|
||||
color: #ffe5d2;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.promise-item text:first-child {
|
||||
color: #ff9a5a;
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
brand: { type: Object, value: {} },
|
||||
presentation: { type: Object, value: {} },
|
||||
offerings: { type: Array, value: [] },
|
||||
},
|
||||
methods: {
|
||||
open(e) {
|
||||
this.triggerEvent("open", { id: e.currentTarget.dataset.id });
|
||||
},
|
||||
inquire() {
|
||||
this.triggerEvent("inquire");
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
{ "component": true }
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view class="head"><text class="eyebrow">{{brand.name}}</text><text class="title">{{presentation.title || '今日菜单'}}</text><text class="subtitle">{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}</text></view><view class="tip">米饭免费续,口味和忌口都可以在预约时备注</view><view class="list"><view wx:for="{{offerings}}" wx:key="id" class="dish" data-id="{{item.id}}" bindtap="open"><image src="{{item.image}}" mode="aspectFill"/><view class="copy"><text class="name">{{item.name}}</text><text class="desc">{{item.desc}}</text><view class="bottom"><text class="price">{{item.priceRange}}</text><text class="action">查看详情 ›</text></view></view></view></view><button class="cta" bindtap="inquire">团体活动 / 定制餐咨询</button></view>
|
||||
@@ -1,93 +0,0 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 28rpx;
|
||||
background: #fff8f0;
|
||||
color: #29231f;
|
||||
}
|
||||
.eyebrow {
|
||||
display: block;
|
||||
color: #d2652b;
|
||||
font-size: 19rpx;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
.title {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 42rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.subtitle {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
color: #8c7b70;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.tip {
|
||||
margin-top: 22rpx;
|
||||
padding: 18rpx 20rpx;
|
||||
border: 1rpx solid #f8d7b4;
|
||||
border-radius: 18rpx;
|
||||
background: #fff7df;
|
||||
color: #8c5c39;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.list {
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
.dish {
|
||||
display: flex;
|
||||
gap: 18rpx;
|
||||
margin-bottom: 16rpx;
|
||||
padding: 14rpx;
|
||||
border: 1rpx solid #f2e2d6;
|
||||
border-radius: 22rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.dish image {
|
||||
width: 196rpx;
|
||||
height: 196rpx;
|
||||
flex: none;
|
||||
border-radius: 16rpx;
|
||||
background: #f3e7de;
|
||||
}
|
||||
.copy {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
}
|
||||
.name {
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.desc {
|
||||
margin-top: 10rpx;
|
||||
color: #8c7b70;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.bottom {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: space-between;
|
||||
margin-top: auto;
|
||||
}
|
||||
.price {
|
||||
color: #dc6429;
|
||||
font-size: 25rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.action {
|
||||
color: #d2652b;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
.cta {
|
||||
margin: 22rpx 0 0;
|
||||
height: 76rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #e87532;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
line-height: 76rpx;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
brand: { type: Object, value: {} },
|
||||
presentation: { type: Object, value: {} },
|
||||
recordsCount: { type: Number, value: 0 },
|
||||
},
|
||||
methods: {
|
||||
call() {
|
||||
this.triggerEvent("call");
|
||||
},
|
||||
copy() {
|
||||
this.triggerEvent("copy");
|
||||
},
|
||||
records() {
|
||||
this.triggerEvent("records");
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
{ "component": true }
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view class="profile-card"><image src="{{brand.avatarUrl}}" mode="aspectFill"/><text class="name">{{brand.founder}}</text><text class="title">{{brand.title}}</text><text class="bio">{{brand.slogan}}</text><view class="contact"><button bindtap="call">电话联系</button><button bindtap="copy">复制微信</button></view></view><view class="card"><text class="card-title">{{presentation.coverageTitle || '出摊与配送'}}</text><text>{{brand.studioAddress || brand.address}}</text><text>{{presentation.coverageContent || '支持校园摊位自取、宿舍配送和班级活动定制。'}}</text></view><view class="card" bindtap="records"><text class="card-title">我的预约记录</text><text>{{recordsCount}} 条记录 ›</text></view></view>
|
||||
@@ -1,72 +0,0 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 28rpx;
|
||||
background: #fff8f0;
|
||||
color: #29231f;
|
||||
}
|
||||
.profile-card {
|
||||
padding: 36rpx 28rpx;
|
||||
text-align: center;
|
||||
border-radius: 28rpx;
|
||||
background: #3b2118;
|
||||
color: #fff;
|
||||
}
|
||||
.profile-card image {
|
||||
width: 132rpx;
|
||||
height: 132rpx;
|
||||
border: 5rpx solid #ffbd8e;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.name,
|
||||
.title,
|
||||
.bio,
|
||||
.card-title,
|
||||
.card text {
|
||||
display: block;
|
||||
}
|
||||
.name {
|
||||
margin-top: 18rpx;
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.title {
|
||||
margin-top: 6rpx;
|
||||
color: #ffc79f;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.bio {
|
||||
margin-top: 16rpx;
|
||||
color: #ffe5d2;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.contact {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.contact button {
|
||||
flex: 1;
|
||||
height: 70rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #e87532;
|
||||
color: #fff;
|
||||
font-size: 22rpx;
|
||||
line-height: 70rpx;
|
||||
}
|
||||
.card {
|
||||
margin-top: 18rpx;
|
||||
padding: 26rpx;
|
||||
border: 1rpx solid #f2d9c6;
|
||||
border-radius: 22rpx;
|
||||
background: #fff;
|
||||
color: #7a6a60;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.card-title {
|
||||
margin-bottom: 10rpx;
|
||||
color: #4b2b1d;
|
||||
font-size: 27rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
brand: { type: Object, value: {} },
|
||||
presentation: { type: Object, value: {} },
|
||||
hero: { type: Object, value: {} },
|
||||
trustContent: { type: Object, value: {} },
|
||||
offerings: { type: Array, value: [] },
|
||||
},
|
||||
methods: {
|
||||
selectOffering(event) {
|
||||
this.triggerEvent("select", { id: event.currentTarget.dataset.id });
|
||||
},
|
||||
goWorks() {
|
||||
this.triggerEvent("works");
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1 +0,0 @@
|
||||
{ "component": true }
|
||||
@@ -1,8 +0,0 @@
|
||||
<view class="page">
|
||||
<view class="founder-card"><image class="avatar" src="{{brand.avatarUrl}}" mode="aspectFill"/><view class="founder-copy"><text class="founder-name">{{brand.founder}}</text><text class="founder-title">{{brand.title}}</text><text class="quote">“{{brand.slogan}}”</text></view><text class="badge">{{presentation.founderBadge}}</text></view>
|
||||
<view class="hero" bindtap="goWorks"><image class="hero-image" src="{{brand.heroImage}}" mode="aspectFill"/><view class="hero-shade"/><view class="hero-copy"><text class="eyebrow">{{hero.eyebrow}}</text><text class="hero-title">{{hero.title}}</text><text class="hero-slogan">{{hero.slogan}}</text><text class="hero-button">{{hero.cta}}</text></view></view>
|
||||
<view class="intro"><text class="eyebrow dark">{{presentation.proofEyebrow}}</text><text class="section-title">{{presentation.proofTitle}}</text><text class="body">{{trustContent.bio}}</text><view class="stats"><view wx:for="{{trustContent.stats}}" wx:key="value"><text class="stat-value">{{item.value}}</text><text class="stat-label">{{item.label}}</text><text class="stat-sub">{{item.sub}}</text></view></view></view>
|
||||
<view class="trust"><text class="eyebrow">{{presentation.manifestoEyebrow}}</text><text class="section-title light">{{presentation.manifestoTitle}}</text><view wx:for="{{trustContent.pillars}}" wx:key="title" class="pillar"><text class="pillar-title">{{item.title}}</text><text class="pillar-desc">{{item.desc}}</text></view></view>
|
||||
<view class="section"><view class="section-head"><view><text class="eyebrow dark">{{presentation.worksEyebrow}}</text><text class="section-title">{{presentation.worksTitle}}</text></view><text class="more" bindtap="goWorks">{{presentation.worksAction}}</text></view><view wx:for="{{offerings}}" wx:key="id" class="work-card" data-id="{{item.id}}" bindtap="selectOffering"><image src="{{item.image}}" mode="aspectFill"/><view class="work-info"><text class="work-category">{{item.category}} · {{item.area}}</text><text class="work-name">{{item.name}}</text><text class="work-desc">{{item.series}} · {{item.keywords[0]}} · {{item.keywords[1]}}</text></view></view></view>
|
||||
<view class="flow"><text class="flow-eyebrow">{{presentation.flowEyebrow}}</text><text class="flow-title">{{presentation.flowTitle}}</text><view class="flow-grid"><view wx:for="{{trustContent.serviceFlow}}" wx:key="step" class="flow-item"><text class="flow-step">{{item.step}}</text><text class="flow-name">{{item.name}}</text><text class="flow-desc">{{item.desc}}</text></view></view></view>
|
||||
</view>
|
||||
@@ -1,261 +0,0 @@
|
||||
.page {
|
||||
background: #f7f5f1;
|
||||
color: #252525;
|
||||
padding-bottom: 30rpx;
|
||||
}
|
||||
.founder-card {
|
||||
position: relative;
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
align-items: flex-start;
|
||||
margin: 32rpx 40rpx 20rpx;
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 28rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.avatar {
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
flex: 0 0 112rpx;
|
||||
border: 4rpx solid #d9c8b2;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.founder-copy {
|
||||
min-width: 0;
|
||||
padding-right: 78rpx;
|
||||
}
|
||||
.founder-name,
|
||||
.founder-title,
|
||||
.quote,
|
||||
.eyebrow,
|
||||
.hero-title,
|
||||
.hero-slogan,
|
||||
.section-title,
|
||||
.body,
|
||||
.stat-value,
|
||||
.stat-label,
|
||||
.stat-sub,
|
||||
.pillar-title,
|
||||
.pillar-desc,
|
||||
.work-category,
|
||||
.work-name,
|
||||
.work-desc,
|
||||
.flow-eyebrow,
|
||||
.flow-title,
|
||||
.flow-step,
|
||||
.flow-name,
|
||||
.flow-desc {
|
||||
display: block;
|
||||
}
|
||||
.founder-name {
|
||||
font: 30rpx serif;
|
||||
}
|
||||
.founder-title {
|
||||
margin-top: 6rpx;
|
||||
color: #77736b;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
.quote {
|
||||
margin-top: 14rpx;
|
||||
font: 21rpx serif;
|
||||
}
|
||||
.badge {
|
||||
position: absolute;
|
||||
top: 24rpx;
|
||||
right: 20rpx;
|
||||
padding: 8rpx 12rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #f3ede6;
|
||||
color: #8a6846;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
.hero {
|
||||
position: relative;
|
||||
height: 400rpx;
|
||||
margin: 0 40rpx 42rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 28rpx;
|
||||
}
|
||||
.hero-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.hero-shade {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(180deg, rgba(20, 22, 21, 0.1), rgba(20, 22, 21, 0.82));
|
||||
}
|
||||
.hero-copy {
|
||||
position: absolute;
|
||||
right: 28rpx;
|
||||
bottom: 28rpx;
|
||||
left: 28rpx;
|
||||
color: #fff;
|
||||
}
|
||||
.eyebrow {
|
||||
margin-bottom: 14rpx;
|
||||
color: #d9c8b2;
|
||||
font-size: 18rpx;
|
||||
letter-spacing: 3rpx;
|
||||
}
|
||||
.dark {
|
||||
color: #8a6846;
|
||||
}
|
||||
.hero-title,
|
||||
.section-title {
|
||||
font: 34rpx serif;
|
||||
}
|
||||
.hero-slogan {
|
||||
margin-top: 10rpx;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.hero-button {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 12rpx 16rpx;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.3);
|
||||
color: #d9c8b2;
|
||||
font-size: 19rpx;
|
||||
}
|
||||
.intro,
|
||||
.section {
|
||||
padding: 0 40rpx 48rpx;
|
||||
}
|
||||
.body {
|
||||
color: #77736b;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
.stats view {
|
||||
padding: 22rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 20rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.stat-value {
|
||||
color: #8a6846;
|
||||
font: 38rpx serif;
|
||||
}
|
||||
.stat-label {
|
||||
margin-top: 4rpx;
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
.stat-sub {
|
||||
margin-top: 6rpx;
|
||||
color: #77736b;
|
||||
font-size: 18rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.trust {
|
||||
padding: 42rpx 40rpx;
|
||||
background: #202221;
|
||||
color: #fff;
|
||||
}
|
||||
.light {
|
||||
color: #fff;
|
||||
}
|
||||
.pillar {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.pillar-title {
|
||||
color: #fff;
|
||||
font: 28rpx serif;
|
||||
}
|
||||
.pillar-desc {
|
||||
margin-top: 8rpx;
|
||||
color: #c6c2ba;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.65;
|
||||
}
|
||||
.section-head {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 22rpx;
|
||||
}
|
||||
.more {
|
||||
color: #8a6846;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.work-card {
|
||||
margin-bottom: 24rpx;
|
||||
overflow: hidden;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 28rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.work-card image {
|
||||
width: 100%;
|
||||
height: 300rpx;
|
||||
}
|
||||
.work-info {
|
||||
padding: 24rpx;
|
||||
}
|
||||
.work-category {
|
||||
color: #8a6846;
|
||||
font-size: 19rpx;
|
||||
}
|
||||
.work-name {
|
||||
margin: 10rpx 0;
|
||||
font: 28rpx serif;
|
||||
}
|
||||
.work-desc {
|
||||
color: #77736b;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.flow {
|
||||
margin: 0 40rpx 42rpx;
|
||||
padding: 30rpx 24rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 20rpx;
|
||||
background: #efece6;
|
||||
text-align: center;
|
||||
}
|
||||
.flow-eyebrow {
|
||||
color: #8a6846;
|
||||
font-size: 18rpx;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
.flow-title {
|
||||
margin-top: 6rpx;
|
||||
font: 30rpx serif;
|
||||
}
|
||||
.flow-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16rpx;
|
||||
margin-top: 24rpx;
|
||||
text-align: left;
|
||||
}
|
||||
.flow-item {
|
||||
padding: 18rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 14rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.flow-step {
|
||||
color: #8a6846;
|
||||
font-size: 18rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.flow-name {
|
||||
margin-top: 5rpx;
|
||||
font-size: 21rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
.flow-desc {
|
||||
margin-top: 6rpx;
|
||||
color: #77736b;
|
||||
font-size: 17rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
Component({
|
||||
properties: {
|
||||
brand: { type: Object, value: {} },
|
||||
presentation: { type: Object, value: {} },
|
||||
recordsCount: { type: Number, value: 0 },
|
||||
},
|
||||
methods: {
|
||||
call() {
|
||||
this.triggerEvent("call");
|
||||
},
|
||||
copy() {
|
||||
this.triggerEvent("copy");
|
||||
},
|
||||
records() {
|
||||
this.triggerEvent("records");
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "/miniprogram_npm/tdesign-miniprogram/icon/icon"
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<view class="profile">
|
||||
<view class="founder-card">
|
||||
<view class="identity">
|
||||
<image class="avatar" src="{{brand.avatarUrl}}" mode="aspectFill" />
|
||||
<view><text class="founder">{{brand.founder}}</text><text class="role">{{brand.title}}</text></view>
|
||||
</view>
|
||||
<view class="contact-lines">
|
||||
<view class="contact-line"><text class="label">{{presentation.phoneLabel}}</text><view class="contact-action"><text class="value">{{brand.phone}}</text><button bindtap="call"><t-icon name="call" size="24rpx" />{{presentation.callAction}}</button></view></view>
|
||||
<view class="contact-line"><text class="label">{{presentation.wechatLabel}}</text><view class="contact-action"><text class="value accent">{{brand.wechat}}</text><button bindtap="copy"><t-icon name="file-copy" size="24rpx" />{{presentation.copyAction}}</button></view></view>
|
||||
<view class="contact-line address"><text class="label">{{presentation.addressLabel}}</text><text class="address-value">{{brand.studioAddress}}</text></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="records-card" bindtap="records">
|
||||
<view class="entry-icon"><t-icon name="logo-notion" size="34rpx" /></view>
|
||||
<view class="entry-copy"><text>{{presentation.recordsTitle}}</text><text>{{presentation.recordsSubtitle}}</text></view>
|
||||
<view class="entry-count"><text>{{recordsCount}} {{presentation.recordsCountUnit}}</text><t-icon name="chevron-right" size="30rpx" /></view>
|
||||
</view>
|
||||
<view class="info-card">
|
||||
<view class="card-title"><t-icon name="map" size="32rpx" /><text>{{presentation.coverageTitle}}</text></view>
|
||||
<view wx:for="{{brand.profilePresentation.coverage}}" wx:key="title" class="note"><text class="note-title">{{item.title}}</text><text>{{item.content}}</text></view>
|
||||
</view>
|
||||
<view class="info-card">
|
||||
<view class="card-title"><t-icon name="secured" size="32rpx" /><text>{{presentation.warrantyTitle}}</text></view>
|
||||
<view wx:for="{{brand.profilePresentation.warranty}}" wx:key="*this" class="warranty"><text class="dot">•</text><text>{{item}}</text></view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -1,194 +0,0 @@
|
||||
.profile {
|
||||
min-height: 100vh;
|
||||
padding: 28rpx 32rpx 56rpx;
|
||||
background: #f7f5f1;
|
||||
color: #252525;
|
||||
}
|
||||
.founder-card {
|
||||
padding: 34rpx 30rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #202221;
|
||||
color: #fff;
|
||||
box-shadow: 0 12rpx 34rpx rgba(32, 34, 33, 0.12);
|
||||
}
|
||||
.identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 22rpx;
|
||||
}
|
||||
.avatar {
|
||||
width: 92rpx;
|
||||
height: 92rpx;
|
||||
border: 2rpx solid #8a6846;
|
||||
border-radius: 50%;
|
||||
background: #343736;
|
||||
}
|
||||
.founder,
|
||||
.role,
|
||||
.label,
|
||||
.value,
|
||||
.address-value,
|
||||
.entry-copy text,
|
||||
.entry-count text,
|
||||
.note-title,
|
||||
.note text,
|
||||
.warranty text {
|
||||
display: block;
|
||||
}
|
||||
.founder {
|
||||
font: 34rpx serif;
|
||||
}
|
||||
.role {
|
||||
margin-top: 8rpx;
|
||||
color: #d9c8b2;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.contact-lines {
|
||||
margin-top: 24rpx;
|
||||
border-top: 1rpx solid rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
.contact-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
padding-top: 18rpx;
|
||||
margin-top: 18rpx;
|
||||
border-top: 1rpx solid rgba(255, 255, 255, 0.1);
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.contact-line:first-child {
|
||||
border-top: 0;
|
||||
margin-top: 0;
|
||||
}
|
||||
.label {
|
||||
flex: 0 0 auto;
|
||||
color: rgba(255, 255, 255, 0.52);
|
||||
}
|
||||
.contact-action {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
.value {
|
||||
color: #fff;
|
||||
font-family: monospace;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.accent {
|
||||
color: #d9c8b2;
|
||||
}
|
||||
.contact-action button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 5rpx;
|
||||
min-width: 86rpx;
|
||||
height: 46rpx;
|
||||
margin: 0;
|
||||
padding: 0 12rpx;
|
||||
border-radius: 9rpx;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #d9c8b2;
|
||||
font-size: 20rpx;
|
||||
line-height: 46rpx;
|
||||
}
|
||||
.address {
|
||||
align-items: flex-start;
|
||||
}
|
||||
.address-value {
|
||||
max-width: 410rpx;
|
||||
color: rgba(255, 255, 255, 0.82);
|
||||
line-height: 1.55;
|
||||
text-align: right;
|
||||
}
|
||||
.records-card,
|
||||
.info-card {
|
||||
margin-top: 20rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 18rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 10rpx 30rpx -12rpx rgba(32, 34, 33, 0.08);
|
||||
}
|
||||
.records-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
padding: 26rpx;
|
||||
}
|
||||
.entry-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 66rpx;
|
||||
height: 66rpx;
|
||||
border-radius: 12rpx;
|
||||
background: rgba(138, 104, 70, 0.1);
|
||||
color: #8a6846;
|
||||
}
|
||||
.entry-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.entry-copy text:first-child {
|
||||
color: #202221;
|
||||
font-size: 25rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
.entry-copy text:last-child {
|
||||
margin-top: 7rpx;
|
||||
color: #77736b;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.entry-count {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4rpx;
|
||||
flex: 0 0 auto;
|
||||
color: #8a6846;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
.info-card {
|
||||
padding: 28rpx;
|
||||
}
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
color: #202221;
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.card-title t-icon {
|
||||
color: #8a6846;
|
||||
}
|
||||
.note {
|
||||
margin-top: 18rpx;
|
||||
padding: 20rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 12rpx;
|
||||
background: #f7f5f1;
|
||||
color: #57534e;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.note-title {
|
||||
margin-bottom: 5rpx;
|
||||
color: #202221;
|
||||
font-size: 23rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
.warranty {
|
||||
display: flex;
|
||||
gap: 10rpx;
|
||||
margin-top: 16rpx;
|
||||
color: #77736b;
|
||||
font-size: 23rpx;
|
||||
line-height: 1.65;
|
||||
}
|
||||
.dot {
|
||||
flex: 0 0 auto;
|
||||
color: #8a6846;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "我的订单",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black",
|
||||
"usingComponents": {
|
||||
"t-icon": "/miniprogram_npm/tdesign-miniprogram/icon/icon",
|
||||
"profile-module": "/components/modules/profile/profile",
|
||||
"linjing-profile": "/components/templates/linjing-profile/linjing-profile",
|
||||
"acheng-profile": "/components/templates/acheng-profile/acheng-profile",
|
||||
"runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view wx:if="{{error}}" class="runtime-error">{{error}}</view><block wx:else><acheng-profile wx:if="{{pageRenderer === 'acheng-profile'}}" brand="{{brand}}" presentation="{{brand.visualPresentation.profile}}" records-count="{{records.length}}" bind:call="call" bind:copy="copyWechat" bind:records="recordsPage" /><linjing-profile wx:elif="{{pageRenderer === 'linjing-profile'}}" brand="{{brand}}" presentation="{{brand.visualPresentation.profile}}" records-count="{{records.length}}" bind:call="call" bind:copy="copyWechat" bind:records="recordsPage" /><block wx:else><profile-module brand="{{brand}}" presentation="{{brand.visualPresentation.profile}}" records-count="{{records.length}}" bind:call="call" bind:copy="copyWechat" bind:records="recordsPage" /></block><runtime-tab-bar template-key="{{templateKey}}" active="owner" /></block></view>
|
||||
@@ -1,166 +0,0 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 0;
|
||||
background: #f7f5f1;
|
||||
color: #252525;
|
||||
}
|
||||
.runtime-error {
|
||||
margin: 48rpx 0;
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 14rpx;
|
||||
background: #fff;
|
||||
color: #8a6846;
|
||||
font-size: 25rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.contact-card {
|
||||
padding: 34rpx 30rpx;
|
||||
background: #202221;
|
||||
color: #fff;
|
||||
border-radius: 18rpx;
|
||||
}
|
||||
.identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
}
|
||||
.avatar {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border: 2rpx solid #8a6846;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #d9c8b2;
|
||||
font: 42rpx serif;
|
||||
}
|
||||
.founder {
|
||||
display: block;
|
||||
font: 34rpx serif;
|
||||
}
|
||||
.role {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
color: #d9c8b2;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.contact-line {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 22rpx;
|
||||
padding-top: 18rpx;
|
||||
border-top: 1rpx solid rgba(255, 255, 255, 0.12);
|
||||
color: #aaa;
|
||||
font-size: 23rpx;
|
||||
}
|
||||
.contact-line > view {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
color: #fff;
|
||||
}
|
||||
.contact-line button {
|
||||
margin: 0;
|
||||
padding: 0 14rpx;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #d9c8b2;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.records-entry,
|
||||
.info-card {
|
||||
margin-top: 20rpx;
|
||||
padding: 28rpx;
|
||||
background: #fff;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
.records-entry {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
.records-entry text:last-child {
|
||||
color: #8a6846;
|
||||
}
|
||||
.card-title {
|
||||
display: block;
|
||||
font-weight: 700;
|
||||
font-size: 27rpx;
|
||||
}
|
||||
.note,
|
||||
.bullet {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
color: #77736b;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.75;
|
||||
}
|
||||
.entry-icon {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 12rpx;
|
||||
background: rgba(138, 104, 70, 0.1);
|
||||
color: #8a6846;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.records-entry {
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
}
|
||||
.entry-copy {
|
||||
flex: 1;
|
||||
}
|
||||
.entry-copy text {
|
||||
display: block;
|
||||
}
|
||||
.entry-copy text:last-child {
|
||||
margin-top: 8rpx;
|
||||
color: #77736b;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
.count {
|
||||
color: #8a6846;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
color: #202221;
|
||||
}
|
||||
.note {
|
||||
padding: 20rpx;
|
||||
background: #f7f5f1;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
.note-title {
|
||||
display: block;
|
||||
margin-bottom: 6rpx;
|
||||
color: #202221;
|
||||
font-weight: 700;
|
||||
}
|
||||
.bullet {
|
||||
padding-left: 8rpx;
|
||||
}
|
||||
.contact-line button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6rpx;
|
||||
height: 44rpx;
|
||||
line-height: 44rpx;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.contact-line button t-icon {
|
||||
display: inline-flex;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.page {
|
||||
padding-bottom: 150rpx;
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const config = require("../../utils/config");
|
||||
Page({
|
||||
data: {
|
||||
brand: {},
|
||||
trustContent: [],
|
||||
offerings: [],
|
||||
modules: [],
|
||||
moduleVariants: {},
|
||||
pageRenderer: "",
|
||||
layout: [],
|
||||
theme: {},
|
||||
hero: { image: "", eyebrow: "", title: "", slogan: "", cta: "" },
|
||||
loading: false,
|
||||
loadedBrandSlug: "",
|
||||
templateKey: "",
|
||||
navigation: [],
|
||||
},
|
||||
onLoad() {
|
||||
this.loadWorkspace();
|
||||
},
|
||||
onShow() {
|
||||
if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) {
|
||||
this.loadWorkspace();
|
||||
}
|
||||
},
|
||||
loadWorkspace() {
|
||||
this.setData({ loading: true });
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) => {
|
||||
const activeBrand = workspace.brand || {};
|
||||
const activeOfferings = workspace.offerings || [];
|
||||
const layout = workspace.layout?.home || [
|
||||
"founder-card",
|
||||
"brand-hero",
|
||||
"trust-proof",
|
||||
"trust-manifesto",
|
||||
"offering-list",
|
||||
];
|
||||
const firstOffering = activeOfferings[0] || {};
|
||||
const configuredHero =
|
||||
activeBrand.homeHero && typeof activeBrand.homeHero === "object"
|
||||
? activeBrand.homeHero
|
||||
: {};
|
||||
this.setData({
|
||||
brand: activeBrand,
|
||||
trustContent: workspace.trustPresentation || {},
|
||||
offerings: activeOfferings,
|
||||
modules: workspace.modules || [],
|
||||
moduleVariants: workspace.moduleVariants || {},
|
||||
pageRenderer: workspace.pageRenderers?.home || "",
|
||||
layout,
|
||||
theme: workspace.theme || {},
|
||||
hero: {
|
||||
...this.data.hero,
|
||||
image: activeBrand.heroImage || this.data.hero.image,
|
||||
eyebrow: activeBrand.tagline || activeBrand.name,
|
||||
title: firstOffering.name || activeBrand.name,
|
||||
slogan: activeBrand.description || "",
|
||||
...configuredHero,
|
||||
},
|
||||
loading: false,
|
||||
loadedBrandSlug: config.brandSlug,
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
navigation: workspace.navigation || [],
|
||||
});
|
||||
wx.setNavigationBarTitle({ title: activeBrand.name || "个人品牌" });
|
||||
})
|
||||
.catch((error) => this.setData({ error: error.message, loading: false }));
|
||||
},
|
||||
showModule(e) {
|
||||
return this.data.layout.includes(e);
|
||||
},
|
||||
selectOffering(e) {
|
||||
const id = e.detail ? e.detail.id : e.currentTarget.dataset.id;
|
||||
wx.navigateTo({ url: "/pages/offering/detail?id=" + id });
|
||||
},
|
||||
goWorks() {
|
||||
wx.switchTab({ url: "/pages/services/index" });
|
||||
},
|
||||
goInquiry() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index" });
|
||||
},
|
||||
goProfile() {
|
||||
wx.navigateTo({ url: "/pages/bookings/index" });
|
||||
},
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "品牌首页",
|
||||
"usingComponents": {
|
||||
"linjing-home": "/components/templates/linjing-home/linjing-home",
|
||||
"acheng-home": "/components/templates/acheng-home/acheng-home",
|
||||
"founder-card": "/components/modules/founder-card/founder-card",
|
||||
"brand-hero": "/components/modules/brand-hero/brand-hero",
|
||||
"trust-proof": "/components/modules/trust-proof/trust-proof",
|
||||
"trust-manifesto": "/components/modules/trust-manifesto/trust-manifesto",
|
||||
"offering-list": "/components/modules/offering-list/offering-list",
|
||||
"runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar"
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<view class="page">
|
||||
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
|
||||
<block wx:else>
|
||||
<linjing-home wx:if="{{pageRenderer === 'linjing-home'}}" brand="{{brand}}" presentation="{{brand.visualPresentation.home}}" hero="{{hero}}" trust-content="{{trustContent}}" offerings="{{offerings}}" bind:select="selectOffering" bind:works="goWorks" />
|
||||
<acheng-home wx:elif="{{pageRenderer === 'acheng-home'}}" brand="{{brand}}" presentation="{{brand.visualPresentation.home}}" trust-content="{{trustContent}}" offerings="{{offerings}}" bind:select="selectOffering" bind:inquiry="goInquiry" bind:offerings="goWorks" />
|
||||
<block wx:else>
|
||||
<block wx:for="{{layout}}" wx:key="*this" wx:for-item="moduleKey">
|
||||
<founder-card wx:if="{{moduleKey === 'founder-card'}}" brand="{{brand}}" presentation="{{brand.visualPresentation.home}}" variant="{{moduleVariants[moduleKey]}}" />
|
||||
<brand-hero wx:if="{{moduleKey === 'brand-hero'}}" hero="{{hero}}" variant="{{moduleVariants[moduleKey]}}" bind:explore="goWorks" />
|
||||
<trust-proof wx:if="{{moduleKey === 'trust-proof'}}" content="{{trustContent}}" presentation="{{brand.visualPresentation.home}}" variant="{{moduleVariants[moduleKey]}}" />
|
||||
<trust-manifesto wx:if="{{moduleKey === 'trust-manifesto'}}" content="{{trustContent}}" presentation="{{brand.visualPresentation.home}}" variant="{{moduleVariants[moduleKey]}}" />
|
||||
<offering-list wx:if="{{moduleKey === 'offering-list'}}" offerings="{{offerings}}" presentation="{{brand.visualPresentation.home}}" variant="{{moduleVariants[moduleKey]}}" bind:open="selectOffering" bind:more="goWorks" />
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
</view>
|
||||
<runtime-tab-bar template-key="{{templateKey}}" active="home" />
|
||||
@@ -1,221 +0,0 @@
|
||||
.page {
|
||||
background: #f7f5f1;
|
||||
color: #252525;
|
||||
min-height: 100vh;
|
||||
padding-bottom: 30rpx;
|
||||
}
|
||||
.runtime-error {
|
||||
margin: 48rpx 32rpx;
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 14rpx;
|
||||
background: #fff;
|
||||
color: #8a6846;
|
||||
font-size: 25rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.founder {
|
||||
margin: 32rpx 40rpx 20rpx;
|
||||
padding: 28rpx;
|
||||
background: #fff;
|
||||
border: 1px solid #e6ded5;
|
||||
border-radius: 28rpx;
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
align-items: flex-start;
|
||||
position: relative;
|
||||
}
|
||||
.avatar {
|
||||
width: 112rpx;
|
||||
height: 112rpx;
|
||||
border-radius: 50%;
|
||||
border: 4rpx solid #d9c8b2;
|
||||
}
|
||||
.founder-name {
|
||||
display: block;
|
||||
font-family: serif;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.founder-title {
|
||||
display: block;
|
||||
color: #77736b;
|
||||
font-size: 20rpx;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
.quote {
|
||||
display: block;
|
||||
font-family: serif;
|
||||
font-size: 21rpx;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
.badge {
|
||||
position: absolute;
|
||||
right: 20rpx;
|
||||
top: 24rpx;
|
||||
color: #8a6846;
|
||||
background: #f3ede6;
|
||||
padding: 8rpx 12rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
.hero {
|
||||
margin: 0 40rpx 42rpx;
|
||||
height: 400rpx;
|
||||
position: relative;
|
||||
border-radius: 28rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
.hero-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.hero-shade {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(180deg, rgba(20, 22, 21, 0.1), rgba(20, 22, 21, 0.82));
|
||||
}
|
||||
.hero-copy {
|
||||
position: absolute;
|
||||
left: 28rpx;
|
||||
right: 28rpx;
|
||||
bottom: 28rpx;
|
||||
color: #fff;
|
||||
}
|
||||
.eyebrow {
|
||||
display: block;
|
||||
font-size: 18rpx;
|
||||
letter-spacing: 3rpx;
|
||||
color: #d9c8b2;
|
||||
margin-bottom: 14rpx;
|
||||
}
|
||||
.eyebrow.dark {
|
||||
color: #8a6846;
|
||||
}
|
||||
.hero-title {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
font-family: serif;
|
||||
}
|
||||
.hero-slogan {
|
||||
display: block;
|
||||
font-size: 21rpx;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
.hero-button {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #d9c8b2;
|
||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||
font-size: 19rpx;
|
||||
height: 54rpx;
|
||||
line-height: 54rpx;
|
||||
margin: 0;
|
||||
}
|
||||
.intro,
|
||||
.section {
|
||||
padding: 0 40rpx 48rpx;
|
||||
}
|
||||
.section-title {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
font-family: serif;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
.body {
|
||||
display: block;
|
||||
color: #77736b;
|
||||
line-height: 1.8;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
.stats {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
.stats view {
|
||||
background: #fff;
|
||||
border: 1px solid #e6ded5;
|
||||
border-radius: 20rpx;
|
||||
padding: 22rpx;
|
||||
}
|
||||
.stat-value {
|
||||
display: block;
|
||||
font-size: 38rpx;
|
||||
color: #8a6846;
|
||||
font-family: serif;
|
||||
}
|
||||
.stat-label {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
.section-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: end;
|
||||
margin-bottom: 22rpx;
|
||||
}
|
||||
.more {
|
||||
font-size: 21rpx;
|
||||
color: #8a6846;
|
||||
}
|
||||
.work-card {
|
||||
background: #fff;
|
||||
border: 1px solid #e6ded5;
|
||||
border-radius: 28rpx;
|
||||
overflow: hidden;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
.work-card image {
|
||||
width: 100%;
|
||||
height: 300rpx;
|
||||
display: block;
|
||||
}
|
||||
.work-info {
|
||||
padding: 24rpx;
|
||||
}
|
||||
.work-category {
|
||||
font-size: 19rpx;
|
||||
color: #8a6846;
|
||||
}
|
||||
.work-name {
|
||||
display: block;
|
||||
font-family: serif;
|
||||
font-size: 28rpx;
|
||||
margin: 10rpx 0;
|
||||
}
|
||||
.work-desc {
|
||||
font-size: 22rpx;
|
||||
color: #77736b;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.trust {
|
||||
margin-top: 10rpx;
|
||||
background: #202221;
|
||||
color: #fff;
|
||||
padding: 42rpx 40rpx;
|
||||
}
|
||||
.light {
|
||||
color: #fff;
|
||||
}
|
||||
.light-body {
|
||||
color: #c6c2ba;
|
||||
margin-bottom: 26rpx;
|
||||
}
|
||||
.outline-button {
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
border: 1px solid #d9c8b2;
|
||||
color: #d9c8b2;
|
||||
border-radius: 0;
|
||||
font-size: 24rpx;
|
||||
height: 72rpx;
|
||||
line-height: 72rpx;
|
||||
}
|
||||
.page {
|
||||
padding-bottom: 150rpx;
|
||||
}
|
||||
@@ -13,8 +13,6 @@ Page({
|
||||
fields: [],
|
||||
formId: "",
|
||||
error: "",
|
||||
templateKey: "",
|
||||
navigation: [],
|
||||
},
|
||||
onLoad(options) {
|
||||
loadWorkspaceWithFallback()
|
||||
@@ -39,8 +37,6 @@ Page({
|
||||
subtitle: presentation.subtitle || "提交信息后由主理人与你联系",
|
||||
submitLabel: isQuote ? "提交报价需求" : presentation.submitLabel || "提交需求",
|
||||
presentation,
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
navigation: workspace.navigation || [],
|
||||
});
|
||||
})
|
||||
.catch((error) => this.setData({ error: error.message }));
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
"brand-field": "/components/ui/brand-field/brand-field",
|
||||
"brand-loading": "/components/ui/brand-loading/brand-loading",
|
||||
"brand-empty": "/components/ui/brand-empty/brand-empty",
|
||||
"inquiry-form": "/components/modules/inquiry-form/inquiry-form",
|
||||
"runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar"
|
||||
"inquiry-form": "/components/modules/inquiry-form/inquiry-form"
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const config = require("../../utils/config");
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
error: "",
|
||||
offerings: [],
|
||||
filtered: [],
|
||||
modules: [],
|
||||
theme: {},
|
||||
brand: {},
|
||||
presentation: {},
|
||||
category: "all",
|
||||
categories: [],
|
||||
pageRenderer: "",
|
||||
loadedBrandSlug: "",
|
||||
templateKey: "",
|
||||
navigation: [],
|
||||
},
|
||||
onLoad() {
|
||||
this.loadWorkspace();
|
||||
},
|
||||
onShow() {
|
||||
if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) {
|
||||
this.loadWorkspace();
|
||||
}
|
||||
},
|
||||
loadWorkspace() {
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) => {
|
||||
const items = workspace.offerings || [];
|
||||
this.setData({
|
||||
offerings: items,
|
||||
filtered: items,
|
||||
categories: [
|
||||
{ key: "all", label: "全部" },
|
||||
...Array.from(new Set(items.map((item) => item.category).filter(Boolean))).map(
|
||||
(key) => ({
|
||||
key,
|
||||
label: key,
|
||||
}),
|
||||
),
|
||||
],
|
||||
modules: workspace.modules || [],
|
||||
theme: workspace.theme || {},
|
||||
brand: workspace.brand || {},
|
||||
presentation: workspace.brand?.visualPresentation?.offerings || {},
|
||||
brand: workspace.brand || {},
|
||||
pageRenderer: workspace.pageRenderers?.offerings || "",
|
||||
loadedBrandSlug: config.brandSlug,
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
navigation: workspace.navigation || [],
|
||||
});
|
||||
})
|
||||
.catch((error) => this.setData({ error: error.message }));
|
||||
},
|
||||
switchCategory(e) {
|
||||
const category = e.currentTarget.dataset.category;
|
||||
const items = this.data.offerings || [];
|
||||
this.setData({
|
||||
category,
|
||||
filtered: category === "all" ? items : items.filter((item) => item.category === category),
|
||||
});
|
||||
},
|
||||
open(e) {
|
||||
wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id });
|
||||
},
|
||||
inquire() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index" });
|
||||
},
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "服务列表",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black",
|
||||
"usingComponents": {
|
||||
"acheng-offerings": "/components/templates/acheng-offerings/acheng-offerings",
|
||||
"linjing-offerings": "/components/templates/linjing-offerings/linjing-offerings",
|
||||
"brand-loading": "/components/ui/brand-loading/brand-loading",
|
||||
"brand-empty": "/components/ui/brand-empty/brand-empty",
|
||||
"runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view wx:if="{{error}}" class="runtime-error">{{error}}</view><block wx:else><acheng-offerings wx:if="{{pageRenderer === 'acheng-offerings'}}" brand="{{brand}}" presentation="{{presentation}}" offerings="{{filtered}}" bind:open="open" bind:inquire="inquire" /><block wx:else><view class="head"><text class="eyebrow">{{brand.name}}</text><text class="title">{{presentation.title}}</text><text class="sub">{{presentation.subtitle}}</text></view><scroll-view scroll-x class="tabs"><text wx:for="{{categories}}" wx:key="key" class="tab {{category===item.key?'active':''}}" data-category="{{item.key}}" bindtap="switchCategory">{{item.label}}</text></scroll-view><view class="list"><view wx:for="{{filtered}}" wx:key="id" class="card"><view class="media" data-id="{{item.id}}" bindtap="open"><image src="{{item.image}}" mode="aspectFill"/><text class="media-category">{{item.category}}</text><text wx:if="{{item.tag}}" class="media-tag">{{item.tag}}</text><view wx:if="{{item.area || item.spaceType}}" class="media-meta"><text>{{item.area}}</text><text>{{item.spaceType}}</text></view></view><view class="card-body"><text class="name" data-id="{{item.id}}" bindtap="open">{{item.name}}</text><text class="series">{{item.series}}</text><view wx:if="{{item.woodMaterial || item.hardware}}" class="specs"><view wx:if="{{item.woodMaterial}}"><text>{{presentation.materialLabel}}</text><text>{{item.woodMaterial}}</text></view><view wx:if="{{item.hardware}}"><text>{{presentation.hardwareLabel}}</text><text>{{item.hardware}}</text></view></view><view class="actions"><button class="detail" data-id="{{item.id}}" bindtap="open">{{presentation.detailAction}}</button><button class="inquire" data-id="{{item.id}}" bindtap="open">{{presentation.inquiryAction}}</button></view></view></view></view></block></block><runtime-tab-bar template-key="{{templateKey}}" active="dishes" /></view>
|
||||
@@ -1,202 +0,0 @@
|
||||
.page {
|
||||
background: #f7f5f1;
|
||||
min-height: 100vh;
|
||||
color: #252525;
|
||||
}
|
||||
.runtime-error {
|
||||
margin: 48rpx 32rpx;
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 14rpx;
|
||||
background: #fff;
|
||||
color: #8a6846;
|
||||
font-size: 25rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.head {
|
||||
background: #252827;
|
||||
color: #fff;
|
||||
padding: 70rpx 40rpx 55rpx;
|
||||
}
|
||||
.eyebrow {
|
||||
font-size: 20rpx;
|
||||
letter-spacing: 3rpx;
|
||||
color: #d9c8b2;
|
||||
display: block;
|
||||
margin-bottom: 18rpx;
|
||||
}
|
||||
.title {
|
||||
font-size: 52rpx;
|
||||
font-family: serif;
|
||||
display: block;
|
||||
}
|
||||
.sub {
|
||||
font-size: 26rpx;
|
||||
color: #c6c2ba;
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
.tabs {
|
||||
white-space: nowrap;
|
||||
padding: 28rpx 32rpx;
|
||||
background: #f7f5f1;
|
||||
}
|
||||
.tab {
|
||||
display: inline-block;
|
||||
font-size: 25rpx;
|
||||
color: #77736b;
|
||||
margin: 0 14rpx;
|
||||
padding-bottom: 12rpx;
|
||||
}
|
||||
.tab.active {
|
||||
color: #8a6846;
|
||||
border-bottom: 2px solid #8a6846;
|
||||
}
|
||||
.list {
|
||||
padding: 0 32rpx 40rpx;
|
||||
}
|
||||
.card {
|
||||
background: #fff;
|
||||
margin-bottom: 30rpx;
|
||||
overflow: hidden;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 18rpx;
|
||||
box-shadow: 0 10rpx 30rpx -12rpx rgba(32, 34, 33, 0.08);
|
||||
}
|
||||
.media {
|
||||
position: relative;
|
||||
height: 380rpx;
|
||||
background: #202221;
|
||||
}
|
||||
.card image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
.media-category,
|
||||
.media-tag,
|
||||
.media-meta {
|
||||
position: absolute;
|
||||
color: #fff;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
.media-category {
|
||||
top: 20rpx;
|
||||
left: 20rpx;
|
||||
padding: 8rpx 14rpx;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.15);
|
||||
border-radius: 8rpx;
|
||||
background: rgba(32, 34, 33, 0.76);
|
||||
color: #d9c8b2;
|
||||
}
|
||||
.media-tag {
|
||||
top: 20rpx;
|
||||
right: 20rpx;
|
||||
padding: 8rpx 14rpx;
|
||||
border-radius: 6rpx;
|
||||
background: #8a6846;
|
||||
}
|
||||
.media-meta {
|
||||
right: 20rpx;
|
||||
bottom: 20rpx;
|
||||
left: 20rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
padding: 10rpx 14rpx;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 10rpx;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
font-size: 19rpx;
|
||||
}
|
||||
.media-meta text:last-child {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
color: #d9c8b2;
|
||||
}
|
||||
.card-body {
|
||||
padding: 28rpx;
|
||||
}
|
||||
.category {
|
||||
font-size: 20rpx;
|
||||
color: #8a6846;
|
||||
display: block;
|
||||
}
|
||||
.name {
|
||||
display: block;
|
||||
font-size: 34rpx;
|
||||
line-height: 1.45;
|
||||
margin: 12rpx 0 6rpx;
|
||||
}
|
||||
.series {
|
||||
display: block;
|
||||
color: #77736b;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
.desc {
|
||||
display: block;
|
||||
color: #77736b;
|
||||
font-size: 25rpx;
|
||||
line-height: 1.7;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
.specs {
|
||||
margin-top: 20rpx;
|
||||
padding: 18rpx;
|
||||
border: 1rpx solid #e6ded5;
|
||||
border-radius: 12rpx;
|
||||
background: #f7f5f1;
|
||||
color: #252525;
|
||||
font-size: 20rpx;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.specs view {
|
||||
display: flex;
|
||||
gap: 8rpx;
|
||||
}
|
||||
.specs view + view {
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
.specs text:first-child {
|
||||
flex: 0 0 auto;
|
||||
color: #77736b;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
.actions button {
|
||||
flex: 1;
|
||||
height: 70rpx;
|
||||
margin: 0;
|
||||
border-radius: 12rpx;
|
||||
font-size: 21rpx;
|
||||
line-height: 70rpx;
|
||||
}
|
||||
.detail {
|
||||
border: 1rpx solid #202221;
|
||||
background: #fff;
|
||||
color: #202221;
|
||||
}
|
||||
.inquire {
|
||||
background: #8a6846;
|
||||
color: #fff;
|
||||
}
|
||||
.foot {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
border-top: 1px solid #eee7de;
|
||||
margin-top: 24rpx;
|
||||
padding-top: 20rpx;
|
||||
color: #999;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.arrow {
|
||||
color: #8a6846;
|
||||
}
|
||||
.page {
|
||||
padding-bottom: 150rpx;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
Page({
|
||||
data: { brand: {}, templateKey: "", presentation: {}, navigation: [], loading: true },
|
||||
onLoad() {
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) =>
|
||||
this.setData({
|
||||
brand: workspace.brand || {},
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
presentation: workspace.brand?.visualPresentation?.home || {},
|
||||
navigation: workspace.navigation || [],
|
||||
loading: false,
|
||||
}),
|
||||
)
|
||||
.catch(() => this.setData({ loading: false }));
|
||||
},
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "出摊服务",
|
||||
"usingComponents": { "runtime-tab-bar": "/components/runtime-tab-bar/runtime-tab-bar" }
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<view class="page"><view class="head"><text class="eyebrow">出摊与服务</text><text class="title">今天在哪里,怎么取餐</text><text class="sub">{{brand.hours || '营业时间以当天通知为准'}}</text></view><view class="card"><text class="card-title">固定出摊与取餐</text><text>{{brand.studioAddress || brand.address || '校园生活区附近'}}</text><text>支持摊位自取、校内配送,以及班级和社团活动定制。</text></view><view class="card"><text class="card-title">定制餐品流程</text><text>1. 提交人数、时间和口味需求</text><text>2. 主理人确认菜单与取餐方式</text><text>3. 当天现做并按约定时间交付</text></view><runtime-tab-bar template-key="{{templateKey}}" active="service" /></view>
|
||||
@@ -1,42 +0,0 @@
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 28rpx 32rpx 150rpx;
|
||||
background: #fff8f0;
|
||||
color: #29231f;
|
||||
}
|
||||
.head {
|
||||
padding: 38rpx 4rpx 28rpx;
|
||||
}
|
||||
.eyebrow {
|
||||
display: block;
|
||||
color: #c65c28;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
.title {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
font-size: 42rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
.sub {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
color: #7a6a60;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
.card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14rpx;
|
||||
margin-bottom: 22rpx;
|
||||
padding: 28rpx;
|
||||
border: 1rpx solid #f2d9c6;
|
||||
border-radius: 24rpx;
|
||||
background: #fff;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.card-title {
|
||||
color: #4f3020;
|
||||
font-size: 29rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// 开发默认配置。template:dev 编译时会用品牌构建参数覆盖此文件。
|
||||
module.exports = {
|
||||
env: "dev",
|
||||
apiBaseUrl: "http://localhost:3001",
|
||||
brandSlug: "default-brand",
|
||||
templateKey: "",
|
||||
templateVersion: "",
|
||||
runtimeContract: "1.0",
|
||||
};
|
||||
@@ -1,5 +1,7 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const os = require("node:os");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
const root = path.resolve(__dirname, "..");
|
||||
const requestSource = fs.readFileSync(path.join(root, "utils/request.js"), "utf8");
|
||||
const configSource = fs.readFileSync(path.join(root, "utils/config.js"), "utf8");
|
||||
@@ -13,7 +15,7 @@ if (
|
||||
console.error("miniapp: public requests must carry the configured brand slug");
|
||||
process.exit(1);
|
||||
}
|
||||
if (!moduleRegistrySource.includes("Object.values(manifest?.pages || {})")) {
|
||||
if (!moduleRegistrySource.includes("manifest.pages")) {
|
||||
console.error("miniapp: visual page renderers must resolve from the manifest");
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -24,10 +26,11 @@ if (
|
||||
console.error("miniapp: customer sessions must be brand-scoped");
|
||||
process.exit(1);
|
||||
}
|
||||
const productionRoots = ["components/modules", "components/templates", "pages"];
|
||||
const productionRoots = ["components/modules", "pages"];
|
||||
const productionSources = [];
|
||||
function collectSources(directory) {
|
||||
const current = path.join(root, directory);
|
||||
if (!fs.existsSync(current)) return;
|
||||
for (const item of fs.readdirSync(current, { withFileTypes: true })) {
|
||||
const itemPath = path.join(current, item.name);
|
||||
if (item.isDirectory()) collectSources(path.relative(root, itemPath));
|
||||
@@ -83,8 +86,23 @@ for (const fixture of fixtures) {
|
||||
records: "pages/records/index",
|
||||
profile: "pages/bookings/index",
|
||||
};
|
||||
const templateKey = fixture.templateKey.startsWith("acheng")
|
||||
? "acheng-campus-food"
|
||||
: "linjing-editorial";
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-fixture-"));
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
path.resolve(root, "../../packages/template-compiler/src/cli.mjs"),
|
||||
"--template",
|
||||
templateKey,
|
||||
"--out",
|
||||
output,
|
||||
],
|
||||
{ stdio: "ignore" },
|
||||
);
|
||||
const missingPages = fixture.pages.filter(
|
||||
(key) => !fs.existsSync(path.join(root, `${pageMap[key]}.json`)),
|
||||
(key) => !fs.existsSync(path.join(output, `${pageMap[key]}.json`)),
|
||||
);
|
||||
if (missingPages.length) {
|
||||
console.error(`${fixture.templateKey}: missing page manifests: ${missingPages.join(", ")}`);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
const runtimeConfig = require("../runtime-config");
|
||||
|
||||
const app = getApp();
|
||||
|
||||
module.exports = {
|
||||
get apiBaseUrl() {
|
||||
return app.globalData.apiBaseUrl;
|
||||
return app.globalData.apiBaseUrl || runtimeConfig.apiBaseUrl;
|
||||
},
|
||||
get brand() {
|
||||
return app.globalData.brand || {};
|
||||
},
|
||||
get brandSlug() {
|
||||
return wx.getStorageSync("brandSlug") || app.globalData.brandSlug || "default-brand";
|
||||
return app.globalData.brandSlug || runtimeConfig.brandSlug;
|
||||
},
|
||||
};
|
||||
@@ -90,10 +90,6 @@ function resolveRuntime(workspace) {
|
||||
: resolved.map((item) => item.type);
|
||||
const moduleVariants = {};
|
||||
for (const item of manifestHome || []) moduleVariants[item.type] = item.variant;
|
||||
const pageRenderers = {};
|
||||
for (const page of Object.values(manifest?.pages || {})) {
|
||||
if (page.renderer) pageRenderers[page.key] = page.renderer;
|
||||
}
|
||||
const navigation = Array.isArray(manifest?.navigation)
|
||||
? manifest.navigation.map((item) => ({
|
||||
...item,
|
||||
@@ -110,7 +106,6 @@ function resolveRuntime(workspace) {
|
||||
modules: resolved,
|
||||
layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) },
|
||||
moduleVariants,
|
||||
pageRenderers,
|
||||
navigation,
|
||||
visualManifest: manifest,
|
||||
capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [],
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# ADR 0015:模板采用构建时叠加编译
|
||||
|
||||
## 背景
|
||||
|
||||
平台需要支持大量行业和视觉风格不同的小程序模板。把所有模板代码放在 `apps/miniapp`,再通过运行时分支选择,会让壳持续膨胀、模板之间互相污染,也无法可靠验证某个品牌最终打开的页面。
|
||||
|
||||
## 决策
|
||||
|
||||
`template:dev` 采用三层构建时叠加:
|
||||
|
||||
1. `apps/miniapp` 只提供品牌无关的运行时、通用 UI、公共页面和 TDesign 依赖。
|
||||
2. `packages/capability-*` 提供独立业务流程页面,由模板 manifest 的 `requiredCapabilities` 声明引入。
|
||||
3. `packages/template-*` 提供完整视觉模板页面、组件、资源和 `app.json` 窗口配置。
|
||||
|
||||
编译器按运行时 → 能力包 → 模板包的顺序复制,并对同路径文件执行显式冲突校验。模板只能通过 `overrides` 声明替换下层页面或组件目录。最终生成 `app.json`、`project.config.json`、`runtime-config.js` 和 `template.runtime.json`,产物可直接由微信开发者工具打开。
|
||||
|
||||
品牌 slug、API 地址和 AppID 是构建参数;开发构建允许通过 storage 覆盖 API 和品牌,生产构建必须显式提供并使用 HTTPS API。模板切换不在小程序运行时完成,而是在构建时选择模板包。
|
||||
|
||||
## 替代方案
|
||||
|
||||
- 运行时携带全部模板并按 `templateKey` 分支:代码和资源随模板数量线性膨胀,容易混用,放弃。
|
||||
- 运行时下载 WXML/JS 模板:微信小程序安全和编译模型不支持,放弃。
|
||||
- 每个模板独立复制完整小程序:公共能力重复、修复无法统一,放弃。
|
||||
|
||||
## 后果
|
||||
|
||||
新增模板只需新增 package 和 manifest,不需要改 compiler 或 runtime。模板包需要自行提供 manifest 声明的页面四件套和 tab 资源,编译测试会阻止缺页、缺图标、组件引用或 `require` 路径错误。后台视觉模板切换不会直接改变已构建小程序,后台切换历史和回滚属于后续治理任务。
|
||||
|
||||
## 迁移计划
|
||||
|
||||
先完成阿成、林境两个模板和 `booking` capability 的迁移,再增加第二行业演练模板。每个新增模板必须通过 compiler 产物校验、模板契约校验和小程序 fixture 检查后才能进入目录 registry。
|
||||
@@ -6,6 +6,14 @@
|
||||
|
||||
`feat/template-runtime-platform`
|
||||
|
||||
### 构建时模板叠加基线
|
||||
|
||||
- [x] Runtime、Capability、Template 三层编译结构已落地,详见 `docs/adr/0015-template-build-time-composition.md`。
|
||||
- [x] 阿成、林境页面与 tab 资源已迁入独立模板包,Runtime 不再携带行业页面和模板组件。
|
||||
- [x] `booking` 下单页面已迁入 `packages/capability-booking`。
|
||||
- [x] 编译产物校验覆盖页面文件、组件引用、`require`、tab 图标、品牌参数和能力依赖错误。
|
||||
- [ ] 增加第二行业最小演练模板并接入视觉截图回归。
|
||||
|
||||
## 阶段状态
|
||||
|
||||
### Phase 0:冻结林境门作基线
|
||||
|
||||
@@ -15,6 +15,7 @@ export default tseslint.config(
|
||||
"apps/miniapp/pages/**/*.js",
|
||||
"apps/miniapp/app.js",
|
||||
"apps/admin/vite.config.ts",
|
||||
"packages/config/src/generated-template-packages.js",
|
||||
],
|
||||
},
|
||||
eslint.configs.recommended,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# booking 能力包
|
||||
|
||||
为需要"选择数量 + 自取/配送"下单流程的模板提供小程序页面。模板在 `template.json` 的
|
||||
`requiredCapabilities` 中声明 `booking` 后,`template:dev` 会把 `miniapp/` 叠加进产物。
|
||||
|
||||
- `miniapp/pages/booking`:下单页,提交到 `POST /customer/bookings`。
|
||||
- `miniapp/utils/booking-templates.js`:下单页文案。
|
||||
|
||||
当前后端仍使用核心 `Booking` 模型;把它迁移为独立 capability 是后续任务。
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"key": "booking",
|
||||
"version": "1.0.0",
|
||||
"runtimeContract": "1.0",
|
||||
"description": "带数量、自取/配送的下单能力,提交到 /customer/bookings。",
|
||||
"pages": ["pages/booking/index"]
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
const { request, customerRequest, customerTokenKey } = require("../../utils/request");
|
||||
const { getTemplate } = require("../../utils/templates");
|
||||
const { getTemplate } = require("../../utils/booking-templates");
|
||||
Page({
|
||||
data: {
|
||||
service: {},
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "@personal-brand/capability-booking",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "下单能力的小程序页面,由声明 booking 能力的模板在编译时引入。"
|
||||
}
|
||||
@@ -341,28 +341,16 @@ export const generatedTemplatePackageRegistry = [
|
||||
"capabilityKey": "booking"
|
||||
}
|
||||
},
|
||||
"renderers": {
|
||||
"home": "acheng-home",
|
||||
"offerings": "acheng-offerings",
|
||||
"profile": "acheng-profile"
|
||||
},
|
||||
"runtimeOwnedPages": [
|
||||
"detail",
|
||||
"inquiry",
|
||||
"success",
|
||||
"records"
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/services/index",
|
||||
"pages/stall-service/index",
|
||||
"pages/bookings/index"
|
||||
],
|
||||
"ownedPaths": [
|
||||
"components/templates/acheng-home",
|
||||
"components/templates/acheng-offerings",
|
||||
"components/templates/acheng-profile",
|
||||
"pages/index",
|
||||
"pages/services",
|
||||
"pages/bookings",
|
||||
"overrides": [
|
||||
"pages/inquiry",
|
||||
"pages/stall-service",
|
||||
"pages/offering",
|
||||
"pages/inquiry-success",
|
||||
"pages/offering",
|
||||
"pages/records"
|
||||
],
|
||||
"visualTemplateKey": "acheng-campus-food"
|
||||
@@ -866,24 +854,13 @@ export const generatedTemplatePackageRegistry = [
|
||||
"capabilityKey": "inquiry"
|
||||
}
|
||||
},
|
||||
"renderers": {
|
||||
"home": "linjing-home",
|
||||
"offerings": "linjing-offerings",
|
||||
"profile": "linjing-profile"
|
||||
},
|
||||
"runtimeOwnedPages": [
|
||||
"detail",
|
||||
"inquiry",
|
||||
"success",
|
||||
"records"
|
||||
],
|
||||
"ownedPaths": [
|
||||
"components/templates/linjing-home",
|
||||
"components/templates/linjing-offerings",
|
||||
"components/templates/linjing-profile"
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/services/index",
|
||||
"pages/bookings/index"
|
||||
],
|
||||
"visualTemplateKey": "linjing-editorial"
|
||||
}
|
||||
];
|
||||
export const generatedTemplatePackageRegistryHash =
|
||||
"6d56212ec96d9b7b99a9e12aa278ca0927dc5e4472ec6ece3098a7d99842897b";
|
||||
"254f31edcf4073091691fc5f88fced2b5857c60aec3d1175a5f1e44b9e45acd0";
|
||||
@@ -310,23 +310,11 @@
|
||||
"capabilityKey": "booking"
|
||||
}
|
||||
},
|
||||
"renderers": {
|
||||
"home": "acheng-home",
|
||||
"offerings": "acheng-offerings",
|
||||
"profile": "acheng-profile"
|
||||
},
|
||||
"runtimeOwnedPages": ["detail", "inquiry", "success", "records"],
|
||||
"ownedPaths": [
|
||||
"components/templates/acheng-home",
|
||||
"components/templates/acheng-offerings",
|
||||
"components/templates/acheng-profile",
|
||||
"pages/index",
|
||||
"pages/services",
|
||||
"pages/bookings",
|
||||
"pages/inquiry",
|
||||
"pages/stall-service",
|
||||
"pages/offering",
|
||||
"pages/inquiry-success",
|
||||
"pages/records"
|
||||
]
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/services/index",
|
||||
"pages/stall-service/index",
|
||||
"pages/bookings/index"
|
||||
],
|
||||
"overrides": ["pages/inquiry", "pages/inquiry-success", "pages/offering", "pages/records"]
|
||||
}
|
||||
@@ -1,306 +1,257 @@
|
||||
#!/usr/bin/env node
|
||||
// 叠加式模板编译器:运行时(apps/miniapp)→ 能力包 → 模板包,再注入品牌构建参数。
|
||||
// 编译器只负责拼装和校验,不改写任何页面源码。
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import {
|
||||
CORE_CAPABILITIES,
|
||||
validateCapabilityPackageManifest,
|
||||
validateTemplatePackageManifest,
|
||||
} from "../../template-contract/src/index.ts";
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
const packagesRoot = path.join(root, "packages");
|
||||
const generatedRoot = path.join(root, "apps/miniapp-generated");
|
||||
export const workspaceRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
const packagesRoot = path.join(workspaceRoot, "packages");
|
||||
const runtimeRoot = path.join(workspaceRoot, "apps/miniapp");
|
||||
|
||||
function usage() {
|
||||
console.log("Usage: template-compiler --template <package-key> [--out <directory>]");
|
||||
}
|
||||
|
||||
function validateManifest(manifest) {
|
||||
const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"];
|
||||
if (!manifest.packageKey || !manifest.version || !manifest.displayName)
|
||||
throw new Error("template.json requires packageKey, version and displayName");
|
||||
if (manifest.runtimeContract !== "1.0") throw new Error("Only runtimeContract 1.0 is supported");
|
||||
for (const page of requiredPages) {
|
||||
if (typeof manifest.entrypoints?.[page] !== "string")
|
||||
throw new Error(`template.json missing entrypoint: ${page}`);
|
||||
}
|
||||
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
|
||||
throw new Error("template.json navigation must not be empty");
|
||||
if (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length)
|
||||
throw new Error("template.json dataSlots must not be empty");
|
||||
if (!Array.isArray(manifest.assetSlots))
|
||||
throw new Error("template.json assetSlots must be an array");
|
||||
if (!manifest.admin || !Array.isArray(manifest.admin.sections) || !manifest.admin.sections.length)
|
||||
throw new Error("template.json admin.sections must not be empty");
|
||||
for (const section of manifest.admin.sections) {
|
||||
if (!section.key || !section.title || !section.description || !Array.isArray(section.fields))
|
||||
throw new Error("template.json admin sections require key, title, description and fields");
|
||||
for (const field of section.fields) {
|
||||
if (!field.key || !field.binding || !field.label || !field.input)
|
||||
throw new Error("template.json admin fields require key, binding, label and input");
|
||||
}
|
||||
}
|
||||
if (
|
||||
manifest.renderers !== undefined &&
|
||||
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
|
||||
)
|
||||
throw new Error("template.json renderers must be an object");
|
||||
for (const page of ["home", "offerings", "profile"]) {
|
||||
if (typeof manifest.renderers?.[page] !== "string" || !manifest.renderers[page]) {
|
||||
throw new Error(`template.json requires a dedicated renderer for visual page: ${page}`);
|
||||
}
|
||||
}
|
||||
if (
|
||||
manifest.runtimeOwnedPages !== undefined &&
|
||||
(!Array.isArray(manifest.runtimeOwnedPages) ||
|
||||
manifest.runtimeOwnedPages.some(
|
||||
(page) => !["detail", "inquiry", "success", "records"].includes(page),
|
||||
))
|
||||
)
|
||||
throw new Error("template.json runtimeOwnedPages contains an unsupported page");
|
||||
for (const item of manifest.navigation) {
|
||||
if (!item || typeof item.key !== "string" || typeof item.label !== "string")
|
||||
throw new Error("template.json navigation items require key and label");
|
||||
if (typeof item.page !== "string" || typeof manifest.entrypoints?.[item.page] !== "string")
|
||||
throw new Error(`template.json navigation page is not a declared entrypoint: ${item.key}`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateEntrypoints(output, manifest) {
|
||||
for (const [key, relativePath] of Object.entries(manifest.entrypoints || {})) {
|
||||
const pagePath = path.join(output, relativePath);
|
||||
for (const extension of [".js", ".json", ".wxml", ".wxss"]) {
|
||||
if (!fs.existsSync(`${pagePath}${extension}`)) {
|
||||
throw new Error(`Template entrypoint ${key} is missing ${relativePath}${extension}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function validateGeneratedIsolation(output) {
|
||||
const forbidden = [
|
||||
const DEV_API_BASE_URL = "http://localhost:3001";
|
||||
const DEV_BRAND_SLUG = "default-brand";
|
||||
// 运行时目录中不属于小程序产物的内容,以及由编译器生成的文件。
|
||||
const RUNTIME_EXCLUDES = new Set([
|
||||
"node_modules",
|
||||
"test",
|
||||
"src",
|
||||
"dist",
|
||||
".turbo",
|
||||
"package.json",
|
||||
"tsconfig.json",
|
||||
"project.private.config.json",
|
||||
"app.json",
|
||||
"project.config.json",
|
||||
"runtime-config.js",
|
||||
"assets",
|
||||
"pages/booking",
|
||||
"utils/templates.js",
|
||||
"components/templates",
|
||||
"runtime-tab-bar",
|
||||
"acheng-",
|
||||
"linjing-",
|
||||
"templateKey ===",
|
||||
];
|
||||
const visit = (directory) => {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const filePath = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) visit(filePath);
|
||||
else if (/\.(wxml|json|js|wxss)$/.test(entry.name)) {
|
||||
const source = fs.readFileSync(filePath, "utf8");
|
||||
for (const token of forbidden) {
|
||||
if (source.includes(token))
|
||||
throw new Error(`Generated output contains forbidden token ${token}: ${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
visit(path.join(output, "pages"));
|
||||
}
|
||||
|
||||
function copyDirectory(source, target) {
|
||||
fs.mkdirSync(target, { recursive: true });
|
||||
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
||||
if (["node_modules", ".turbo", "dist"].includes(entry.name)) continue;
|
||||
const from = path.join(source, entry.name);
|
||||
const to = path.join(target, entry.name);
|
||||
if (entry.isDirectory()) copyDirectory(from, to);
|
||||
else fs.copyFileSync(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
function removeOwnedPaths(rootDirectory, ownedPaths = []) {
|
||||
for (const relativePath of ownedPaths) {
|
||||
fs.rmSync(path.join(rootDirectory, relativePath), { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
function removeRuntimeTabBar(output) {
|
||||
const pagesDirectory = path.join(output, "pages");
|
||||
if (!fs.existsSync(pagesDirectory)) return;
|
||||
const visit = (directory) => {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const filePath = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) visit(filePath);
|
||||
else if (entry.name.endsWith(".wxml")) {
|
||||
const source = fs.readFileSync(filePath, "utf8");
|
||||
const cleaned = source.replace(/<runtime-tab-bar\b[^>]*\/\s*>/g, "");
|
||||
if (cleaned !== source) fs.writeFileSync(filePath, cleaned);
|
||||
} else if (entry.name.endsWith(".json")) {
|
||||
const json = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
if (json.usingComponents?.["runtime-tab-bar"]) {
|
||||
delete json.usingComponents["runtime-tab-bar"];
|
||||
fs.writeFileSync(filePath, JSON.stringify(json, null, 2) + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
visit(pagesDirectory);
|
||||
fs.rmSync(path.join(output, "components/runtime-tab-bar"), { recursive: true, force: true });
|
||||
}
|
||||
|
||||
function pruneUndeclaredPages(output, manifest) {
|
||||
const appJsonPath = path.join(output, "app.json");
|
||||
const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf8"));
|
||||
const allowed = new Set([
|
||||
...manifest.navigation.map((item) => manifest.entrypoints[item.page]),
|
||||
...(manifest.runtimeOwnedPages || []).map((page) => manifest.entrypoints[page]),
|
||||
"components/runtime-tab-bar",
|
||||
"pages/index",
|
||||
"pages/services",
|
||||
"pages/bookings",
|
||||
"pages/stall-service",
|
||||
]);
|
||||
for (const page of appJson.pages || []) {
|
||||
if (allowed.has(page)) continue;
|
||||
fs.rmSync(path.join(output, path.dirname(page)), { recursive: true, force: true });
|
||||
}
|
||||
appJson.pages = (appJson.pages || []).filter((page) => allowed.has(page));
|
||||
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2) + "\n");
|
||||
const appJsPath = path.join(output, "app.js");
|
||||
if (fs.existsSync(appJsPath) && manifest.defaultBrandSlug) {
|
||||
const appJs = fs
|
||||
.readFileSync(appJsPath, "utf8")
|
||||
.replace(
|
||||
/const DEFAULT_BRAND_SLUG = "[^"]*";/,
|
||||
`const DEFAULT_BRAND_SLUG = ${JSON.stringify(manifest.defaultBrandSlug)};`,
|
||||
);
|
||||
fs.writeFileSync(appJsPath, appJs);
|
||||
}
|
||||
const LAYER_EXCLUDES = new Set(["node_modules", ".turbo", "dist", ".gitkeep", "app.json"]);
|
||||
const PAGE_EXTENSIONS = [".js", ".json", ".wxml"];
|
||||
|
||||
class CompileError extends Error {}
|
||||
|
||||
function fail(message) {
|
||||
throw new CompileError(message);
|
||||
}
|
||||
|
||||
function materializeRendererAliases(output, packageDirectory, manifest) {
|
||||
const rendererRoot = path.join(packageDirectory, "miniapp/components/templates");
|
||||
const pagePaths = {
|
||||
home: "pages/index/index",
|
||||
offerings: "pages/services/index",
|
||||
profile: "pages/bookings/index",
|
||||
};
|
||||
for (const page of Object.keys(pagePaths)) {
|
||||
const renderer = manifest.renderers?.[page];
|
||||
const source = path.join(rendererRoot, renderer);
|
||||
if (!fs.existsSync(source)) {
|
||||
throw new Error(`Template renderer source is missing: ${renderer}`);
|
||||
}
|
||||
const aliasDirectory = path.join(output, "components/template-pages", page);
|
||||
fs.mkdirSync(aliasDirectory, { recursive: true });
|
||||
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
||||
if (!entry.isFile()) continue;
|
||||
fs.copyFileSync(
|
||||
path.join(source, entry.name),
|
||||
path.join(aliasDirectory, `${page}${path.extname(entry.name)}`),
|
||||
);
|
||||
}
|
||||
const pageDirectory = path.join(output, pagePaths[page]);
|
||||
const jsonPath = `${pageDirectory}.json`;
|
||||
const wxmlPath = `${pageDirectory}.wxml`;
|
||||
const pageJson = JSON.parse(fs.readFileSync(jsonPath, "utf8"));
|
||||
pageJson.usingComponents = pageJson.usingComponents || {};
|
||||
for (const key of Object.keys(pageJson.usingComponents)) {
|
||||
if (/-home$|-offerings$|-profile$/.test(key)) delete pageJson.usingComponents[key];
|
||||
}
|
||||
pageJson.usingComponents[`template-${page}`] = `/components/template-pages/${page}/${page}`;
|
||||
fs.writeFileSync(jsonPath, JSON.stringify(pageJson, null, 2) + "\n");
|
||||
const rendererPattern = new RegExp(`<([a-z0-9-]+)-${page}\\b`, "g");
|
||||
const originalWxml = fs.readFileSync(wxmlPath, "utf8");
|
||||
const wxml =
|
||||
page === "offerings"
|
||||
? `<view class="page"><template-${page} brand="{{brand}}" presentation="{{presentation}}" offerings="{{offerings}}" bind:open="open" bind:more="inquire" /></view>`
|
||||
: originalWxml.replace(rendererPattern, `<template-${page}`);
|
||||
fs.writeFileSync(wxmlPath, wxml);
|
||||
}
|
||||
function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function freezeRendererConditions(output, manifest) {
|
||||
const rendererByPage = manifest.renderers || {};
|
||||
const pagePaths = {
|
||||
home: "pages/index/index.wxml",
|
||||
offerings: "pages/services/index.wxml",
|
||||
profile: "pages/bookings/index.wxml",
|
||||
};
|
||||
for (const [page, relativePath] of Object.entries(pagePaths)) {
|
||||
const filePath = path.join(output, relativePath);
|
||||
if (!fs.existsSync(filePath)) continue;
|
||||
const selected = rendererByPage[page] || "";
|
||||
const source = fs.readFileSync(filePath, "utf8");
|
||||
const frozen = source.replace(
|
||||
/wx:(if|elif)="\{\{pageRenderer === '([^']+)'\}\}"/g,
|
||||
(_match, branch, renderer) => `wx:${branch}="{{${renderer === selected}}}"`,
|
||||
);
|
||||
const selectedAlias =
|
||||
page === "offerings"
|
||||
? frozen.replace(
|
||||
'<template-offerings wx:if="{{false}}"',
|
||||
'<template-offerings wx:if="{{true}}"',
|
||||
function toPosix(relativePath) {
|
||||
return relativePath.split(path.sep).join("/");
|
||||
}
|
||||
|
||||
function listFiles(directory, exclude, base = directory) {
|
||||
const files = [];
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const entryPath = toPosix(path.relative(base, path.join(directory, entry.name)));
|
||||
if (
|
||||
exclude.has(entry.name) ||
|
||||
[...exclude].some((value) => entryPath === value || entryPath.startsWith(value + "/"))
|
||||
)
|
||||
: frozen;
|
||||
fs.writeFileSync(filePath, selectedAlias);
|
||||
continue;
|
||||
if (entry.name === ".gitkeep") continue;
|
||||
const filePath = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) files.push(...listFiles(filePath, exclude, base));
|
||||
else files.push(toPosix(path.relative(base, filePath)));
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const templateIndex = args.indexOf("--template");
|
||||
if (templateIndex < 0 || !args[templateIndex + 1]) return usage();
|
||||
const packageKey = args[templateIndex + 1];
|
||||
const outputIndex = args.indexOf("--out");
|
||||
const output = path.resolve(outputIndex >= 0 ? args[outputIndex + 1] : generatedRoot);
|
||||
const packageDirectory = fs.existsSync(path.join(packagesRoot, packageKey))
|
||||
? path.join(packagesRoot, packageKey)
|
||||
: path.join(packagesRoot, `template-${packageKey}`);
|
||||
const manifestPath = path.join(packageDirectory, "template.json");
|
||||
if (!fs.existsSync(manifestPath)) throw new Error(`Template package not found: ${packageKey}`);
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
if (manifest.packageKey !== packageKey)
|
||||
throw new Error("template.json packageKey does not match requested template");
|
||||
validateManifest(manifest);
|
||||
fs.rmSync(output, { recursive: true, force: true });
|
||||
const shell = path.join(root, "apps/miniapp");
|
||||
if (!fs.existsSync(shell)) throw new Error("Mini Program shell is missing: apps/miniapp");
|
||||
copyDirectory(shell, output);
|
||||
// 迁移期间保留 shell 的模板目录,直到模板包提供对应页面的完整覆盖。
|
||||
// ownedPaths 只记录最终所有权,不在不完整迁移时删除可用 renderer。
|
||||
const source = path.join(packageDirectory, "miniapp");
|
||||
if (!fs.existsSync(source))
|
||||
throw new Error(`Template package has no miniapp directory: ${packageKey}`);
|
||||
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
|
||||
if (entry.name === "app.json") continue;
|
||||
const from = path.join(source, entry.name);
|
||||
const to = path.join(output, entry.name);
|
||||
if (entry.isDirectory()) copyDirectory(from, to);
|
||||
else fs.copyFileSync(from, to);
|
||||
function underPrefix(relativePath, prefix) {
|
||||
return relativePath === prefix || relativePath.startsWith(prefix + "/");
|
||||
}
|
||||
materializeRendererAliases(output, packageDirectory, manifest);
|
||||
freezeRendererConditions(output, manifest);
|
||||
removeRuntimeTabBar(output);
|
||||
pruneUndeclaredPages(output, manifest);
|
||||
validateEntrypoints(output, manifest);
|
||||
for (const relativePath of manifest.ownedPaths || []) {
|
||||
if (!fs.existsSync(path.join(output, relativePath)))
|
||||
throw new Error(`Template package did not provide owned path: ${relativePath}`);
|
||||
|
||||
function resolveTemplateDirectory(options) {
|
||||
if (options.templateDir) return path.resolve(options.templateDir);
|
||||
const candidates = [
|
||||
path.join(packagesRoot, `template-${options.template}`),
|
||||
path.join(packagesRoot, options.template),
|
||||
];
|
||||
const found = candidates.find((candidate) =>
|
||||
fs.existsSync(path.join(candidate, "template.json")),
|
||||
);
|
||||
if (!found) fail(`Template package not found: ${options.template}`);
|
||||
return found;
|
||||
}
|
||||
for (const renderer of Object.values(manifest.renderers || {})) {
|
||||
const rendererPath = path.join(output, "components/templates", renderer, `${renderer}.wxml`);
|
||||
if (!fs.existsSync(rendererPath)) throw new Error(`Template renderer is missing: ${renderer}`);
|
||||
|
||||
function loadTemplate(options) {
|
||||
const directory = resolveTemplateDirectory(options);
|
||||
const manifest = readJson(path.join(directory, "template.json"));
|
||||
if (options.template && manifest.packageKey !== options.template)
|
||||
fail(`template.json packageKey ${manifest.packageKey} does not match ${options.template}`);
|
||||
const errors = validateTemplatePackageManifest(manifest);
|
||||
if (errors.length) fail(`Invalid template ${manifest.packageKey}:\n ${errors.join("\n ")}`);
|
||||
if (!fs.existsSync(path.join(directory, "miniapp")))
|
||||
fail(`Template package has no miniapp directory: ${manifest.packageKey}`);
|
||||
return { directory, manifest };
|
||||
}
|
||||
fs.rmSync(path.join(output, "components/templates"), { recursive: true, force: true });
|
||||
validateGeneratedIsolation(output);
|
||||
const appJsonPath = path.join(output, "app.json");
|
||||
const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf8"));
|
||||
appJson.window = {
|
||||
...appJson.window,
|
||||
navigationBarTitleText: manifest.displayName,
|
||||
|
||||
function loadCapabilities(manifest, capabilitiesRoot) {
|
||||
const capabilities = [];
|
||||
for (const key of manifest.requiredCapabilities) {
|
||||
if (CORE_CAPABILITIES.includes(key)) continue;
|
||||
const directory = path.join(capabilitiesRoot, `capability-${key}`);
|
||||
const manifestPath = path.join(directory, "capability.json");
|
||||
if (!fs.existsSync(manifestPath))
|
||||
fail(`Template ${manifest.packageKey} requires unknown capability: ${key}`);
|
||||
const capability = readJson(manifestPath);
|
||||
const errors = validateCapabilityPackageManifest(capability);
|
||||
if (capability.key !== key) errors.push(`capability.json key must be ${key}`);
|
||||
if (errors.length) fail(`Invalid capability ${key}:\n ${errors.join("\n ")}`);
|
||||
capabilities.push({ key, directory, manifest: capability });
|
||||
}
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
function resolveParams(options, manifest) {
|
||||
const env = options.env || "dev";
|
||||
if (!["dev", "prod"].includes(env)) fail(`--env must be dev or prod, got ${env}`);
|
||||
if (env === "prod") {
|
||||
const missing = ["brand", "appid", "api"].filter((key) => !options[key]);
|
||||
if (missing.length)
|
||||
fail(`Production build requires ${missing.map((key) => "--" + key).join(", ")}`);
|
||||
if (!options.api.startsWith("https://")) fail("Production --api must use https://");
|
||||
}
|
||||
const runtimeProject = readJson(path.join(runtimeRoot, "project.config.json"));
|
||||
return {
|
||||
env,
|
||||
brandSlug: options.brand || manifest.defaultBrandSlug || DEV_BRAND_SLUG,
|
||||
appid: options.appid || runtimeProject.appid,
|
||||
apiBaseUrl: options.api || DEV_API_BASE_URL,
|
||||
};
|
||||
appJson.tabBar = {
|
||||
color: "#8b8178",
|
||||
selectedColor: "#3b2118",
|
||||
backgroundColor: "#ffffff",
|
||||
borderStyle: "white",
|
||||
}
|
||||
|
||||
function prepareOutput(output) {
|
||||
const resolved = path.resolve(output);
|
||||
if (
|
||||
resolved === path.parse(resolved).root ||
|
||||
resolved === workspaceRoot ||
|
||||
workspaceRoot.startsWith(resolved + path.sep)
|
||||
)
|
||||
fail(`Refusing to use output directory: ${resolved}`);
|
||||
if (fs.existsSync(resolved)) {
|
||||
const entries = fs.readdirSync(resolved);
|
||||
if (entries.length && !entries.includes("template.runtime.json"))
|
||||
fail(`Output directory is not empty and was not generated by the compiler: ${resolved}`);
|
||||
fs.rmSync(resolved, { recursive: true, force: true });
|
||||
}
|
||||
fs.mkdirSync(resolved, { recursive: true });
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/** 按层复制文件;除模板显式 override 的目录外,任何同名文件都视为冲突。 */
|
||||
function createLayerWriter(output) {
|
||||
const owners = new Map();
|
||||
return {
|
||||
owners,
|
||||
copy(sourceDirectory, layer, exclude) {
|
||||
for (const relativePath of listFiles(sourceDirectory, exclude)) {
|
||||
if (owners.has(relativePath))
|
||||
fail(
|
||||
`${layer} conflicts with ${owners.get(relativePath)} at ${relativePath}; declare it in overrides`,
|
||||
);
|
||||
const target = path.join(output, relativePath);
|
||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||
fs.copyFileSync(path.join(sourceDirectory, relativePath), target);
|
||||
owners.set(relativePath, layer);
|
||||
}
|
||||
},
|
||||
release(prefix, layer) {
|
||||
const released = [...owners.keys()].filter((relativePath) =>
|
||||
underPrefix(relativePath, prefix),
|
||||
);
|
||||
if (!released.length) fail(`${layer} overrides ${prefix}, but no lower layer provides it`);
|
||||
for (const relativePath of released) {
|
||||
fs.rmSync(path.join(output, relativePath), { force: true });
|
||||
owners.delete(relativePath);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function unique(values) {
|
||||
return [...new Set(values)];
|
||||
}
|
||||
|
||||
function buildAppJson(manifest, templateDirectory, capabilities) {
|
||||
const runtimeApp = readJson(path.join(runtimeRoot, "app.json"));
|
||||
const templateAppPath = path.join(templateDirectory, "miniapp/app.json");
|
||||
const templateApp = fs.existsSync(templateAppPath) ? readJson(templateAppPath) : {};
|
||||
const pages = unique([
|
||||
manifest.entrypoints.home,
|
||||
...manifest.pages,
|
||||
...(runtimeApp.pages || []),
|
||||
...capabilities.flatMap((capability) => capability.manifest.pages),
|
||||
]);
|
||||
for (const [key, page] of Object.entries(manifest.entrypoints)) {
|
||||
if (!pages.includes(page)) fail(`entrypoints.${key} (${page}) is not provided by any layer`);
|
||||
}
|
||||
const tabBarStyle = templateApp.tabBar || {};
|
||||
return {
|
||||
...runtimeApp,
|
||||
pages,
|
||||
window: {
|
||||
...runtimeApp.window,
|
||||
navigationBarTitleText: manifest.displayName,
|
||||
...(templateApp.window || {}),
|
||||
},
|
||||
tabBar: {
|
||||
color: tabBarStyle.color || "#8b8178",
|
||||
selectedColor: tabBarStyle.selectedColor || "#3b2118",
|
||||
backgroundColor: tabBarStyle.backgroundColor || "#ffffff",
|
||||
borderStyle: tabBarStyle.borderStyle || "white",
|
||||
list: manifest.navigation.map((item) => ({
|
||||
pagePath: manifest.entrypoints[item.page],
|
||||
text: item.label,
|
||||
...(item.iconPath ? { iconPath: item.iconPath } : {}),
|
||||
...(item.selectedIconPath ? { selectedIconPath: item.selectedIconPath } : {}),
|
||||
})),
|
||||
},
|
||||
};
|
||||
fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2) + "\n");
|
||||
}
|
||||
|
||||
function writeGeneratedFiles(output, manifest, params, appJson, capabilities) {
|
||||
fs.writeFileSync(path.join(output, "app.json"), JSON.stringify(appJson, null, 2) + "\n");
|
||||
const project = readJson(path.join(runtimeRoot, "project.config.json"));
|
||||
fs.writeFileSync(
|
||||
path.join(output, "template.manifest.json"),
|
||||
JSON.stringify(manifest, null, 2) + "\n",
|
||||
path.join(output, "project.config.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
...project,
|
||||
appid: params.appid,
|
||||
projectname: `${params.brandSlug}-${manifest.packageKey}`,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
const runtimeConfig = {
|
||||
env: params.env,
|
||||
apiBaseUrl: params.apiBaseUrl,
|
||||
brandSlug: params.brandSlug,
|
||||
templateKey: manifest.packageKey,
|
||||
templateVersion: manifest.version,
|
||||
runtimeContract: manifest.runtimeContract,
|
||||
};
|
||||
fs.writeFileSync(
|
||||
path.join(output, "runtime-config.js"),
|
||||
`// 由 template-compiler 生成,请勿手动修改。\nmodule.exports = ${JSON.stringify(runtimeConfig, null, 2)};\n`,
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(output, "template.runtime.json"),
|
||||
@@ -309,18 +260,191 @@ function main() {
|
||||
packageKey: manifest.packageKey,
|
||||
version: manifest.version,
|
||||
runtimeContract: manifest.runtimeContract,
|
||||
brandSlug: params.brandSlug,
|
||||
env: params.env,
|
||||
capabilities: capabilities.map((capability) => ({
|
||||
key: capability.key,
|
||||
version: capability.manifest.version,
|
||||
})),
|
||||
pages: appJson.pages,
|
||||
entrypoints: manifest.entrypoints,
|
||||
navigation: manifest.navigation,
|
||||
requiredCapabilities: manifest.requiredCapabilities,
|
||||
renderers: manifest.renderers || {},
|
||||
runtimeOwnedPages: manifest.runtimeOwnedPages || [],
|
||||
ownedPaths: manifest.ownedPaths || [],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
);
|
||||
console.log(`Generated ${packageKey}@${manifest.version} -> ${path.relative(root, output)}`);
|
||||
}
|
||||
|
||||
function otherTemplateComponentNames(currentDirectory) {
|
||||
const names = new Set();
|
||||
for (const entry of fs.readdirSync(packagesRoot, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || !entry.name.startsWith("template-")) continue;
|
||||
const directory = path.join(packagesRoot, entry.name);
|
||||
if (path.resolve(directory) === path.resolve(currentDirectory)) continue;
|
||||
const componentRoot = path.join(directory, "miniapp/components/templates");
|
||||
if (!fs.existsSync(componentRoot)) continue;
|
||||
for (const component of fs.readdirSync(componentRoot)) names.add(component);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
function resolveComponent(output, fromFile, reference) {
|
||||
const base = reference.startsWith("/")
|
||||
? path.join(output, reference)
|
||||
: reference.startsWith(".")
|
||||
? path.resolve(path.dirname(path.join(output, fromFile)), reference)
|
||||
: path.join(output, "miniprogram_npm", reference);
|
||||
return [".json", ".js", ".wxml"].every((extension) => fs.existsSync(base + extension));
|
||||
}
|
||||
|
||||
function resolveRequire(output, fromFile, reference) {
|
||||
const base = path.resolve(path.dirname(path.join(output, fromFile)), reference);
|
||||
return [base, base + ".js", path.join(base, "index.js")].some(
|
||||
(candidate) => fs.existsSync(candidate) && fs.statSync(candidate).isFile(),
|
||||
);
|
||||
}
|
||||
|
||||
/** 校验产物可以被微信开发者工具直接打开:页面、组件、require、图标和模板隔离。 */
|
||||
function validateOutput(output, appJson, templateDirectory) {
|
||||
const errors = [];
|
||||
const warnings = [];
|
||||
for (const page of appJson.pages) {
|
||||
for (const extension of PAGE_EXTENSIONS) {
|
||||
if (!fs.existsSync(path.join(output, page + extension)))
|
||||
errors.push(`page ${page} is missing ${extension}`);
|
||||
}
|
||||
}
|
||||
for (const item of appJson.tabBar.list) {
|
||||
for (const icon of [item.iconPath, item.selectedIconPath]) {
|
||||
if (icon && !fs.existsSync(path.join(output, icon)))
|
||||
errors.push(`tabBar icon is missing: ${icon}`);
|
||||
}
|
||||
}
|
||||
const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm"));
|
||||
const forbiddenComponents = otherTemplateComponentNames(templateDirectory);
|
||||
const sourceFiles = listFiles(output, new Set(["miniprogram_npm"])).filter((file) =>
|
||||
/\.(js|json|wxml)$/.test(file),
|
||||
);
|
||||
for (const file of sourceFiles) {
|
||||
const source = fs.readFileSync(path.join(output, file), "utf8");
|
||||
if (file.endsWith(".json") && (file.startsWith("pages/") || file.startsWith("components/"))) {
|
||||
const usingComponents = JSON.parse(source).usingComponents || {};
|
||||
for (const [name, reference] of Object.entries(usingComponents)) {
|
||||
if (reference.startsWith("/miniprogram_npm/") && !hasNpm) {
|
||||
warnings.push(`${file}: ${name} needs miniprogram_npm (build npm in apps/miniapp first)`);
|
||||
continue;
|
||||
}
|
||||
if (reference.startsWith("plugin://")) continue;
|
||||
if (!resolveComponent(output, file, reference))
|
||||
errors.push(`${file}: component ${name} cannot be resolved (${reference})`);
|
||||
}
|
||||
}
|
||||
if (file.endsWith(".js")) {
|
||||
for (const match of source.matchAll(/require\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/g)) {
|
||||
if (!resolveRequire(output, file, match[1]))
|
||||
errors.push(`${file}: require("${match[1]}") cannot be resolved`);
|
||||
}
|
||||
}
|
||||
if (file.startsWith("pages/") || file.startsWith("components/")) {
|
||||
for (const token of ["pageRenderer", "templateKey ==="]) {
|
||||
if (source.includes(token)) errors.push(`${file}: contains template branch token ${token}`);
|
||||
}
|
||||
for (const component of forbiddenComponents) {
|
||||
if (source.includes(component))
|
||||
errors.push(`${file}: references another template's ${component}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { errors, warnings };
|
||||
}
|
||||
|
||||
/**
|
||||
* 编译一个模板为完整的小程序目录。
|
||||
* @param {{ template?: string, templateDir?: string, brand?: string, appid?: string, api?: string,
|
||||
* env?: "dev" | "prod", out?: string, capabilitiesRoot?: string }} options
|
||||
*/
|
||||
export function compileTemplate(options) {
|
||||
const { directory: templateDirectory, manifest } = loadTemplate(options);
|
||||
const capabilities = loadCapabilities(manifest, options.capabilitiesRoot || packagesRoot);
|
||||
const params = resolveParams(options, manifest);
|
||||
const output = prepareOutput(
|
||||
options.out || path.join(workspaceRoot, "dist/miniapp", params.brandSlug),
|
||||
);
|
||||
const writer = createLayerWriter(output);
|
||||
writer.copy(runtimeRoot, "runtime", RUNTIME_EXCLUDES);
|
||||
for (const capability of capabilities) {
|
||||
writer.copy(
|
||||
path.join(capability.directory, "miniapp"),
|
||||
`capability:${capability.key}`,
|
||||
LAYER_EXCLUDES,
|
||||
);
|
||||
for (const page of capability.manifest.pages) {
|
||||
if (!fs.existsSync(path.join(output, page + ".js")))
|
||||
fail(`capability ${capability.key} declares ${page} but does not provide it`);
|
||||
}
|
||||
}
|
||||
for (const prefix of manifest.overrides || [])
|
||||
writer.release(prefix, `template:${manifest.packageKey}`);
|
||||
writer.copy(
|
||||
path.join(templateDirectory, "miniapp"),
|
||||
`template:${manifest.packageKey}`,
|
||||
LAYER_EXCLUDES,
|
||||
);
|
||||
const appJson = buildAppJson(manifest, templateDirectory, capabilities);
|
||||
writeGeneratedFiles(output, manifest, params, appJson, capabilities);
|
||||
const { errors, warnings } = validateOutput(output, appJson, templateDirectory);
|
||||
if (errors.length) fail(`Generated mini program is invalid:\n ${errors.join("\n ")}`);
|
||||
return { output, manifest, params, warnings };
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const options = {};
|
||||
const names = {
|
||||
"--template": "template",
|
||||
"--template-dir": "templateDir",
|
||||
"--brand": "brand",
|
||||
"--appid": "appid",
|
||||
"--api": "api",
|
||||
"--env": "env",
|
||||
"--out": "out",
|
||||
};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const argument = argv[index];
|
||||
if (!names[argument]) {
|
||||
if (!options.template && !argument.startsWith("--")) options.template = argument;
|
||||
else fail(`Unknown argument: ${argument}`);
|
||||
continue;
|
||||
}
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith("--")) fail(`${argument} requires a value`);
|
||||
options[names[argument]] = value;
|
||||
index += 1;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const usage =
|
||||
"Usage: template:dev <template> [--brand <slug>] [--appid <id>] [--api <url>] [--env dev|prod] [--out <dir>]";
|
||||
try {
|
||||
const options = parseArgs(process.argv.slice(2));
|
||||
if (!options.template && !options.templateDir) {
|
||||
console.log(usage);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const result = compileTemplate(options);
|
||||
for (const warning of result.warnings) console.warn(`warning: ${warning}`);
|
||||
console.log(
|
||||
`Generated ${result.manifest.packageKey}@${result.manifest.version} for ${result.params.brandSlug} (${result.params.env}) -> ${path.relative(workspaceRoot, result.output) || result.output}`,
|
||||
);
|
||||
} catch (error) {
|
||||
if (!(error instanceof CompileError)) throw error;
|
||||
console.error(error.message);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href)
|
||||
main();
|
||||
@@ -10,6 +10,13 @@ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "
|
||||
const workspaceRoot = path.resolve(packageRoot, "../..");
|
||||
const compiler = path.join(packageRoot, "src/cli.mjs");
|
||||
|
||||
function assertPageBundle(output, app) {
|
||||
for (const page of app.pages) {
|
||||
for (const extension of [".js", ".json", ".wxml", ".wxss"])
|
||||
assert.equal(fs.existsSync(path.join(output, page + extension)), true, `${page}${extension}`);
|
||||
}
|
||||
}
|
||||
|
||||
test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
execFileSync(process.execPath, [compiler, "--template", "acheng-campus-food", "--out", output], {
|
||||
@@ -20,58 +27,24 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
const runtime = JSON.parse(fs.readFileSync(path.join(output, "template.runtime.json"), "utf8"));
|
||||
assert.equal(app.window.navigationBarTitleText, "阿成校园餐");
|
||||
assert.equal(runtime.packageKey, "acheng-campus-food");
|
||||
assert.equal(runtime.renderers.home, "acheng-home");
|
||||
assert.match(fs.readFileSync(path.join(output, "app.js"), "utf8"), /default-brand/);
|
||||
assert.equal(runtime.entrypoints.home, "pages/index/index");
|
||||
assert.match(fs.readFileSync(path.join(output, "runtime-config.js"), "utf8"), /default-brand/);
|
||||
assert.equal(runtime.navigation.length, 5);
|
||||
assert.equal(runtime.navigation[2].page, "service");
|
||||
assert.equal(
|
||||
JSON.parse(fs.readFileSync(path.join(output, "app.json"), "utf8")).tabBar.list.length,
|
||||
5,
|
||||
);
|
||||
assertPageBundle(output, app);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/runtime-tab-bar")), false);
|
||||
assert.equal(
|
||||
fs
|
||||
.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8")
|
||||
.includes("runtime-tab-bar"),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/templates/linjing-home")), false);
|
||||
assert.equal(
|
||||
fs.existsSync(path.join(output, "components/templates/acheng-home/acheng-home.wxml")),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/template-pages/home/home.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/templates")), false);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/<template-home/,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/acheng-home/,
|
||||
);
|
||||
assert.equal(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8").trim().length > 20,
|
||||
true,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/pageRenderer ===/,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service/index.wxml")), true);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/services/index.wxml"), "utf8"),
|
||||
/<template-offerings/,
|
||||
);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/bookings/index.wxml"), "utf8"),
|
||||
/<template-profile/,
|
||||
);
|
||||
assert.equal(
|
||||
fs
|
||||
.readFileSync(path.join(output, "pages/inquiry/index.wxml"), "utf8")
|
||||
.includes("runtime-tab-bar"),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/booking.png")), true);
|
||||
});
|
||||
|
||||
test("compiler generates the Linjing navigation contract", () => {
|
||||
@@ -82,9 +55,10 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
});
|
||||
const runtime = JSON.parse(fs.readFileSync(path.join(output, "template.runtime.json"), "utf8"));
|
||||
assert.equal(runtime.packageKey, "linjing-editorial");
|
||||
assert.equal(runtime.renderers.home, "linjing-home");
|
||||
assert.equal(runtime.renderers.offerings, "linjing-offerings");
|
||||
assert.match(fs.readFileSync(path.join(output, "app.js"), "utf8"), /linjing-doors/);
|
||||
assert.equal(runtime.entrypoints.home, "pages/index/index");
|
||||
assert.match(fs.readFileSync(path.join(output, "runtime-config.js"), "utf8"), /linjing-doors/);
|
||||
const app = JSON.parse(fs.readFileSync(path.join(output, "app.json"), "utf8"));
|
||||
assertPageBundle(output, app);
|
||||
assert.equal(runtime.navigation.length, 3);
|
||||
assert.equal(runtime.navigation[0].iconPath, "assets/tab/home.png");
|
||||
assert.equal(
|
||||
@@ -94,7 +68,7 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/works.png")), true);
|
||||
assert.equal(
|
||||
fs.existsSync(path.join(output, "components/templates/linjing-home/linjing-home.wxml")),
|
||||
false,
|
||||
true,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service")), false);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking")), false);
|
||||
@@ -102,10 +76,7 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
fs.readFileSync(path.join(output, "app.json"), "utf8"),
|
||||
/stall-service|booking\/index/,
|
||||
);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/services/index.wxml"), "utf8"),
|
||||
/<template-offerings/,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/services/index.wxml")), true);
|
||||
});
|
||||
|
||||
test("release manifest pins every workspace template version", () => {
|
||||
@@ -124,3 +95,38 @@ test("release manifest pins every workspace template version", () => {
|
||||
assert.equal(manifest.runtimeContract, releaseConfig.runtimeContract);
|
||||
}
|
||||
});
|
||||
|
||||
test("compiler rejects production builds without deployment parameters", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template", "linjing-editorial", "--env", "prod"],
|
||||
{ cwd: workspaceRoot },
|
||||
),
|
||||
/Production build requires --brand, --appid, --api/,
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler rejects unknown capabilities before copying layers", () => {
|
||||
const templateDirectory = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "personal-brand-template-package-"),
|
||||
);
|
||||
fs.cpSync(path.join(workspaceRoot, "packages/template-linjing-editorial"), templateDirectory, {
|
||||
recursive: true,
|
||||
});
|
||||
const manifestPath = path.join(templateDirectory, "template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.requiredCapabilities.push("missing");
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest));
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template-dir", templateDirectory, "--out", output],
|
||||
{ cwd: workspaceRoot },
|
||||
),
|
||||
/requires unknown capability: missing/,
|
||||
);
|
||||
});
|
||||
@@ -1,3 +1,13 @@
|
||||
# Template Contract
|
||||
|
||||
模板包是构建期输入。模板必须声明 runtime contract、页面入口、导航、行业兼容性和能力依赖;不得在模板包中实现数据库访问、鉴权或业务状态机。
|
||||
|
||||
## 新增模板
|
||||
|
||||
1. 在 `packages/template-<key>/` 创建 `template.json` 和 `miniapp/`。
|
||||
2. 在 manifest 中声明 `entrypoints`、`pages`、`navigation`、`requiredCapabilities`、数据槽位、媒体槽位和面向管理员的 `admin.sections`。
|
||||
3. 将模板自己的页面、组件、tab 图标和 `miniapp/app.json` 放入模板包。页面必须提供 `.js`、`.json`、`.wxml`、`.wxss` 四个文件。
|
||||
4. 如果需要替换运行时或能力包页面,必须在 `overrides` 中声明目录;未声明的同路径文件会被 compiler 拒绝。
|
||||
5. 执行 `pnpm generate:template-catalog --write`、`pnpm validate:templates` 和 `pnpm test:template-compiler`。
|
||||
|
||||
使用 `pnpm template:dev <key> --brand <slug>` 生成微信开发者工具项目。生产构建还必须提供 `--appid` 和 HTTPS `--api`。模板在构建时选择,运行时不会下载或解释模板代码。
|
||||
@@ -3,9 +3,13 @@ export const TEMPLATE_RUNTIME_CONTRACT = "1.0" as const;
|
||||
export type TemplatePageKey =
|
||||
"home" | "offerings" | "detail" | "inquiry" | "success" | "records" | "profile" | (string & {});
|
||||
|
||||
export type TemplateRenderers = Partial<Record<"home" | "offerings" | "profile", string>>;
|
||||
/** 运行时(apps/miniapp)提供的核心能力,不需要能力包。 */
|
||||
export const CORE_CAPABILITIES = ["offerings", "inquiry"] as const;
|
||||
|
||||
export type TemplateRuntimeOwnedPage = "detail" | "inquiry" | "success" | "records";
|
||||
/** 小程序页面路径,例如 `pages/index/index`,不带扩展名。 */
|
||||
const PAGE_PATH_PATTERN = /^pages\/[a-z0-9-]+(\/[a-z0-9-]+)*$/;
|
||||
/** 叠加路径:页面目录或组件目录,例如 `pages/inquiry`、`components/templates/acheng-home`。 */
|
||||
const LAYER_PATH_PATTERN = /^(pages|components)\/[a-z0-9-]+(\/[a-z0-9-]+)*$/;
|
||||
|
||||
/**
|
||||
* 模板向平台声明的内容来源。它只描述稳定的业务事实,不描述页面结构或 renderer。
|
||||
@@ -83,9 +87,12 @@ export type TemplatePackageManifest = {
|
||||
selectedIconPath?: string;
|
||||
}>;
|
||||
requiredCapabilities: string[];
|
||||
renderers?: TemplateRenderers;
|
||||
runtimeOwnedPages?: TemplateRuntimeOwnedPage[];
|
||||
ownedPaths?: string[];
|
||||
/** 模板包自己提供的页面;编译器据此生成 app.json。 */
|
||||
pages: string[];
|
||||
/** 模板替换运行时或能力包中的页面/组件目录;未声明的同名文件视为冲突。 */
|
||||
overrides?: string[];
|
||||
/** 开发时的默认品牌;构建参数 `--brand` 优先。 */
|
||||
defaultBrandSlug?: string;
|
||||
dataSlots: TemplateDataSlot[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
@@ -139,13 +146,25 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
|
||||
errors.push("ownedPaths must be an array when provided");
|
||||
if (!Array.isArray(manifest.requiredCapabilities))
|
||||
errors.push("requiredCapabilities must be an array");
|
||||
if (!Array.isArray(manifest.pages) || !manifest.pages.length)
|
||||
errors.push("pages must not be empty");
|
||||
else if (manifest.pages.some((page) => typeof page !== "string" || !PAGE_PATH_PATTERN.test(page)))
|
||||
errors.push("pages must contain mini program page paths such as pages/index/index");
|
||||
if (manifest.overrides !== undefined) {
|
||||
if (
|
||||
manifest.renderers !== undefined &&
|
||||
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
|
||||
!Array.isArray(manifest.overrides) ||
|
||||
manifest.overrides.some((item) => typeof item !== "string" || !LAYER_PATH_PATTERN.test(item))
|
||||
)
|
||||
errors.push("renderers must be an object when provided");
|
||||
errors.push("overrides must contain pages/... or components/... directories");
|
||||
}
|
||||
for (const item of manifest.navigation ?? []) {
|
||||
if (!item?.key?.trim() || !item.label?.trim())
|
||||
errors.push("navigation items require key and label");
|
||||
if (typeof item?.page !== "string" || typeof manifest.entrypoints?.[item.page] !== "string")
|
||||
errors.push(`navigation page is not a declared entrypoint: ${String(item?.key)}`);
|
||||
}
|
||||
for (const page of [
|
||||
"home",
|
||||
"offerings",
|
||||
@@ -158,6 +177,10 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
if (!manifest.entrypoints || typeof manifest.entrypoints[page] !== "string")
|
||||
errors.push(`entrypoints.${page} is required`);
|
||||
}
|
||||
for (const [key, page] of Object.entries(manifest.entrypoints ?? {})) {
|
||||
if (typeof page !== "string" || !PAGE_PATH_PATTERN.test(page))
|
||||
errors.push(`entrypoints.${key} must be a mini program page path`);
|
||||
}
|
||||
if (manifest.sampleContent !== undefined) {
|
||||
for (const [industryKey, sample] of Object.entries(manifest.sampleContent)) {
|
||||
if (!manifest.supportedIndustryTemplates?.includes(industryKey))
|
||||
@@ -180,3 +203,33 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* 能力包清单(packages/capability-<key>/capability.json)。
|
||||
* 能力包为需要独立业务流程的能力提供小程序页面,由模板的 requiredCapabilities 引入。
|
||||
*/
|
||||
export type CapabilityPackageManifest = {
|
||||
key: string;
|
||||
version: string;
|
||||
runtimeContract: typeof TEMPLATE_RUNTIME_CONTRACT;
|
||||
description: string;
|
||||
pages: string[];
|
||||
};
|
||||
|
||||
export function validateCapabilityPackageManifest(value: unknown): string[] {
|
||||
const errors: string[] = [];
|
||||
if (!value || typeof value !== "object") return ["capability manifest must be an object"];
|
||||
const manifest = value as Partial<CapabilityPackageManifest>;
|
||||
if (!manifest.key?.trim()) errors.push("key is required");
|
||||
if ((CORE_CAPABILITIES as readonly string[]).includes(manifest.key ?? ""))
|
||||
errors.push(`${manifest.key} is a core capability provided by the runtime`);
|
||||
if (!manifest.version?.trim()) errors.push("version is required");
|
||||
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
|
||||
errors.push(`runtimeContract must be ${TEMPLATE_RUNTIME_CONTRACT}`);
|
||||
if (!manifest.description?.trim()) errors.push("description is required");
|
||||
if (!Array.isArray(manifest.pages) || !manifest.pages.length)
|
||||
errors.push("pages must not be empty");
|
||||
else if (manifest.pages.some((page) => typeof page !== "string" || !PAGE_PATH_PATTERN.test(page)))
|
||||
errors.push("pages must contain mini program page paths");
|
||||
return errors;
|
||||
}
|
||||
+3
-22
@@ -1,27 +1,11 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
const { customerRequest, customerTokenKey } = require("../../utils/request");
|
||||
|
||||
Page({
|
||||
data: {
|
||||
brand: {},
|
||||
trustContent: [],
|
||||
records: [],
|
||||
pageRenderer: "",
|
||||
error: "",
|
||||
templateKey: "",
|
||||
navigation: [],
|
||||
},
|
||||
data: { brand: {}, records: [], error: "" },
|
||||
onLoad() {
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) =>
|
||||
this.setData({
|
||||
brand: workspace.brand || {},
|
||||
trustContent: workspace.trustPresentation || {},
|
||||
pageRenderer: workspace.pageRenderers?.profile || "",
|
||||
records: [],
|
||||
templateKey: workspace.visualTemplate?.key || "",
|
||||
navigation: workspace.navigation || [],
|
||||
}),
|
||||
)
|
||||
.then((workspace) => this.setData({ brand: workspace.brand || {} }))
|
||||
.catch((error) => this.setData({ error: error.message }));
|
||||
},
|
||||
onShow() {
|
||||
@@ -50,7 +34,4 @@ Page({
|
||||
recordsPage() {
|
||||
wx.navigateTo({ url: "/pages/records/index" });
|
||||
},
|
||||
inquire() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index" });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "主理人与我",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black",
|
||||
"usingComponents": {
|
||||
"linjing-profile": "/components/templates/linjing-profile/linjing-profile"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<view class="page">
|
||||
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
|
||||
<linjing-profile wx:else brand="{{brand}}" presentation="{{brand.visualPresentation.profile}}" records-count="{{records.length}}" bind:call="call" bind:copy="copyWechat" bind:records="recordsPage" />
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 页面样式由林境模板组件提供。 */
|
||||
@@ -0,0 +1,41 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
|
||||
Page({
|
||||
data: {
|
||||
brand: {},
|
||||
trustContent: {},
|
||||
offerings: [],
|
||||
hero: { image: "", eyebrow: "", title: "", slogan: "", cta: "" },
|
||||
error: "",
|
||||
},
|
||||
onLoad() {
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) => {
|
||||
const brand = workspace.brand || {};
|
||||
const offerings = workspace.offerings || [];
|
||||
const configuredHero =
|
||||
brand.homeHero && typeof brand.homeHero === "object" ? brand.homeHero : {};
|
||||
this.setData({
|
||||
brand,
|
||||
trustContent: workspace.trustPresentation || {},
|
||||
offerings,
|
||||
hero: {
|
||||
...this.data.hero,
|
||||
image: brand.heroImage || "",
|
||||
eyebrow: brand.tagline || brand.name,
|
||||
title: (offerings[0] && offerings[0].name) || brand.name,
|
||||
slogan: brand.description || "",
|
||||
...configuredHero,
|
||||
},
|
||||
});
|
||||
wx.setNavigationBarTitle({ title: brand.name || "个人品牌" });
|
||||
})
|
||||
.catch((error) => this.setData({ error: error.message }));
|
||||
},
|
||||
selectOffering(event) {
|
||||
wx.navigateTo({ url: "/pages/offering/detail?id=" + event.detail.id });
|
||||
},
|
||||
goWorks() {
|
||||
wx.switchTab({ url: "/pages/services/index" });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"navigationBarTitleText": "品牌首页",
|
||||
"usingComponents": {
|
||||
"linjing-home": "/components/templates/linjing-home/linjing-home"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<view class="page">
|
||||
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
|
||||
<linjing-home wx:else brand="{{brand}}" presentation="{{brand.visualPresentation.home}}" hero="{{hero}}" trust-content="{{trustContent}}" offerings="{{offerings}}" bind:select="selectOffering" bind:works="goWorks" />
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 页面样式由林境模板组件提供。 */
|
||||
@@ -0,0 +1,22 @@
|
||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||
|
||||
Page({
|
||||
data: { brand: {}, presentation: {}, offerings: [], error: "" },
|
||||
onLoad() {
|
||||
loadWorkspaceWithFallback()
|
||||
.then((workspace) =>
|
||||
this.setData({
|
||||
brand: workspace.brand || {},
|
||||
presentation: workspace.brand?.visualPresentation?.offerings || {},
|
||||
offerings: workspace.offerings || [],
|
||||
}),
|
||||
)
|
||||
.catch((error) => this.setData({ error: error.message }));
|
||||
},
|
||||
open(event) {
|
||||
wx.navigateTo({ url: "/pages/offering/detail?id=" + event.detail.id });
|
||||
},
|
||||
inquire() {
|
||||
wx.navigateTo({ url: "/pages/inquiry/index" });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"navigationBarTitleText": "案例与体系",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black",
|
||||
"usingComponents": {
|
||||
"linjing-offerings": "/components/templates/linjing-offerings/linjing-offerings"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<view class="page">
|
||||
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
|
||||
<linjing-offerings wx:else brand="{{brand}}" presentation="{{presentation}}" offerings="{{offerings}}" bind:open="open" bind:more="inquire" />
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* 页面样式由林境模板组件提供。 */
|
||||
@@ -413,15 +413,5 @@
|
||||
"capabilityKey": "inquiry"
|
||||
}
|
||||
},
|
||||
"renderers": {
|
||||
"home": "linjing-home",
|
||||
"offerings": "linjing-offerings",
|
||||
"profile": "linjing-profile"
|
||||
},
|
||||
"runtimeOwnedPages": ["detail", "inquiry", "success", "records"],
|
||||
"ownedPaths": [
|
||||
"components/templates/linjing-home",
|
||||
"components/templates/linjing-offerings",
|
||||
"components/templates/linjing-profile"
|
||||
]
|
||||
"pages": ["pages/index/index", "pages/services/index", "pages/bookings/index"]
|
||||
}
|
||||
@@ -3,55 +3,9 @@ const path = require("node:path");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
require(path.join(root, "scripts/generate-template-catalog.cjs"));
|
||||
const packageRoot = path.join(root, "templates");
|
||||
const workspacePackageRoot = path.join(root, "packages");
|
||||
const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"];
|
||||
const errors = [];
|
||||
|
||||
for (const entry of fs.readdirSync(packageRoot, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const packageDir = path.join(packageRoot, entry.name);
|
||||
const manifestPath = path.join(packageDir, "template.json");
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
errors.push(`${entry.name}: template.json is missing`);
|
||||
continue;
|
||||
}
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
} catch (error) {
|
||||
errors.push(`${entry.name}: invalid template.json (${error.message})`);
|
||||
continue;
|
||||
}
|
||||
if (manifest.packageKey !== entry.name)
|
||||
errors.push(`${entry.name}: packageKey must match directory name`);
|
||||
if (!manifest.version) errors.push(`${entry.name}: version is required`);
|
||||
if (manifest.runtimeContract !== "1.0") errors.push(`${entry.name}: unsupported runtimeContract`);
|
||||
for (const page of requiredPages) {
|
||||
if (typeof manifest.entrypoints?.[page] !== "string" || !manifest.entrypoints[page]) {
|
||||
errors.push(`${entry.name}: entrypoints.${page} is required`);
|
||||
}
|
||||
}
|
||||
if (
|
||||
!Array.isArray(manifest.supportedIndustryTemplates) ||
|
||||
!manifest.supportedIndustryTemplates.length
|
||||
) {
|
||||
errors.push(`${entry.name}: supportedIndustryTemplates must not be empty`);
|
||||
}
|
||||
if (!Array.isArray(manifest.requiredCapabilities))
|
||||
errors.push(`${entry.name}: requiredCapabilities must be an array`);
|
||||
if (!fs.existsSync(path.join(packageDir, "README.md")))
|
||||
errors.push(`${entry.name}: README.md is missing`);
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join("\n"));
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(
|
||||
`Template packages validated: ${fs.readdirSync(packageRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).length}`,
|
||||
);
|
||||
|
||||
const workspacePackageRoot = path.join(root, "packages");
|
||||
const workspaceTemplates = fs
|
||||
.readdirSync(workspacePackageRoot, { withFileTypes: true })
|
||||
.filter(
|
||||
@@ -60,18 +14,21 @@ const workspaceTemplates = fs
|
||||
entry.name.startsWith("template-") &&
|
||||
fs.existsSync(path.join(workspacePackageRoot, entry.name, "template.json")),
|
||||
);
|
||||
|
||||
for (const entry of workspaceTemplates) {
|
||||
const manifestPath = path.join(workspacePackageRoot, entry.name, "template.json");
|
||||
if (!fs.existsSync(manifestPath)) errors.push(`${entry.name}: template.json is missing`);
|
||||
else {
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
if (
|
||||
manifest.packageKey !== entry.name &&
|
||||
manifest.packageKey !== entry.name.replace(/^template-/, "")
|
||||
)
|
||||
const packageDir = path.join(workspacePackageRoot, entry.name);
|
||||
const manifestPath = path.join(packageDir, "template.json");
|
||||
let manifest;
|
||||
try {
|
||||
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
} catch (error) {
|
||||
errors.push(`${entry.name}: invalid template.json (${error.message})`);
|
||||
continue;
|
||||
}
|
||||
if (![entry.name, entry.name.replace(/^template-/, "")].includes(manifest.packageKey))
|
||||
errors.push(`${entry.name}: packageKey must match directory name or template key`);
|
||||
if (manifest.runtimeContract !== "1.0")
|
||||
errors.push(`${entry.name}: unsupported runtimeContract`);
|
||||
if (!manifest.version) errors.push(`${entry.name}: version is required`);
|
||||
if (manifest.runtimeContract !== "1.0") errors.push(`${entry.name}: unsupported runtimeContract`);
|
||||
if (!manifest.displayName) errors.push(`${entry.name}: displayName is required`);
|
||||
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
|
||||
errors.push(`${entry.name}: navigation is required`);
|
||||
@@ -79,38 +36,21 @@ for (const entry of workspaceTemplates) {
|
||||
errors.push(`${entry.name}: dataSlots is required`);
|
||||
if (!Array.isArray(manifest.assetSlots))
|
||||
errors.push(`${entry.name}: assetSlots must be an array`);
|
||||
if (
|
||||
!manifest.admin ||
|
||||
!Array.isArray(manifest.admin.sections) ||
|
||||
!manifest.admin.sections.length
|
||||
)
|
||||
if (!manifest.admin || !Array.isArray(manifest.admin.sections) || !manifest.admin.sections.length)
|
||||
errors.push(`${entry.name}: admin.sections is required`);
|
||||
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
|
||||
errors.push(`${entry.name}: ownedPaths must be an array`);
|
||||
if (
|
||||
manifest.renderers !== undefined &&
|
||||
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
|
||||
)
|
||||
errors.push(`${entry.name}: renderers must be an object`);
|
||||
if (
|
||||
manifest.runtimeOwnedPages !== undefined &&
|
||||
(!Array.isArray(manifest.runtimeOwnedPages) ||
|
||||
manifest.runtimeOwnedPages.some(
|
||||
(page) => !["detail", "inquiry", "success", "records"].includes(page),
|
||||
))
|
||||
)
|
||||
errors.push(`${entry.name}: runtimeOwnedPages contains an unsupported page`);
|
||||
for (const item of manifest.navigation || []) {
|
||||
for (const asset of [item.iconPath, item.selectedIconPath]) {
|
||||
if (asset && !fs.existsSync(path.join(workspacePackageRoot, entry.name, "miniapp", asset)))
|
||||
errors.push(`${entry.name}: navigation asset is missing: ${asset}`);
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(manifest.pages) || !manifest.pages.length)
|
||||
errors.push(`${entry.name}: pages is required`);
|
||||
for (const page of requiredPages)
|
||||
if (typeof manifest.entrypoints?.[page] !== "string")
|
||||
errors.push(`${entry.name}: entrypoints.${page} is required`);
|
||||
for (const item of manifest.navigation || []) {
|
||||
for (const asset of [item.iconPath, item.selectedIconPath]) {
|
||||
if (asset && !fs.existsSync(path.join(packageDir, "miniapp", asset)))
|
||||
errors.push(`${entry.name}: navigation asset is missing: ${asset}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join("\n"));
|
||||
process.exit(1);
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# 阿成校园餐模板包
|
||||
|
||||
第二个真实视觉模板,源自用户提供的 React 原型。模板采用校园餐饮的暖橙色、菜单卡片、出摊提示和预约转化表达。
|
||||
|
||||
生产内容必须来自 Runtime Workspace;原型中的 mock 菜品、预约记录和图片仅用于视觉参考。
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"packageKey": "acheng-campus-food",
|
||||
"version": "1.0.0",
|
||||
"displayName": "阿成校园餐",
|
||||
"visualTemplateKey": "acheng-campus-food",
|
||||
"runtimeContract": "1.0",
|
||||
"supportedIndustryTemplates": ["food"],
|
||||
"requiredCapabilities": ["offerings", "inquiry", "booking"],
|
||||
"entrypoints": {
|
||||
"home": "apps/miniapp/components/templates/acheng-home",
|
||||
"offerings": "apps/miniapp/pages/services/index",
|
||||
"detail": "apps/miniapp/pages/offering/detail",
|
||||
"inquiry": "apps/miniapp/pages/inquiry/index",
|
||||
"success": "apps/miniapp/pages/inquiry-success/index",
|
||||
"records": "apps/miniapp/pages/records/index",
|
||||
"profile": "apps/miniapp/components/templates/acheng-profile"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
# 林境建筑画册模板包
|
||||
|
||||
当前唯一正式视觉模板包,版本 `1.0.0`。
|
||||
|
||||
模板页面消费统一的 Runtime Workspace,不直接读取数据库或行业专属字段。个人、餐饮、门窗的差异来自行业模板、业务提供项、信任内容、咨询表单和 capability。
|
||||
|
||||
当前实现入口仍位于 `apps/miniapp`,本目录是模板包的归一化元数据边界。后续接入独立构建流水线时,页面、组件、资源和 fixture 应整体迁入本包,并保持 `template.json` 的入口和 Contract 不变。
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"packageKey": "linjing-editorial",
|
||||
"version": "1.0.0",
|
||||
"displayName": "林境建筑画册",
|
||||
"visualTemplateKey": "linjing-editorial",
|
||||
"runtimeContract": "1.0",
|
||||
"supportedIndustryTemplates": ["personal", "food", "doors"],
|
||||
"requiredCapabilities": ["offerings", "inquiry"],
|
||||
"entrypoints": {
|
||||
"home": "apps/miniapp/components/templates/linjing-home",
|
||||
"offerings": "apps/miniapp/pages/services/index",
|
||||
"detail": "apps/miniapp/pages/offering/detail",
|
||||
"inquiry": "apps/miniapp/pages/inquiry/index",
|
||||
"success": "apps/miniapp/pages/inquiry-success/index",
|
||||
"records": "apps/miniapp/pages/records/index",
|
||||
"profile": "apps/miniapp/components/templates/linjing-profile"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user