Compare commits
21
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbcee45bb | ||
|
|
46b1690f6c | ||
|
|
0e0ca201a7 | ||
|
|
569156c977 | ||
|
|
20e7e8bb81 | ||
|
|
20eb160abf | ||
|
|
d0ef25cfb3 | ||
|
|
d2ce2d2a84 | ||
|
|
f57e1b1336 | ||
|
|
22a82dbfba | ||
|
|
fa6b492bce | ||
|
|
860d9266fe | ||
|
|
a2932b1134 | ||
|
|
849ae5df05 | ||
|
|
df2b1f6031 | ||
|
|
66dbba5748 | ||
|
|
c5db30f817 | ||
|
|
541304a763 | ||
|
|
fd2e970d8b | ||
|
|
5b85fe769f | ||
|
|
0b14b5a814 |
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
# Admin 编辑工作区重构
|
||||||
|
|
||||||
|
## 目标
|
||||||
|
|
||||||
|
把 Admin 的品牌配置与小程序页面编辑整理成一个层级清晰、可持续扩展的工作区。用户能够明确区分品牌基础资料、模板内容、业务记录和页面预览;页面预览、区域选择和字段编辑保持统一行为。
|
||||||
|
|
||||||
|
## 交付边界
|
||||||
|
|
||||||
|
- 品牌资料页面减少 Card 堆叠,形成连续的配置分组。
|
||||||
|
- 小程序页面配置成为主要编辑工作区,使用页面导航、预览画布和编辑面板的稳定布局。
|
||||||
|
- 详情页只提供业务记录选择和动态预览,不出现品牌级详情编辑表单。
|
||||||
|
- 预览选区、高亮、编辑状态、空状态和错误状态保持一致。
|
||||||
|
- 不改变后端数据模型和小程序业务语义;模板仍通过 manifest 声明页面、区域和字段。
|
||||||
|
|
||||||
|
## 设计原则
|
||||||
|
|
||||||
|
- 基础品牌事实只提供一个编辑入口。
|
||||||
|
- 模板专属字段由模板 manifest 驱动,不在共享页面中写行业逻辑。
|
||||||
|
- 预览是编辑上下文的一部分,不单独启动每个模板服务。
|
||||||
|
- 详情页数据来自选中的业务记录,视觉文案只能作为模板配置存在。
|
||||||
|
- 页面区块使用平面分组和分隔线,只有真正需要独立操作的区域使用 Card。
|
||||||
|
|
||||||
|
## 验收标准
|
||||||
|
|
||||||
|
- 1920、1280、1024、768 和 390 宽度下布局无横向溢出。
|
||||||
|
- 品牌资料、页面配置和发布状态的层级可以在首屏理解。
|
||||||
|
- 首页、业务、服务、详情、咨询、成功和记录页面均可切换并保持稳定高度。
|
||||||
|
- 点击模板区域后,选区高亮和右侧编辑面板始终同步。
|
||||||
|
- 详情页只能选择业务记录并预览,不能出现品牌级详情字段编辑。
|
||||||
|
- 通过 Admin/Taro typecheck、模板契约测试、生产构建和关键浏览器交互测试。
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# Progress
|
||||||
|
|
||||||
|
## 保存体验收尾
|
||||||
|
|
||||||
|
- 品牌资料、页面字段、记录和咨询字段暴露未保存状态;保存成功清除对应状态,失败保留输入。
|
||||||
|
- 切换页面/记录提供取消或放弃确认,刷新关闭窗口提供提醒,工作区内链接离开提供确认。
|
||||||
|
- 保存操作区采用统一的面板底部样式;业务记录与品牌配置继续分别保存到原有接口。
|
||||||
|
- 浏览器测试补充未保存取消切换与失败重试场景;测试采用独立接口 fixture,不冒充当前数据库的端到端验收。
|
||||||
|
- 本轮没有重构品牌切换器或新增跨实体批量保存 API,这些不作为已验证能力。
|
||||||
|
|
||||||
|
## 工作台重构补充验收
|
||||||
|
|
||||||
|
- 上一轮将布局整理判为全部完成不准确,补充真正的工作台任务:视图分离、三栏布局和层级区域导航。
|
||||||
|
- 默认显示页面编辑,品牌基础表单在“品牌资料”视图访问;两套组件保持挂载,切换不丢弃草稿。
|
||||||
|
- 区域导航移至左栏,预览居中,属性编辑位于右栏;子区域缩进,选区与导航选中状态同步。
|
||||||
|
- 顶部区分草稿工作区与检查发布入口,保存仍由各内容表单负责,避免错误承诺跨实体统一保存。
|
||||||
|
- 已通过 2 项浏览器回归和五种宽度检查,并查看 1920 宽度实际截图。
|
||||||
|
|
||||||
|
## 2026-10-10
|
||||||
|
|
||||||
|
- 建立 Admin 编辑工作区重构 Epic。
|
||||||
|
- 当前已知问题:品牌资料上方存在多个连续 Card;小程序页面配置仍是普通 Card;预览区和编辑面板层级不够明确;详情页需要保持动态只读预览;选区高亮需要继续验证真实鼠标路径。
|
||||||
|
- 当前基线能力:模板 manifest、Taro renderer、RuntimeWorkspace 和 Admin 字段绑定已经形成契约;本 Epic 主要调整 Admin 信息架构与视觉层。
|
||||||
|
- 第 1 项已完成:确认 `BrandPage` 的两列 Card 结构、页面配置固定最小高度、模板说明右栏和编辑器内部重复导航。
|
||||||
|
- 第 2 项开始:先整理品牌资料页面层级,减少 Card 作为页面区块容器的使用。
|
||||||
|
- 第 2 项阶段性完成:`BrandPage` 已将品牌身份、联系合作、模板视觉改为连续分组,模板说明改为右侧辅助 `Alert`,并增加移动端断点。
|
||||||
|
- 验证:Admin typecheck 通过,`admin-editor.spec.ts` 2 项通过。
|
||||||
|
- 第 2 项完成,第 3 项开始:`PresentationEditor` 已移除外层 Card 和固定最小高度,改为独立工作区标题区;下一步处理工作区内部布局和视觉状态。
|
||||||
|
|
||||||
|
- 工作区完成:品牌配置使用连续分组;模板辅助信息移入基础资料尾部;编辑器使用完整宽度两栏布局,窄屏上下排列。
|
||||||
|
- 未选中时显示引导,详情页目标列表为空且不显示点选工具。
|
||||||
|
- 新增 1920/1280/1024/768/390 宽度无溢出断言和截图,已人工查看 1280 与 390 截图。
|
||||||
|
- 验证通过:Admin/Taro typecheck、Admin lint、全仓 format:check、19 项模板契约测试、Admin build、2 项浏览器测试。
|
||||||
|
- lint 暴露已有 InquiryPreviewEditor 类型问题,已通过 Form 泛型和普通对象传入修复。
|
||||||
|
- 保留已知构建 api chunk 超过 500 kB 提示,后续由 Admin 前端打包优化任务负责;记录在 ADR 0021。
|
||||||
|
- 本轮不涉及新增 API 或数据迁移。
|
||||||
|
|
||||||
|
- 最终收尾完成:新增全局未保存离开提醒、切换确认、保存状态和失败保留输入;属性面板保存按钮固定在底部。
|
||||||
|
- 验证通过:Admin/Taro typecheck、Admin lint、format:check、19 项模板契约、Admin build、浏览器 2 项(含未保存取消切换与失败重试)。
|
||||||
|
- 构建仍有 api chunk 超过 500 kB 的提示,属于后续打包优化项,不影响构建结果。
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
id,title,status,task_type,depends_on,acceptance_criteria,validation_command,task_dir,notes
|
||||||
|
1,建立现状基线与页面覆盖清单,DONE,single-full,,记录当前布局层级、Card 使用、响应式问题和关键交互,测试基线截图与 DOM 检查,.codex-tasks/admin-editor-workspace/tasks/01-baseline/,已完成代码结构基线与验证记录
|
||||||
|
2,重构品牌配置的信息架构,DONE,single-full,1,品牌资料按身份联系模板视觉分组且减少卡片嵌套,Admin typecheck; browser brand page test,.codex-tasks/admin-editor-workspace/tasks/02-information-architecture/,已完成分组与模板说明层级调整
|
||||||
|
3,重构小程序页面编辑工作区,DONE,single-full,1;2,页面导航预览画布编辑面板形成稳定三栏或响应式两栏布局,Admin build; browser editor test,.codex-tasks/admin-editor-workspace/tasks/03-workspace-ui/,完整宽度两栏工作区,窄屏堆叠;详情页只读;未选中显示引导
|
||||||
|
4,统一编辑器视觉系统与状态样式,DONE,single-full,3,间距层级按钮选区空状态错误状态统一且无 Card 堆叠,Prettier; Admin build; screenshot review,.codex-tasks/admin-editor-workspace/tasks/04-visual-system/,统一导航工具条、画布边界、区域按钮和面板间距;已检查 1280 与 390 截图
|
||||||
|
5,全页面回归与交付验收,DONE,single-full,2;3;4,关键页面交互和响应式检查通过并记录残余风险,validate:templates; typecheck; build; browser tests,.codex-tasks/admin-editor-workspace/tasks/05-regression/,5 种宽度无溢出;浏览器 2 项、契约 19 项、格式、lint、类型和构建通过
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
# 当前基线
|
||||||
|
|
||||||
|
## 页面结构
|
||||||
|
|
||||||
|
- `BrandPage` 使用两列布局:左侧 `xl=16`,右侧 `xl=8`。
|
||||||
|
- 左侧依次渲染“我是谁”“如何联系与合作”“模板与品牌视觉”三个 `Card`。
|
||||||
|
- 左侧表单之后渲染“小程序页面配置” `Card`。
|
||||||
|
- 右侧单独渲染“模板说明” `Card`。
|
||||||
|
- 页面配置内部还有页面导航、页面预览、详情业务选择器、预览目标按钮和右侧编辑表单。
|
||||||
|
|
||||||
|
## 已确认问题
|
||||||
|
|
||||||
|
- 配置 Card 与页面编辑 Card 在视觉上处于同一层级,用户难以判断基础资料和页面编辑的关系。
|
||||||
|
- “模板说明”占据右侧固定列,但对编辑流程帮助有限,造成首屏空间浪费。
|
||||||
|
- 页面配置使用 `minHeight: 760/620`,内容较少的页面会出现大面积空白。
|
||||||
|
- 页面配置内部的预览目标按钮与画布选区重复表达同一件事。
|
||||||
|
- 详情页已经改为动态预览提示,但页面整体仍沿用通用编辑器的表单布局。
|
||||||
|
- 品牌资料表单保存按钮位于所有配置分组之后,长页面中不够容易发现。
|
||||||
|
|
||||||
|
## 现有可复用能力
|
||||||
|
|
||||||
|
- 模板 manifest 声明页面、区域、字段和 preview target。
|
||||||
|
- `RuntimeWorkspace` 为组件预览提供品牌、业务记录、信任内容和咨询表单数据。
|
||||||
|
- `ComponentTemplatePreview` 支持点选、高亮、组合区域和浏览模式。
|
||||||
|
- `PresentationEditor` 已支持业务记录编辑、信任内容编辑和咨询字段编辑。
|
||||||
|
|
||||||
|
## 基线验证
|
||||||
|
|
||||||
|
- `pnpm --filter @personal-brand/admin typecheck`:通过。
|
||||||
|
- `pnpm --filter @personal-brand/taro typecheck`:通过。
|
||||||
|
- `pnpm validate:templates`:19 项模板契约测试通过。
|
||||||
|
- 已有 `admin-editor.spec.ts` 覆盖页面切换、预览选区、业务记录、信任内容、咨询表单和详情页动态预览。
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
# 本轮执行进度
|
||||||
|
|
||||||
|
## 当前恢复点
|
||||||
|
|
||||||
|
- 任务:现有两模板按通用规则诊断、修复、验收。
|
||||||
|
- 形态:single-full。
|
||||||
|
- 进度:7/7;任务真源为 TODO.csv。
|
||||||
|
- 当前:本轮审计修复和证据归档完成,详见 docs/template-audit-2026-10-10.md。
|
||||||
|
- 验证:真实数据库集成 41 项通过,覆盖 193 个声明绑定;真实 manifest 浏览器逐页/320 与 390 宽布局、全部实际存在目标的画布内部点选、方法和流程子字段修改重载共 2 项通过(42.3 秒)。
|
||||||
|
- 静态报告:两模板 blocker 均为 0,food review 55,linjing review 23;命令仍退出 1,保留原报告 completionStatus=unverified。
|
||||||
|
- 动态审查:raw/manual-review.json 为每条 review 保存来源、只读理由和证据;条件组合未穷举,不将源码审查冒充浏览器全分支验证。
|
||||||
|
- 数据:只在随机独立 schema 做 integration;没有生产 migration 或 seed 改写。
|
||||||
|
- 下一步:当前无剩余实现任务;保持未提交 diff,后续模板按相同规则验收。静态 completionStatus 不自动改为完整通过。
|
||||||
|
|
||||||
|
## 本轮新增故障与修复
|
||||||
|
|
||||||
|
1. 新 config 被旧完整品牌对象覆盖:仅发送改变的标准字段和新 config,剔除模板选择字段。
|
||||||
|
2. 保存后 Admin 预览读取旧发布快照:从当前品牌记录构建内存草稿,与公开投影共用服务;公开仍读取发布快照。
|
||||||
|
3. 旧 config.avatarUrl 覆盖共享头像:标准列优先,主动清空后旧别名不得复活。
|
||||||
|
4. templateFields 错页、templateData 未同步:按 page 分组并同步专属草稿。
|
||||||
|
5. 列表只检查 binding:补逐个 itemFields 检查及排序;空区域提供内容管理入口。
|
||||||
|
6. 详情正文与底部按钮共用目标:拆为两个公共编辑区,业务记录仍仅选择预览。
|
||||||
|
|
||||||
|
## 画布检查的失败记录
|
||||||
|
|
||||||
|
新增检查先后发现测试命中点不正确:圆角透明角落、父容器采样落在子区、装饰图片被遮罩覆盖。原始失败保留 raw/browser-*-failure.log;最终也发现林境 fixture 缺少所有介绍标题,使父区域没有显示文字,补真实结构的标题内容后验收通过。重新审查测试输入后,改为点击目标内有文字的叶子内容,并先确认浏览器真实 elementFromPoint 命中的最近目标。没有强制点击、删业务断言或改变模板视觉。
|
||||||
|
|
||||||
|
## 前轮历史(已被本轮验证补充)
|
||||||
|
|
||||||
|
# 本轮审计结果
|
||||||
|
|
||||||
|
本轮按 skill 完成诊断、修复、回归与剩余项归档;模板整体验收仍为 unverified。
|
||||||
|
|
||||||
|
## 静态结果
|
||||||
|
|
||||||
|
- acheng-campus-food:blocker 11 → 2;review 120
|
||||||
|
- linjing-editorial:blocker 26 → 2;review 65
|
||||||
|
|
||||||
|
## 已验证
|
||||||
|
|
||||||
|
- 林境真实 manifest:主理人完整字段、最近选区、统计 2×2、数值编辑保存重载、共享简介保存重载、侧栏信任记录定位、主理人页不出现首页统计目标。
|
||||||
|
- 餐饮现有浏览器回归通过,新增共享字段未逐一完成端到端验证。
|
||||||
|
- 浏览器 2 项通过;模板契约 19 项、诊断器 15 项通过;Admin 单元测试、Admin/Taro 类型、Admin lint 与生产构建、全仓格式及 diff 检查通过。
|
||||||
|
- 独立随机 schema 的 API 集成 40 项通过;不等于所有新模板字段发布流程逐项已验证。
|
||||||
|
|
||||||
|
## 未完成与限制
|
||||||
|
|
||||||
|
- 两模板详情页公共按钮文案仍由品牌配置读取,与只读详情预览边界需进一步明确,4 条静态 blocker 保留。
|
||||||
|
- 动态循环、条件分支等 review 仍需逐项核对,不能用静态报告证明完整。
|
||||||
|
- 林境截图验证 2×2,使用 fixture 主图且头像未加载,不能作为真实原型视觉一致性证明;原型全量对照未完成。
|
||||||
|
- 未对每个新增共享字段执行真实数据库发布后公开读取;现有集成通过不能替代该覆盖。
|
||||||
|
- Admin 构建仍有已有大于 500 kB chunk 提示。
|
||||||
|
|
||||||
|
## 经验沉淀
|
||||||
|
|
||||||
|
新增多入口绑定同步及未挂载字段保留规则,补入 skill 和回归。未提交 commit,未迁移生产数据。
|
||||||
|
|
||||||
|
## 最终门槛
|
||||||
|
|
||||||
|
- browser-current.log:2/2 通过,42.3 秒;实际画布目标检查没有使用 force 或 dispatchEvent。
|
||||||
|
- integration-final.log:41/41 通过,193 个真实绑定保存/草稿/发布验证。
|
||||||
|
- API Client 3/3、模板契约 19/19、诊断器 19/19;API/Admin/Taro 类型检查通过。
|
||||||
|
- API/Admin lint、Admin 构建、两模板 H5 与 weapp 构建通过;格式和 diff 检查通过。
|
||||||
|
- 完整范围、78 条动态映射 review 的源码审阅和视觉限制保留在最终文档及 raw/manual-review.json;没有将静态退出 1 隐藏为通过。
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# 按 template-completion-audit 执行现有模板审计
|
||||||
|
|
||||||
|
范围:自动发现两个模板,修复共享字段入口、选区、信任页作用域与实际绑定,运行真实 manifest 浏览器及隔离数据库回归,记录未完成证据。没有生产数据迁移或自动提交。
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
id,task,status,acceptance_criteria,validation_command,completed_at,retry_count,notes
|
||||||
|
1,采集真实基线,DONE,before 报告已存档,node scripts/template-doctor.mjs,2026-10-10,0,退出 1 保留实际问题
|
||||||
|
2,修复公共编辑和字段绑定,DONE,真实 manifest 修改保存重载测试通过,playwright admin-editor.spec.ts,2026-10-10,1,修复共享字段未挂载覆盖
|
||||||
|
3,执行审计验证并归档边界,DONE,保留未验证和失败项,pnpm format:check,2026-10-10,0,详情按钮与原型全量验收未完成
|
||||||
|
4,补齐详情公共文案和真实卡片字段,DONE,所有展示字段有对应入口,pnpm validate:templates,2026-10-10,0,详情正文与底部按钮独立目标;真实卡片字段补齐;模板契约 19 项通过
|
||||||
|
5,验证真实声明的浏览器编辑闭环,DONE,两个模板真实声明保存重载测试通过,playwright admin-editor.spec.ts,2026-10-10,0,2 项真实 manifest 浏览器通过;含逐页画布内部点击、字段面板、列表子项修改重载和多宽检查
|
||||||
|
6,验证数据库保存发布隔离,DONE,新增字段真实持久化发布回归通过,pnpm --filter @personal-brand/api test:integration,2026-10-10,0,41 项集成通过;193 个真实绑定隔离数据库保存草稿发布验证
|
||||||
|
7,归档动态映射和视觉验收,DONE,逐项证据与门槛验证完成,pnpm template:doctor,2026-10-10,4,78 条动态审查归档;最终画布检查通过;原型结构与视觉边界详见 docs/template-audit-2026-10-10.md
|
||||||
|
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
|||||||
|
# 可视化编辑闭环
|
||||||
|
|
||||||
|
执行方案:docs/visual-editor-next-steps.md。
|
||||||
|
基线:feat/admin-component-preview / 541304a。
|
||||||
|
状态源:本目录 SUBTASKS.csv;旧 visual-editor 任务保留为历史。
|
||||||
|
当前仅完成规划,实现未开始。各子任务开始前建立 tasks 对应目录的 SPEC.md、TODO.csv、PROGRESS.md,补充具体验证命令和证据。
|
||||||
|
完成条件:全部子任务通过,业务内容有明确编辑入口,真实保存、发布隔离及生产部署验证完成。
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# 进度记录
|
||||||
|
|
||||||
|
2026-10-09:与现有 ADR 0020、后续计划和交付清单对齐,制定四阶段实施计划。
|
||||||
|
2026-10-09:完成任务 1。盘点两套模板页面与 manifest / renderer 目标,修复餐饮首页身份区点选、咨询页字段过滤和首页业务目标 key;`pnpm validate:templates` 19 项通过,浏览器测试 2 项通过。
|
||||||
|
2026-10-09:完成任务 2、3、4。区域来源改为按 binding 推导;编辑面板改单列自适应;咨询表单字段可独立点选和编辑。Admin/Taro 类型检查与浏览器测试通过。
|
||||||
|
|
||||||
|
- 任务:可视化内容编辑闭环。
|
||||||
|
- 形态:epic。
|
||||||
|
- 进度:5/5 子任务完成。
|
||||||
|
- 当前:本轮计划已完成;后续可继续做真实数据库持久化和发布隔离验收。
|
||||||
|
- 验证:`pnpm validate:templates`、Admin/Taro typecheck、Admin build、`ADMIN_URL=http://localhost:3005 pnpm --filter @personal-brand/taro test:browser -- admin-editor.spec.ts` 均通过;计划 CSV 未纳入 Prettier 检查。
|
||||||
|
- 文件:.codex-tasks/visual-editor-closure/SUBTASKS.csv。
|
||||||
|
- 下一步:使用隔离品牌执行真实 API 保存、发布隔离和重载验证。
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
id,task,task_type,status,depends_on,task_dir,acceptance_criteria,validation_command,completed_at,retry_count,notes
|
||||||
|
1,逐页建立覆盖清单,single-full,DONE,,tasks/coverage,所有页面内容与字段对应且缺陷可复现,pnpm validate:templates; pnpm --filter @personal-brand/taro test:browser -- admin-editor.spec.ts,2026-10-09,0,已盘点两套模板页面;首批缺口已复现并修复:首页身份区目标、咨询品牌字段过滤、餐饮首页目标 key;契约 19 项和浏览器 2 项通过
|
||||||
|
2,修复通用选区绑定与模板发现,single-full,DONE,1,tasks/contract,混合来源及重复记录映射正确且契约测试通过,pnpm validate:templates; pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,区域来源按 binding 推导;餐饮首页身份目标和业务卡片目标对齐;切页及记录失效选择已有清理逻辑
|
||||||
|
3,整理选区面板与保存交互,single-full,DONE,2,tasks/inspector,布局及失败和未保存切换验证通过,pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,选区字段改单列自适应并移除固定最小高度;保持保存失败输入不重置
|
||||||
|
4,接通咨询字段编辑,single-full,DONE,2;3,tasks/inquiry,配置保存重载一致且历史提交不受损,pnpm --filter @personal-brand/admin typecheck; 浏览器测试,2026-10-09,0,咨询字段可独立点选并编辑标题、类型、必填、选项;预览草稿不提交真实咨询
|
||||||
|
5,全页面回归与部署验收,single-full,DONE,1;2;3;4,tasks/delivery,覆盖清单及工程门槛和部署验收通过,pnpm validate:templates; pnpm --filter @personal-brand/admin build; pnpm --filter @personal-brand/admin typecheck; pnpm --filter @personal-brand/taro typecheck; 浏览器测试,2026-10-09,0,模板契约 19 项、浏览器 2 项、Admin build、Admin/Taro typecheck 通过;CSV 不交给 Prettier
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
template,page,visible_content,renderer_target,manifest_editor,source,status,evidence
|
||||||
|
acheng-campus-food,home,主理人身份、地点、出摊图片、餐品标题、首页操作按钮、承诺、业务卡片,food.home.identity; food.home.location; food.home.hero; food.home.offerings-heading; food.home.actions; food.home.promise-heading; acheng-campus-food.home.offering,对应 sections 已声明并补齐身份与操作目标,brand; offering; trust,已覆盖,契约测试 + 浏览器点选
|
||||||
|
acheng-campus-food,offerings,菜单说明、业务卡片,acheng-campus-food.offerings.menu; acheng-campus-food.offerings.item,对应 sections 已声明,brand; offering,已覆盖,契约测试 + 浏览器点选
|
||||||
|
acheng-campus-food,service,出摊说明、日程、配送、流程,acheng-campus-food.service.service; trust:schedule; trust:coverage; trust:process,对应 sections / trust declarations 已声明,brand; trust,待第二阶段复核,已存在浏览器点选路径
|
||||||
|
acheng-campus-food,profile,主理人与信任内容,acheng-campus-food.profile.identity; trust:credential; trust:case; trust:promise,对应 sections / trust declarations 已声明,brand; trust,待第二阶段复核,已存在 renderer target
|
||||||
|
acheng-campus-food,detail,餐品详情、详情说明,acheng-campus-food.detail.dishDetail; acheng-campus-food.detail.detailCopy,对应 sections 已声明,offering; brand,已覆盖,浏览器已验证底栏与编辑入口
|
||||||
|
acheng-campus-food,inquiry,页面文案、访客表单,acheng-campus-food.inquiry.booking,对应 section 已声明;Admin 已允许 inquiry section 编辑,brand; inquiry,首批已修复,浏览器已验证表单展示
|
||||||
|
acheng-campus-food,success,提交结果文案,acheng-campus-food.success.successCopy,对应 section 已声明,brand,待第二阶段复核,已验证页面可切换
|
||||||
|
acheng-campus-food,records,记录页文案,acheng-campus-food.records.recordsCopy,对应 section 已声明,brand; records,待第二阶段复核,已验证页面可切换
|
||||||
|
linjing-editorial,home,身份、主视觉、证明、主张、案例,editorial.home.identity; editorial.home.hero; editorial.home.proof; editorial.home.manifesto; editorial.home.works; linjing-editorial.home.home,对应 sections 已声明,brand; trust; offering,已覆盖,契约测试 + 浏览器点选
|
||||||
|
linjing-editorial,offerings,案例说明、业务卡片,linjing-editorial.offerings.cases; linjing-editorial.offerings.item,对应 sections 已声明,brand; offering,待第二阶段复核,已有 renderer target
|
||||||
|
linjing-editorial,profile,身份、履约、联系方式、信任内容,linjing-editorial.profile.identity; linjing-editorial.profile.profileDetails; trust:*,对应 sections / trust declarations 已声明,brand; trust,已覆盖,契约测试 + 浏览器点选
|
||||||
|
linjing-editorial,detail,案例详情、详情说明,linjing-editorial.detail.projectDetail; linjing-editorial.detail.detailCopy,对应 sections 已声明,offering; brand,待第二阶段复核,已有 renderer target
|
||||||
|
@@ -14,6 +14,7 @@ apps/miniapp/project.private.config.json
|
|||||||
|
|
||||||
.worktrees/
|
.worktrees/
|
||||||
apps/taro/src/assets/
|
apps/taro/src/assets/
|
||||||
|
apps/admin/public/template-preview/
|
||||||
|
|
||||||
apps/taro/test-results/
|
apps/taro/test-results/
|
||||||
apps/taro/playwright-report/
|
apps/taro/playwright-report/
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.turbo
|
.turbo
|
||||||
dist
|
dist
|
||||||
|
apps/admin/public/template-preview
|
||||||
.next
|
.next
|
||||||
prototype
|
prototype
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# Product Direction
|
# Product Direction
|
||||||
|
|
||||||
|
- 模板新增、绑定修改及宣称完成前,执行 pnpm template:doctor 并遵循 docs/template-completion-rules.md。静态校验、输入框出现、mock 成功不能单独证明完成;回归使用真实 manifest,按区域全部可见变量验收。
|
||||||
|
|
||||||
- The core product is a personal-brand platform whose primary goal is to build trust and convert that trust into qualified inquiries or collaborations.
|
- The core product is a personal-brand platform whose primary goal is to build trust and convert that trust into qualified inquiries or collaborations.
|
||||||
- Personal-brand identity, positioning, proof of work, communication expectations, and contact paths are higher priority than any single industry workflow.
|
- Personal-brand identity, positioning, proof of work, communication expectations, and contact paths are higher priority than any single industry workflow.
|
||||||
- Industry behavior is implemented as replaceable templates. Food, consulting, design, photography, and future industries must not hard-code their terminology or fields into the shared brand model or shared UI.
|
- Industry behavior is implemented as replaceable templates. Food, consulting, design, photography, and future industries must not hard-code their terminology or fields into the shared brand model or shared UI.
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ VITE_APP_BASE_PATH=/admin/
|
|||||||
VITE_API_BASE_URL=/api
|
VITE_API_BASE_URL=/api
|
||||||
VITE_DEV_API_TARGET=http://localhost:3001
|
VITE_DEV_API_TARGET=http://localhost:3001
|
||||||
ADMIN_PORT=3000
|
ADMIN_PORT=3000
|
||||||
VITE_TEMPLATE_PREVIEW_URLS={"acheng-campus-food":"http://localhost:3002","linjing-editorial":"http://localhost:3003"}
|
VITE_TEMPLATE_PREVIEW_URL=http://localhost:3002
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
import {
|
||||||
|
Alert,
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
InputNumber,
|
||||||
|
Row,
|
||||||
|
Select,
|
||||||
|
Space,
|
||||||
|
Switch,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from "antd";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useEffect, useMemo } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import type {
|
||||||
|
Offering,
|
||||||
|
TemplateAdminField,
|
||||||
|
TemplateAdminSection,
|
||||||
|
TrustContent,
|
||||||
|
} from "@personal-brand/api-client";
|
||||||
|
import { createApiClient } from "../lib/api.js";
|
||||||
|
import { ImageUrlField } from "./ImageUrlField.js";
|
||||||
|
import { TemplateListField } from "./TemplateListField.js";
|
||||||
|
import { MutationError } from "./QueryState.js";
|
||||||
|
import {
|
||||||
|
applyPresentationValues,
|
||||||
|
applyStandardEntityValues,
|
||||||
|
presentationFieldName,
|
||||||
|
readPresentationValue,
|
||||||
|
type PresentationValues,
|
||||||
|
} from "../features/brand/presentation-bindings.js";
|
||||||
|
|
||||||
|
export type RecordContentSource = "offering" | "trust";
|
||||||
|
|
||||||
|
export interface RecordContentEditorProps {
|
||||||
|
source: RecordContentSource;
|
||||||
|
record: Offering | TrustContent;
|
||||||
|
section: TemplateAdminSection;
|
||||||
|
context: "visual" | "services";
|
||||||
|
onDraft?: (values: PresentationValues) => void;
|
||||||
|
onSaved?: () => void;
|
||||||
|
visualSelection?: { targetKey: string; page: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderField(field: TemplateAdminField) {
|
||||||
|
if (field.input === "textarea")
|
||||||
|
return (
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
maxLength={field.maxLength}
|
||||||
|
showCount={!!field.maxLength}
|
||||||
|
placeholder={field.placeholder}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (field.input === "image")
|
||||||
|
return <ImageUrlField {...(field.placeholder ? { placeholder: field.placeholder } : {})} />;
|
||||||
|
if (field.input === "phone") return <Input type="tel" placeholder={field.placeholder} />;
|
||||||
|
if (field.input === "number") return <InputNumber min={0} placeholder={field.placeholder} />;
|
||||||
|
if (field.input === "boolean") return <Switch />;
|
||||||
|
if (field.input === "select")
|
||||||
|
return <Select options={(field.options ?? []).map((item) => ({ ...item }))} />;
|
||||||
|
if (field.input === "multi-select")
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
mode="multiple"
|
||||||
|
options={(field.options ?? []).map((item) => ({ ...item }))}
|
||||||
|
placeholder={field.placeholder}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
return <Input placeholder={field.placeholder} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RecordContentFields({ section }: { section: TemplateAdminSection }) {
|
||||||
|
return (
|
||||||
|
<Row gutter={16}>
|
||||||
|
{section.fields.map((field) => (
|
||||||
|
<Col key={field.key} xs={24} md={24}>
|
||||||
|
{field.input === "list" ? (
|
||||||
|
<TemplateListField field={field} name={presentationFieldName(section.key, field.key)} />
|
||||||
|
) : (
|
||||||
|
<Form.Item
|
||||||
|
name={presentationFieldName(section.key, field.key)}
|
||||||
|
label={field.label}
|
||||||
|
{...(field.help ? { help: field.help } : {})}
|
||||||
|
{...(field.required
|
||||||
|
? { rules: [{ required: true, message: `请填写${field.label}` }] }
|
||||||
|
: {})}
|
||||||
|
>
|
||||||
|
{renderField(field)}
|
||||||
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
</Col>
|
||||||
|
))}
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RecordContentEditor({
|
||||||
|
source,
|
||||||
|
record,
|
||||||
|
section,
|
||||||
|
context,
|
||||||
|
onDraft,
|
||||||
|
onSaved,
|
||||||
|
visualSelection,
|
||||||
|
}: RecordContentEditorProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [form] = Form.useForm<PresentationValues>();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const recordName = "name" in record ? record.name : record.title;
|
||||||
|
const initialValues = useMemo(
|
||||||
|
() =>
|
||||||
|
Object.fromEntries(
|
||||||
|
section.fields.map((field) => [
|
||||||
|
presentationFieldName(section.key, field.key),
|
||||||
|
readPresentationValue(
|
||||||
|
record.config,
|
||||||
|
field.binding,
|
||||||
|
field,
|
||||||
|
record as unknown as Record<string, unknown>,
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
[record, section],
|
||||||
|
);
|
||||||
|
useEffect(() => form.setFieldsValue(initialValues), [form, initialValues]);
|
||||||
|
const save = useMutation({
|
||||||
|
mutationFn: async (values: PresentationValues): Promise<void> => {
|
||||||
|
const config = applyPresentationValues(record.config, [section], values);
|
||||||
|
const standard = applyStandardEntityValues(
|
||||||
|
record as unknown as Record<string, unknown>,
|
||||||
|
source,
|
||||||
|
[section],
|
||||||
|
values,
|
||||||
|
);
|
||||||
|
const changed = Object.fromEntries(
|
||||||
|
Object.entries(standard).filter(
|
||||||
|
([key, value]) =>
|
||||||
|
key !== "config" && value !== (record as unknown as Record<string, unknown>)[key],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const client = createApiClient();
|
||||||
|
if (source === "offering")
|
||||||
|
await client.updateAdminOffering(record.id, { ...changed, config });
|
||||||
|
else await client.updateAdminTrustContent(record.id, { ...changed, config });
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
message.success("已保存内容草稿,发布后访客才会看到更新");
|
||||||
|
onSaved?.();
|
||||||
|
void queryClient.invalidateQueries({
|
||||||
|
queryKey: [source === "offering" ? "admin-offerings" : "trust-content"],
|
||||||
|
});
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["admin-workspace"] });
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
initialValues={initialValues}
|
||||||
|
onValuesChange={(_, values) => onDraft?.(values)}
|
||||||
|
onFinish={(values) => save.mutate(values)}
|
||||||
|
style={{ minHeight: 0, display: "flex", flexDirection: "column" }}
|
||||||
|
>
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
showIcon
|
||||||
|
message={
|
||||||
|
source === "offering"
|
||||||
|
? `正在编辑业务提供项:${recordName}`
|
||||||
|
: `正在编辑信任内容:${recordName}`
|
||||||
|
}
|
||||||
|
description={
|
||||||
|
context === "visual"
|
||||||
|
? "这里修改的是业务或信任记录本身;业务提供项列表中打开同一项目,看到并修改的是同一份数据。"
|
||||||
|
: "这里修改的内容也会显示在小程序页面对应的卡片、列表或详情中;两处入口修改的是同一份数据。"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{save.isPending ? <Typography.Text type="secondary">正在保存内容…</Typography.Text> : null}
|
||||||
|
<Typography.Paragraph type="secondary">{section.description}</Typography.Paragraph>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<RecordContentFields section={section} />
|
||||||
|
</div>
|
||||||
|
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||||
|
<MutationError error={save.error} />
|
||||||
|
<Space wrap>
|
||||||
|
<Button type="primary" htmlType="submit" loading={save.isPending}>
|
||||||
|
保存此项内容
|
||||||
|
</Button>
|
||||||
|
{source === "offering" ? (
|
||||||
|
<Button
|
||||||
|
htmlType="button"
|
||||||
|
onClick={() =>
|
||||||
|
navigate("/admin/brand", {
|
||||||
|
state: {
|
||||||
|
targetKey: visualSelection?.targetKey ?? "linjing-editorial.offerings.item",
|
||||||
|
recordId: record.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
在小程序页面编辑
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ export function TemplateListField({
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{(rows, { add, remove }, { errors }) => (
|
{(rows, { add, remove, move }, { errors }) => (
|
||||||
<Space direction="vertical" style={{ width: "100%" }}>
|
<Space direction="vertical" style={{ width: "100%" }}>
|
||||||
{rows.map((row, index) => (
|
{rows.map((row, index) => (
|
||||||
<Space key={row.key} align="start" wrap>
|
<Space key={row.key} align="start" wrap>
|
||||||
@@ -40,6 +40,20 @@ export function TemplateListField({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
))}
|
||||||
<Button onClick={() => remove(row.name)}>删除</Button>
|
<Button onClick={() => remove(row.name)}>删除</Button>
|
||||||
|
<Button
|
||||||
|
aria-label={`上移第 ${index + 1} 项`}
|
||||||
|
disabled={index === 0}
|
||||||
|
onClick={() => move(index, index - 1)}
|
||||||
|
>
|
||||||
|
上移
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
aria-label={`下移第 ${index + 1} 项`}
|
||||||
|
disabled={index === rows.length - 1}
|
||||||
|
onClick={() => move(index, index + 1)}
|
||||||
|
>
|
||||||
|
下移
|
||||||
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
))}
|
))}
|
||||||
<Form.ErrorList errors={errors} />
|
<Form.ErrorList errors={errors} />
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
.brand-page__content {
|
||||||
|
max-width: 960px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-page__content[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.brand-page__toolbar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 16px 0;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
@media (max-width: 575px) {
|
||||||
|
.brand-page__toolbar {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-page__settings {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section {
|
||||||
|
padding: 24px 0;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section:first-child {
|
||||||
|
padding-top: 8px;
|
||||||
|
border-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section__header .ant-typography {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section__header .ant-typography + .ant-typography {
|
||||||
|
display: block;
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-page__template-note {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1199px) {
|
||||||
|
.brand-page__content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-page__template-note {
|
||||||
|
position: static;
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 575px) {
|
||||||
|
.brand-settings-section__header {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-settings-section__header .ant-tag {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,36 @@
|
|||||||
import { Button, Card, Col, Form, Input, Row, Select, Space, Tag, Typography, message } from "antd";
|
import {
|
||||||
|
Alert,
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Row,
|
||||||
|
Select,
|
||||||
|
Segmented,
|
||||||
|
Space,
|
||||||
|
Tag,
|
||||||
|
Typography,
|
||||||
|
message,
|
||||||
|
} from "antd";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Link, useLocation } from "react-router-dom";
|
||||||
import type { BrandProfile } from "@personal-brand/api-client";
|
import type { BrandProfile } from "@personal-brand/api-client";
|
||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||||
import { PresentationEditor } from "./PresentationEditor.js";
|
import { PresentationEditor } from "./PresentationEditor.js";
|
||||||
|
import type { PreviewSelection } from "./preview-selection.js";
|
||||||
|
import "./BrandPage.css";
|
||||||
|
import { useEditorDraft } from "./use-editor-draft.js";
|
||||||
|
|
||||||
export function BrandPage() {
|
export function BrandPage() {
|
||||||
|
const location = useLocation();
|
||||||
|
const initialSelection = location.state as PreviewSelection | undefined;
|
||||||
|
const [panel, setPanel] = useState("pages");
|
||||||
|
const [dirty, setDirty] = useState(false);
|
||||||
|
useEditorDraft(dirty);
|
||||||
const client = createApiClient();
|
const client = createApiClient();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [form] = Form.useForm<BrandProfile>();
|
const [form] = Form.useForm<BrandProfile>();
|
||||||
@@ -16,6 +39,10 @@ export function BrandPage() {
|
|||||||
queryKey: ["admin-workspace"],
|
queryKey: ["admin-workspace"],
|
||||||
queryFn: () => client.getAdminWorkspace(),
|
queryFn: () => client.getAdminWorkspace(),
|
||||||
});
|
});
|
||||||
|
const previewWorkspace = useQuery({
|
||||||
|
queryKey: ["admin-preview-workspace"],
|
||||||
|
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||||
|
});
|
||||||
const template = useQuery({
|
const template = useQuery({
|
||||||
queryKey: ["template", brand.data?.templateKey],
|
queryKey: ["template", brand.data?.templateKey],
|
||||||
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
queryFn: () => client.getPublicTemplate(brand.data!.templateKey),
|
||||||
@@ -24,8 +51,10 @@ export function BrandPage() {
|
|||||||
const save = useMutation({
|
const save = useMutation({
|
||||||
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
mutationFn: (values: Partial<BrandProfile>) => client.updateAdminBrand(values),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
setDirty(false);
|
||||||
message.success("品牌表达已保存");
|
message.success("品牌表达已保存");
|
||||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||||
|
void queryClient.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
@@ -33,22 +62,50 @@ export function BrandPage() {
|
|||||||
{!brand.data ? null : (
|
{!brand.data ? null : (
|
||||||
<>
|
<>
|
||||||
<AdminPageHeader
|
<AdminPageHeader
|
||||||
title="品牌资料"
|
title="小程序工作台"
|
||||||
description="先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
description={
|
||||||
|
template.data?.description
|
||||||
|
? `先让访客理解你是谁、服务谁,以及为什么值得信任。${template.data.description}`
|
||||||
|
: "先让访客理解你是谁、服务谁,以及为什么值得信任。"
|
||||||
|
}
|
||||||
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
extra={<Tag color="blue">{template.data?.name ?? "当前模板"}</Tag>}
|
||||||
/>
|
/>
|
||||||
<Row gutter={[24, 24]} align="top">
|
<div className="brand-page__toolbar">
|
||||||
<Col xs={24} xl={16}>
|
<Segmented
|
||||||
|
aria-label="工作台视图"
|
||||||
|
value={panel}
|
||||||
|
onChange={(value) => setPanel(String(value))}
|
||||||
|
options={[
|
||||||
|
{ value: "pages", label: "页面编辑" },
|
||||||
|
{ value: "brand", label: "品牌资料" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Space>
|
||||||
|
<Tag color={dirty ? "orange" : "default"}>
|
||||||
|
{dirty ? "品牌资料有未保存修改" : "草稿工作区"}
|
||||||
|
</Tag>
|
||||||
|
<Link to="/admin/publication">检查与发布 →</Link>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
<div className="brand-page__content" hidden={panel !== "brand"}>
|
||||||
|
<div className="brand-page__settings">
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
initialValues={brand.data}
|
initialValues={brand.data}
|
||||||
|
onValuesChange={() => setDirty(true)}
|
||||||
onFinish={(values) => save.mutate(values)}
|
onFinish={(values) => save.mutate(values)}
|
||||||
>
|
>
|
||||||
<Card
|
<section className="brand-settings-section" aria-labelledby="brand-identity-title">
|
||||||
title="我是谁"
|
<div className="brand-settings-section__header">
|
||||||
extra={<Typography.Text type="secondary">公开展示</Typography.Text>}
|
<div>
|
||||||
>
|
<Typography.Title id="brand-identity-title" level={4}>
|
||||||
|
我是谁
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">公开展示的品牌身份和定位。</Typography.Text>
|
||||||
|
</div>
|
||||||
|
<Tag>品牌基础信息</Tag>
|
||||||
|
</div>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="name"
|
name="name"
|
||||||
label="品牌名称"
|
label="品牌名称"
|
||||||
@@ -73,8 +130,18 @@ export function BrandPage() {
|
|||||||
placeholder="让第一次认识你的人快速建立基本信任。"
|
placeholder="让第一次认识你的人快速建立基本信任。"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Card>
|
</section>
|
||||||
<Card title="如何联系与合作" style={{ marginTop: 24 }}>
|
<section className="brand-settings-section" aria-labelledby="brand-contact-title">
|
||||||
|
<div className="brand-settings-section__header">
|
||||||
|
<div>
|
||||||
|
<Typography.Title id="brand-contact-title" level={4}>
|
||||||
|
如何联系与合作
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
让访客知道联系渠道、服务范围和响应预期。
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col xs={24} md={12}>
|
<Col xs={24} md={12}>
|
||||||
<Form.Item name="hours" label="可联系时间">
|
<Form.Item name="hours" label="可联系时间">
|
||||||
@@ -104,8 +171,18 @@ export function BrandPage() {
|
|||||||
>
|
>
|
||||||
<Input.TextArea rows={3} placeholder="例如:收到咨询后 1 个工作日内回复。" />
|
<Input.TextArea rows={3} placeholder="例如:收到咨询后 1 个工作日内回复。" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Card>
|
</section>
|
||||||
<Card title="模板与品牌视觉" style={{ marginTop: 24 }}>
|
<section className="brand-settings-section" aria-labelledby="brand-visual-title">
|
||||||
|
<div className="brand-settings-section__header">
|
||||||
|
<div>
|
||||||
|
<Typography.Title id="brand-visual-title" level={4}>
|
||||||
|
模板与品牌视觉
|
||||||
|
</Typography.Title>
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
模板负责业务表达,品牌信息仍由你统一维护。
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="templateKey"
|
name="templateKey"
|
||||||
label="业务表达模板"
|
label="业务表达模板"
|
||||||
@@ -135,7 +212,7 @@ export function BrandPage() {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Card>
|
</section>
|
||||||
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
<Space direction="vertical" style={{ width: "100%", marginTop: 24 }}>
|
||||||
<MutationError error={save.error} />
|
<MutationError error={save.error} />
|
||||||
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
|
<Button type="primary" htmlType="submit" loading={save.isPending} size="large">
|
||||||
@@ -143,25 +220,28 @@ export function BrandPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</Form>
|
</Form>
|
||||||
<PresentationEditor
|
</div>
|
||||||
templateContent={workspace.data?.templateContent}
|
{template.data ? (
|
||||||
config={brand.data.config}
|
<Alert
|
||||||
brand={brand.data}
|
className="brand-page__template-note"
|
||||||
loading={workspace.isLoading}
|
type="info"
|
||||||
error={workspace.error}
|
showIcon
|
||||||
|
message={`当前使用:${template.data.name}`}
|
||||||
|
description={`适用场景:${template.data.serviceCategories.join("、") || "通用品牌展示"}`}
|
||||||
/>
|
/>
|
||||||
</Col>
|
) : null}
|
||||||
<Col xs={24} xl={8}>
|
</div>
|
||||||
{template.data && (
|
<div hidden={panel !== "pages"}>
|
||||||
<Card title="模板说明" style={{ marginTop: 24 }}>
|
<PresentationEditor
|
||||||
<Typography.Paragraph>{template.data.description}</Typography.Paragraph>
|
templateContent={workspace.data?.templateContent}
|
||||||
<Typography.Text type="secondary">
|
previewWorkspace={previewWorkspace.data}
|
||||||
服务分类:{template.data.serviceCategories.join("、")}
|
config={brand.data.config}
|
||||||
</Typography.Text>
|
brand={brand.data}
|
||||||
</Card>
|
loading={workspace.isLoading}
|
||||||
)}
|
error={workspace.error}
|
||||||
</Col>
|
{...(initialSelection ? { initialSelection } : {})}
|
||||||
</Row>
|
/>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</QueryState>
|
</QueryState>
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
.component-template-preview-shell {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__tools {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-bottom: 1px solid #e8e8e8;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__tools button {
|
||||||
|
padding: 4px 12px;
|
||||||
|
border: 1px solid #d9d9d9;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__tools button[aria-pressed="true"] {
|
||||||
|
border-color: #1677ff;
|
||||||
|
color: #1677ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: calc(100% - 49px);
|
||||||
|
min-height: 510px;
|
||||||
|
padding: 24px 16px;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: auto;
|
||||||
|
background: #f3f4f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__canvas {
|
||||||
|
position: relative;
|
||||||
|
container-type: inline-size;
|
||||||
|
width: min(100%, 390px);
|
||||||
|
min-height: calc(100% - 48px);
|
||||||
|
margin: 0 auto;
|
||||||
|
overflow: visible;
|
||||||
|
border-radius: 14px;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow:
|
||||||
|
0 0 0 1px rgba(0, 0, 0, 0.04),
|
||||||
|
0 10px 30px rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__canvas,
|
||||||
|
.component-template-preview__canvas * {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__canvas > * {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
:where(.component-template-preview__canvas) button {
|
||||||
|
display: block;
|
||||||
|
width: -webkit-fill-available;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
font: inherit;
|
||||||
|
font-size: 4.8cqw;
|
||||||
|
line-height: 2.55555556;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
:where(.component-template-preview__canvas) input {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__canvas img {
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview[data-editor-mode="edit"] [data-editor-target] {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__outline {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 5;
|
||||||
|
pointer-events: none;
|
||||||
|
border: 2px solid #91caff;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__outline.is-selected {
|
||||||
|
z-index: 6;
|
||||||
|
border-color: #1677ff;
|
||||||
|
box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.16);
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__composite-select {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 7;
|
||||||
|
width: auto !important;
|
||||||
|
padding: 2px 8px !important;
|
||||||
|
border: 1px solid #1677ff !important;
|
||||||
|
border-radius: 4px !important;
|
||||||
|
background: #fff !important;
|
||||||
|
color: #0958d9 !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
line-height: 20px !important;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__outline span {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 100%;
|
||||||
|
left: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
padding: 2px 7px;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 4px 4px 0 0;
|
||||||
|
background: #1677ff;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 18px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview__tools[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.component-template-preview-shell:has(.component-template-preview__tools[hidden])
|
||||||
|
.component-template-preview {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,227 @@
|
|||||||
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||||
|
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||||
|
import { Alert } from "antd";
|
||||||
|
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||||
|
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||||
|
import "../../../../../packages/template-acheng-campus-food/taro/style.css";
|
||||||
|
import "../../../../../packages/template-linjing-editorial/taro/style.css";
|
||||||
|
import "./ComponentTemplatePreview.css";
|
||||||
|
|
||||||
|
type PreviewProps = {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
page: string;
|
||||||
|
offeringId?: string;
|
||||||
|
selection?: PreviewSelection;
|
||||||
|
targets: PreviewTarget[];
|
||||||
|
onTargetSelected: (selection?: PreviewSelection) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Outline = { top: number; left: number; width: number; height: number; label: string };
|
||||||
|
|
||||||
|
export function ComponentTemplatePreview({
|
||||||
|
workspace,
|
||||||
|
page,
|
||||||
|
offeringId,
|
||||||
|
selection,
|
||||||
|
targets,
|
||||||
|
onTargetSelected,
|
||||||
|
}: PreviewProps) {
|
||||||
|
const Renderer = resolveTemplateRenderer(workspace);
|
||||||
|
const root = useRef<HTMLDivElement>(null);
|
||||||
|
const [mode, setMode] = useState<"edit" | "browse">("edit");
|
||||||
|
const [hovered, setHovered] = useState<HTMLElement | null>(null);
|
||||||
|
const [hoverOutline, setHoverOutline] = useState<Outline | null>(null);
|
||||||
|
const [selectedOutline, setSelectedOutline] = useState<Outline | null>(null);
|
||||||
|
const [compositeOutlines, setCompositeOutlines] = useState<Array<Outline & { key: string }>>([]);
|
||||||
|
const targetFor = useCallback(
|
||||||
|
(element: Element | null): HTMLElement | null => {
|
||||||
|
let candidate = element?.closest<HTMLElement>("[data-editor-target]");
|
||||||
|
let deepest: HTMLElement | null = null;
|
||||||
|
let composite: HTMLElement | null = null;
|
||||||
|
while (candidate && root.current?.contains(candidate)) {
|
||||||
|
const target = targets.find((item) => item.key === candidate?.dataset.editorTarget);
|
||||||
|
if (target && !deepest) deepest = candidate;
|
||||||
|
if (target?.composite) composite = candidate;
|
||||||
|
candidate = candidate.parentElement?.closest<HTMLElement>("[data-editor-target]") ?? null;
|
||||||
|
}
|
||||||
|
return deepest ?? composite;
|
||||||
|
},
|
||||||
|
[targets],
|
||||||
|
);
|
||||||
|
const selectedElement = useCallback(() => {
|
||||||
|
if (!selection) return null;
|
||||||
|
return (
|
||||||
|
Array.from(root.current?.querySelectorAll<HTMLElement>("[data-editor-target]") ?? []).find(
|
||||||
|
(element) =>
|
||||||
|
element.dataset.editorTarget === selection.targetKey &&
|
||||||
|
(element.dataset.editorRecordId || undefined) === selection.recordId,
|
||||||
|
) ?? null
|
||||||
|
);
|
||||||
|
}, [selection]);
|
||||||
|
const measure = useCallback(
|
||||||
|
(element: HTMLElement | null): Outline | null => {
|
||||||
|
const viewport = root.current;
|
||||||
|
if (!element || !viewport || !viewport.contains(element)) return null;
|
||||||
|
const box = element.getBoundingClientRect();
|
||||||
|
const parent = viewport.getBoundingClientRect();
|
||||||
|
const target = targets.find((item) => item.key === element.dataset.editorTarget);
|
||||||
|
if (!target || !box.width || !box.height) return null;
|
||||||
|
return {
|
||||||
|
top: box.top - parent.top + viewport.scrollTop,
|
||||||
|
left: box.left - parent.left + viewport.scrollLeft,
|
||||||
|
width: box.width,
|
||||||
|
height: box.height,
|
||||||
|
label: target.label,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[targets],
|
||||||
|
);
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const viewport = root.current;
|
||||||
|
if (!viewport) return;
|
||||||
|
let frame = 0;
|
||||||
|
const update = () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
frame = requestAnimationFrame(() => {
|
||||||
|
setSelectedOutline(measure(selectedElement()));
|
||||||
|
setHoverOutline(measure(hovered));
|
||||||
|
setCompositeOutlines(
|
||||||
|
targets
|
||||||
|
.filter((target) => target.composite)
|
||||||
|
.flatMap((target) => {
|
||||||
|
const element = viewport.querySelector<HTMLElement>(
|
||||||
|
`[data-editor-target="${CSS.escape(target.key)}"]`,
|
||||||
|
);
|
||||||
|
const outline = measure(element);
|
||||||
|
return outline ? [{ ...outline, key: target.key }] : [];
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
update();
|
||||||
|
const resize = new ResizeObserver(update);
|
||||||
|
resize.observe(viewport);
|
||||||
|
viewport
|
||||||
|
.querySelectorAll<HTMLElement>("[data-editor-target]")
|
||||||
|
.forEach((node) => resize.observe(node));
|
||||||
|
window.addEventListener("resize", update);
|
||||||
|
viewport.addEventListener("scroll", update);
|
||||||
|
viewport.addEventListener("load", update, true);
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
resize.disconnect();
|
||||||
|
window.removeEventListener("resize", update);
|
||||||
|
viewport.removeEventListener("scroll", update);
|
||||||
|
viewport.removeEventListener("load", update, true);
|
||||||
|
};
|
||||||
|
}, [hovered, measure, selectedElement, workspace, page]);
|
||||||
|
useEffect(() => {
|
||||||
|
selectedElement()?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||||
|
}, [selectedElement]);
|
||||||
|
useEffect(() => {
|
||||||
|
const clear = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === "Escape") onTargetSelected(undefined);
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", clear);
|
||||||
|
return () => window.removeEventListener("keydown", clear);
|
||||||
|
}, [onTargetSelected]);
|
||||||
|
if (!Renderer)
|
||||||
|
return <Alert type="warning" showIcon message="此模板尚无组件预览,请使用页面预览" />;
|
||||||
|
return (
|
||||||
|
<div className="component-template-preview-shell">
|
||||||
|
<div
|
||||||
|
className="component-template-preview__tools"
|
||||||
|
aria-label="预览操作模式"
|
||||||
|
hidden={!targets.length}
|
||||||
|
>
|
||||||
|
<button type="button" aria-pressed={mode === "edit"} onClick={() => setMode("edit")}>
|
||||||
|
点选编辑
|
||||||
|
</button>
|
||||||
|
<button type="button" aria-pressed={mode === "browse"} onClick={() => setMode("browse")}>
|
||||||
|
浏览页面
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
ref={root}
|
||||||
|
className="component-template-preview"
|
||||||
|
data-active-target={selection?.targetKey}
|
||||||
|
data-active-record-id={selection?.recordId}
|
||||||
|
data-editor-mode={mode}
|
||||||
|
onPointerMoveCapture={(event) => {
|
||||||
|
if (mode !== "edit" || !targets.length) return;
|
||||||
|
const next = targetFor(event.target instanceof Element ? event.target : null);
|
||||||
|
if (next !== hovered) setHovered(next);
|
||||||
|
}}
|
||||||
|
onPointerLeave={() => setHovered(null)}
|
||||||
|
onClickCapture={(event) => {
|
||||||
|
if (mode !== "edit" || !targets.length) return;
|
||||||
|
const canvas = root.current?.querySelector(".component-template-preview__canvas");
|
||||||
|
if (!event.target || !(event.target instanceof Node) || !canvas?.contains(event.target))
|
||||||
|
return;
|
||||||
|
const pointTarget = document.elementFromPoint(event.clientX, event.clientY);
|
||||||
|
const element = targetFor(
|
||||||
|
pointTarget && canvas.contains(pointTarget) ? pointTarget : null,
|
||||||
|
);
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
onTargetSelected(
|
||||||
|
element
|
||||||
|
? {
|
||||||
|
targetKey: element.dataset.editorTarget!,
|
||||||
|
...(element.dataset.editorRecordId
|
||||||
|
? { recordId: element.dataset.editorRecordId }
|
||||||
|
: {}),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="component-template-preview__canvas">
|
||||||
|
<Renderer workspace={workspace} page={page} {...(offeringId ? { offeringId } : {})} />
|
||||||
|
</div>
|
||||||
|
{mode === "edit"
|
||||||
|
? compositeOutlines.map((outline) => (
|
||||||
|
<button
|
||||||
|
key={outline.key}
|
||||||
|
type="button"
|
||||||
|
className="component-template-preview__composite-select"
|
||||||
|
style={{ top: outline.top + 4, left: outline.left + 4 }}
|
||||||
|
aria-label={`选择${targets.find((target) => target.key === outline.key)?.label ?? outline.label}`}
|
||||||
|
onClick={() => onTargetSelected({ targetKey: outline.key })}
|
||||||
|
>
|
||||||
|
选择{targets.find((target) => target.key === outline.key)?.label ?? outline.label}
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
: null}
|
||||||
|
{mode === "edit" && hoverOutline ? (
|
||||||
|
<div
|
||||||
|
className="component-template-preview__outline is-hovered"
|
||||||
|
style={{
|
||||||
|
top: hoverOutline.top,
|
||||||
|
left: hoverOutline.left,
|
||||||
|
width: hoverOutline.width,
|
||||||
|
height: hoverOutline.height,
|
||||||
|
}}
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{mode === "edit" && selectedOutline ? (
|
||||||
|
<div
|
||||||
|
className="component-template-preview__outline is-selected"
|
||||||
|
style={{
|
||||||
|
top: selectedOutline.top,
|
||||||
|
left: selectedOutline.left,
|
||||||
|
width: selectedOutline.width,
|
||||||
|
height: selectedOutline.height,
|
||||||
|
}}
|
||||||
|
data-selected-target={selection?.targetKey}
|
||||||
|
data-selected-record-id={selection?.recordId}
|
||||||
|
>
|
||||||
|
<span>{selectedOutline.label}</span>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// @ts-nocheck
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
import { Alert, Button, Form, Input, Select, Space, Switch, Typography, message } from "antd";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||||
|
import { createApiClient } from "../../lib/api.js";
|
||||||
|
import { MutationError } from "../../components/QueryState.js";
|
||||||
|
|
||||||
|
type RuntimeInquiryForm = RuntimeWorkspace["inquiryForms"][number];
|
||||||
|
|
||||||
|
export function InquiryPreviewEditor({
|
||||||
|
runtime,
|
||||||
|
fieldKey,
|
||||||
|
onDraft,
|
||||||
|
onSaved,
|
||||||
|
}: {
|
||||||
|
runtime: RuntimeInquiryForm;
|
||||||
|
fieldKey: string;
|
||||||
|
onDraft: (fields: RuntimeInquiryForm["fields"]) => void;
|
||||||
|
onSaved?: () => void;
|
||||||
|
}) {
|
||||||
|
const [form] = Form.useForm<Record<string, unknown>>();
|
||||||
|
const cache = useQueryClient();
|
||||||
|
const query = useQuery({
|
||||||
|
queryKey: ["admin-inquiry-forms"],
|
||||||
|
queryFn: () => createApiClient().listAdminInquiryForms(),
|
||||||
|
});
|
||||||
|
const record = query.data?.find((item) => item.id === runtime.key);
|
||||||
|
const field = runtime.fields.find((item) => item.key === fieldKey);
|
||||||
|
useEffect(() => {
|
||||||
|
if (field) form.setFieldsValue({ ...field });
|
||||||
|
}, [fieldKey, runtime.key, form]);
|
||||||
|
const update = (values: Record<string, unknown>) =>
|
||||||
|
runtime.fields.map((item) => (item.key === fieldKey ? { ...item, ...values } : item));
|
||||||
|
const save = useMutation({
|
||||||
|
mutationFn: async (values: Record<string, unknown>) => {
|
||||||
|
if (!record || !field) throw new Error("表单已不存在,请刷新后重试");
|
||||||
|
const fieldsSnapshot = record.fieldsSnapshot.map((item) => {
|
||||||
|
if (!item || typeof item !== "object" || (item as { key?: string }).key !== fieldKey)
|
||||||
|
return item;
|
||||||
|
const type =
|
||||||
|
values.type === "tel"
|
||||||
|
? "phone"
|
||||||
|
: values.type === "checkbox"
|
||||||
|
? "multi-select"
|
||||||
|
: values.type;
|
||||||
|
return { ...item, ...values, type };
|
||||||
|
});
|
||||||
|
return createApiClient().updateAdminInquiryForm(record.id, { fieldsSnapshot });
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
onSaved?.();
|
||||||
|
message.success("表单字段已保存为草稿");
|
||||||
|
void cache.invalidateQueries({ queryKey: ["admin-inquiry-forms"] });
|
||||||
|
void cache.invalidateQueries({ queryKey: ["admin-preview-workspace"] });
|
||||||
|
void cache.invalidateQueries({ queryKey: ["publication-readiness"] });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (query.isError)
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
type="error"
|
||||||
|
message="表单读取失败"
|
||||||
|
action={<Button onClick={() => void query.refetch()}>重试</Button>}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (!record)
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
type="info"
|
||||||
|
message={query.isPending ? "正在读取表单" : "未找到对应表单,请刷新后重试"}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (!field) return <Alert type="warning" message="字段已不存在" />;
|
||||||
|
return (
|
||||||
|
<Form<Record<string, unknown>>
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
initialValues={field}
|
||||||
|
onValuesChange={(_, values) => onDraft(update(values))}
|
||||||
|
onFinish={(values) => save.mutate(values)}
|
||||||
|
>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
{record.name} · 编辑字段:{field.label}
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Form.Item
|
||||||
|
name="label"
|
||||||
|
label="字段标题"
|
||||||
|
rules={[{ required: true, message: "请填写字段标题" }]}
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="type" label="输入方式">
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: "text", label: "简短文字" },
|
||||||
|
{ value: "textarea", label: "详细说明" },
|
||||||
|
{ value: "tel", label: "联系电话" },
|
||||||
|
{ value: "number", label: "数字" },
|
||||||
|
{ value: "date", label: "日期" },
|
||||||
|
{ value: "select", label: "单项选择" },
|
||||||
|
{ value: "radio", label: "单选按钮" },
|
||||||
|
{ value: "checkbox", label: "多项选择" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="required" label="必填" valuePropName="checked">
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.List name="options">
|
||||||
|
{(fields, { add, remove }) => (
|
||||||
|
<div>
|
||||||
|
{fields.length ? <Typography.Title level={5}>选项</Typography.Title> : null}
|
||||||
|
{fields.map(({ key, name }) => (
|
||||||
|
<Space key={key} align="start">
|
||||||
|
<Form.Item name={[name, "label"]} label="选项名称" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name={[name, "value"]} label="选项标识" rules={[{ required: true }]}>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
<Button onClick={() => remove(name)}>删除</Button>
|
||||||
|
</Space>
|
||||||
|
))}
|
||||||
|
<Button onClick={() => add({ label: "新选项", value: crypto.randomUUID() })}>
|
||||||
|
添加选项
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Form.List>
|
||||||
|
<MutationError error={save.error} />
|
||||||
|
<Button style={{ marginTop: 24 }} type="primary" htmlType="submit" loading={save.isPending}>
|
||||||
|
保存表单字段
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
.presentation-editor {
|
||||||
|
margin-top: 0;
|
||||||
|
padding-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__header .ant-typography {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__header .ant-typography + .ant-typography {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor > .ant-space {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 24px !important;
|
||||||
|
padding: 6px;
|
||||||
|
border: 1px solid #e8e8e8;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 575px) {
|
||||||
|
.presentation-editor__header {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__header .ant-tag {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__workspace {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 200px minmax(300px, 1fr) minmax(280px, 360px);
|
||||||
|
grid-template-areas: "outline preview inspector";
|
||||||
|
margin: 0 !important;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__preview {
|
||||||
|
grid-area: preview;
|
||||||
|
padding: 20px !important;
|
||||||
|
background: #f8fafc;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__inspector {
|
||||||
|
grid-area: inspector;
|
||||||
|
padding: 24px !important;
|
||||||
|
min-width: 0;
|
||||||
|
border-left: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__outline {
|
||||||
|
grid-area: outline;
|
||||||
|
padding: 20px 12px;
|
||||||
|
border-right: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
.presentation-editor__regions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.presentation-editor__regions .ant-space-item {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.presentation-editor__regions .ant-btn {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
border: 0;
|
||||||
|
box-shadow: none;
|
||||||
|
padding: 10px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__regions .is-child-region {
|
||||||
|
padding-left: 24px;
|
||||||
|
}
|
||||||
|
.presentation-editor__regions .ant-btn[aria-pressed="true"] {
|
||||||
|
background: #e6f4ff;
|
||||||
|
color: #0958d9;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__preview .template-preview {
|
||||||
|
height: 680px;
|
||||||
|
min-height: 0;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__regions .ant-btn {
|
||||||
|
height: auto;
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__empty {
|
||||||
|
padding: 56px 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__inspector .ant-form-item {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.presentation-editor__inspector form > .ant-space:last-child {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
z-index: 2;
|
||||||
|
padding: 16px 0 4px;
|
||||||
|
border-top: 1px solid #e5e7eb;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.presentation-editor__inspector form > .ant-space:last-child .ant-btn-primary {
|
||||||
|
min-width: 140px;
|
||||||
|
}
|
||||||
|
.presentation-editor__inspector > .ant-tag {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1199px) {
|
||||||
|
.presentation-editor__workspace {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
grid-template-areas: "outline" "preview" "inspector";
|
||||||
|
}
|
||||||
|
.presentation-editor__outline {
|
||||||
|
border-right: 0;
|
||||||
|
border-bottom: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
.presentation-editor__inspector {
|
||||||
|
border-left: 0;
|
||||||
|
border-top: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 575px) {
|
||||||
|
.presentation-editor__preview,
|
||||||
|
.presentation-editor__inspector {
|
||||||
|
padding: 12px !important;
|
||||||
|
}
|
||||||
|
.presentation-editor__preview .template-preview {
|
||||||
|
height: 600px;
|
||||||
|
}
|
||||||
|
.presentation-editor__navigation {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -4,42 +4,51 @@ import type {
|
|||||||
BrandProfile,
|
BrandProfile,
|
||||||
EditorPreviewFrameMessage,
|
EditorPreviewFrameMessage,
|
||||||
EditorPreviewHostMessage,
|
EditorPreviewHostMessage,
|
||||||
|
RuntimeWorkspace,
|
||||||
} from "@personal-brand/api-client";
|
} from "@personal-brand/api-client";
|
||||||
import { templatePreviewUrl } from "../../lib/template-preview.js";
|
import { templatePreviewUrl } from "../../lib/template-preview.js";
|
||||||
|
import { ComponentTemplatePreview } from "./ComponentTemplatePreview.js";
|
||||||
|
import { resolveTemplateRenderer } from "./component-renderers.jsx";
|
||||||
|
import type { PreviewSelection, PreviewTarget } from "./preview-selection.js";
|
||||||
import "./TemplatePreview.css";
|
import "./TemplatePreview.css";
|
||||||
|
|
||||||
export function TemplatePreview({
|
export function TemplatePreview({
|
||||||
brand,
|
brand,
|
||||||
|
workspace,
|
||||||
page,
|
page,
|
||||||
|
offeringId,
|
||||||
targetKey,
|
targetKey,
|
||||||
route,
|
selection,
|
||||||
|
targets,
|
||||||
onTargetSelected,
|
onTargetSelected,
|
||||||
}: {
|
}: {
|
||||||
brand: BrandProfile;
|
brand: BrandProfile;
|
||||||
|
workspace?: RuntimeWorkspace;
|
||||||
page: string;
|
page: string;
|
||||||
|
offeringId?: string;
|
||||||
targetKey?: string;
|
targetKey?: string;
|
||||||
route: string;
|
selection?: PreviewSelection;
|
||||||
onTargetSelected: (key: string) => void;
|
targets: PreviewTarget[];
|
||||||
|
onTargetSelected: (selection?: PreviewSelection) => void;
|
||||||
}) {
|
}) {
|
||||||
const frame = useRef<HTMLIFrameElement>(null);
|
const frame = useRef<HTMLIFrameElement>(null);
|
||||||
|
const useComponent = Boolean(workspace && resolveTemplateRenderer(workspace));
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [reloadKey, setReloadKey] = useState(0);
|
const [reloadKey, setReloadKey] = useState(0);
|
||||||
const config = brand.config ?? {};
|
const url = useMemo(() => {
|
||||||
const templateKey =
|
const value = templatePreviewUrl(
|
||||||
typeof config.visualTemplateKey === "string" ? config.visualTemplateKey : brand.templateKey;
|
brand.slug,
|
||||||
const url = useMemo(
|
page,
|
||||||
() =>
|
import.meta.env.VITE_TEMPLATE_PREVIEW_URL || "/template-preview/index.html",
|
||||||
templatePreviewUrl(
|
window.location.origin,
|
||||||
templateKey,
|
`/pages/${encodeURIComponent(page)}/index`,
|
||||||
brand.slug,
|
);
|
||||||
page,
|
if (!value) return undefined;
|
||||||
import.meta.env.VITE_TEMPLATE_PREVIEW_URLS,
|
const preview = new URL(value);
|
||||||
window.location.origin,
|
preview.searchParams.set("refresh", String(reloadKey));
|
||||||
route,
|
return preview.toString();
|
||||||
),
|
}, [brand.slug, page, reloadKey]);
|
||||||
[brand.slug, page, reloadKey, route, templateKey],
|
|
||||||
);
|
|
||||||
const origin = useMemo(() => (url ? new URL(url).origin : ""), [url]);
|
const origin = useMemo(() => (url ? new URL(url).origin : ""), [url]);
|
||||||
const brandDraft = useMemo(
|
const brandDraft = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -70,7 +79,7 @@ export function TemplatePreview({
|
|||||||
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
||||||
if (message.type === "ready") setReady(true);
|
if (message.type === "ready") setReady(true);
|
||||||
if (message.type === "targetSelected" && message.page === page)
|
if (message.type === "targetSelected" && message.page === page)
|
||||||
onTargetSelected(message.targetKey);
|
onTargetSelected({ targetKey: message.targetKey });
|
||||||
};
|
};
|
||||||
window.addEventListener("message", onMessage);
|
window.addEventListener("message", onMessage);
|
||||||
return () => window.removeEventListener("message", onMessage);
|
return () => window.removeEventListener("message", onMessage);
|
||||||
@@ -80,12 +89,21 @@ export function TemplatePreview({
|
|||||||
if (!ready || !frame.current?.contentWindow || !origin) return;
|
if (!ready || !frame.current?.contentWindow || !origin) return;
|
||||||
const send = (message: EditorPreviewHostMessage) =>
|
const send = (message: EditorPreviewHostMessage) =>
|
||||||
frame.current?.contentWindow?.postMessage(message, origin);
|
frame.current?.contentWindow?.postMessage(message, origin);
|
||||||
send({
|
if (workspace) {
|
||||||
protocol: "personal-brand-editor-preview",
|
send({
|
||||||
version: 1,
|
protocol: "personal-brand-editor-preview",
|
||||||
type: "brandDraft",
|
version: 1,
|
||||||
brand: brandDraft,
|
type: "workspaceDraft",
|
||||||
});
|
workspace,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
send({
|
||||||
|
protocol: "personal-brand-editor-preview",
|
||||||
|
version: 1,
|
||||||
|
type: "brandDraft",
|
||||||
|
brand: brandDraft,
|
||||||
|
});
|
||||||
|
}
|
||||||
if (targetKey)
|
if (targetKey)
|
||||||
send({
|
send({
|
||||||
protocol: "personal-brand-editor-preview",
|
protocol: "personal-brand-editor-preview",
|
||||||
@@ -93,7 +111,7 @@ export function TemplatePreview({
|
|||||||
type: "focusTarget",
|
type: "focusTarget",
|
||||||
targetKey,
|
targetKey,
|
||||||
});
|
});
|
||||||
}, [brandDraft, origin, ready, targetKey]);
|
}, [brandDraft, origin, ready, targetKey, workspace]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const refresh = () => setReloadKey((value) => value + 1);
|
const refresh = () => setReloadKey((value) => value + 1);
|
||||||
@@ -101,35 +119,50 @@ export function TemplatePreview({
|
|||||||
return () => window.removeEventListener("template-preview-refresh", refresh);
|
return () => window.removeEventListener("template-preview-refresh", refresh);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (!url)
|
if (!useComponent && !url)
|
||||||
return (
|
return (
|
||||||
<Alert
|
<Alert
|
||||||
type="warning"
|
type="warning"
|
||||||
showIcon
|
showIcon
|
||||||
message="尚未配置模板预览服务"
|
message="页面预览暂不可用"
|
||||||
description="请在 Admin 环境变量 VITE_TEMPLATE_PREVIEW_URLS 中为模板配置 H5 预览地址。"
|
description="请确认模板预览资源已构建并发布,或本地预览服务正在运行。"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="template-preview">
|
<div className="template-preview">
|
||||||
{!ready && !error ? (
|
{workspace && useComponent ? (
|
||||||
<div className="template-preview__loading">
|
<ComponentTemplatePreview
|
||||||
<Spin tip="正在加载页面预览" />
|
workspace={workspace}
|
||||||
</div>
|
page={page}
|
||||||
|
{...(offeringId ? { offeringId } : {})}
|
||||||
|
{...(targetKey ? { targetKey } : {})}
|
||||||
|
{...(selection ? { selection } : {})}
|
||||||
|
targets={targets}
|
||||||
|
onTargetSelected={onTargetSelected}
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{error ? (
|
{!useComponent ? (
|
||||||
<Alert type="error" showIcon message="页面预览加载失败" description={error} />
|
<>
|
||||||
|
{!ready && !error ? (
|
||||||
|
<div className="template-preview__loading">
|
||||||
|
<Spin tip="正在加载页面预览" />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{error ? (
|
||||||
|
<Alert type="error" showIcon message="页面预览加载失败" description={error} />
|
||||||
|
) : null}
|
||||||
|
<iframe
|
||||||
|
key={url}
|
||||||
|
ref={frame}
|
||||||
|
title="小程序页面预览"
|
||||||
|
src={url}
|
||||||
|
referrerPolicy="origin"
|
||||||
|
onError={() => setError("请检查预览服务地址和网络连接。")}
|
||||||
|
style={{ opacity: ready ? 1 : 0 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
<iframe
|
|
||||||
key={url}
|
|
||||||
ref={frame}
|
|
||||||
title="小程序页面预览"
|
|
||||||
src={url}
|
|
||||||
referrerPolicy="origin"
|
|
||||||
onError={() => setError("请检查预览服务地址和网络连接。")}
|
|
||||||
style={{ opacity: ready ? 1 : 0 }}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import type { ComponentType } from "react";
|
||||||
|
import type { RuntimeWorkspace } from "@personal-brand/api-client";
|
||||||
|
|
||||||
|
declare module "./component-renderers.jsx" {
|
||||||
|
export function resolveTemplateRenderer(workspace: RuntimeWorkspace): ComponentType<{
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
page: string;
|
||||||
|
offeringId?: string;
|
||||||
|
}> | null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { TemplatePage as FoodTemplatePage } from "../../../../../packages/template-acheng-campus-food/taro/index.tsx";
|
||||||
|
import { TemplatePage as EditorialTemplatePage } from "../../../../../packages/template-linjing-editorial/taro/index.tsx";
|
||||||
|
import React from "react";
|
||||||
|
import { Inquiry } from "../../../../taro/src/components/Inquiry.tsx";
|
||||||
|
import { Records } from "../../../../taro/src/components/Records.tsx";
|
||||||
|
import { Success } from "../../../../taro/src/components/Success.tsx";
|
||||||
|
import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||||
|
|
||||||
|
function pageContent({ workspace, page }) {
|
||||||
|
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||||
|
if (page === "records") return <Records workspace={workspace} preview />;
|
||||||
|
if (page === "success") return <Success workspace={workspace} preview />;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FoodPreview(props) {
|
||||||
|
return (
|
||||||
|
<TemplateAssetContext.Provider value="acheng-campus-food">
|
||||||
|
<FoodTemplatePage {...props}>{pageContent(props)}</FoodTemplatePage>
|
||||||
|
</TemplateAssetContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function EditorialPreview(props) {
|
||||||
|
return (
|
||||||
|
<TemplateAssetContext.Provider value="linjing-editorial">
|
||||||
|
<EditorialTemplatePage {...props}>{pageContent(props)}</EditorialTemplatePage>
|
||||||
|
</TemplateAssetContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveTemplateRenderer(workspace) {
|
||||||
|
const config = workspace?.brand?.config;
|
||||||
|
const key =
|
||||||
|
config && typeof config === "object" && !Array.isArray(config)
|
||||||
|
? config.visualTemplateKey
|
||||||
|
: undefined;
|
||||||
|
if (key === "acheng-campus-food") return FoodPreview;
|
||||||
|
if (key === "linjing-editorial") return EditorialPreview;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
@@ -31,11 +31,14 @@ function asObject(value: unknown): Record<string, unknown> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function safePath(binding: string): string[] | null {
|
function safePath(binding: string): string[] | null {
|
||||||
const prefix = ["brand.config.", "offering.config.", "trust.config."].find((candidate) =>
|
const prefixes = ["brand.config.", "offering.config.", "trust.config."];
|
||||||
binding.startsWith(candidate),
|
const prefix = prefixes.find((candidate) => binding.startsWith(candidate));
|
||||||
);
|
const standardField =
|
||||||
if (!prefix) return null;
|
/^(brand\.(name|tagline|avatarUrl|description|contactPhone|contactWechat|address|hours|deliveryNote)|offering\.(name|summary|description|coverUrl|priceText)|trust\.(title|summary|content|coverUrl))$/.test(
|
||||||
const path = binding.slice(prefix.length).split(".");
|
binding,
|
||||||
|
);
|
||||||
|
if (!prefix && !standardField) return null;
|
||||||
|
const path = prefix ? binding.slice(prefix.length).split(".") : [binding.split(".")[1] ?? ""];
|
||||||
if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part)))
|
if (path.some((part) => !part || ["__proto__", "prototype", "constructor"].includes(part)))
|
||||||
return null;
|
return null;
|
||||||
return path;
|
return path;
|
||||||
@@ -49,10 +52,15 @@ export function readPresentationValue(
|
|||||||
config: Record<string, unknown> | null | undefined,
|
config: Record<string, unknown> | null | undefined,
|
||||||
binding: string,
|
binding: string,
|
||||||
field?: PresentationField,
|
field?: PresentationField,
|
||||||
|
brand?: Record<string, unknown>,
|
||||||
): unknown {
|
): unknown {
|
||||||
const path = safePath(binding);
|
const path = safePath(binding);
|
||||||
if (!path) return undefined;
|
if (!path) return undefined;
|
||||||
let value: unknown = asObject(config);
|
const isConfigBinding =
|
||||||
|
binding.startsWith("brand.config.") ||
|
||||||
|
binding.startsWith("offering.config.") ||
|
||||||
|
binding.startsWith("trust.config.");
|
||||||
|
let value: unknown = isConfigBinding ? asObject(config) : asObject(brand);
|
||||||
for (const part of path) value = asObject(value)[part];
|
for (const part of path) value = asObject(value)[part];
|
||||||
if (field?.input === "list") {
|
if (field?.input === "list") {
|
||||||
if (!Array.isArray(value)) return [];
|
if (!Array.isArray(value)) return [];
|
||||||
@@ -88,9 +96,11 @@ export function applyPresentationValues(
|
|||||||
let nextConfig = { ...asObject(config) };
|
let nextConfig = { ...asObject(config) };
|
||||||
for (const section of sections) {
|
for (const section of sections) {
|
||||||
for (const field of section.fields) {
|
for (const field of section.fields) {
|
||||||
|
if (!field.binding.includes(".config.")) continue;
|
||||||
const path = safePath(field.binding);
|
const path = safePath(field.binding);
|
||||||
if (!path) continue;
|
if (!path) continue;
|
||||||
const raw = values[presentationFieldName(section.key, field.key)];
|
const raw = values[presentationFieldName(section.key, field.key)];
|
||||||
|
if (raw === undefined) continue;
|
||||||
const value =
|
const value =
|
||||||
field.input === "list" && Array.isArray(raw)
|
field.input === "list" && Array.isArray(raw)
|
||||||
? field.itemValueKey
|
? field.itemValueKey
|
||||||
@@ -104,3 +114,51 @@ export function applyPresentationValues(
|
|||||||
}
|
}
|
||||||
return nextConfig;
|
return nextConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function applyStandardBrandValues(
|
||||||
|
brand: Record<string, unknown>,
|
||||||
|
sections: PresentationSection[],
|
||||||
|
values: PresentationValues,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const next = { ...brand };
|
||||||
|
for (const section of sections) {
|
||||||
|
for (const field of section.fields) {
|
||||||
|
if (!field.binding.startsWith("brand.") || field.binding.startsWith("brand.config."))
|
||||||
|
continue;
|
||||||
|
const value = values[presentationFieldName(section.key, field.key)];
|
||||||
|
if (value !== undefined) next[field.binding.slice("brand.".length)] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyStandardEntityValues(
|
||||||
|
entity: Record<string, unknown>,
|
||||||
|
entityType: "offering" | "trust",
|
||||||
|
sections: PresentationSection[],
|
||||||
|
values: PresentationValues,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const next = { ...entity };
|
||||||
|
for (const section of sections) {
|
||||||
|
for (const field of section.fields) {
|
||||||
|
if (!field.binding.startsWith(`${entityType}.`) || field.binding.includes(".config."))
|
||||||
|
continue;
|
||||||
|
const value = values[presentationFieldName(section.key, field.key)];
|
||||||
|
if (value !== undefined) next[field.binding.slice(entityType.length + 1)] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyBrandPreviewValues(
|
||||||
|
brand: Record<string, unknown>,
|
||||||
|
config: Record<string, unknown> | null | undefined,
|
||||||
|
sections: PresentationSection[],
|
||||||
|
values: PresentationValues,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const nextBrand = applyStandardBrandValues(brand, sections, values);
|
||||||
|
return {
|
||||||
|
...nextBrand,
|
||||||
|
config: applyPresentationValues(config, sections, values),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
export type PreviewSelection = { targetKey: string; recordId?: string };
|
||||||
|
|
||||||
|
// 与模板 slot 一致,优先选择承载结构化内容的记录。
|
||||||
|
export function previewTrustRecordId(
|
||||||
|
items: { id?: string; type: string; config: Record<string, unknown> }[],
|
||||||
|
type: string | undefined,
|
||||||
|
): string | undefined {
|
||||||
|
const matches = items.filter((item) => item.type === type);
|
||||||
|
return (matches.find((item) => Object.keys(item.config).length > 0) ?? matches[0])?.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PreviewTarget = {
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
source: "brand" | "offering" | "trust" | "inquiry";
|
||||||
|
page: string;
|
||||||
|
composite?: boolean;
|
||||||
|
trustType?: string;
|
||||||
|
children?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function resolvePreviewSelection(
|
||||||
|
targetKey: string,
|
||||||
|
recordId: string | undefined,
|
||||||
|
targets: PreviewTarget[],
|
||||||
|
page: string,
|
||||||
|
): PreviewSelection | undefined {
|
||||||
|
const target = targets.find((item) => item.key === targetKey && item.page === page);
|
||||||
|
if (!target) return undefined;
|
||||||
|
if (recordId && target.source !== "offering" && target.source !== "trust") return undefined;
|
||||||
|
// 空区域仍可选中,编辑面板提供创建内容的入口。
|
||||||
|
return recordId ? { targetKey, recordId } : { targetKey };
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export const TemplateAssetContext = React.createContext("");
|
||||||
|
const templateAssets = import.meta.glob("../../../../../packages/template-*/miniapp/assets/**/*", {
|
||||||
|
eager: true,
|
||||||
|
query: "?url",
|
||||||
|
import: "default",
|
||||||
|
});
|
||||||
|
|
||||||
|
function resolveImageSource(src, templateKey) {
|
||||||
|
if (typeof src !== "string" || !src.startsWith("/assets/")) return src;
|
||||||
|
const relative = src.slice("/assets/".length);
|
||||||
|
for (const [file, url] of Object.entries(templateAssets)) {
|
||||||
|
const parts = file.split("/packages/template-")[1]?.split("/miniapp/assets/");
|
||||||
|
if (!parts) continue;
|
||||||
|
const [key, asset] = parts;
|
||||||
|
if (relative === key + "/" + asset || (key === templateKey && relative === asset)) return url;
|
||||||
|
}
|
||||||
|
return src;
|
||||||
|
}
|
||||||
|
|
||||||
|
const element = (tag) =>
|
||||||
|
React.forwardRef(({ children, className, style, onClick, ...props }, ref) =>
|
||||||
|
React.createElement(tag, { ...props, ref, className, style, onClick }, children),
|
||||||
|
);
|
||||||
|
|
||||||
|
export const View = element("div");
|
||||||
|
export const Text = element("span");
|
||||||
|
export const Button = element("button");
|
||||||
|
export const Input = React.forwardRef(({ onInput, ...props }, ref) =>
|
||||||
|
React.createElement("input", {
|
||||||
|
...props,
|
||||||
|
ref,
|
||||||
|
onInput: (event) => onInput?.({ detail: { value: event.currentTarget.value } }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
export const Textarea = React.forwardRef(({ onInput, maxlength, ...props }, ref) =>
|
||||||
|
React.createElement("textarea", {
|
||||||
|
...props,
|
||||||
|
ref,
|
||||||
|
maxLength: maxlength,
|
||||||
|
onInput: (event) => onInput?.({ detail: { value: event.currentTarget.value } }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
export function Picker({ children, mode, range = [], value, onChange }) {
|
||||||
|
return (
|
||||||
|
<div style={{ position: "relative" }}>
|
||||||
|
{children}
|
||||||
|
{mode === "date" ? (
|
||||||
|
<input
|
||||||
|
aria-label="选择日期"
|
||||||
|
type="date"
|
||||||
|
value={value || ""}
|
||||||
|
onChange={(event) => onChange?.({ detail: { value: event.currentTarget.value } })}
|
||||||
|
style={{ position: "absolute", inset: 0, width: "100%", opacity: 0, cursor: "pointer" }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<select
|
||||||
|
aria-label="选择选项"
|
||||||
|
value={value ?? 0}
|
||||||
|
onChange={(event) => onChange?.({ detail: { value: event.currentTarget.value } })}
|
||||||
|
style={{ position: "absolute", inset: 0, width: "100%", opacity: 0, cursor: "pointer" }}
|
||||||
|
>
|
||||||
|
{range.map((label, index) => (
|
||||||
|
<option key={index} value={index}>
|
||||||
|
{label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const CheckboxContext = React.createContext(null);
|
||||||
|
export function CheckboxGroup({ children, onChange }) {
|
||||||
|
const [selected, setSelected] = React.useState([]);
|
||||||
|
const update = (value, checked) => {
|
||||||
|
const next = checked ? [...selected, value] : selected.filter((item) => item !== value);
|
||||||
|
setSelected(next);
|
||||||
|
onChange?.({ detail: { value: next } });
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<CheckboxContext.Provider value={update}>
|
||||||
|
<div>{children}</div>
|
||||||
|
</CheckboxContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export function Checkbox({ value, checked }) {
|
||||||
|
const update = React.useContext(CheckboxContext);
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
value={value}
|
||||||
|
checked={Boolean(checked)}
|
||||||
|
onChange={(event) => update?.(value, event.currentTarget.checked)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export const Label = element("label");
|
||||||
|
export const Image = React.forwardRef(({ mode, src, style, ...props }, ref) => {
|
||||||
|
const key = React.useContext(TemplateAssetContext);
|
||||||
|
return React.createElement("img", {
|
||||||
|
...props,
|
||||||
|
ref,
|
||||||
|
src: resolveImageSource(src, key),
|
||||||
|
style: { objectFit: mode === "aspectFit" ? "contain" : "cover", ...style },
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import React from "react";
|
||||||
|
const noop = () => Promise.resolve();
|
||||||
|
export const useRouter = () => ({ params: {} });
|
||||||
|
export const useDidShow = (callback) => React.useEffect(callback, []);
|
||||||
|
const Taro = {
|
||||||
|
setStorageSync() {},
|
||||||
|
getStorageSync() {
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
removeStorageSync() {},
|
||||||
|
switchTab: noop,
|
||||||
|
navigateTo: noop,
|
||||||
|
};
|
||||||
|
export default Taro;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
import { Modal } from "antd";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
|
export function useEditorDraft(dirty: boolean) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
useEffect(() => {
|
||||||
|
if (!dirty) return;
|
||||||
|
const beforeUnload = (event: BeforeUnloadEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.returnValue = "";
|
||||||
|
};
|
||||||
|
window.addEventListener("beforeunload", beforeUnload);
|
||||||
|
const leave = (event: MouseEvent) => {
|
||||||
|
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey)
|
||||||
|
return;
|
||||||
|
const anchor =
|
||||||
|
event.target instanceof Element ? event.target.closest<HTMLAnchorElement>("a[href]") : null;
|
||||||
|
if (!anchor || anchor.target === "_blank" || anchor.hasAttribute("download")) return;
|
||||||
|
const url = new URL(anchor.href, window.location.href);
|
||||||
|
if (url.origin !== window.location.origin || url.pathname === window.location.pathname)
|
||||||
|
return;
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
Modal.confirm({
|
||||||
|
title: "有尚未保存的修改",
|
||||||
|
content: "离开工作台会丢失未保存内容。请先保存,或确认放弃修改。",
|
||||||
|
okText: "放弃修改并继续",
|
||||||
|
cancelText: "继续编辑",
|
||||||
|
onOk: () => {
|
||||||
|
void navigate(`${url.pathname}${url.search}${url.hash}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener("click", leave, true);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("beforeunload", beforeUnload);
|
||||||
|
document.removeEventListener("click", leave, true);
|
||||||
|
};
|
||||||
|
}, [dirty, navigate]);
|
||||||
|
return (action: () => void) => {
|
||||||
|
if (!dirty) return action();
|
||||||
|
Modal.confirm({
|
||||||
|
title: "有尚未保存的修改",
|
||||||
|
content: "切换后当前内容可能丢失。请先保存,或确认放弃修改。",
|
||||||
|
okText: "放弃修改并继续",
|
||||||
|
cancelText: "继续编辑",
|
||||||
|
onOk: action,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
.service-offering-editor {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(320px, 1fr) minmax(340px, 440px);
|
||||||
|
gap: 20px;
|
||||||
|
max-height: 76vh;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__preview {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 72vh;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__view {
|
||||||
|
align-self: flex-start;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__preview > .component-template-preview-shell {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__form {
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-height: 72vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__form-scroll {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__preview .ant-alert {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 860px) {
|
||||||
|
.service-offering-editor {
|
||||||
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
max-height: none;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__preview {
|
||||||
|
height: 560px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-offering-editor__form {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
Form,
|
Form,
|
||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
|
Segmented,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
@@ -12,25 +14,40 @@ import {
|
|||||||
message,
|
message,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { Offering, TemplateAdminField } from "@personal-brand/api-client";
|
import type {
|
||||||
import { useState } from "react";
|
Offering,
|
||||||
|
RuntimeWorkspace,
|
||||||
|
TemplateAdminField,
|
||||||
|
TemplateAdminSection,
|
||||||
|
} from "@personal-brand/api-client";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
import { createApiClient } from "../../lib/api.js";
|
import { createApiClient } from "../../lib/api.js";
|
||||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||||
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
import { ImageUrlField } from "../../components/ImageUrlField.js";
|
||||||
import { TemplateListField } from "../../components/TemplateListField.js";
|
import { RecordContentFields } from "../../components/RecordContentEditor.js";
|
||||||
|
import { ComponentTemplatePreview } from "../brand/ComponentTemplatePreview.js";
|
||||||
|
import type { PreviewTarget } from "../brand/preview-selection.js";
|
||||||
import {
|
import {
|
||||||
applyPresentationValues,
|
applyPresentationValues,
|
||||||
presentationFieldName,
|
presentationFieldName,
|
||||||
readPresentationValue,
|
readPresentationValue,
|
||||||
} from "../brand/presentation-bindings.js";
|
} from "../brand/presentation-bindings.js";
|
||||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import "./ServicesPage.css";
|
||||||
|
|
||||||
export function ServicesPage() {
|
export function ServicesPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const client = createApiClient();
|
const client = createApiClient();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [offeringForm] = Form.useForm();
|
const [offeringForm] = Form.useForm();
|
||||||
const [offeringOpen, setOfferingOpen] = useState(false);
|
const [offeringOpen, setOfferingOpen] = useState(false);
|
||||||
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
const [editingOffering, setEditingOffering] = useState<Offering | null>(null);
|
||||||
|
const [previewPage, setPreviewPage] = useState<"offerings" | "detail">("detail");
|
||||||
|
const listFieldsRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const detailFieldsRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const formScrollRef = useRef<HTMLDivElement | null>(null);
|
||||||
const offerings = useQuery({
|
const offerings = useQuery({
|
||||||
queryKey: ["admin-offerings"],
|
queryKey: ["admin-offerings"],
|
||||||
queryFn: () => client.listAdminOfferings(),
|
queryFn: () => client.listAdminOfferings(),
|
||||||
@@ -39,6 +56,10 @@ export function ServicesPage() {
|
|||||||
queryKey: ["admin-workspace-offering-fields"],
|
queryKey: ["admin-workspace-offering-fields"],
|
||||||
queryFn: () => client.getAdminWorkspace(),
|
queryFn: () => client.getAdminWorkspace(),
|
||||||
});
|
});
|
||||||
|
const previewWorkspace = useQuery({
|
||||||
|
queryKey: ["admin-preview-workspace-services"],
|
||||||
|
queryFn: () => client.getAdminPreviewWorkspace(),
|
||||||
|
});
|
||||||
const templateFields: TemplateAdminField[] = (
|
const templateFields: TemplateAdminField[] = (
|
||||||
workspace.data?.templateContent?.admin.sections ?? []
|
workspace.data?.templateContent?.admin.sections ?? []
|
||||||
)
|
)
|
||||||
@@ -46,6 +67,17 @@ export function ServicesPage() {
|
|||||||
.flatMap((section) =>
|
.flatMap((section) =>
|
||||||
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
section.fields.filter((field) => field.binding.startsWith("offering.config.")),
|
||||||
);
|
);
|
||||||
|
const templateFieldSection = useMemo<TemplateAdminSection>(
|
||||||
|
() => ({
|
||||||
|
key: "offering",
|
||||||
|
title: "模板内容",
|
||||||
|
description: "",
|
||||||
|
page: "detail",
|
||||||
|
target: "offering",
|
||||||
|
fields: templateFields,
|
||||||
|
}),
|
||||||
|
[templateFields],
|
||||||
|
);
|
||||||
const offeringPageLabel =
|
const offeringPageLabel =
|
||||||
workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
|
workspace.data?.templateContent?.navigation.find((item) => item.page === "offerings")?.label ??
|
||||||
"业务展示页";
|
"业务展示页";
|
||||||
@@ -55,9 +87,116 @@ export function ServicesPage() {
|
|||||||
const detailSections = (workspace.data?.templateContent?.admin.sections ?? []).filter(
|
const detailSections = (workspace.data?.templateContent?.admin.sections ?? []).filter(
|
||||||
(section) => section.target === "offering" && section.page === "detail",
|
(section) => section.target === "offering" && section.page === "detail",
|
||||||
);
|
);
|
||||||
|
const visualOfferingTarget = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||||
|
.filter((section) => section.target === "offering" && section.page === "offerings")
|
||||||
|
.flatMap((section) => section.previewTargets ?? [])
|
||||||
|
.find((target) => templateFields.some((field) => field.previewTarget === target.key)) ?? {
|
||||||
|
key: "linjing-editorial.offerings.item",
|
||||||
|
label: "业务卡片",
|
||||||
|
};
|
||||||
const hasTemplateDetailCopy = templateFields.some(
|
const hasTemplateDetailCopy = templateFields.some(
|
||||||
(field) => field.binding === "offering.config.details.background",
|
(field) => field.binding === "offering.config.details.background",
|
||||||
);
|
);
|
||||||
|
const previewTargets = useMemo<Record<string, PreviewTarget[]>>(
|
||||||
|
() =>
|
||||||
|
["offerings", "detail"].reduce<Record<string, PreviewTarget[]>>((result, page) => {
|
||||||
|
result[page] = (workspace.data?.templateContent?.admin.sections ?? [])
|
||||||
|
.filter((section) => section.page === page)
|
||||||
|
.flatMap((section) =>
|
||||||
|
(section.previewTargets ?? []).map((target) => ({
|
||||||
|
...target,
|
||||||
|
page: section.page,
|
||||||
|
source: section.fields.some(
|
||||||
|
(field) =>
|
||||||
|
field.binding.startsWith("offering.") && field.previewTarget === target.key,
|
||||||
|
)
|
||||||
|
? "offering"
|
||||||
|
: section.target,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}, {}),
|
||||||
|
[workspace.data?.templateContent],
|
||||||
|
);
|
||||||
|
const listFields = useMemo(
|
||||||
|
() => templateFields.filter((field) => field.previewTarget === visualOfferingTarget.key),
|
||||||
|
[templateFields, visualOfferingTarget.key],
|
||||||
|
);
|
||||||
|
const detailTarget = previewTargets.detail?.find((target) => target.source === "offering");
|
||||||
|
const detailFields = useMemo(
|
||||||
|
() => templateFields.filter((field) => field.previewTarget === detailTarget?.key),
|
||||||
|
[templateFields, detailTarget?.key],
|
||||||
|
);
|
||||||
|
const otherFields = useMemo(
|
||||||
|
() =>
|
||||||
|
templateFields.filter(
|
||||||
|
(field) => !listFields.includes(field) && !detailFields.includes(field),
|
||||||
|
),
|
||||||
|
[templateFields, listFields, detailFields],
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
const target = previewPage === "offerings" ? listFieldsRef.current : detailFieldsRef.current;
|
||||||
|
if (!target || !formScrollRef.current) return;
|
||||||
|
formScrollRef.current.scrollTo({
|
||||||
|
top: target.offsetTop - formScrollRef.current.offsetTop - 12,
|
||||||
|
behavior: "smooth",
|
||||||
|
});
|
||||||
|
}, [previewPage, editingOffering?.id]);
|
||||||
|
const previewWorkspaceDraft = useMemo<RuntimeWorkspace | undefined>(() => {
|
||||||
|
if (!previewWorkspace.data || !editingOffering) return undefined;
|
||||||
|
const values = offeringForm.getFieldsValue(true) as Record<string, unknown>;
|
||||||
|
const config = applyPresentationValues(
|
||||||
|
editingOffering.config,
|
||||||
|
[{ key: "offering", fields: templateFields }],
|
||||||
|
values,
|
||||||
|
);
|
||||||
|
const offeringValues = {
|
||||||
|
name: values.name,
|
||||||
|
summary: values.summary,
|
||||||
|
description: values.description,
|
||||||
|
priceText: values.priceText,
|
||||||
|
coverUrl: values.coverUrl,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...previewWorkspace.data,
|
||||||
|
offerings: previewWorkspace.data.offerings.map((item) =>
|
||||||
|
item.id === editingOffering.id
|
||||||
|
? {
|
||||||
|
...item,
|
||||||
|
name:
|
||||||
|
typeof offeringValues.name === "string" && offeringValues.name.trim()
|
||||||
|
? offeringValues.name
|
||||||
|
: item.name,
|
||||||
|
summary:
|
||||||
|
typeof offeringValues.summary === "string" ? offeringValues.summary : item.summary,
|
||||||
|
priceText:
|
||||||
|
typeof offeringValues.priceText === "string"
|
||||||
|
? offeringValues.priceText
|
||||||
|
: item.priceText,
|
||||||
|
coverUrl:
|
||||||
|
typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||||
|
? offeringValues.coverUrl
|
||||||
|
: item.coverUrl,
|
||||||
|
config,
|
||||||
|
presentation: {
|
||||||
|
...item.presentation,
|
||||||
|
...config,
|
||||||
|
...(config.presentation && typeof config.presentation === "object"
|
||||||
|
? (config.presentation as Record<string, unknown>)
|
||||||
|
: {}),
|
||||||
|
heroImage:
|
||||||
|
typeof config.detailHero === "string"
|
||||||
|
? config.detailHero
|
||||||
|
: typeof offeringValues.coverUrl === "string" && offeringValues.coverUrl.trim()
|
||||||
|
? offeringValues.coverUrl
|
||||||
|
: (item.coverUrl ?? null),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: item,
|
||||||
|
),
|
||||||
|
brand: previewWorkspace.data.brand,
|
||||||
|
};
|
||||||
|
}, [previewWorkspace.data, editingOffering, templateFields]);
|
||||||
const saveOffering = useMutation({
|
const saveOffering = useMutation({
|
||||||
mutationFn: (values: Record<string, unknown>) => {
|
mutationFn: (values: Record<string, unknown>) => {
|
||||||
const fields = Object.fromEntries(
|
const fields = Object.fromEntries(
|
||||||
@@ -239,6 +378,7 @@ export function ServicesPage() {
|
|||||||
<Modal
|
<Modal
|
||||||
open={offeringOpen}
|
open={offeringOpen}
|
||||||
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
title={editingOffering ? "编辑业务提供项" : "新增业务提供项"}
|
||||||
|
width={960}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setOfferingOpen(false);
|
setOfferingOpen(false);
|
||||||
setEditingOffering(null);
|
setEditingOffering(null);
|
||||||
@@ -247,83 +387,156 @@ export function ServicesPage() {
|
|||||||
onOk={() => offeringForm.submit()}
|
onOk={() => offeringForm.submit()}
|
||||||
confirmLoading={saveOffering.isPending}
|
confirmLoading={saveOffering.isPending}
|
||||||
>
|
>
|
||||||
<Form
|
<div className="service-offering-editor">
|
||||||
form={offeringForm}
|
{editingOffering && previewWorkspaceDraft ? (
|
||||||
layout="vertical"
|
<div className="service-offering-editor__preview">
|
||||||
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
<Segmented
|
||||||
>
|
className="service-offering-editor__view"
|
||||||
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
value={previewPage}
|
||||||
<Select
|
options={[
|
||||||
options={[
|
{ value: "offerings", label: "列表卡片" },
|
||||||
{ value: "service", label: "服务" },
|
{ value: "detail", label: "详情内容" },
|
||||||
{ value: "product", label: "定制产品" },
|
]}
|
||||||
{ value: "package", label: "套餐" },
|
onChange={(value) => setPreviewPage(value as "offerings" | "detail")}
|
||||||
{ value: "subscription", label: "订阅" },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="summary" label="一句话说明">
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
{!hasTemplateDetailCopy ? (
|
|
||||||
<Form.Item name="description" label="详细介绍">
|
|
||||||
<Input.TextArea rows={5} />
|
|
||||||
</Form.Item>
|
|
||||||
) : null}
|
|
||||||
<Form.Item name="priceText" label="价格展示">
|
|
||||||
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="coverUrl"
|
|
||||||
label="封面图片地址"
|
|
||||||
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
|
|
||||||
>
|
|
||||||
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="sortOrder"
|
|
||||||
label="展示顺序"
|
|
||||||
help="数字越小越靠前,不确定时填写 0。"
|
|
||||||
rules={[{ type: "number", min: 0, max: 9999 }]}
|
|
||||||
>
|
|
||||||
<Input type="number" min={0} max={9999} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="isEnabled" label="公开状态">
|
|
||||||
<Select
|
|
||||||
options={[
|
|
||||||
{ value: true, label: "已启用" },
|
|
||||||
{ value: false, label: "已停用" },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
{templateFields.map((field) =>
|
|
||||||
field.input === "list" ? (
|
|
||||||
<TemplateListField
|
|
||||||
key={field.key}
|
|
||||||
field={field}
|
|
||||||
name={presentationFieldName("offering", field.key)}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
<Alert
|
||||||
<Form.Item
|
type="info"
|
||||||
key={field.key}
|
showIcon
|
||||||
name={presentationFieldName("offering", field.key)}
|
message={previewPage === "offerings" ? "正在核对列表展示" : "正在核对详情展示"}
|
||||||
label={field.label}
|
description={
|
||||||
help={field.help}
|
previewPage === "offerings"
|
||||||
>
|
? "右侧「列表展示」字段修改后,会实时反映在当前卡片。"
|
||||||
{field.input === "textarea" ? (
|
: "右侧「详情展示」字段修改后,会实时反映在当前详情内容。"
|
||||||
<Input.TextArea rows={3} />
|
}
|
||||||
) : field.input === "image" ? (
|
/>
|
||||||
<ImageUrlField />
|
<ComponentTemplatePreview
|
||||||
) : (
|
workspace={previewWorkspaceDraft}
|
||||||
<Input />
|
page={previewPage}
|
||||||
)}
|
targets={previewTargets[previewPage] ?? []}
|
||||||
|
selection={{
|
||||||
|
targetKey:
|
||||||
|
previewPage === "offerings"
|
||||||
|
? visualOfferingTarget.key
|
||||||
|
: (detailTarget?.key ?? ""),
|
||||||
|
recordId: editingOffering.id,
|
||||||
|
}}
|
||||||
|
onTargetSelected={() => {}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<Form
|
||||||
|
className="service-offering-editor__form"
|
||||||
|
form={offeringForm}
|
||||||
|
layout="vertical"
|
||||||
|
onFinish={(values) => saveOffering.mutate(values as Record<string, unknown>)}
|
||||||
|
>
|
||||||
|
<div ref={formScrollRef} className="service-offering-editor__form-scroll">
|
||||||
|
<Typography.Title level={5}>基础信息</Typography.Title>
|
||||||
|
<Form.Item name="kind" label="类型" rules={[{ required: true }]}>
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: "service", label: "服务" },
|
||||||
|
{ value: "product", label: "定制产品" },
|
||||||
|
{ value: "package", label: "套餐" },
|
||||||
|
{ value: "subscription", label: "订阅" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
),
|
<Form.Item name="name" label="名称" rules={[{ required: true }]}>
|
||||||
)}
|
<Input />
|
||||||
</Form>
|
</Form.Item>
|
||||||
|
<Form.Item name="summary" label="一句话说明">
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
|
{!hasTemplateDetailCopy ? (
|
||||||
|
<Form.Item name="description" label="详细介绍">
|
||||||
|
<Input.TextArea rows={5} />
|
||||||
|
</Form.Item>
|
||||||
|
) : null}
|
||||||
|
<Form.Item name="priceText" label="价格展示">
|
||||||
|
<Input placeholder="例如:按现场评估报价 / ¥ 2,800 起" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="coverUrl"
|
||||||
|
label="封面图片地址"
|
||||||
|
help="填写图片地址;图片上传能力将在后续媒体管理中提供。"
|
||||||
|
>
|
||||||
|
<ImageUrlField placeholder="粘贴服务或产品封面图片地址" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="sortOrder"
|
||||||
|
label="展示顺序"
|
||||||
|
help="数字越小越靠前,不确定时填写 0。"
|
||||||
|
rules={[{ type: "number", min: 0, max: 9999 }]}
|
||||||
|
>
|
||||||
|
<Input type="number" min={0} max={9999} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item name="isEnabled" label="公开状态">
|
||||||
|
<Select
|
||||||
|
options={[
|
||||||
|
{ value: true, label: "已启用" },
|
||||||
|
{ value: false, label: "已停用" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
{templateFields.length ? (
|
||||||
|
<>
|
||||||
|
<Typography.Paragraph type="secondary">
|
||||||
|
以下模板字段与左侧预览及小程序页面编辑的是同一份业务数据。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
{listFields.length ? (
|
||||||
|
<div ref={listFieldsRef}>
|
||||||
|
<Typography.Title level={5}>列表展示</Typography.Title>
|
||||||
|
<RecordContentFields
|
||||||
|
section={{
|
||||||
|
...templateFieldSection,
|
||||||
|
fields: listFields,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{detailFields.length ? (
|
||||||
|
<div ref={detailFieldsRef}>
|
||||||
|
<Typography.Title level={5}>详情展示</Typography.Title>
|
||||||
|
<RecordContentFields
|
||||||
|
section={{
|
||||||
|
...templateFieldSection,
|
||||||
|
fields: detailFields,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{otherFields.length ? (
|
||||||
|
<>
|
||||||
|
<Typography.Title level={5}>其他模板内容</Typography.Title>
|
||||||
|
<RecordContentFields
|
||||||
|
section={{
|
||||||
|
...templateFieldSection,
|
||||||
|
fields: otherFields,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
{editingOffering ? (
|
||||||
|
<Button
|
||||||
|
htmlType="button"
|
||||||
|
onClick={() =>
|
||||||
|
navigate("/admin/brand", {
|
||||||
|
state: {
|
||||||
|
targetKey: visualOfferingTarget.key,
|
||||||
|
recordId: editingOffering.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
>
|
||||||
|
在小程序页面编辑
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</QueryState>
|
</QueryState>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,25 +1,13 @@
|
|||||||
export function templatePreviewUrl(
|
export function templatePreviewUrl(
|
||||||
templateKey: string,
|
|
||||||
brandSlug: string | undefined,
|
brandSlug: string | undefined,
|
||||||
page: string,
|
page: string,
|
||||||
configured: string | undefined,
|
configured: string | undefined,
|
||||||
parentOrigin?: string,
|
parentOrigin?: string,
|
||||||
route?: string,
|
route?: string,
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
let urls: Record<string, unknown>;
|
const raw = configured || "http://localhost:3002";
|
||||||
try {
|
try {
|
||||||
const parsed: unknown = configured ? JSON.parse(configured) : {};
|
const url = new URL(raw, parentOrigin);
|
||||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
urls = parsed as Record<string, unknown>;
|
|
||||||
} catch {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const raw = urls[templateKey];
|
|
||||||
if (typeof raw !== "string" || !raw) return undefined;
|
|
||||||
try {
|
|
||||||
const url = new URL(raw);
|
|
||||||
url.searchParams.set("editor", "1");
|
url.searchParams.set("editor", "1");
|
||||||
if (parentOrigin) url.searchParams.set("parentOrigin", parentOrigin);
|
if (parentOrigin) url.searchParams.set("parentOrigin", parentOrigin);
|
||||||
if (brandSlug) url.searchParams.set("brand", brandSlug);
|
if (brandSlug) url.searchParams.set("brand", brandSlug);
|
||||||
|
|||||||
Vendored
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
|
readonly DEV: boolean;
|
||||||
|
readonly PROD: boolean;
|
||||||
readonly VITE_API_BASE_URL?: string;
|
readonly VITE_API_BASE_URL?: string;
|
||||||
readonly VITE_APP_BASE_PATH?: string;
|
readonly VITE_APP_BASE_PATH?: string;
|
||||||
readonly VITE_TEMPLATE_PREVIEW_URLS?: string;
|
readonly VITE_TEMPLATE_PREVIEW_URL?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// 模板 CSS 使用 Taro 的 750 设计宽度,转换到预览容器单位。
|
||||||
|
export function templatePreviewCss() {
|
||||||
|
return {
|
||||||
|
postcssPlugin: "template-preview-css",
|
||||||
|
Once(root) {
|
||||||
|
const file = root.source?.input.file || "";
|
||||||
|
const templateStyle =
|
||||||
|
file.includes("/packages/template-") && file.endsWith("/taro/style.css");
|
||||||
|
const sharedFormStyle = file.endsWith("/apps/taro/src/components/forms.css");
|
||||||
|
if (!templateStyle && !sharedFormStyle) return;
|
||||||
|
root.walkRules((rule) => {
|
||||||
|
rule.selector = rule.selector
|
||||||
|
.split(",")
|
||||||
|
.map(
|
||||||
|
(selector) =>
|
||||||
|
".component-template-preview__canvas " +
|
||||||
|
selector
|
||||||
|
.trim()
|
||||||
|
.replace(
|
||||||
|
/(^|[ >+~])(image|text|view)(?=[ .#:[>+~)]|$)/g,
|
||||||
|
(_, prefix, tag) => prefix + { image: "img", text: "span", view: "div" }[tag],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.join(", ");
|
||||||
|
});
|
||||||
|
root.walkDecls((declaration) => {
|
||||||
|
// 组件预览中的固定按钮必须以页面画布为定位基准。
|
||||||
|
if (declaration.prop === "position" && declaration.value === "fixed")
|
||||||
|
declaration.value = "absolute";
|
||||||
|
// 模板页面的视口高度按手机画布宽度计算,避免引用 Admin 浏览器高度。
|
||||||
|
declaration.value = declaration.value.replace(/100vh/g, "178cqw");
|
||||||
|
declaration.value = declaration.value.replace(
|
||||||
|
/(-?(?:[0-9]*[.])?[0-9]+)px/g,
|
||||||
|
(_, value) => Number((Number(value) / 7.5).toFixed(8)) + "cqw",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import {
|
import {
|
||||||
applyPresentationValues,
|
applyPresentationValues,
|
||||||
|
applyBrandPreviewValues,
|
||||||
|
applyStandardEntityValues,
|
||||||
filterSectionsForPreviewTarget,
|
filterSectionsForPreviewTarget,
|
||||||
presentationFieldName,
|
presentationFieldName,
|
||||||
readPresentationValue,
|
readPresentationValue,
|
||||||
} from "../src/features/brand/presentation-bindings.ts";
|
} from "../src/features/brand/presentation-bindings.ts";
|
||||||
|
import {
|
||||||
|
resolvePreviewSelection,
|
||||||
|
previewTrustRecordId,
|
||||||
|
} from "../src/features/brand/preview-selection.ts";
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
founder: "阿成",
|
founder: "阿成",
|
||||||
@@ -124,3 +130,95 @@ const offering = applyPresentationValues(
|
|||||||
{ [presentationFieldName("offering", "background")]: "新背景" },
|
{ [presentationFieldName("offering", "background")]: "新背景" },
|
||||||
);
|
);
|
||||||
assert.deepEqual(offering.details, { background: "新背景", preserve: "保留" });
|
assert.deepEqual(offering.details, { background: "新背景", preserve: "保留" });
|
||||||
|
|
||||||
|
const brandDraft = applyBrandPreviewValues(
|
||||||
|
{ description: "旧简介", address: "旧地址", config: { visualPresentation: {} } },
|
||||||
|
{ visualPresentation: {} },
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: "identity",
|
||||||
|
fields: [
|
||||||
|
{ key: "description", binding: "brand.description" },
|
||||||
|
{ key: "address", binding: "brand.address" },
|
||||||
|
{ key: "headline", binding: "brand.config.visualPresentation.home.title" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{
|
||||||
|
[presentationFieldName("identity", "description")]: "新简介",
|
||||||
|
[presentationFieldName("identity", "address")]: "新地址",
|
||||||
|
[presentationFieldName("identity", "headline")]: "新标题",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert.equal(brandDraft.description, "新简介");
|
||||||
|
assert.equal(brandDraft.address, "新地址");
|
||||||
|
assert.equal(brandDraft.config.visualPresentation.home.title, "新标题");
|
||||||
|
|
||||||
|
const entitySection = [
|
||||||
|
{
|
||||||
|
key: "card",
|
||||||
|
fields: [
|
||||||
|
{ key: "name", binding: "offering.name" },
|
||||||
|
{ key: "summary", binding: "offering.summary" },
|
||||||
|
{ key: "category", binding: "offering.config.categoryLabel" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const updatedEntity = applyStandardEntityValues(
|
||||||
|
{ id: "one", name: "旧名称", summary: "旧简介", config: { categoryLabel: "分类" } },
|
||||||
|
"offering",
|
||||||
|
entitySection,
|
||||||
|
{ "card:name": "新名称", "card:summary": "新简介", "card:category": "新分类" },
|
||||||
|
);
|
||||||
|
assert.equal(updatedEntity.name, "新名称");
|
||||||
|
assert.equal(updatedEntity.summary, "新简介");
|
||||||
|
assert.equal(updatedEntity.id, "one");
|
||||||
|
assert.deepEqual(updatedEntity.config, { categoryLabel: "分类" });
|
||||||
|
assert.equal(readPresentationValue({}, "offering.name", undefined, updatedEntity), "新名称");
|
||||||
|
|
||||||
|
const targets = [
|
||||||
|
{ key: "brand.hero", label: "主视觉", source: "brand", page: "home" },
|
||||||
|
{ key: "offering.card", label: "餐品", source: "offering", page: "offerings" },
|
||||||
|
];
|
||||||
|
assert.deepEqual(resolvePreviewSelection("brand.hero", undefined, targets, "home"), {
|
||||||
|
targetKey: "brand.hero",
|
||||||
|
});
|
||||||
|
assert.deepEqual(resolvePreviewSelection("offering.card", "one", targets, "offerings"), {
|
||||||
|
targetKey: "offering.card",
|
||||||
|
recordId: "one",
|
||||||
|
});
|
||||||
|
assert.deepEqual(resolvePreviewSelection("offering.card", undefined, targets, "offerings"), {
|
||||||
|
targetKey: "offering.card",
|
||||||
|
});
|
||||||
|
assert.equal(resolvePreviewSelection("brand.hero", "one", targets, "home"), undefined);
|
||||||
|
assert.equal(resolvePreviewSelection("brand.hero", undefined, targets, "offerings"), undefined);
|
||||||
|
|
||||||
|
// 未挂载的同源编辑入口不能清空已有字段。
|
||||||
|
assert.deepEqual(
|
||||||
|
applyPresentationValues(
|
||||||
|
{ founder: "保留姓名", title: "保留职位" },
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: "identity",
|
||||||
|
fields: [
|
||||||
|
{ key: "founder", binding: "brand.config.founder" },
|
||||||
|
{ key: "title", binding: "brand.config.title" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ "identity:founder": "修改姓名" },
|
||||||
|
),
|
||||||
|
{ founder: "修改姓名", title: "保留职位" },
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
previewTrustRecordId(
|
||||||
|
[
|
||||||
|
{ id: "plain", type: "credential", config: {} },
|
||||||
|
{ id: "structured", type: "credential", config: { stats: [] } },
|
||||||
|
],
|
||||||
|
"credential",
|
||||||
|
),
|
||||||
|
"structured",
|
||||||
|
);
|
||||||
|
assert.equal(previewTrustRecordId([], "credential"), undefined);
|
||||||
@@ -2,12 +2,11 @@ import assert from "node:assert/strict";
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
|
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
|
||||||
|
|
||||||
test("template preview URL is resolved from generic deployment configuration", () => {
|
test("template preview URL is resolved from one shared deployment address", () => {
|
||||||
const url = templatePreviewUrl(
|
const url = templatePreviewUrl(
|
||||||
"new-template",
|
|
||||||
"brand-a",
|
"brand-a",
|
||||||
"profile",
|
"profile",
|
||||||
JSON.stringify({ "new-template": "https://preview.example.test/app/" }),
|
"https://preview.example.test/app/",
|
||||||
"https://admin.example.test",
|
"https://admin.example.test",
|
||||||
"/pages/profile/index",
|
"/pages/profile/index",
|
||||||
);
|
);
|
||||||
@@ -17,11 +16,18 @@ test("template preview URL is resolved from generic deployment configuration", (
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("missing, malformed or invalid template preview configuration fails closed", () => {
|
test("the shared same-origin preview address is the default", () => {
|
||||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", undefined), undefined);
|
|
||||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", "{"), undefined);
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
templatePreviewUrl("broken", "brand-a", "home", JSON.stringify({ broken: "not a URL" })),
|
templatePreviewUrl("brand-a", "home", undefined),
|
||||||
undefined,
|
"http://localhost:3002/?editor=1&brand=brand-a#/pages/home/index",
|
||||||
|
);
|
||||||
|
assert.equal(templatePreviewUrl("brand-a", "home", "{"), undefined);
|
||||||
|
assert.equal(templatePreviewUrl("brand-a", "home", "not a URL"), undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("same-origin static preview uses its explicit entry document", () => {
|
||||||
|
assert.equal(
|
||||||
|
templatePreviewUrl("brand-a", "home", "/template-preview/index.html", "http://localhost:3005"),
|
||||||
|
"http://localhost:3005/template-preview/index.html?editor=1&parentOrigin=http%3A%2F%2Flocalhost%3A3005&brand=brand-a#/pages/home/index",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -1,9 +1,23 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react";
|
import react from "@vitejs/plugin-react";
|
||||||
|
import { templatePreviewCss } from "./template-preview-css.mjs";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
css: { postcss: { plugins: [templatePreviewCss()] } },
|
||||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@tarojs/components": `${process.cwd()}/src/features/brand/taro-web-components.jsx`,
|
||||||
|
"@tarojs/taro": `${process.cwd()}/src/features/brand/taro-web-runtime.jsx`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
"process.env.TARO_PLATFORM": JSON.stringify("web"),
|
||||||
|
"process.env.TARO_ENV": JSON.stringify("h5"),
|
||||||
|
PREVIEW_ALL_TEMPLATES: JSON.stringify(true),
|
||||||
|
TEMPLATE_MANIFEST: JSON.stringify({ navigation: [] }),
|
||||||
|
},
|
||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
port: Number(process.env.ADMIN_PORT ?? 3000),
|
port: Number(process.env.ADMIN_PORT ?? 3000),
|
||||||
|
|||||||
@@ -36,12 +36,14 @@ import {
|
|||||||
} from "@personal-brand/config";
|
} from "@personal-brand/config";
|
||||||
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
import { TemplateWorkspaceService } from "./template-workspace.service.js";
|
||||||
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
import { validateFieldSnapshot, validateOfferingConfig } from "@personal-brand/validation";
|
||||||
|
import { PublicWorkspaceService } from "./modules/public/public-workspace.controller.js";
|
||||||
|
|
||||||
@Controller("admin/workspace")
|
@Controller("admin/workspace")
|
||||||
class AdminWorkspaceController {
|
class AdminWorkspaceController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly prisma: PrismaService,
|
private readonly prisma: PrismaService,
|
||||||
private readonly templateWorkspace: TemplateWorkspaceService,
|
private readonly templateWorkspace: TemplateWorkspaceService,
|
||||||
|
private readonly publicWorkspace: PublicWorkspaceService,
|
||||||
) {}
|
) {}
|
||||||
private brandId(): string {
|
private brandId(): string {
|
||||||
return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
return process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||||
@@ -194,6 +196,11 @@ class AdminWorkspaceController {
|
|||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@Get("preview")
|
||||||
|
async getPreviewWorkspace(@Req() request: FastifyRequest): Promise<unknown> {
|
||||||
|
const { brandId } = this.requireAdmin(request);
|
||||||
|
return this.publicWorkspace.getForBrandId(brandId, true);
|
||||||
|
}
|
||||||
private jsonObject(value: unknown): Record<string, unknown> {
|
private jsonObject(value: unknown): Record<string, unknown> {
|
||||||
return value && typeof value === "object" && !Array.isArray(value)
|
return value && typeof value === "object" && !Array.isArray(value)
|
||||||
? (value as Record<string, unknown>)
|
? (value as Record<string, unknown>)
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import { BookingService } from "./booking.service.js";
|
|||||||
import { AdminAuthService } from "./admin-auth.service.js";
|
import { AdminAuthService } from "./admin-auth.service.js";
|
||||||
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js";
|
||||||
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
import { AdminWorkspaceController } from "./admin-workspace.controller.js";
|
||||||
import { PublicWorkspaceController } from "./modules/public/public-workspace.controller.js";
|
import {
|
||||||
|
PublicWorkspaceController,
|
||||||
|
PublicWorkspaceService,
|
||||||
|
} from "./modules/public/public-workspace.controller.js";
|
||||||
import { PublicBrandContextService } from "./modules/public/public-brand-context.service.js";
|
import { PublicBrandContextService } from "./modules/public/public-brand-context.service.js";
|
||||||
import { AdminConfigController } from "./modules/admin/admin-config.controller.js";
|
import { AdminConfigController } from "./modules/admin/admin-config.controller.js";
|
||||||
import { PublicOfferingController } from "./modules/public/public-offering.controller.js";
|
import { PublicOfferingController } from "./modules/public/public-offering.controller.js";
|
||||||
@@ -70,6 +73,7 @@ export class HealthController {
|
|||||||
BrandReleaseService,
|
BrandReleaseService,
|
||||||
BrandReleaseApiService,
|
BrandReleaseApiService,
|
||||||
PublicBrandContextService,
|
PublicBrandContextService,
|
||||||
|
PublicWorkspaceService,
|
||||||
],
|
],
|
||||||
exports: [PrismaService, WechatAuthService],
|
exports: [PrismaService, WechatAuthService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Controller, Get, Query } from "@nestjs/common";
|
import { Controller, Get, Injectable, Query } from "@nestjs/common";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { PrismaService } from "../../prisma.service.js";
|
import { PrismaService } from "../../prisma.service.js";
|
||||||
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||||
@@ -18,6 +18,7 @@ import type {
|
|||||||
RuntimeTrustItem,
|
RuntimeTrustItem,
|
||||||
RuntimeWorkspace,
|
RuntimeWorkspace,
|
||||||
} from "@personal-brand/types";
|
} from "@personal-brand/types";
|
||||||
|
import { buildBrandReleaseSnapshot } from "../../brand-release.service.js";
|
||||||
import {
|
import {
|
||||||
projectBrandAliases,
|
projectBrandAliases,
|
||||||
projectOfferingDetails,
|
projectOfferingDetails,
|
||||||
@@ -26,22 +27,20 @@ import {
|
|||||||
projectTrustPresentation,
|
projectTrustPresentation,
|
||||||
} from "@personal-brand/types";
|
} from "@personal-brand/types";
|
||||||
|
|
||||||
@Controller("public/workspace")
|
@Injectable()
|
||||||
export class PublicWorkspaceController {
|
export class PublicWorkspaceService {
|
||||||
constructor(
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
private readonly prisma: PrismaService,
|
|
||||||
private readonly brandContext: PublicBrandContextService,
|
async getForBrandId(brandId: string, draft = false): Promise<unknown> {
|
||||||
) {}
|
|
||||||
@Get()
|
|
||||||
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
|
||||||
const brandId = await this.brandContext.resolveId(brandSlug);
|
|
||||||
const release = await this.prisma.brandRelease.findFirst({
|
const release = await this.prisma.brandRelease.findFirst({
|
||||||
where: { brandId, status: "published" },
|
where: { brandId, status: "published" },
|
||||||
orderBy: { version: "desc" },
|
orderBy: { version: "desc" },
|
||||||
select: { version: true, createdAt: true, snapshot: true },
|
select: { version: true, createdAt: true, snapshot: true },
|
||||||
});
|
});
|
||||||
const releaseSnapshot = this.jsonObject(release?.snapshot) as unknown as BrandReleaseSnapshot;
|
const draftSnapshot = draft ? await buildBrandReleaseSnapshot(this.prisma, brandId) : null;
|
||||||
if (!release) {
|
const sourceSnapshot = draftSnapshot ?? release?.snapshot;
|
||||||
|
const releaseSnapshot = this.jsonObject(sourceSnapshot) as unknown as BrandReleaseSnapshot;
|
||||||
|
if (!release && !draftSnapshot) {
|
||||||
return {
|
return {
|
||||||
contractVersion: "1.0",
|
contractVersion: "1.0",
|
||||||
schemaVersion: "1.0.0",
|
schemaVersion: "1.0.0",
|
||||||
@@ -262,9 +261,9 @@ export class PublicWorkspaceController {
|
|||||||
const runtimeWorkspace: RuntimeWorkspace = {
|
const runtimeWorkspace: RuntimeWorkspace = {
|
||||||
schemaVersion: "1.0.0",
|
schemaVersion: "1.0.0",
|
||||||
publication: {
|
publication: {
|
||||||
status: "published",
|
status: draftSnapshot ? "draft" : "published",
|
||||||
version: release.version,
|
version: draftSnapshot ? null : (release?.version ?? null),
|
||||||
publishedAt: release.createdAt.toISOString(),
|
...(!draftSnapshot && release ? { publishedAt: release.createdAt.toISOString() } : {}),
|
||||||
},
|
},
|
||||||
brand: runtimeBrand,
|
brand: runtimeBrand,
|
||||||
templateData,
|
templateData,
|
||||||
@@ -370,3 +369,17 @@ export class PublicWorkspaceController {
|
|||||||
return value === "create-booking" || value === "create-quote" ? value : "create-inquiry";
|
return value === "create-booking" || value === "create-quote" ? value : "create-inquiry";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Controller("public/workspace")
|
||||||
|
export class PublicWorkspaceController {
|
||||||
|
constructor(
|
||||||
|
private readonly brandContext: PublicBrandContextService,
|
||||||
|
private readonly workspaceService: PublicWorkspaceService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async get(@Query("brandSlug") brandSlug?: string): Promise<unknown> {
|
||||||
|
const brandId = await this.brandContext.resolveId(brandSlug);
|
||||||
|
return this.workspaceService.getForBrandId(brandId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,254 @@ after(async () => {
|
|||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("real template declarations persist brand offering and trust bindings through draft and publication", async (context) => {
|
||||||
|
const user = await prisma.adminUser.findUniqueOrThrow({ where: { username: "admin" } });
|
||||||
|
const { runtimeContractForBinding } = await import("@personal-brand/types");
|
||||||
|
const readPath = (object, path) => path.reduce((value, key) => value?.[key], object);
|
||||||
|
const writePath = (object, path, value) => {
|
||||||
|
const [key, ...tail] = path;
|
||||||
|
if (!tail.length) object[key] = value;
|
||||||
|
else {
|
||||||
|
object[key] ??= {};
|
||||||
|
writePath(object[key], tail, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let checked = 0;
|
||||||
|
for (const slug of ["default-brand", "linjing-doors"]) {
|
||||||
|
const original = await prisma.brandProfile.findUniqueOrThrow({ where: { slug } });
|
||||||
|
const originalOffering = await prisma.offering.findFirstOrThrow({
|
||||||
|
where: { brandId: original.id, isEnabled: true },
|
||||||
|
orderBy: { sortOrder: "asc" },
|
||||||
|
});
|
||||||
|
const originalReleases = await prisma.brandRelease.findMany({
|
||||||
|
where: { brandId: original.id },
|
||||||
|
});
|
||||||
|
const originalTrust = await prisma.trustContent.findMany({
|
||||||
|
where: { brandId: original.id, isPublished: true },
|
||||||
|
orderBy: { sortOrder: "asc" },
|
||||||
|
});
|
||||||
|
const headers = {
|
||||||
|
authorization: `Bearer ${signIdentity({ subject: user.id, brandId: original.id, role: "admin" })}`,
|
||||||
|
};
|
||||||
|
const manifest = JSON.parse(
|
||||||
|
(await request("/admin/workspace", { headers })).body,
|
||||||
|
).templateContent;
|
||||||
|
const fields = [
|
||||||
|
...manifest.admin.sections.flatMap((section) => section.fields),
|
||||||
|
...(manifest.templateFields ?? []),
|
||||||
|
];
|
||||||
|
const distinct = [...new Map(fields.map((field) => [field.binding, field])).values()];
|
||||||
|
const brandPatch = { config: structuredClone(original.config ?? {}) };
|
||||||
|
const offeringPatch = { config: structuredClone(originalOffering.config ?? {}) };
|
||||||
|
const expected = [];
|
||||||
|
for (const field of distinct) {
|
||||||
|
const [source, ...path] = field.binding.split(".");
|
||||||
|
if (!["brand", "offering"].includes(source)) continue;
|
||||||
|
const token = "binding-" + slug + "-" + field.key;
|
||||||
|
const value =
|
||||||
|
field.input === "list"
|
||||||
|
? [
|
||||||
|
field.itemValueKey
|
||||||
|
? token
|
||||||
|
: Object.fromEntries(
|
||||||
|
(field.itemFields ?? []).map((child) => [child.key, token + "-" + child.key]),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: field.input === "image"
|
||||||
|
? "https://example.com/" + token + ".jpg"
|
||||||
|
: field.input === "phone"
|
||||||
|
? "13800138001"
|
||||||
|
: field.input === "number"
|
||||||
|
? 73
|
||||||
|
: field.input === "boolean"
|
||||||
|
? true
|
||||||
|
: token;
|
||||||
|
writePath(source === "brand" ? brandPatch : offeringPatch, path, value);
|
||||||
|
expected.push({ field, source, path, value });
|
||||||
|
}
|
||||||
|
delete brandPatch.config.visualTemplateKey;
|
||||||
|
const createdTrustIds = [];
|
||||||
|
try {
|
||||||
|
assert.equal(
|
||||||
|
(await request("/admin/config/brand", { method: "PATCH", headers, payload: brandPatch }))
|
||||||
|
.statusCode,
|
||||||
|
200,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
(
|
||||||
|
await request("/admin/workspace/offerings/" + originalOffering.id, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers,
|
||||||
|
payload: offeringPatch,
|
||||||
|
})
|
||||||
|
).statusCode,
|
||||||
|
200,
|
||||||
|
);
|
||||||
|
const savedBrand = JSON.parse((await request("/admin/config/brand", { headers })).body);
|
||||||
|
const expectedTrust = [];
|
||||||
|
for (const declaration of manifest.trustContentTypes) {
|
||||||
|
const records = originalTrust.filter((item) => item.type === declaration.type);
|
||||||
|
let record =
|
||||||
|
records.find((item) => Object.keys(item.config ?? {}).length > 0) ?? records[0];
|
||||||
|
if (!record) {
|
||||||
|
record = await prisma.trustContent.create({
|
||||||
|
data: {
|
||||||
|
brandId: original.id,
|
||||||
|
type: declaration.type,
|
||||||
|
title: "字段验收占位",
|
||||||
|
content: "字段验收占位",
|
||||||
|
isPublished: true,
|
||||||
|
config: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
createdTrustIds.push(record.id);
|
||||||
|
}
|
||||||
|
const patch = { config: structuredClone(record.config ?? {}) };
|
||||||
|
const trustFields = [
|
||||||
|
...["title", "summary", "content"]
|
||||||
|
.filter((key) => !declaration.hideStandardFields?.includes(key))
|
||||||
|
.map((key) => ({ key, binding: "trust." + key, input: "text" })),
|
||||||
|
...(declaration.configFields ?? []),
|
||||||
|
];
|
||||||
|
for (const field of trustFields) {
|
||||||
|
const token = "binding-" + slug + "-" + declaration.type + "-" + field.key;
|
||||||
|
const path = field.binding.split(".").slice(1);
|
||||||
|
const existing = readPath(record, path);
|
||||||
|
const value =
|
||||||
|
field.input === "list"
|
||||||
|
? Array.from(
|
||||||
|
{ length: Array.isArray(existing) && existing.length ? existing.length : 1 },
|
||||||
|
(_, index) =>
|
||||||
|
Object.fromEntries(
|
||||||
|
(field.itemFields ?? []).map((child) => [
|
||||||
|
child.key,
|
||||||
|
token + "-" + index + "-" + child.key,
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: token;
|
||||||
|
writePath(patch, path, value);
|
||||||
|
expectedTrust.push({ id: record.id, path, value, binding: field.binding });
|
||||||
|
}
|
||||||
|
const updated = await request("/admin/config/trust-content/" + record.id, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers,
|
||||||
|
payload: patch,
|
||||||
|
});
|
||||||
|
assert.equal(updated.statusCode, 200, updated.body);
|
||||||
|
}
|
||||||
|
const savedTrust = JSON.parse(
|
||||||
|
(await request("/admin/config/trust-content", { headers })).body,
|
||||||
|
);
|
||||||
|
const savedOffering = JSON.parse(
|
||||||
|
(await request("/admin/workspace/offerings", { headers })).body,
|
||||||
|
).find((item) => item.id === originalOffering.id);
|
||||||
|
const draft = JSON.parse((await request("/admin/workspace/preview", { headers })).body);
|
||||||
|
for (const item of expectedTrust) {
|
||||||
|
assert.deepEqual(
|
||||||
|
readPath(
|
||||||
|
savedTrust.find((record) => record.id === item.id),
|
||||||
|
item.path,
|
||||||
|
),
|
||||||
|
item.value,
|
||||||
|
item.binding + " persistence",
|
||||||
|
);
|
||||||
|
assert.deepEqual(
|
||||||
|
readPath(
|
||||||
|
draft.trustItems.find((record) => record.id === item.id),
|
||||||
|
item.path,
|
||||||
|
),
|
||||||
|
item.value,
|
||||||
|
item.binding + " draft projection",
|
||||||
|
);
|
||||||
|
checked += 1;
|
||||||
|
}
|
||||||
|
for (const item of expected) {
|
||||||
|
assert.deepEqual(
|
||||||
|
readPath(item.source === "brand" ? savedBrand : savedOffering, item.path),
|
||||||
|
item.value,
|
||||||
|
item.field.binding + " persistence",
|
||||||
|
);
|
||||||
|
const contract = runtimeContractForBinding(item.field.binding);
|
||||||
|
assert.ok(contract, item.field.binding);
|
||||||
|
let runtimePath = contract.runtimePath.replace(/^workspace\./, "");
|
||||||
|
if (item.field.binding === "offering.config.detailHero")
|
||||||
|
runtimePath = "offerings[].presentation.heroImage";
|
||||||
|
const offeringIndex = draft.offerings.findIndex(
|
||||||
|
(offering) => offering.id === originalOffering.id,
|
||||||
|
);
|
||||||
|
runtimePath = runtimePath.replace("offerings[]", "offerings." + offeringIndex);
|
||||||
|
assert.deepEqual(
|
||||||
|
readPath(draft, runtimePath.split(".")),
|
||||||
|
item.value,
|
||||||
|
item.field.binding + " draft projection",
|
||||||
|
);
|
||||||
|
checked += 1;
|
||||||
|
}
|
||||||
|
const publish = await request("/admin/releases/publish", {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
payload: { note: "真实声明全部品牌和业务字段验收" },
|
||||||
|
});
|
||||||
|
assert.equal(publish.statusCode, 201, publish.body);
|
||||||
|
const publicWorkspace = JSON.parse(
|
||||||
|
(await request("/public/workspace?brandSlug=" + slug)).body,
|
||||||
|
);
|
||||||
|
assert.deepEqual(publicWorkspace.brand, draft.brand);
|
||||||
|
assert.deepEqual(publicWorkspace.templateData, draft.templateData);
|
||||||
|
assert.deepEqual(publicWorkspace.offerings, draft.offerings);
|
||||||
|
assert.deepEqual(publicWorkspace.trustItems, draft.trustItems);
|
||||||
|
assert.deepEqual(publicWorkspace.trustPresentation, draft.trustPresentation);
|
||||||
|
} finally {
|
||||||
|
const columns = [
|
||||||
|
"name",
|
||||||
|
"tagline",
|
||||||
|
"description",
|
||||||
|
"avatarUrl",
|
||||||
|
"contactPhone",
|
||||||
|
"contactWechat",
|
||||||
|
"address",
|
||||||
|
"coverUrl",
|
||||||
|
"hours",
|
||||||
|
"deliveryNote",
|
||||||
|
"config",
|
||||||
|
];
|
||||||
|
await prisma.brandProfile.update({
|
||||||
|
where: { id: original.id },
|
||||||
|
data: Object.fromEntries(columns.map((key) => [key, original[key]])),
|
||||||
|
});
|
||||||
|
const offeringColumns = ["name", "summary", "description", "priceText", "coverUrl", "config"];
|
||||||
|
await prisma.offering.update({
|
||||||
|
where: { id: originalOffering.id },
|
||||||
|
data: Object.fromEntries(offeringColumns.map((key) => [key, originalOffering[key]])),
|
||||||
|
});
|
||||||
|
await prisma.brandRelease.deleteMany({
|
||||||
|
where: { brandId: original.id, id: { notIn: originalReleases.map((item) => item.id) } },
|
||||||
|
});
|
||||||
|
for (const record of originalTrust)
|
||||||
|
await prisma.trustContent.update({
|
||||||
|
where: { id: record.id },
|
||||||
|
data: {
|
||||||
|
title: record.title,
|
||||||
|
summary: record.summary,
|
||||||
|
content: record.content,
|
||||||
|
config: record.config,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await prisma.trustContent.deleteMany({ where: { id: { in: createdTrustIds } } });
|
||||||
|
for (const release of originalReleases)
|
||||||
|
await prisma.brandRelease.update({
|
||||||
|
where: { id: release.id },
|
||||||
|
data: { status: release.status },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert.ok(checked > 100, "真实声明应覆盖两个模板全部品牌和业务字段");
|
||||||
|
context.diagnostic(
|
||||||
|
"Validated " + checked + " manifest bindings through persistence draft and publication",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("food structured edits survive publication and reach the generated page slots", async () => {
|
test("food structured edits survive publication and reach the generated page slots", async () => {
|
||||||
const { readFileSync } = await import("node:fs");
|
const { readFileSync } = await import("node:fs");
|
||||||
const { runInNewContext } = await import("node:vm");
|
const { runInNewContext } = await import("node:vm");
|
||||||
@@ -1325,6 +1573,59 @@ test("admin can install a template and public workspace exposes enabled configur
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("admin preview workspace is authorized and brand-scoped draft runtime", async () => {
|
||||||
|
const user = await prisma.adminUser.findUniqueOrThrow({ where: { username: "admin" } });
|
||||||
|
const token = signIdentity({ subject: user.id, brandId, role: "admin" });
|
||||||
|
const unauthorized = await request("/admin/workspace/preview");
|
||||||
|
assert.equal(unauthorized.statusCode, 401);
|
||||||
|
const invalid = await request("/admin/workspace/preview", {
|
||||||
|
headers: { authorization: "Bearer invalid-preview-token" },
|
||||||
|
});
|
||||||
|
assert.equal(invalid.statusCode, 401);
|
||||||
|
const wrongRole = await request("/admin/workspace/preview", {
|
||||||
|
headers: { authorization: `Bearer ${customerToken}` },
|
||||||
|
});
|
||||||
|
assert.equal(wrongRole.statusCode, 403);
|
||||||
|
const authorized = await request("/admin/workspace/preview", {
|
||||||
|
headers: { authorization: `Bearer ${token}` },
|
||||||
|
});
|
||||||
|
assert.equal(authorized.statusCode, 200);
|
||||||
|
const workspace = JSON.parse(authorized.body);
|
||||||
|
assert.equal(workspace.publication?.status, "draft");
|
||||||
|
assert.equal(
|
||||||
|
workspace.brand.slug,
|
||||||
|
(await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } })).slug,
|
||||||
|
);
|
||||||
|
assert.equal(workspace.brand.visualTemplateKey, "acheng-campus-food");
|
||||||
|
const unpublishedBrand = await prisma.brandProfile.create({
|
||||||
|
data: {
|
||||||
|
slug: "unpublished-preview-fixture",
|
||||||
|
name: "未发布预览品牌",
|
||||||
|
templateKey: "personal",
|
||||||
|
config: { visualTemplateKey: "linjing-editorial" },
|
||||||
|
adminMemberships: { create: { adminUserId: user.id, role: "owner" } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const draftToken = signIdentity({
|
||||||
|
subject: user.id,
|
||||||
|
brandId: unpublishedBrand.id,
|
||||||
|
role: "admin",
|
||||||
|
});
|
||||||
|
const draft = await request("/admin/workspace/preview", {
|
||||||
|
headers: { authorization: `Bearer ${draftToken}` },
|
||||||
|
});
|
||||||
|
assert.equal(draft.statusCode, 200);
|
||||||
|
assert.equal(JSON.parse(draft.body).brand.slug, unpublishedBrand.slug);
|
||||||
|
assert.equal(JSON.parse(draft.body).publication.status, "draft");
|
||||||
|
const publicResult = await request("/public/workspace?brandSlug=" + unpublishedBrand.slug);
|
||||||
|
assert.equal(JSON.parse(publicResult.body).publication.status, "unpublished");
|
||||||
|
assert.equal(JSON.parse(publicResult.body).brand, null);
|
||||||
|
} finally {
|
||||||
|
await prisma.brandProfile.delete({ where: { id: unpublishedBrand.id } });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("admin can customize workspace fields with brand isolation", async () => {
|
test("admin can customize workspace fields with brand isolation", async () => {
|
||||||
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
|
await prisma.brandFieldDefinition.deleteMany({ where: { brandId } });
|
||||||
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
|
await prisma.brandTemplateInstallation.deleteMany({ where: { brandId } });
|
||||||
@@ -1496,7 +1797,8 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
const changedDetailHero = "https://example.com/integration-detail.jpg";
|
const changedDetailHero = "https://example.com/integration-detail.jpg";
|
||||||
const changedDetailBackground = "集成测试案例详情正文";
|
const changedDetailBackground = "集成测试案例详情正文";
|
||||||
const changedTemplateData = "集成测试设计理念";
|
const changedTemplateData = "集成测试设计理念";
|
||||||
const changedStats = [{ value: "42", label: "测试成果" }];
|
const changedStats = [{ value: "42", label: "测试成果", sub: "持久化子标题" }];
|
||||||
|
const changedDescription = "唯一品牌简介保存发布验证";
|
||||||
const obsolete = await prisma.trustContent.create({
|
const obsolete = await prisma.trustContent.create({
|
||||||
data: {
|
data: {
|
||||||
brandId: doorsBrand.id,
|
brandId: doorsBrand.id,
|
||||||
@@ -1515,6 +1817,7 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers,
|
headers,
|
||||||
payload: {
|
payload: {
|
||||||
|
description: changedDescription,
|
||||||
config: {
|
config: {
|
||||||
homeHero: { ...brandConfig.homeHero, title: changedTitle },
|
homeHero: { ...brandConfig.homeHero, title: changedTitle },
|
||||||
visualPresentation: {
|
visualPresentation: {
|
||||||
@@ -1531,6 +1834,8 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.equal(brandUpdate.statusCode, 200);
|
assert.equal(brandUpdate.statusCode, 200);
|
||||||
|
const reloadedBrand = await request("/admin/config/brand", { headers });
|
||||||
|
assert.equal(JSON.parse(reloadedBrand.body).description, changedDescription);
|
||||||
const trustUpdate = await request(`/admin/config/trust-content/${trust.id}`, {
|
const trustUpdate = await request(`/admin/config/trust-content/${trust.id}`, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers,
|
headers,
|
||||||
@@ -1553,9 +1858,21 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.equal(offeringUpdate.statusCode, 200);
|
assert.equal(offeringUpdate.statusCode, 200);
|
||||||
|
const preview = await request("/admin/workspace/preview", { headers });
|
||||||
|
assert.equal(preview.statusCode, 200);
|
||||||
|
const savedDraft = JSON.parse(preview.body);
|
||||||
|
assert.equal(savedDraft.publication.status, "draft");
|
||||||
|
assert.equal(savedDraft.brand.description, changedDescription);
|
||||||
|
assert.equal(savedDraft.templateData.designPhilosophy, changedTemplateData);
|
||||||
|
assert.deepEqual(savedDraft.trustPresentation.stats, changedStats);
|
||||||
|
assert.equal(
|
||||||
|
savedDraft.offerings.find((item) => item.id === offering.id).presentation.area,
|
||||||
|
changedArea,
|
||||||
|
);
|
||||||
|
|
||||||
const draftView = JSON.parse((await request("/public/workspace?brandSlug=linjing-doors")).body);
|
const draftView = JSON.parse((await request("/public/workspace?brandSlug=linjing-doors")).body);
|
||||||
assert.deepEqual(draftView.brand.homeHero, before.brand.homeHero);
|
assert.deepEqual(draftView.brand.homeHero, before.brand.homeHero);
|
||||||
|
assert.equal(draftView.brand.description, before.brand.description);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
draftView.brand.visualPresentation.success.intro,
|
draftView.brand.visualPresentation.success.intro,
|
||||||
before.brand.visualPresentation.success.intro,
|
before.brand.visualPresentation.success.intro,
|
||||||
@@ -1581,6 +1898,7 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
(await request("/public/workspace?brandSlug=linjing-doors")).body,
|
(await request("/public/workspace?brandSlug=linjing-doors")).body,
|
||||||
);
|
);
|
||||||
assert.equal(afterPublish.brand.homeHero.title, changedTitle);
|
assert.equal(afterPublish.brand.homeHero.title, changedTitle);
|
||||||
|
assert.equal(afterPublish.brand.description, changedDescription);
|
||||||
assert.equal(afterPublish.templateData.designPhilosophy, changedTemplateData);
|
assert.equal(afterPublish.templateData.designPhilosophy, changedTemplateData);
|
||||||
assert.equal(Object.hasOwn(afterPublish.templateData, "internalOnly"), false);
|
assert.equal(Object.hasOwn(afterPublish.templateData, "internalOnly"), false);
|
||||||
assert.equal(afterPublish.brand.visualPresentation.success.intro, changedIntro);
|
assert.equal(afterPublish.brand.visualPresentation.success.intro, changedIntro);
|
||||||
@@ -1601,7 +1919,7 @@ test("edited template facts reach public workspace only after publication", asyn
|
|||||||
await prisma.trustContent.delete({ where: { id: obsolete.id } });
|
await prisma.trustContent.delete({ where: { id: obsolete.id } });
|
||||||
await prisma.brandProfile.update({
|
await prisma.brandProfile.update({
|
||||||
where: { id: doorsBrand.id },
|
where: { id: doorsBrand.id },
|
||||||
data: { config: originalBrandConfig },
|
data: { config: originalBrandConfig, description: doorsBrand.description },
|
||||||
});
|
});
|
||||||
await prisma.trustContent.update({
|
await prisma.trustContent.update({
|
||||||
where: { id: trust.id },
|
where: { id: trust.id },
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
|||||||
|
|
||||||
const root = path.resolve(__dirname, "../../..");
|
const root = path.resolve(__dirname, "../../..");
|
||||||
const key = process.env.TEMPLATE_KEY || "acheng-campus-food";
|
const key = process.env.TEMPLATE_KEY || "acheng-campus-food";
|
||||||
|
const previewAllTemplates = process.env.PREVIEW_ALL_TEMPLATES === "true";
|
||||||
const templates = fs
|
const templates = fs
|
||||||
.readdirSync(path.join(root, "packages"))
|
.readdirSync(path.join(root, "packages"))
|
||||||
.filter(
|
.filter(
|
||||||
@@ -30,20 +31,33 @@ export default defineConfig({
|
|||||||
designWidth: 750,
|
designWidth: 750,
|
||||||
deviceRatio: { 750: 1 },
|
deviceRatio: { 750: 1 },
|
||||||
sourceRoot: "src",
|
sourceRoot: "src",
|
||||||
outputRoot: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
|
outputRoot: previewAllTemplates
|
||||||
|
? "dist/template-preview/h5"
|
||||||
|
: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
|
||||||
framework: "react",
|
framework: "react",
|
||||||
compiler: { type: "vite" },
|
compiler: { type: "vite" },
|
||||||
plugins: [],
|
plugins: [],
|
||||||
alias: { "@template": path.join(template, "taro") },
|
alias: {
|
||||||
|
"@template": previewAllTemplates
|
||||||
|
? path.resolve(__dirname, "../src/runtime/template-preview-entry.tsx")
|
||||||
|
: path.join(template, "taro"),
|
||||||
|
},
|
||||||
defineConstants: {
|
defineConstants: {
|
||||||
TEMPLATE_KEY: JSON.stringify(key),
|
TEMPLATE_KEY: JSON.stringify(key),
|
||||||
BRAND_SLUG: JSON.stringify(brand),
|
BRAND_SLUG: JSON.stringify(brand),
|
||||||
API_BASE_URL: JSON.stringify(process.env.API_BASE_URL || "http://localhost:3001"),
|
API_BASE_URL: JSON.stringify(process.env.API_BASE_URL || "http://localhost:3001"),
|
||||||
TEMPLATE_MANIFEST: JSON.stringify(manifest),
|
TEMPLATE_MANIFEST: JSON.stringify(manifest),
|
||||||
|
PREVIEW_ALL_TEMPLATES: JSON.stringify(previewAllTemplates),
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
options: {},
|
options: {},
|
||||||
patterns: [
|
patterns: [
|
||||||
|
...(previewAllTemplates
|
||||||
|
? templates.map((templateKey) => ({
|
||||||
|
from: path.join(root, "packages", `template-${templateKey}`, "miniapp/assets"),
|
||||||
|
to: `dist/template-preview/h5/assets/${templateKey}`,
|
||||||
|
}))
|
||||||
|
: []),
|
||||||
...(process.env.TARO_ENV === "weapp"
|
...(process.env.TARO_ENV === "weapp"
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
@@ -52,15 +66,19 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
{
|
...(!previewAllTemplates
|
||||||
from: path.join(template, "miniapp/assets"),
|
? [
|
||||||
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
|
{
|
||||||
},
|
from: path.join(template, "miniapp/assets"),
|
||||||
|
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
mini: {},
|
mini: {},
|
||||||
h5: {
|
h5: {
|
||||||
publicPath: "/",
|
publicPath: process.env.PREVIEW_PUBLIC_PATH || "/",
|
||||||
router: { mode: "hash" },
|
router: { mode: "hash" },
|
||||||
devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) },
|
devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) },
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev:h5": "taro build --type h5 --watch",
|
"dev:h5": "taro build --type h5 --watch",
|
||||||
|
"dev:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5 --watch",
|
||||||
"build:h5": "taro build --type h5",
|
"build:h5": "taro build --type h5",
|
||||||
|
"build:preview": "PREVIEW_ALL_TEMPLATES=true taro build --type h5",
|
||||||
"build:weapp": "taro build --type weapp",
|
"build:weapp": "taro build --type weapp",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config packages/template-acheng-campus-food/taro packages/template-linjing-editorial/taro",
|
"lint": "pnpm --workspace-root exec eslint apps/taro/src apps/taro/config packages/template-acheng-campus-food/taro packages/template-linjing-editorial/taro",
|
||||||
|
|||||||
+15
-11
@@ -21,15 +21,19 @@ export default defineAppConfig({
|
|||||||
navigationBarBackgroundColor: "#ffffff",
|
navigationBarBackgroundColor: "#ffffff",
|
||||||
navigationBarTextStyle: "black",
|
navigationBarTextStyle: "black",
|
||||||
},
|
},
|
||||||
tabBar: {
|
...(!PREVIEW_ALL_TEMPLATES
|
||||||
color: "#8b8178",
|
? {
|
||||||
selectedColor: "#3b2118",
|
tabBar: {
|
||||||
backgroundColor: "#ffffff",
|
color: "#8b8178",
|
||||||
list: TEMPLATE_MANIFEST.navigation.map((tab) => ({
|
selectedColor: "#3b2118",
|
||||||
pagePath: routes[tab.page],
|
backgroundColor: "#ffffff",
|
||||||
text: tab.label,
|
list: TEMPLATE_MANIFEST.navigation.map((tab) => ({
|
||||||
iconPath: tab.iconPath,
|
pagePath: routes[tab.page],
|
||||||
selectedIconPath: tab.selectedIconPath,
|
text: tab.label,
|
||||||
})),
|
iconPath: tab.iconPath,
|
||||||
},
|
selectedIconPath: tab.selectedIconPath,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
});
|
});
|
||||||
@@ -17,7 +17,13 @@ import type { Values } from "../runtime/content";
|
|||||||
import { ensureSession, request, brandSlug } from "../runtime/api";
|
import { ensureSession, request, brandSlug } from "../runtime/api";
|
||||||
import { takeQuery, navigate } from "../runtime/navigation";
|
import { takeQuery, navigate } from "../runtime/navigation";
|
||||||
import "./forms.css";
|
import "./forms.css";
|
||||||
export function Inquiry({ workspace }: { workspace: RuntimeWorkspace }) {
|
export function Inquiry({
|
||||||
|
workspace,
|
||||||
|
preview = false,
|
||||||
|
}: {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
preview?: boolean;
|
||||||
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [offeringId, setOfferingId] = useState(router.params.offeringId || "");
|
const [offeringId, setOfferingId] = useState(router.params.offeringId || "");
|
||||||
const form: RuntimeInquiryForm | undefined =
|
const form: RuntimeInquiryForm | undefined =
|
||||||
@@ -28,7 +34,7 @@ export function Inquiry({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
const [sending, setSending] = useState(false);
|
const [sending, setSending] = useState(false);
|
||||||
const busy = useRef(false);
|
const busy = useRef(false);
|
||||||
const p = presentation(workspace, "inquiry");
|
const p = presentation(workspace, "inquiry");
|
||||||
const food = TEMPLATE_KEY === "acheng-campus-food";
|
const food = workspace.brand.visualTemplateKey === "acheng-campus-food";
|
||||||
useDidShow(() => {
|
useDidShow(() => {
|
||||||
const query = takeQuery("inquiry");
|
const query = takeQuery("inquiry");
|
||||||
if (query.offeringId) setOfferingId(query.offeringId);
|
if (query.offeringId) setOfferingId(query.offeringId);
|
||||||
@@ -40,6 +46,7 @@ export function Inquiry({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
const setValue = (key: string, value: string | string[]) =>
|
const setValue = (key: string, value: string | string[]) =>
|
||||||
setValues((current) => ({ ...current, [key]: value }));
|
setValues((current) => ({ ...current, [key]: value }));
|
||||||
async function submit() {
|
async function submit() {
|
||||||
|
if (preview) return;
|
||||||
if (busy.current) return;
|
if (busy.current) return;
|
||||||
if (!form) {
|
if (!form) {
|
||||||
setError("咨询表单暂不可用,请稍后重试");
|
setError("咨询表单暂不可用,请稍后重试");
|
||||||
@@ -96,6 +103,7 @@ export function Inquiry({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View
|
<View
|
||||||
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
|
className={`form-field ${food && ["people", "date", "budget", "delivery"].includes(field.key) ? "half-field" : ""}`}
|
||||||
key={field.key}
|
key={field.key}
|
||||||
|
data-editor-target={preview ? `inquiry-field:${field.key}` : undefined}
|
||||||
>
|
>
|
||||||
<Text className="field-label">
|
<Text className="field-label">
|
||||||
{field.label}
|
{field.label}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { Inquiry } from "./Inquiry";
|
|||||||
import { Records } from "./Records";
|
import { Records } from "./Records";
|
||||||
import { Success } from "./Success";
|
import { Success } from "./Success";
|
||||||
export function Page({ page }: { page: PageKey }) {
|
export function Page({ page }: { page: PageKey }) {
|
||||||
const { workspace, error, loading, reload, setBrandDraft } = useWorkspace();
|
const { workspace, error, loading, reload, setBrandDraft, setWorkspaceDraft } = useWorkspace();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (process.env.TARO_ENV !== "h5" || window.parent === window) return;
|
if (process.env.TARO_ENV !== "h5" || window.parent === window) return;
|
||||||
@@ -27,6 +27,7 @@ export function Page({ page }: { page: PageKey }) {
|
|||||||
if (event.source !== window.parent || event.origin !== parentOrigin) return;
|
if (event.source !== window.parent || event.origin !== parentOrigin) return;
|
||||||
const message = event.data;
|
const message = event.data;
|
||||||
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
if (message?.protocol !== "personal-brand-editor-preview" || message.version !== 1) return;
|
||||||
|
if (message.type === "workspaceDraft") setWorkspaceDraft(message.workspace);
|
||||||
if (message.type === "brandDraft") setBrandDraft(message.brand);
|
if (message.type === "brandDraft") setBrandDraft(message.brand);
|
||||||
if (message.type === "focusTarget") {
|
if (message.type === "focusTarget") {
|
||||||
document.querySelectorAll<HTMLElement>("[data-editor-target]").forEach((element) => {
|
document.querySelectorAll<HTMLElement>("[data-editor-target]").forEach((element) => {
|
||||||
@@ -63,7 +64,7 @@ export function Page({ page }: { page: PageKey }) {
|
|||||||
window.removeEventListener("message", onMessage);
|
window.removeEventListener("message", onMessage);
|
||||||
document.removeEventListener("click", onClick, true);
|
document.removeEventListener("click", onClick, true);
|
||||||
};
|
};
|
||||||
}, [setBrandDraft]);
|
}, [setBrandDraft, setWorkspaceDraft]);
|
||||||
if (loading) return <View className="runtime-state">正在加载…</View>;
|
if (loading) return <View className="runtime-state">正在加载…</View>;
|
||||||
if (error || !workspace)
|
if (error || !workspace)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -25,13 +25,20 @@ const labels: Record<string, string> = {
|
|||||||
converted: "已转化",
|
converted: "已转化",
|
||||||
closed: "已关闭",
|
closed: "已关闭",
|
||||||
};
|
};
|
||||||
export function Records({ workspace }: { workspace: RuntimeWorkspace }) {
|
export function Records({
|
||||||
|
workspace,
|
||||||
|
preview = false,
|
||||||
|
}: {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
preview?: boolean;
|
||||||
|
}) {
|
||||||
const [records, setRecords] = useState<RecordItem[]>([]);
|
const [records, setRecords] = useState<RecordItem[]>([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [authenticated, setAuthenticated] = useState(hasSession());
|
const [authenticated, setAuthenticated] = useState(preview ? false : hasSession());
|
||||||
const p = presentation(workspace, "records");
|
const p = presentation(workspace, "records");
|
||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
|
if (preview) return;
|
||||||
if (!hasSession()) {
|
if (!hasSession()) {
|
||||||
setAuthenticated(false);
|
setAuthenticated(false);
|
||||||
setRecords([]);
|
setRecords([]);
|
||||||
@@ -46,7 +53,7 @@ export function Records({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
setAuthenticated(hasSession());
|
setAuthenticated(hasSession());
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, []);
|
}, [preview]);
|
||||||
useDidShow(load);
|
useDidShow(load);
|
||||||
return (
|
return (
|
||||||
<View className="records-page">
|
<View className="records-page">
|
||||||
|
|||||||
@@ -4,10 +4,18 @@ import type { RuntimeWorkspace } from "@personal-brand/types";
|
|||||||
import { presentation, object, text } from "../runtime/content";
|
import { presentation, object, text } from "../runtime/content";
|
||||||
import { brandSlug } from "../runtime/api";
|
import { brandSlug } from "../runtime/api";
|
||||||
import { navigate } from "../runtime/navigation";
|
import { navigate } from "../runtime/navigation";
|
||||||
export function Success({ workspace }: { workspace: RuntimeWorkspace }) {
|
export function Success({
|
||||||
|
workspace,
|
||||||
|
preview = false,
|
||||||
|
}: {
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
preview?: boolean;
|
||||||
|
}) {
|
||||||
const p = presentation(workspace, "success");
|
const p = presentation(workspace, "success");
|
||||||
const result = object(Taro.getStorageSync<unknown>(`latestInquiry:${brandSlug()}`));
|
const submitted =
|
||||||
if (!text(result.id))
|
preview ||
|
||||||
|
Boolean(text(object(Taro.getStorageSync<unknown>(`latestInquiry:${brandSlug()}`)).id));
|
||||||
|
if (!submitted)
|
||||||
return (
|
return (
|
||||||
<View className="runtime-state">
|
<View className="runtime-state">
|
||||||
尚未提交咨询<Button onClick={() => navigate("inquiry")}>填写需求</Button>
|
尚未提交咨询<Button onClick={() => navigate("inquiry")}>填写需求</Button>
|
||||||
|
|||||||
Vendored
+4
@@ -12,7 +12,11 @@ declare const TEMPLATE_MANIFEST: {
|
|||||||
selectedIconPath: string;
|
selectedIconPath: string;
|
||||||
}[];
|
}[];
|
||||||
};
|
};
|
||||||
|
declare const PREVIEW_ALL_TEMPLATES: boolean;
|
||||||
declare module "*.css";
|
declare module "*.css";
|
||||||
|
interface ImportMeta {
|
||||||
|
glob<T = unknown>(pattern: string, options?: { eager?: boolean }): Record<string, T>;
|
||||||
|
}
|
||||||
declare module "@template" {
|
declare module "@template" {
|
||||||
export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro";
|
export { TemplatePage } from "../../../packages/template-acheng-campus-food/taro";
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,12 @@ export function brandSlug() {
|
|||||||
}
|
}
|
||||||
return BRAND_SLUG;
|
return BRAND_SLUG;
|
||||||
}
|
}
|
||||||
|
function isEditorPreview() {
|
||||||
|
return (
|
||||||
|
process.env.TARO_ENV === "h5" &&
|
||||||
|
new URLSearchParams(window.location.search).get("editor") === "1"
|
||||||
|
);
|
||||||
|
}
|
||||||
export const tokenKey = () => `customerToken:${brandSlug()}`;
|
export const tokenKey = () => `customerToken:${brandSlug()}`;
|
||||||
export function hasSession() {
|
export function hasSession() {
|
||||||
return Boolean(Taro.getStorageSync<string>(tokenKey()));
|
return Boolean(Taro.getStorageSync<string>(tokenKey()));
|
||||||
@@ -16,9 +22,10 @@ export async function request<T>(
|
|||||||
options: { method?: "GET" | "POST"; data?: unknown; customer?: boolean } = {},
|
options: { method?: "GET" | "POST"; data?: unknown; customer?: boolean } = {},
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const context = path.startsWith("/public/") || path.startsWith("/customer/session/wechat");
|
const context = path.startsWith("/public/") || path.startsWith("/customer/session/wechat");
|
||||||
const query = context
|
const query =
|
||||||
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
|
context && !(isEditorPreview() && path === "/public/workspace")
|
||||||
: "";
|
? `${path.includes("?") ? "&" : "?"}brandSlug=${encodeURIComponent(brandSlug())}`
|
||||||
|
: "";
|
||||||
const response = await Taro.request<T & { error?: { message?: string; requestId?: string } }>({
|
const response = await Taro.request<T & { error?: { message?: string; requestId?: string } }>({
|
||||||
url: API_BASE_URL.replace(/\/$/, "") + path + query,
|
url: API_BASE_URL.replace(/\/$/, "") + path + query,
|
||||||
method: options.method || "GET",
|
method: options.method || "GET",
|
||||||
@@ -38,9 +45,7 @@ export async function request<T>(
|
|||||||
}
|
}
|
||||||
export async function loadWorkspace() {
|
export async function loadWorkspace() {
|
||||||
const data = await request<RuntimeWorkspace>("/public/workspace");
|
const data = await request<RuntimeWorkspace>("/public/workspace");
|
||||||
const editorPreview =
|
const editorPreview = isEditorPreview();
|
||||||
process.env.TARO_ENV === "h5" &&
|
|
||||||
new URLSearchParams(window.location.search).get("editor") === "1";
|
|
||||||
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
|
if (!editorPreview && data.publication?.status !== "published") throw new Error("品牌尚未发布");
|
||||||
if (!editorPreview && data.brand.visualTemplateKey !== TEMPLATE_KEY)
|
if (!editorPreview && data.brand.visualTemplateKey !== TEMPLATE_KEY)
|
||||||
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");
|
throw new Error("该品牌使用其他模板,请选择匹配的模板预览地址");
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import type { ComponentType } from "react";
|
||||||
|
import type { TemplateProps } from "./template";
|
||||||
|
|
||||||
|
type TemplateRenderer = ComponentType<TemplateProps>;
|
||||||
|
|
||||||
|
const renderers = import.meta.glob<{
|
||||||
|
TemplatePage: TemplateRenderer;
|
||||||
|
}>("../../../../packages/template-*/taro/index.tsx", { eager: true });
|
||||||
|
|
||||||
|
export function TemplatePage(props: TemplateProps) {
|
||||||
|
const config = props.workspace.brand.config;
|
||||||
|
const visualTemplateKey =
|
||||||
|
config && typeof config === "object" && !Array.isArray(config)
|
||||||
|
? (config as Record<string, unknown>).visualTemplateKey
|
||||||
|
: undefined;
|
||||||
|
const templateKey = typeof visualTemplateKey === "string" ? visualTemplateKey : TEMPLATE_KEY;
|
||||||
|
const suffix = `/template-${templateKey}/taro/index.tsx`;
|
||||||
|
const rendererModule = Object.entries(renderers).find(([path]) => path.endsWith(suffix))?.[1];
|
||||||
|
if (!rendererModule)
|
||||||
|
return <div className="runtime-state">当前模板没有可用的 H5 预览 renderer</div>;
|
||||||
|
const Renderer = rendererModule.TemplatePage;
|
||||||
|
return <Renderer {...props} />;
|
||||||
|
}
|
||||||
@@ -8,19 +8,22 @@ const Context = createContext<{
|
|||||||
error: string;
|
error: string;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
setBrandDraft: (brand: Partial<RuntimeWorkspace["brand"]>) => void;
|
setBrandDraft: (brand: Partial<RuntimeWorkspace["brand"]>) => void;
|
||||||
|
setWorkspaceDraft: (workspace: RuntimeWorkspace) => void;
|
||||||
reload: () => void;
|
reload: () => void;
|
||||||
}>({ error: "", loading: true, setBrandDraft() {}, reload() {} });
|
}>({ error: "", loading: true, setBrandDraft() {}, setWorkspaceDraft() {}, reload() {} });
|
||||||
export function WorkspaceProvider({ children }: PropsWithChildren) {
|
export function WorkspaceProvider({ children }: PropsWithChildren) {
|
||||||
const [baseWorkspace, setBaseWorkspace] = useState<RuntimeWorkspace>();
|
const [baseWorkspace, setBaseWorkspace] = useState<RuntimeWorkspace>();
|
||||||
const [brandDraft, setBrandDraft] = useState<Partial<RuntimeWorkspace["brand"]>>({});
|
const [brandDraft, setBrandDraft] = useState<Partial<RuntimeWorkspace["brand"]>>({});
|
||||||
const workspace = baseWorkspace
|
const [workspaceDraft, setWorkspaceDraft] = useState<RuntimeWorkspace>();
|
||||||
|
const workspace = workspaceDraft ?? baseWorkspace;
|
||||||
|
const resolvedWorkspace = workspace
|
||||||
? {
|
? {
|
||||||
...baseWorkspace,
|
...workspace,
|
||||||
brand: projectBrandAliases(
|
brand: projectBrandAliases(
|
||||||
{ ...baseWorkspace.brand, ...brandDraft },
|
{ ...workspace.brand, ...brandDraft },
|
||||||
brandDraft.config && typeof brandDraft.config === "object"
|
brandDraft.config && typeof brandDraft.config === "object"
|
||||||
? (brandDraft.config as Record<string, unknown>)
|
? (brandDraft.config as Record<string, unknown>)
|
||||||
: ((baseWorkspace.brand.config as Record<string, unknown> | undefined) ?? {}),
|
: ((workspace.brand.config as Record<string, unknown> | undefined) ?? {}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -29,16 +32,35 @@ export function WorkspaceProvider({ children }: PropsWithChildren) {
|
|||||||
const reload = useCallback(() => {
|
const reload = useCallback(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setError("");
|
setError("");
|
||||||
void loadWorkspace()
|
const editorPreview =
|
||||||
.then(setBaseWorkspace)
|
process.env.TARO_ENV === "h5" &&
|
||||||
|
new URLSearchParams(window.location.search).get("editor") === "1";
|
||||||
|
const workspacePromise = editorPreview ? Promise.resolve(undefined) : loadWorkspace();
|
||||||
|
void workspacePromise
|
||||||
|
.then((value) => {
|
||||||
|
if (value) setBaseWorkspace(value);
|
||||||
|
})
|
||||||
.catch((error: unknown) =>
|
.catch((error: unknown) =>
|
||||||
setError(error instanceof Error ? error.message : "加载失败,请重试"),
|
setError(error instanceof Error ? error.message : "加载失败,请重试"),
|
||||||
)
|
)
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(!editorPreview));
|
||||||
}, []);
|
}, []);
|
||||||
useEffect(reload, [reload]);
|
useEffect(reload, [reload]);
|
||||||
return (
|
return (
|
||||||
<Context.Provider value={{ workspace, error, loading, setBrandDraft, reload }}>
|
<Context.Provider
|
||||||
|
value={{
|
||||||
|
workspace: resolvedWorkspace,
|
||||||
|
error,
|
||||||
|
loading:
|
||||||
|
process.env.TARO_ENV === "h5" &&
|
||||||
|
new URLSearchParams(window.location.search).get("editor") === "1"
|
||||||
|
? !workspace
|
||||||
|
: loading,
|
||||||
|
setBrandDraft,
|
||||||
|
setWorkspaceDraft,
|
||||||
|
reload,
|
||||||
|
}}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</Context.Provider>
|
</Context.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,75 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import fs from "node:fs";
|
||||||
|
import { test, expect, type Page } from "@playwright/test";
|
||||||
|
|
||||||
const adminOrigin = "http://localhost:3011";
|
// 从真实 DOM 点选区域,避免侧栏测试掩盖画布目标无法激活。
|
||||||
|
async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
|
||||||
|
const preview = page.locator(".component-template-preview");
|
||||||
|
const targets = manifest.admin.sections
|
||||||
|
.filter(
|
||||||
|
(section: any) =>
|
||||||
|
section.page === pageKey && (pageKey !== "detail" || section.target === "brand"),
|
||||||
|
)
|
||||||
|
.flatMap((section: any) =>
|
||||||
|
(section.previewTargets ?? [])
|
||||||
|
.filter((target: any) => !target.composite)
|
||||||
|
.map((target: any) => target.key),
|
||||||
|
);
|
||||||
|
if (pageKey !== "detail") {
|
||||||
|
targets.push(
|
||||||
|
...manifest.trustContentTypes.flatMap((item: any) =>
|
||||||
|
(item.previewTargets ?? [])
|
||||||
|
.filter((target: any) => target.page === pageKey)
|
||||||
|
.map((target: any) => target.key),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
targets.push(
|
||||||
|
...manifest.trustContentTypes
|
||||||
|
.filter((item: any) => item.pages.includes(pageKey))
|
||||||
|
.map((item: any) => "trust:" + item.type),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const target of new Set<string>(targets)) {
|
||||||
|
const elements = preview.locator(`[data-editor-target="${target}"]`);
|
||||||
|
for (let index = 0; index < (await elements.count()); index++) {
|
||||||
|
const element = elements.nth(index);
|
||||||
|
if (!(await element.isVisible())) continue;
|
||||||
|
const leafIndex = await element.evaluate((node, key) => {
|
||||||
|
return Array.from(node.querySelectorAll("*")).findIndex((child) => {
|
||||||
|
const rect = child.getBoundingClientRect();
|
||||||
|
return (
|
||||||
|
child.childElementCount === 0 &&
|
||||||
|
rect.width > 0 &&
|
||||||
|
rect.height > 0 &&
|
||||||
|
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}, target);
|
||||||
|
// 点击区内真实叶子内容,避开圆角的透明区域及嵌套子选区。
|
||||||
|
const content = leafIndex >= 0 ? element.locator("*").nth(leafIndex) : element;
|
||||||
|
await content.scrollIntoViewIfNeeded();
|
||||||
|
const point = await content.evaluate((node) => {
|
||||||
|
const rect = node.getBoundingClientRect();
|
||||||
|
const x = rect.left + rect.width / 2;
|
||||||
|
const y = rect.top + rect.height / 2;
|
||||||
|
return {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
target: document
|
||||||
|
.elementFromPoint(x, y)
|
||||||
|
?.closest("[data-editor-target]")
|
||||||
|
?.getAttribute("data-editor-target"),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(point.target, "实际命中区域:" + target).toBe(target);
|
||||||
|
await page.mouse.click(point.x, point.y);
|
||||||
|
await expect(
|
||||||
|
preview.locator(".component-template-preview__outline.is-selected"),
|
||||||
|
).toHaveAttribute("data-selected-target", target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||||
const brand = {
|
const brand = {
|
||||||
id: "brand-fixture",
|
id: "brand-fixture",
|
||||||
slug: "preview-fixture",
|
slug: "preview-fixture",
|
||||||
@@ -8,7 +77,7 @@ const brand = {
|
|||||||
templateKey: "food",
|
templateKey: "food",
|
||||||
tagline: "校园家常餐",
|
tagline: "校园家常餐",
|
||||||
description: "认真做好每一餐",
|
description: "认真做好每一餐",
|
||||||
avatarUrl: "",
|
avatarUrl: "/assets/owner/portrait.jpg",
|
||||||
coverUrl: "",
|
coverUrl: "",
|
||||||
hours: "每日 17:00",
|
hours: "每日 17:00",
|
||||||
address: "东门附近",
|
address: "东门附近",
|
||||||
@@ -23,6 +92,33 @@ const brand = {
|
|||||||
visualPresentation: { home: { stallTitle: "原服务地点", worksTitle: "原餐品标题" } },
|
visualPresentation: { home: { stallTitle: "原服务地点", worksTitle: "原餐品标题" } },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const adminOffering = {
|
||||||
|
id: "menu-fixture",
|
||||||
|
kind: "service",
|
||||||
|
name: "家庭聚餐定制",
|
||||||
|
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||||
|
description: "餐品详情",
|
||||||
|
priceText: "88.88",
|
||||||
|
coverUrl: brand.avatarUrl,
|
||||||
|
isEnabled: true,
|
||||||
|
sortOrder: 0,
|
||||||
|
config: { categoryLabel: "业务提供项" },
|
||||||
|
};
|
||||||
|
const adminTrust = {
|
||||||
|
id: "schedule-fixture",
|
||||||
|
type: "schedule",
|
||||||
|
title: "出摊安排",
|
||||||
|
summary: "工作日安排",
|
||||||
|
content: "周末安排",
|
||||||
|
sortOrder: 0,
|
||||||
|
isPublished: true,
|
||||||
|
config: {
|
||||||
|
weekdayLabel: "周一至周五",
|
||||||
|
weekdayDetail: "东门附近",
|
||||||
|
weekendLabel: "周六至周日",
|
||||||
|
weekendDetail: "周末晚间出摊",
|
||||||
|
},
|
||||||
|
};
|
||||||
const runtimeWorkspace = {
|
const runtimeWorkspace = {
|
||||||
schemaVersion: "1.0.0",
|
schemaVersion: "1.0.0",
|
||||||
publication: { status: "published", version: 1 },
|
publication: { status: "published", version: 1 },
|
||||||
@@ -35,59 +131,78 @@ const runtimeWorkspace = {
|
|||||||
},
|
},
|
||||||
templateData: {},
|
templateData: {},
|
||||||
navigation: { tabs: [] },
|
navigation: { tabs: [] },
|
||||||
offerings: [],
|
offerings: [
|
||||||
inquiryForms: [],
|
{
|
||||||
trustItems: [],
|
id: adminOffering.id,
|
||||||
|
name: adminOffering.name,
|
||||||
|
summary: adminOffering.summary,
|
||||||
|
priceText: adminOffering.priceText,
|
||||||
|
coverUrl: adminOffering.coverUrl,
|
||||||
|
presentation: {
|
||||||
|
categoryLabel: "业务提供项",
|
||||||
|
keywords: [],
|
||||||
|
details: { background: "餐品详情", designConcept: "", crafts: [], materialsList: [] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inquiryForms: [
|
||||||
|
{
|
||||||
|
key: "brand-inquiry",
|
||||||
|
version: "1",
|
||||||
|
purpose: "inquiry",
|
||||||
|
target: "brand",
|
||||||
|
submissionAction: "create-inquiry",
|
||||||
|
fields: [
|
||||||
|
{ key: "name", label: "称呼", type: "text", required: true },
|
||||||
|
{ key: "message", label: "需求说明", type: "textarea", required: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
trustItems: [{ ...adminTrust }],
|
||||||
trustPresentation: {},
|
trustPresentation: {},
|
||||||
capabilities: [],
|
capabilities: [],
|
||||||
theme: { colors: {} },
|
theme: { colors: {} },
|
||||||
};
|
};
|
||||||
const templateContent = {
|
const templateContent = JSON.parse(
|
||||||
displayName: "餐饮模板",
|
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
|
||||||
navigation: [{ key: "home", page: "home", label: "首页" }],
|
);
|
||||||
assetSlots: [],
|
|
||||||
trustContentTypes: [],
|
// 根据真实声明生成完整列表数据,让每种内容区域都实际渲染。
|
||||||
admin: {
|
const additionalFoodTrust = templateContent.trustContentTypes
|
||||||
sections: [
|
.filter((item: { type: string }) => item.type !== "schedule")
|
||||||
{
|
.map(
|
||||||
key: "home",
|
(declaration: {
|
||||||
title: "首页内容",
|
type: string;
|
||||||
description: "首页可编辑项",
|
label: string;
|
||||||
page: "home",
|
configFields?: Array<{ key: string; input: string; itemFields?: Array<{ key: string }> }>;
|
||||||
target: "brand",
|
}) => ({
|
||||||
previewTargets: [
|
id: "food-" + declaration.type,
|
||||||
{ key: "food.home.location", label: "服务地点" },
|
type: declaration.type,
|
||||||
{ key: "food.home.offerings-heading", label: "餐品区域标题" },
|
title: declaration.label,
|
||||||
],
|
summary: "测试摘要",
|
||||||
fields: [
|
content: "测试正文",
|
||||||
{
|
isPublished: true,
|
||||||
key: "stallTitle",
|
sortOrder: 0,
|
||||||
binding: "brand.config.visualPresentation.home.stallTitle",
|
config: Object.fromEntries(
|
||||||
previewTarget: "food.home.location",
|
(declaration.configFields ?? []).map((field) => [
|
||||||
label: "出摊信息标题",
|
field.key,
|
||||||
input: "text",
|
field.input === "list"
|
||||||
},
|
? [
|
||||||
{
|
Object.fromEntries(
|
||||||
key: "stallTime",
|
(field.itemFields ?? []).map((child) => [child.key, child.key + "测试值"]),
|
||||||
binding: "brand.config.visualPresentation.home.stallTime",
|
),
|
||||||
previewTarget: "food.home.location",
|
]
|
||||||
label: "营业时间说明",
|
: field.key + "测试值",
|
||||||
input: "text",
|
]),
|
||||||
},
|
),
|
||||||
{
|
}),
|
||||||
key: "worksTitle",
|
);
|
||||||
binding: "brand.config.visualPresentation.home.worksTitle",
|
runtimeWorkspace.trustItems.push(...additionalFoodTrust);
|
||||||
previewTarget: "food.home.offerings-heading",
|
|
||||||
label: "招牌餐品标题",
|
|
||||||
input: "text",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
|
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
|
||||||
|
test.setTimeout(60000);
|
||||||
|
let rejectOfferingSave = false;
|
||||||
|
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||||
await page.route("http://localhost:3001/public/workspace**", (route) =>
|
await page.route("http://localhost:3001/public/workspace**", (route) =>
|
||||||
route.fulfill({ json: runtimeWorkspace }),
|
route.fulfill({ json: runtimeWorkspace }),
|
||||||
);
|
);
|
||||||
@@ -107,15 +222,69 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
|||||||
if (url.pathname === "/admin/brands")
|
if (url.pathname === "/admin/brands")
|
||||||
return route.fulfill({ json: [{ id: brand.id, role: "owner", brand }] });
|
return route.fulfill({ json: [{ id: brand.id, role: "owner", brand }] });
|
||||||
if (url.pathname === "/admin/config/brand" && request.method() === "PATCH") {
|
if (url.pathname === "/admin/config/brand" && request.method() === "PATCH") {
|
||||||
Object.assign(brand, request.postDataJSON());
|
const patch = request.postDataJSON();
|
||||||
|
if (patch.config) patch.config = { ...brand.config, ...patch.config };
|
||||||
|
Object.assign(brand, patch);
|
||||||
Object.assign(runtimeWorkspace.brand, brand);
|
Object.assign(runtimeWorkspace.brand, brand);
|
||||||
return route.fulfill({ json: brand });
|
return route.fulfill({ json: brand });
|
||||||
}
|
}
|
||||||
if (url.pathname === "/admin/config/brand") return route.fulfill({ json: brand });
|
if (url.pathname === "/admin/config/brand") return route.fulfill({ json: brand });
|
||||||
|
if (url.pathname === "/admin/workspace/offerings")
|
||||||
|
return route.fulfill({ json: [adminOffering] });
|
||||||
|
if (url.pathname === "/admin/workspace/forms")
|
||||||
|
return route.fulfill({
|
||||||
|
json: [
|
||||||
|
{
|
||||||
|
id: "brand-inquiry",
|
||||||
|
name: "品牌咨询",
|
||||||
|
version: 1,
|
||||||
|
isEnabled: true,
|
||||||
|
purpose: "inquiry",
|
||||||
|
targetType: "brand",
|
||||||
|
submissionAction: "create-inquiry",
|
||||||
|
fieldsSnapshot: runtimeWorkspace.inquiryForms[0].fields,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
url.pathname === `/admin/workspace/offerings/${adminOffering.id}` &&
|
||||||
|
request.method() === "PATCH"
|
||||||
|
) {
|
||||||
|
if (rejectOfferingSave) {
|
||||||
|
rejectOfferingSave = false;
|
||||||
|
return route.fulfill({
|
||||||
|
status: 500,
|
||||||
|
json: {
|
||||||
|
error: { message: "保存暂时失败,请重试", code: "TEST_FAILURE", requestId: "fixture" },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Object.assign(adminOffering, request.postDataJSON());
|
||||||
|
Object.assign(runtimeWorkspace.offerings[0], {
|
||||||
|
name: adminOffering.name,
|
||||||
|
summary: adminOffering.summary,
|
||||||
|
});
|
||||||
|
return route.fulfill({ json: adminOffering });
|
||||||
|
}
|
||||||
|
if (url.pathname === "/admin/config/trust-content")
|
||||||
|
return route.fulfill({ json: [adminTrust, ...additionalFoodTrust] });
|
||||||
|
if (
|
||||||
|
url.pathname === `/admin/config/trust-content/${adminTrust.id}` &&
|
||||||
|
request.method() === "PATCH"
|
||||||
|
) {
|
||||||
|
Object.assign(adminTrust, request.postDataJSON());
|
||||||
|
Object.assign(runtimeWorkspace.trustItems[0], {
|
||||||
|
title: adminTrust.title,
|
||||||
|
config: adminTrust.config,
|
||||||
|
});
|
||||||
|
return route.fulfill({ json: adminTrust });
|
||||||
|
}
|
||||||
if (url.pathname === "/admin/workspace")
|
if (url.pathname === "/admin/workspace")
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
||||||
});
|
});
|
||||||
|
if (url.pathname === "/admin/workspace/preview")
|
||||||
|
return route.fulfill({ json: runtimeWorkspace });
|
||||||
if (url.pathname === "/public/templates/food")
|
if (url.pathname === "/public/templates/food")
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
json: { name: "餐饮模板", description: "fixture", serviceCategories: [] },
|
json: { name: "餐饮模板", description: "fixture", serviceCategories: [] },
|
||||||
@@ -129,16 +298,612 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
|||||||
await page.getByLabel("密码").fill("fixture-password");
|
await page.getByLabel("密码").fill("fixture-password");
|
||||||
await page.locator('button[type="submit"]').click();
|
await page.locator('button[type="submit"]').click();
|
||||||
await expect(page.getByText("小程序页面配置")).toBeVisible();
|
await expect(page.getByText("小程序页面配置")).toBeVisible();
|
||||||
const frame = page.frameLocator('iframe[title="小程序页面预览"]');
|
await expect(page.getByLabel("品牌名称", { exact: true })).toBeHidden();
|
||||||
await expect(frame.locator(".food-home .name")).toContainText("测试主理人");
|
await page.getByText("品牌资料", { exact: true }).last().click();
|
||||||
await frame.locator('[data-editor-target="food.home.location"]').click();
|
await expect(page.getByLabel("品牌名称", { exact: true })).toBeVisible();
|
||||||
|
await page.getByText("页面编辑", { exact: true }).click();
|
||||||
|
const preview = page.locator(".component-template-preview");
|
||||||
|
await expect(preview.locator(".food-home .name")).toContainText("测试主理人");
|
||||||
|
await expect(page.getByText("选择要编辑的区域", { exact: true })).toBeVisible();
|
||||||
|
for (const width of [1920, 1280, 1024, 768, 390]) {
|
||||||
|
await page.setViewportSize({ width, height: 1000 });
|
||||||
|
const editor = page.locator(".presentation-editor");
|
||||||
|
await editor.scrollIntoViewIfNeeded();
|
||||||
|
await expect
|
||||||
|
.poll(() => editor.evaluate((element) => element.scrollWidth - element.clientWidth))
|
||||||
|
.toBeLessThanOrEqual(1);
|
||||||
|
await editor.screenshot({
|
||||||
|
path: "../../.codex-tasks/admin-editor-workspace/raw/editor-" + width + ".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "选择品牌信息区" }).click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
|
"data-selected-target",
|
||||||
|
"food.home.brand-card",
|
||||||
|
);
|
||||||
|
await expect(page.getByRole("button", { name: "编辑主理人身份" })).toBeVisible();
|
||||||
|
await page.getByRole("button", { name: "编辑服务地点" }).click();
|
||||||
|
await expect(page.getByLabel("出摊信息标题")).toBeVisible();
|
||||||
|
await page.getByRole("button", { name: "选择品牌信息区" }).click();
|
||||||
|
await page.getByRole("button", { name: "编辑主理人身份" }).click();
|
||||||
|
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
const dimensions = await preview.evaluate((element) => {
|
||||||
|
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||||
|
const name = element.querySelector(".name")!;
|
||||||
|
const avatar = element.querySelector(".identity img")!;
|
||||||
|
return {
|
||||||
|
width: canvas.getBoundingClientRect().width,
|
||||||
|
font: parseFloat(getComputedStyle(name).fontSize),
|
||||||
|
avatar: avatar.getBoundingClientRect().width,
|
||||||
|
transform: getComputedStyle(canvas.firstElementChild!).transform,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(dimensions.font / dimensions.width).toBeCloseTo(32 / 750, 3);
|
||||||
|
expect(dimensions.avatar / dimensions.width).toBeCloseTo(128 / 750, 3);
|
||||||
|
expect(dimensions.transform).toBe("none");
|
||||||
|
await expect
|
||||||
|
.poll(() =>
|
||||||
|
preview.locator(".identity img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||||
|
)
|
||||||
|
.toBeGreaterThan(0);
|
||||||
|
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/home.png" });
|
||||||
|
const actionButtons = preview.locator(".food-home .actions button");
|
||||||
|
await expect(actionButtons).toHaveCount(2);
|
||||||
|
const previewBox = await preview.locator(".component-template-preview__canvas").boundingBox();
|
||||||
|
const firstActionBox = await actionButtons.nth(0).boundingBox();
|
||||||
|
const secondActionBox = await actionButtons.nth(1).boundingBox();
|
||||||
|
expect(previewBox && firstActionBox && secondActionBox).toBeTruthy();
|
||||||
|
expect(firstActionBox!.x).toBeGreaterThanOrEqual(previewBox!.x);
|
||||||
|
expect(secondActionBox!.x + secondActionBox!.width).toBeLessThanOrEqual(
|
||||||
|
previewBox!.x + previewBox!.width,
|
||||||
|
);
|
||||||
|
await expect(actionButtons.nth(0)).toContainText("咨询 / 预订");
|
||||||
|
await expect(actionButtons.nth(1)).toContainText("查看餐品");
|
||||||
|
await page.getByRole("button", { name: "选择品牌信息区" }).click();
|
||||||
|
await page.getByRole("button", { name: "编辑首页操作按钮" }).click();
|
||||||
|
await expect(page.getByLabel("咨询按钮")).toBeVisible();
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
await page.getByRole("button", { name: "选择品牌信息区" }).click();
|
||||||
|
await page.getByRole("button", { name: "编辑服务地点" }).click();
|
||||||
await expect(page.getByText("出摊信息标题")).toBeVisible();
|
await expect(page.getByText("出摊信息标题")).toBeVisible();
|
||||||
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||||
await page.getByLabel("出摊信息标题").fill("后台草稿地点");
|
await page.getByLabel("出摊信息标题").fill("后台草稿地点");
|
||||||
|
await expect(preview.locator(".notice-title")).toContainText("后台草稿地点");
|
||||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||||
await expect(frame.locator(".notice-title")).toContainText("后台草稿地点");
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
await expect(frame.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
"data-selected-target",
|
||||||
/editor-target-selected/,
|
"food.home.location",
|
||||||
);
|
);
|
||||||
|
await page.getByRole("button", { name: "浏览页面" }).click();
|
||||||
|
await preview.locator(".food-home .actions button").nth(1).click();
|
||||||
|
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||||
|
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||||
|
await page.getByRole("button", { name: "选择品牌信息区" }).click();
|
||||||
|
await page.getByRole("button", { name: "编辑服务地点" }).click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
|
"data-selected-target",
|
||||||
|
"food.home.location",
|
||||||
|
);
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||||
|
await page.getByText("套餐餐品", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||||
|
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
|
"data-selected-record-id",
|
||||||
|
adminOffering.id,
|
||||||
|
);
|
||||||
|
await page.getByLabel("名称", { exact: true }).fill("编辑后的家庭餐");
|
||||||
|
await expect(page.getByText("有未保存修改", { exact: true })).toBeVisible();
|
||||||
|
await page.getByText("出摊服务", { exact: true }).click();
|
||||||
|
await expect(page.getByRole("dialog", { name: "有尚未保存的修改" })).toBeVisible();
|
||||||
|
await page.getByRole("button", { name: "继续编辑" }).click();
|
||||||
|
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("编辑后的家庭餐");
|
||||||
|
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||||
|
rejectOfferingSave = true;
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect(page.getByText("保存暂时失败,请重试", { exact: true })).toBeVisible();
|
||||||
|
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("编辑后的家庭餐");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
|
||||||
|
await page.reload();
|
||||||
|
await page.getByText("套餐餐品", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||||
|
await page.getByText("出摊服务", { exact: true }).click();
|
||||||
|
await preview.locator('[data-editor-target="trust:schedule"]').click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
|
"data-selected-record-id",
|
||||||
|
adminTrust.id,
|
||||||
|
);
|
||||||
|
await page.getByLabel("工作日标题").fill("周一到周五营业");
|
||||||
|
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect.poll(() => adminTrust.config.weekdayLabel).toBe("周一到周五营业");
|
||||||
|
await page.reload();
|
||||||
|
await page.getByText("出摊服务", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".schedule-card")).toContainText("周一到周五营业");
|
||||||
|
await page.getByText("详情页", { exact: true }).click();
|
||||||
|
await expect(page.locator(".component-template-preview")).toHaveCount(1);
|
||||||
|
await expect(preview.locator(".component-template-preview__canvas")).toHaveCount(1);
|
||||||
|
await expect(preview.locator(".food-detail")).toHaveCount(1);
|
||||||
|
const detailBounds = await preview.evaluate((element) => {
|
||||||
|
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||||
|
const bar = element.querySelector(".food-detail .bar")!;
|
||||||
|
const canvasBox = canvas.getBoundingClientRect();
|
||||||
|
const barBox = bar.getBoundingClientRect();
|
||||||
|
return {
|
||||||
|
position: getComputedStyle(bar).position,
|
||||||
|
left: barBox.left - canvasBox.left,
|
||||||
|
right: canvasBox.right - barBox.right,
|
||||||
|
bottom: canvasBox.bottom - barBox.bottom,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(detailBounds.position).toBe("absolute");
|
||||||
|
expect(detailBounds.left).toBeGreaterThanOrEqual(-1);
|
||||||
|
expect(detailBounds.right).toBeGreaterThanOrEqual(-1);
|
||||||
|
expect(detailBounds.bottom).toBeGreaterThanOrEqual(-1);
|
||||||
|
await preview.locator(".food-detail .bar").scrollIntoViewIfNeeded();
|
||||||
|
await expect(preview.locator(".food-detail .bar button")).toBeVisible();
|
||||||
|
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/detail.png" });
|
||||||
|
await expect(page.getByText("详情页由所选业务内容动态生成")).toBeVisible();
|
||||||
|
await expect(page.getByRole("button", { name: "点选编辑" })).toBeVisible();
|
||||||
|
await expect(page.getByLabel("价格标题")).toHaveCount(0);
|
||||||
|
await expect(page.getByLabel("餐品介绍")).toHaveCount(0);
|
||||||
|
await page.getByRole("button", { name: "详情页咨询入口", exact: true }).click();
|
||||||
|
await preview.locator(".food-detail .bar button").click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||||
|
"data-selected-target",
|
||||||
|
"acheng-campus-food.detail.action",
|
||||||
|
);
|
||||||
|
await page.getByLabel("咨询按钮文字", { exact: true }).fill("详情公共按钮回归");
|
||||||
|
await expect(preview.locator(".food-detail .bar button")).toContainText("详情公共按钮回归");
|
||||||
|
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||||
|
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||||
|
await page.reload();
|
||||||
|
await page.getByText("详情页", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".food-detail .bar button")).toContainText("详情公共按钮回归");
|
||||||
|
await page.getByText("定制/咨询", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".inquiry-form .form-field")).toHaveCount(2);
|
||||||
|
await expect(preview.locator(".inquiry-form")).toContainText("称呼");
|
||||||
|
await expect(preview.locator(".inquiry-form")).toContainText("需求说明");
|
||||||
|
await preview.locator('[data-editor-target="inquiry-field:name"]').click();
|
||||||
|
await expect(page.getByLabel("字段标题")).toHaveValue("称呼");
|
||||||
|
await preview.locator(".inquiry-form").scrollIntoViewIfNeeded();
|
||||||
|
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/inquiry.png" });
|
||||||
|
const formOverflow = await preview
|
||||||
|
.locator(".inquiry-form")
|
||||||
|
.evaluate((form) => form.scrollWidth - form.clientWidth);
|
||||||
|
expect(formOverflow).toBeLessThanOrEqual(1);
|
||||||
|
await page.getByRole("button", { name: "浏览页面" }).click();
|
||||||
|
await preview.locator(".inquiry-form input").first().fill("预览访客");
|
||||||
|
await expect(preview.locator(".inquiry-form input").first()).toHaveValue("预览访客");
|
||||||
|
await page.getByText("提交成功页", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".success-page")).toBeVisible();
|
||||||
|
await expect(preview.locator(".success-page")).toContainText("已收到你的需求");
|
||||||
|
await page.getByText("记录页", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".records-page")).toBeVisible();
|
||||||
|
await expect(preview.locator(".records-page")).toContainText("请在微信小程序内登录查看");
|
||||||
|
await page.getByText("套餐餐品", { exact: true }).click();
|
||||||
|
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||||
|
await expect
|
||||||
|
.poll(() =>
|
||||||
|
preview.locator(".dish-media img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||||
|
)
|
||||||
|
.toBeGreaterThan(0);
|
||||||
|
for (const width of [390, 320]) {
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||||
|
(element as HTMLElement).style.width = size + "px";
|
||||||
|
}, width);
|
||||||
|
const layout = await preview.evaluate((element) => {
|
||||||
|
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||||
|
const card = element.querySelector(".offering-card")!;
|
||||||
|
const media = element.querySelector(".dish-media")!;
|
||||||
|
return {
|
||||||
|
canvas: canvas.getBoundingClientRect().width,
|
||||||
|
overflow: card.scrollWidth - card.clientWidth,
|
||||||
|
media: media.getBoundingClientRect().width,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
expect(layout.overflow).toBeLessThanOrEqual(1);
|
||||||
|
expect(layout.media / layout.canvas).toBeCloseTo(224 / 750, 3);
|
||||||
|
await preview.screenshot({
|
||||||
|
path: "../../.codex-tasks/preview-proportion/menu-" + width + ".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||||
|
(element as HTMLElement).style.width = "";
|
||||||
|
});
|
||||||
|
const inspector = page.locator(".presentation-editor__inspector");
|
||||||
|
for (const pageKey of [
|
||||||
|
"home",
|
||||||
|
"offerings",
|
||||||
|
"profile",
|
||||||
|
"service",
|
||||||
|
"detail",
|
||||||
|
"inquiry",
|
||||||
|
"success",
|
||||||
|
"records",
|
||||||
|
]) {
|
||||||
|
const label =
|
||||||
|
templateContent.navigation.find((item: { page: string }) => item.page === pageKey)?.label ??
|
||||||
|
(
|
||||||
|
{ detail: "详情页", inquiry: "咨询页", success: "提交成功页", records: "记录页" } as Record<
|
||||||
|
string,
|
||||||
|
string
|
||||||
|
>
|
||||||
|
)[pageKey];
|
||||||
|
await page.getByText(label, { exact: true }).click();
|
||||||
|
await verifyCanvasTargets(page, templateContent, pageKey);
|
||||||
|
for (const section of templateContent.admin.sections.filter(
|
||||||
|
(item: { page: string }) => item.page === pageKey,
|
||||||
|
)) {
|
||||||
|
if (pageKey === "detail" && section.target !== "brand") continue;
|
||||||
|
for (const target of section.previewTargets ?? []) {
|
||||||
|
if (target.composite) continue;
|
||||||
|
await page
|
||||||
|
.locator(".presentation-editor__regions")
|
||||||
|
.getByRole("button", { name: target.label, exact: true })
|
||||||
|
.click();
|
||||||
|
const fields = section.fields.filter(
|
||||||
|
(field: { previewTarget: string }) => field.previewTarget === target.key,
|
||||||
|
);
|
||||||
|
for (const field of fields)
|
||||||
|
await expect(
|
||||||
|
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||||
|
).toBeVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pageKey !== "detail") {
|
||||||
|
for (const declaration of templateContent.trustContentTypes.filter(
|
||||||
|
(item: { pages: string[] }) => item.pages.includes(pageKey),
|
||||||
|
)) {
|
||||||
|
await page
|
||||||
|
.locator(".presentation-editor__regions")
|
||||||
|
.getByRole("button", { name: declaration.label, exact: true })
|
||||||
|
.click();
|
||||||
|
await expect(
|
||||||
|
inspector.getByLabel(declaration.adminFields.title, { exact: true }),
|
||||||
|
).toBeVisible();
|
||||||
|
for (const field of declaration.configFields ?? []) {
|
||||||
|
await expect(
|
||||||
|
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||||
|
).toBeVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const width of [320, 390]) {
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||||
|
(element as HTMLElement).style.width = size + "px";
|
||||||
|
}, width);
|
||||||
|
await expect
|
||||||
|
.poll(() =>
|
||||||
|
preview
|
||||||
|
.locator(".component-template-preview__canvas")
|
||||||
|
.evaluate((element) => element.scrollWidth - element.clientWidth),
|
||||||
|
)
|
||||||
|
.toBeLessThanOrEqual(1);
|
||||||
|
await preview.screenshot({
|
||||||
|
path:
|
||||||
|
"../../.codex-tasks/template-audit-execution/raw/food-" + pageKey + "-" + width + ".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||||
|
(element as HTMLElement).style.width = "";
|
||||||
|
});
|
||||||
|
await preview.screenshot({
|
||||||
|
path: "../../.codex-tasks/template-audit-execution/raw/food-" + pageKey + ".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||||
|
test.setTimeout(60000);
|
||||||
|
await page.setViewportSize({ width: 1600, height: 900 });
|
||||||
|
const editorialBrand = {
|
||||||
|
...structuredClone(brand),
|
||||||
|
templateKey: "personal",
|
||||||
|
avatarUrl: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||||
|
config: {
|
||||||
|
visualTemplateKey: "linjing-editorial",
|
||||||
|
founder: "林境主理人",
|
||||||
|
title: "建筑设计师",
|
||||||
|
heroImage: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||||
|
homeHero: { title: "林境作品" },
|
||||||
|
visualPresentation: {
|
||||||
|
home: {
|
||||||
|
proofEyebrow: "专业积累",
|
||||||
|
proofTitle: "信任介绍",
|
||||||
|
manifestoEyebrow: "工作方法",
|
||||||
|
manifestoTitle: "专业方法",
|
||||||
|
worksEyebrow: "代表项目",
|
||||||
|
worksTitle: "作品与服务",
|
||||||
|
worksAction: "查看作品",
|
||||||
|
flowEyebrow: "合作方式",
|
||||||
|
flowTitle: "合作流程",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const editorialPillars = [
|
||||||
|
{ title: "比例与空间", desc: "根据建筑比例设计" },
|
||||||
|
{ title: "材料与工艺", desc: "可验证的材料标准" },
|
||||||
|
];
|
||||||
|
const editorialFlow = [
|
||||||
|
{ step: "01", name: "需求沟通", desc: "了解现场条件" },
|
||||||
|
{ step: "02", name: "方案确认", desc: "明确交付范围" },
|
||||||
|
{ step: "03", name: "制作安装", desc: "按方案实施" },
|
||||||
|
{ step: "04", name: "验收跟进", desc: "长期维护" },
|
||||||
|
];
|
||||||
|
const editorialWorkspace = {
|
||||||
|
...structuredClone(runtimeWorkspace),
|
||||||
|
brand: {
|
||||||
|
...structuredClone(runtimeWorkspace.brand),
|
||||||
|
...editorialBrand,
|
||||||
|
...editorialBrand.config,
|
||||||
|
founder: "林境主理人",
|
||||||
|
title: "建筑设计师",
|
||||||
|
heroImage: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||||
|
homeHero: { title: "林境作品" },
|
||||||
|
},
|
||||||
|
offerings: structuredClone(runtimeWorkspace.offerings).map((item) => ({
|
||||||
|
...item,
|
||||||
|
coverUrl: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||||
|
})),
|
||||||
|
trustItems: [
|
||||||
|
{
|
||||||
|
id: "credential-fixture",
|
||||||
|
type: "credential",
|
||||||
|
title: "专业资历",
|
||||||
|
summary: "建筑与门系统经验",
|
||||||
|
content: "持续服务私宅项目",
|
||||||
|
config: {
|
||||||
|
pillars: editorialPillars,
|
||||||
|
serviceFlow: editorialFlow,
|
||||||
|
stats: [
|
||||||
|
{ value: "10 年", label: "从业经验", sub: "持续服务私宅" },
|
||||||
|
{ value: "200+", label: "项目落地", sub: "覆盖多个城市" },
|
||||||
|
{ value: "30+", label: "合作品牌", sub: "长期协作" },
|
||||||
|
{ value: "98%", label: "客户好评", sub: "来自真实反馈" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
trustPresentation: {
|
||||||
|
pillars: editorialPillars,
|
||||||
|
serviceFlow: editorialFlow,
|
||||||
|
stats: [
|
||||||
|
{ value: "10 年", label: "从业经验", sub: "持续服务私宅" },
|
||||||
|
{ value: "200+", label: "项目落地", sub: "覆盖多个城市" },
|
||||||
|
{ value: "30+", label: "合作品牌", sub: "长期协作" },
|
||||||
|
{ value: "98%", label: "客户好评", sub: "来自真实反馈" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const editorialContent = JSON.parse(
|
||||||
|
fs.readFileSync("../../packages/template-linjing-editorial/template.json", "utf8"),
|
||||||
|
);
|
||||||
|
await page.route("**/api/**", (route) => {
|
||||||
|
const url = new URL(route.request().url());
|
||||||
|
const path = url.pathname.replace(/^\/api/, "");
|
||||||
|
if (path === "/admin/session/login")
|
||||||
|
return route.fulfill({
|
||||||
|
json: { token: "fixture-token", displayName: "测试管理员", role: "owner" },
|
||||||
|
});
|
||||||
|
if (path === "/admin/brands")
|
||||||
|
return route.fulfill({
|
||||||
|
json: [{ id: editorialBrand.id, role: "owner", brand: editorialBrand }],
|
||||||
|
});
|
||||||
|
if (path === "/admin/config/brand") {
|
||||||
|
if (route.request().method() === "PATCH") {
|
||||||
|
const patch = route.request().postDataJSON();
|
||||||
|
if (patch.config) patch.config = { ...editorialBrand.config, ...patch.config };
|
||||||
|
Object.assign(editorialBrand, patch);
|
||||||
|
Object.assign(editorialWorkspace.brand, editorialBrand, editorialBrand.config);
|
||||||
|
}
|
||||||
|
return route.fulfill({ json: editorialBrand });
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
path === "/admin/config/trust-content/credential-fixture" &&
|
||||||
|
route.request().method() === "PATCH"
|
||||||
|
) {
|
||||||
|
Object.assign(editorialWorkspace.trustItems[0], route.request().postDataJSON());
|
||||||
|
Object.assign(editorialWorkspace.trustPresentation, editorialWorkspace.trustItems[0].config);
|
||||||
|
return route.fulfill({ json: editorialWorkspace.trustItems[0] });
|
||||||
|
}
|
||||||
|
if (path === "/admin/workspace/offerings") return route.fulfill({ json: [adminOffering] });
|
||||||
|
if (
|
||||||
|
path === "/admin/workspace/offerings/" + adminOffering.id &&
|
||||||
|
route.request().method() === "PATCH"
|
||||||
|
) {
|
||||||
|
Object.assign(adminOffering, route.request().postDataJSON());
|
||||||
|
Object.assign(editorialWorkspace.offerings[0].presentation, adminOffering.config);
|
||||||
|
return route.fulfill({ json: adminOffering });
|
||||||
|
}
|
||||||
|
if (path === "/admin/config/trust-content")
|
||||||
|
return route.fulfill({ json: editorialWorkspace.trustItems });
|
||||||
|
if (path === "/public/templates/personal")
|
||||||
|
return route.fulfill({
|
||||||
|
json: { name: "个人品牌", description: "林境模板", serviceCategories: [] },
|
||||||
|
});
|
||||||
|
if (path === "/admin/workspace")
|
||||||
|
return route.fulfill({
|
||||||
|
json: {
|
||||||
|
brand: editorialBrand,
|
||||||
|
installations: [],
|
||||||
|
fields: [],
|
||||||
|
offerings: [],
|
||||||
|
forms: [],
|
||||||
|
templateContent: editorialContent,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (path === "/admin/workspace/preview" || path === "/public/workspace")
|
||||||
|
return route.fulfill({ json: editorialWorkspace });
|
||||||
|
return route.fulfill({ json: {} });
|
||||||
|
});
|
||||||
|
await page.goto(adminOrigin + "/admin/brand");
|
||||||
|
await page.getByLabel("账号").fill("admin");
|
||||||
|
await page.getByLabel("密码").fill("fixture-password");
|
||||||
|
await page.locator('button[type="submit"]').click();
|
||||||
|
const preview = page.locator(".component-template-preview");
|
||||||
|
await expect(preview.locator(".editorial-home")).toBeVisible();
|
||||||
|
await expect(preview.locator(".hero-title")).toContainText("林境作品");
|
||||||
|
await expect
|
||||||
|
.poll(() =>
|
||||||
|
preview.locator(".hero-image").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||||
|
)
|
||||||
|
.toBeGreaterThan(0);
|
||||||
|
const stats = preview.locator('[data-editor-target="editorial.home.proof.stats"]');
|
||||||
|
await expect(stats.locator(":scope > *")).toHaveCount(4);
|
||||||
|
expect(
|
||||||
|
await stats.evaluate(
|
||||||
|
(element) => getComputedStyle(element).gridTemplateColumns.split(" ").length,
|
||||||
|
),
|
||||||
|
).toBe(2);
|
||||||
|
await preview.screenshot({
|
||||||
|
path: "../../.codex-tasks/template-audit-execution/raw/linjing-stats.png",
|
||||||
|
});
|
||||||
|
await stats.click();
|
||||||
|
const inspector = page.locator(".presentation-editor__inspector");
|
||||||
|
await expect(inspector.getByRole("heading", { name: "信任数据" })).toBeVisible();
|
||||||
|
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("10 年");
|
||||||
|
await expect(page.getByLabel("2. 说明")).toHaveValue("项目落地");
|
||||||
|
await page.getByLabel("1. 数字或成果").fill("25 年");
|
||||||
|
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||||
|
await inspector.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("25 年");
|
||||||
|
await preview.locator(".founder-name").click();
|
||||||
|
await expect(inspector.getByRole("heading", { name: "主理人介绍", exact: true })).toBeVisible();
|
||||||
|
for (const label of ["主理人姓名", "身份或职位", "主理人简介", "主理人标签"])
|
||||||
|
await expect(inspector.getByLabel(label, { exact: true })).toBeVisible();
|
||||||
|
await inspector.getByLabel("主理人简介").fill("跨页面共享的简介回归");
|
||||||
|
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
|
||||||
|
await inspector.getByRole("button", { name: "保存页面内容" }).click();
|
||||||
|
await expect.poll(() => editorialBrand.description).toBe("跨页面共享的简介回归");
|
||||||
|
await page.reload();
|
||||||
|
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
|
||||||
|
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||||
|
await page.getByRole("button", { name: "信任数据", exact: true }).click();
|
||||||
|
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("25 年");
|
||||||
|
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
|
||||||
|
await expect(page.getByLabel("首页主标题")).toBeVisible();
|
||||||
|
await page.getByLabel("设计理念", { exact: true }).fill("模板专属理念回归");
|
||||||
|
await expect(preview.locator(".hero-slogan")).toContainText("模板专属理念回归");
|
||||||
|
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||||
|
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||||
|
await page.reload();
|
||||||
|
await expect(preview.locator(".hero-slogan")).toContainText("模板专属理念回归");
|
||||||
|
await page.getByRole("button", { name: "信任数据", exact: true }).click();
|
||||||
|
await page.getByRole("button", { name: "下移第 1 项", exact: true }).click();
|
||||||
|
await expect(stats.locator(".stat-value").first()).toContainText("200+");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("200+");
|
||||||
|
await page.reload();
|
||||||
|
await expect(stats.locator(".stat-value").first()).toContainText("200+");
|
||||||
|
await preview.locator(".pillar-title").first().click();
|
||||||
|
await expect(page.getByLabel("1. 方法说明")).toBeVisible();
|
||||||
|
await page.getByLabel("1. 方法名称").fill("方法名称回归");
|
||||||
|
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||||
|
await page.reload();
|
||||||
|
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||||
|
await preview.locator(".flow-name").first().click();
|
||||||
|
await expect(page.getByLabel("1. 步骤编号")).toBeVisible();
|
||||||
|
await expect(page.getByLabel("1. 步骤名称")).toBeVisible();
|
||||||
|
await page.getByLabel("1. 步骤说明").fill("步骤说明回归");
|
||||||
|
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||||
|
await page.reload();
|
||||||
|
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||||
|
await preview.locator(".work-card").click();
|
||||||
|
for (const label of ["案例类别", "项目地点", "产品系列", "项目关键词"])
|
||||||
|
await expect(inspector.getByText(label, { exact: true })).toBeVisible();
|
||||||
|
await page.getByLabel("项目地点", { exact: true }).fill("项目地点回归");
|
||||||
|
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||||
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||||
|
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||||
|
await page.reload();
|
||||||
|
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||||
|
await page.getByText("主理人与我", { exact: true }).click();
|
||||||
|
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||||
|
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
|
||||||
|
await expect(page.getByRole("button", { name: "信任数据", exact: true })).toHaveCount(0);
|
||||||
|
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||||
|
await page.getByLabel("主理人姓名").fill("修改后的主理人");
|
||||||
|
await expect(preview.locator(".editorial-profile .founder")).toContainText("修改后的主理人");
|
||||||
|
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||||
|
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||||
|
await page.getByRole("button", { name: "服务范围与适用对象", exact: true }).click();
|
||||||
|
await expect(page.getByText("此区域尚未配置内容")).toBeVisible();
|
||||||
|
await expect(page.getByRole("button", { name: "配置此区域内容" })).toBeVisible();
|
||||||
|
for (const pageKey of [
|
||||||
|
"home",
|
||||||
|
"offerings",
|
||||||
|
"profile",
|
||||||
|
"detail",
|
||||||
|
"inquiry",
|
||||||
|
"success",
|
||||||
|
"records",
|
||||||
|
]) {
|
||||||
|
const label =
|
||||||
|
editorialContent.navigation.find((item: { page: string }) => item.page === pageKey)?.label ??
|
||||||
|
(
|
||||||
|
{ detail: "详情页", inquiry: "咨询页", success: "提交成功页", records: "记录页" } as Record<
|
||||||
|
string,
|
||||||
|
string
|
||||||
|
>
|
||||||
|
)[pageKey];
|
||||||
|
await page.getByText(label, { exact: true }).click();
|
||||||
|
await verifyCanvasTargets(page, editorialContent, pageKey);
|
||||||
|
for (const section of editorialContent.admin.sections.filter(
|
||||||
|
(item: { page: string }) => item.page === pageKey,
|
||||||
|
)) {
|
||||||
|
if (pageKey === "detail" && section.target !== "brand") continue;
|
||||||
|
for (const target of section.previewTargets ?? []) {
|
||||||
|
if (target.composite) continue;
|
||||||
|
await page
|
||||||
|
.locator(".presentation-editor__regions")
|
||||||
|
.getByRole("button", { name: target.label, exact: true })
|
||||||
|
.click();
|
||||||
|
const fields = section.fields.filter(
|
||||||
|
(field: { previewTarget: string }) => field.previewTarget === target.key,
|
||||||
|
);
|
||||||
|
for (const field of fields)
|
||||||
|
await expect(
|
||||||
|
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||||
|
).toBeVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const width of [320, 390]) {
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||||
|
(element as HTMLElement).style.width = size + "px";
|
||||||
|
}, width);
|
||||||
|
await expect
|
||||||
|
.poll(() =>
|
||||||
|
preview
|
||||||
|
.locator(".component-template-preview__canvas")
|
||||||
|
.evaluate((element) => element.scrollWidth - element.clientWidth),
|
||||||
|
)
|
||||||
|
.toBeLessThanOrEqual(1);
|
||||||
|
await preview.screenshot({
|
||||||
|
path:
|
||||||
|
"../../.codex-tasks/template-audit-execution/raw/linjing-" +
|
||||||
|
pageKey +
|
||||||
|
"-" +
|
||||||
|
width +
|
||||||
|
".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||||
|
(element as HTMLElement).style.width = "";
|
||||||
|
});
|
||||||
|
await preview.screenshot({
|
||||||
|
path: "../../.codex-tasks/template-audit-execution/raw/linjing-" + pageKey + ".png",
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# 0020:后台可视化页面编辑预览
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
后台已能根据模板 manifest 展示字段,但管理员难以判断字段对应小程序的哪个区块。Taro H5 renderer 可复用小程序页面结构;按模板分别构建和运行 H5 服务、编译时固定单个 renderer,则无法支撑多个品牌和模板的生产部署。
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
采用基于模板 renderer 的可视化编辑器,并将 H5 预览作为同一套 Admin 产品的静态运行时:
|
||||||
|
|
||||||
|
1. `admin.sections` 是编辑字段分组,不等同 DOM 区块。section 声明稳定的 `previewTargets`,字段声明 `previewTarget`。
|
||||||
|
2. renderer 在可编辑区域输出 `data-editor-target`。新增模板必须为所有页面字段声明 binding 和 target,并通过自动发现的契约测试。
|
||||||
|
3. 一个 H5 预览应用在构建时收集所有带 Taro renderer 的模板包,运行时根据品牌当前模板选择 renderer。
|
||||||
|
4. 本地开发只启动一个 Vite H5 预览服务。生产构建将 H5 静态文件复制到 Admin `/template-preview/`,与 Admin 一起部署;线上不运行 Vite,也不按模板运行服务。
|
||||||
|
5. Admin iframe 与 renderer 使用带版本的 `postMessage` 协议,校验 origin、source 和协议版本。Admin 发送品牌草稿和 target focus;renderer 回传 target 选择。
|
||||||
|
6. 表单输入立即投影到预览草稿,保存仍是显式动作。失败时保留用户输入和草稿。
|
||||||
|
7. Admin 按模板契约运行,不按模板 key、行业名或字段名增加业务分支。
|
||||||
|
8. 信任内容、业务提供项、咨询表单等记录数据继续由通用 Admin feature 编辑;它们的页面区域需提供明确的对应编辑入口,不能冒充品牌 config 字段。
|
||||||
|
9. 不支持拖拽布局或持久化 HTML。
|
||||||
|
|
||||||
|
## Alternatives
|
||||||
|
|
||||||
|
- 在 Admin 复制一套 React 预览:会造成后台和小程序视觉分叉,弃用。
|
||||||
|
- 每模板单独构建并运行 H5 服务:开发和部署负担随模板数量增长,弃用。
|
||||||
|
- 生产环境运行 Vite:不是静态部署方案且扩大运行时依赖,弃用。
|
||||||
|
- 将 HTML 存进数据库:无法保持模板升级和字段 binding 一致,弃用。
|
||||||
|
- 一开始建设完整低代码画布:范围过大,暂缓。
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- Preview build、静态资源打包和部署路径是 Admin 发布门槛。
|
||||||
|
- renderer 需要显式标记可编辑区域;漏掉的字段由模板契约测试拒绝。
|
||||||
|
- H5 iframe 使用当前已发布 workspace 作为底稿,管理员草稿只在客户端预览,不伪造已发布状态。
|
||||||
|
- 新模板新增 renderer 后自动进入 preview build;未实现 Taro renderer 的模板必须明确显示不支持,不能显示空白预览。
|
||||||
|
|
||||||
|
## Migration Plan
|
||||||
|
|
||||||
|
### 组件预览阶段补充
|
||||||
|
|
||||||
|
Admin 有 workspace 时直接复用 Taro renderer,iframe 保留为 H5 回退。组件预览必须补齐原运行环境的尺寸、元素选择器及资源映射:750 设计宽度通过容器单位转换,image/text/view 选择器映射到对应 DOM,模板静态资源经 Vite 打包。不得通过猜测 transform 系数修复单位不一致。此方案避免额外预览服务,但仍需验证所有模板的适配能力;当前 renderer 注册尚为显式列表,自动发现纳入后续任务。详见 `docs/visual-editor-next-steps.md`。
|
||||||
|
|
||||||
|
先实现单一多模板 H5 静态构建和 Admin 同源部署;补齐现有模板所有页面字段 target;验证即时草稿、保存失败和业务记录编辑入口;再将 preview build 纳入正式部署流水线。
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# 0021 Admin 品牌配置与页面编辑工作区
|
||||||
|
|
||||||
|
## 背景
|
||||||
|
|
||||||
|
品牌基础资料、模板说明和可视化编辑被多个 Card 包裹,预览仅占页面的一部分。用户难以理解编辑入口与实际展示之间的关系。
|
||||||
|
|
||||||
|
## 决策
|
||||||
|
|
||||||
|
工作台默认进入页面编辑,通过顶部视图切换访问品牌资料。编辑器采用左侧区域导航、中间预览、右侧属性编辑三栏布局,窄屏堆叠。组合区域的子区域在导航中缩进,并与画布选区同步。视图切换保持组件挂载,避免丢弃未保存输入。发布操作通过顶部入口进入已有发布流程。
|
||||||
|
|
||||||
|
品牌基础资料使用连续的身份、联系合作和视觉分组。模板说明作为基础配置的辅助信息。页面编辑工作区使用完整页面宽度,页面导航位于顶部,预览与选区面板并列,窄屏上下排列。未选择区域时提供明确的点选引导,避免展示整页字段。
|
||||||
|
|
||||||
|
详情页只提供业务记录选择和动态预览,隐藏区域列表和点选工具;业务记录在业务提供项中维护。模板 manifest 的字段声明继续供业务内容编辑器和模板校验使用。
|
||||||
|
|
||||||
|
## 替代方案
|
||||||
|
|
||||||
|
继续嵌套 Card 会保留视觉层级混乱。单独建立第二套预览页面会造成 renderer 与模板实际展示分离。采用现有 renderer 和表单机制可以复用既有契约。
|
||||||
|
|
||||||
|
## 后果
|
||||||
|
|
||||||
|
配置与预览的空间更明确,区域编辑仍由模板声明驱动。基础品牌信息与模板区域保存仍分别执行,保存后的内容是草稿,需要发布才能公开展示。没有可编辑区域的页面不显示点选工具。
|
||||||
|
|
||||||
|
## 迁移计划
|
||||||
|
|
||||||
|
仅调整 Admin 布局与详情页编辑入口,不迁移数据库。使用已有字段绑定和 API,并通过多宽度截图、真实鼠标交互、类型检查、lint 和生产构建验收。
|
||||||
|
|
||||||
|
## 已知后续项
|
||||||
|
|
||||||
|
Admin 生产构建的共享 api chunk 超过 500 kB。由 Admin 前端后续打包优化任务负责拆分,当前构建成功。
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# 0022 模板完成度诊断与修复闭环
|
||||||
|
|
||||||
|
## 背景
|
||||||
|
|
||||||
|
可点击但变量不全、数据来源错位、编辑标记破坏网格反复出现。旧检查只证明字段存在;简化 manifest 的 fixture 不能验证真实层级。
|
||||||
|
|
||||||
|
## 决策
|
||||||
|
|
||||||
|
以视觉区域为验收单位,连接 renderer 数据读取、manifest 绑定、编辑交互、保存重载发布、视觉证据。静态诊断自动发现模板,输出问题码及位置;未验证不能当作通过。规则见 [模板完成度规则](../template-completion-rules.md)。
|
||||||
|
|
||||||
|
## 替代方案
|
||||||
|
|
||||||
|
增加点选标记不能判断字段完整性;模板特判不能覆盖新模板;静态分析不能证明浏览器布局和持久化。采用静态诊断加真实 manifest 驱动交互验证。
|
||||||
|
|
||||||
|
## 后果
|
||||||
|
|
||||||
|
编译通过的模板也可能未完成。诊断器测试通过不代表模板通过。同一事实的多个入口必须写回同一值;单记录编辑器不能静默承接跨来源保存。
|
||||||
|
|
||||||
|
## 迁移计划
|
||||||
|
|
||||||
|
先提供独立只读命令和 skill,生成现有缺口报告,逐项修复补证据。不修改数据库、seed 或旧发布快照。不将现有缺口隐藏在绿色旧校验中;所有模板交付必须执行新诊断并归档剩余项。
|
||||||
|
|
||||||
|
## 草稿预览修正
|
||||||
|
|
||||||
|
Admin 的 /admin/workspace/preview 从当前品牌记录构建内存快照,并使用公开 Runtime 的同一投影服务,返回 publication.status=draft。公开路由仍只读取发布快照。此更改解决保存后预览退回发布旧值、未发布品牌无法预览的问题,不创建数据库发布记录。原有客户端 Runtime 类型增加 draft 状态,集成测试同时验证授权、品牌范围、草稿重载和发布隔离。
|
||||||
+13
-2
@@ -21,10 +21,21 @@ location /api/ {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
构建管理后台时使用:
|
生产构建会先把所有已接入模板的 H5 renderer 编译进一个静态预览应用,再将其放到 Admin 的 `/template-preview/` 下。线上无需启动 Vite,也无需为每个模板运行单独服务。构建管理后台与预览应用时使用:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
VITE_APP_BASE_PATH=/admin/ VITE_API_BASE_URL=/api pnpm --filter @personal-brand/admin build
|
pnpm build:admin:preview
|
||||||
```
|
```
|
||||||
|
|
||||||
|
部署时将 `apps/admin/dist` 作为同一个静态站点发布。预览 iframe 与 Admin 同源,运行时根据品牌公开工作区中的 `visualTemplateKey` 选择已打包的模板 renderer,并通过 `/api` 读取已发布数据;管理员正在编辑的草稿由 Admin 经 `postMessage` 投影到 iframe,不会写回公开 API。
|
||||||
|
|
||||||
|
本地开发只需启动一个多模板 H5 服务和 Admin:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm preview:templates
|
||||||
|
VITE_APP_BASE_PATH=/ ADMIN_PORT=3000 pnpm --filter @personal-brand/admin dev
|
||||||
|
```
|
||||||
|
|
||||||
|
本地 Admin 默认连接 `http://localhost:3002` 上的统一预览服务。`VITE_TEMPLATE_PREVIEW_URL` 只用于部署时覆盖预览应用地址,不再按模板配置 URL map。
|
||||||
|
|
||||||
如果希望 API 服务自身也带前缀,可设置 `API_PREFIX=api`。使用 Nginx 去前缀转发时保持默认空值即可,避免重复 `/api/api`。
|
如果希望 API 服务自身也带前缀,可设置 `API_PREFIX=api`。使用 Nginx 去前缀转发时保持默认空值即可,避免重复 `/api/api`。
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
## 模板与配置包
|
## 模板与配置包
|
||||||
|
|
||||||
|
- 执行 pnpm template:doctor 并遵循 [模板完成度规则](template-completion-rules.md),诊断未解决项和未验证项不能视为完成;
|
||||||
|
|
||||||
- 模板声明必须真正驱动安装和升级,不能只增加类型而保留 Controller 硬编码;
|
- 模板声明必须真正驱动安装和升级,不能只增加类型而保留 Controller 硬编码;
|
||||||
- 每个页面上的品牌事实、信任资料、业务详情和可编辑文案都必须来自 Runtime 数据,并在同一页面声明对应 Admin editor binding;`pnpm validate:templates` 的逐页 renderer / editor 契约测试通过后才能判定模板完成;
|
- 每个页面上的品牌事实、信任资料、业务详情和可编辑文案都必须来自 Runtime 数据,并在同一页面声明对应 Admin editor binding;`pnpm validate:templates` 的逐页 renderer / editor 契约测试通过后才能判定模板完成;
|
||||||
- 每种模板信任内容必须声明实际展示页面,逐页测试要同时验证“声明的类型有 renderer 消费”和“renderer 使用的类型已声明”;
|
- 每种模板信任内容必须声明实际展示页面,逐页测试要同时验证“声明的类型有 renderer 消费”和“renderer 使用的类型已声明”;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
name: template-completion-audit
|
||||||
|
description: Diagnose and repair personal-brand template editability, region selection, field bindings, persistence and visual regressions. Use for new template acceptance or recurring template editor defects; distinguish static coverage from complete delivery.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Template completion audit
|
||||||
|
|
||||||
|
在目标仓库运行;先读取 AGENTS.md、docs/template-completion-rules.md 和 docs/engineering-delivery-checklist.md。此 skill 的版本化来源位于 docs/skills/template-completion-audit/SKILL.md;仓库规则是唯一标准。
|
||||||
|
|
||||||
|
## 执行
|
||||||
|
|
||||||
|
1. 确认当前分支、已有修改、真实模板包与原始视觉参考。使用真实 manifest,禁止为方便测试重新写简化声明。
|
||||||
|
2. 运行 pnpm template:doctor --output <task-dir>/before.json;按需加 --template <packageKey>。退出 1 是发现问题,退出 2 是工具错误;完整保留两者,不吞掉失败。
|
||||||
|
3. 检查每个区域的全部展示变量、来源、绑定、页面和记录 ID;特别核查共享事实、fallback 优先级、组合选区对子区的拦截、列表项和未消费字段。未知映射标 review,不猜测为通过。
|
||||||
|
4. 优先修同根公共逻辑,补失败回归后小批修改。诊断命令只读,不提供猜测式 --fix。catalog 和格式化可以自动运行;不以清报告为由复制数据库字段、修改 seed、删除显示内容或放宽检查。用户授权编辑不等于授权破坏性迁移。
|
||||||
|
5. 对每个修改的字段使用独特值执行点选、预览、正确请求、保存、重载、发布验证;真实数据库测试必须隔离。mock PATCH 只能证明前端请求;必须说明缺失的持久化证据。
|
||||||
|
6. 比较原型与多屏宽截图,特别核查新增 DOM wrapper 对 grid/flex 直接子项的影响。未见原型时记录视觉基线待核实。
|
||||||
|
7. 重跑诊断、相关测试、类型与构建门槛;保存 after.json、命令结果、截图及剩余项。连续 3 次同类失败时重新审查数据链和测试输入,不能继续堆补丁。
|
||||||
|
8. 将新的故障模式写入通用规则和故障注入测试。报告工具交付与模板完成两种状态,不能用静态绿色或单条 fixture 成功代替完整验收。
|
||||||
|
|
||||||
|
## 验收证据
|
||||||
|
|
||||||
|
记录模板/代码版本、真实 manifest 来源、page/target/binding 覆盖、失败与修复、保存重载发布证据、视觉对照、未验证项。对静态分析无法处理的跨组件、动态路径和布局问题保留人工审查及浏览器测试,不自动免责。
|
||||||
|
|
||||||
|
已有案例:整张主理人卡片只编辑标签;统计块绑定到介绍标题;额外 wrapper 将 2×2 变成 1×4;trust 子目标缺页面或导航无法解析记录;两套简介导致保存值不是渲染值。将这些作为复现模式,不把具体模板布局写成所有模板的规则。
|
||||||
|
|
||||||
|
新增共享字段入口时,检查同一 binding 多个表单名的同步;未挂载字段必须保留原值。真实 manifest 的多入口修改、保存、重载是必测项,单入口 fixture 不能替代。
|
||||||
|
|
||||||
|
保存回归必须检查请求 payload 中的新 config 不被旧对象覆盖,内容修改不携带模板选择字段。验证真实 Admin 草稿预览刷新后仍为新值,同时公开 Runtime 保持旧值直至发布。模板专属字段须按 page 分组并同步 templateData;列表逐个核对 itemFields,空区域必须有配置入口。
|
||||||
|
|
||||||
|
检查标准品牌列与旧 config 同名冲突和清空优先级;主动清空后旧别名不得恢复。除侧栏逐页字段覆盖外,从画布内部叶子内容实际点击并核对选区;不能使用强制点击伪造可用性证据。
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# 两套模板编辑闭环验收(2026-10-10)
|
||||||
|
|
||||||
|
范围为餐饮 acheng-campus-food 和林境 linjing-editorial 的可编辑区域、实际字段、草稿与发布数据链。基线 commit 为 fa6b492,分支 feat/admin-component-preview;结果对应当前未提交 diff。两个模板 manifest 均为包内 template.json,版本 1.0.0,测试直接读取真实声明,没有重写简化 manifest。
|
||||||
|
|
||||||
|
## 本轮修复
|
||||||
|
|
||||||
|
- 主理人区域展示的姓名、身份、简介、头像和标签提供完整入口;多个入口同步共享值。
|
||||||
|
- 组合区域只导航,子区域优先点选;信任内容按页面定位真实记录,列表每个子字段可编辑并支持排序。
|
||||||
|
- 林境信任数据在原 stats 容器加标记,保持 2×2;专业方法、合作流程及主理人页范围/说明独立编辑。
|
||||||
|
- 餐饮日程的工作日和周末各自对应 4 个配置字段;配送方式对应自取/配送标题和说明;流程对应结构化步骤及附注。
|
||||||
|
- 首页业务卡片声明补齐实际显示的地点、类别、系列、关键词、优先图片;移除该卡不消费的字段入口。
|
||||||
|
- 详情仅选择业务记录预览,并提供业务管理入口;详情正文公共文案与底部咨询入口分为两个可编辑区域。
|
||||||
|
- 保存仅发送真正修改的标准字段和新 config,防止旧 config 覆盖新值;跨区域未挂载修改保留,普通内容保存不携带切换模板字段。
|
||||||
|
- 模板专属字段按各自 page 分组,预览同步 templateData。
|
||||||
|
- Admin 预览改用当前品牌草稿的内存快照;公开 Runtime 仍只读取发布快照。未发布品牌也能预览,不产生发布记录。
|
||||||
|
- 标准品牌列优先于旧 config 同名残留;主动清空后旧别名也不能恢复旧联系方式或简介。
|
||||||
|
- 无记录的区域仍可定位,并显示进入相应内容管理页面的配置入口。
|
||||||
|
|
||||||
|
## 验证证据
|
||||||
|
|
||||||
|
原始证据目录为 .codex-tasks/template-audit-execution/raw/。
|
||||||
|
|
||||||
|
| 范围 | 证据与结果 |
|
||||||
|
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| 数据持久化 | integration-final.log:41 项通过;其中 generic manifest 回归对 193 个 distinct binding 写入独特值,验证 Admin 重载、草稿 Runtime、发布后公开输出 |
|
||||||
|
| 草稿与公开隔离 | 同一集成套件覆盖草稿改变而公开保持旧值、发布后更新、未发布品牌、授权及品牌范围 |
|
||||||
|
| 授权 | Admin preview 无凭证、无效凭证、customer 错误角色和授权成功路径均有自动化验证 |
|
||||||
|
| 实际编辑器 | browser-current.log:使用两套真实 manifest;逐页侧栏字段、实际画布区域内部点击、共享字段与业务记录修改重载、保存失败保留、切页保护 |
|
||||||
|
| 列表 | 林境统计值、排序、专业方法名称、流程说明修改预览及保存重载;数据库回归覆盖所有声明列表 itemFields |
|
||||||
|
| 详情/表单 | 动态业务内容不在详情编辑;公共底部按钮独立点选、修改、保存重载;咨询字段预览、成功页和记录页可显示 |
|
||||||
|
| 布局 | 每个页面在 320/390 像素画布验证无横向溢出,并归档对应截图;统计检查两列四项;详情按钮限制在画布范围 |
|
||||||
|
| 契约与诊断器 | contracts-final.log:19 项;doctor-tests-final.log:19 项,含故障注入 |
|
||||||
|
| 客户端与纯函数 | api-client-final.log:3 项;types 标准列冲突及清空回归、Admin binding 单元测试通过 |
|
||||||
|
| 工程门槛 | API/Admin/Taro 类型检查,API/Admin lint,Admin build,food/linjing 各自 H5 和 weapp 构建,format:check 与 git diff --check |
|
||||||
|
|
||||||
|
集成测试使用随机隔离 schema,迁移并 seed 后运行,最后删除测试 schema;临时发布记录和 fixture 有清理。没有修改生产数据、Prisma schema、migration 或 seed。
|
||||||
|
|
||||||
|
## 动态映射与原型审阅
|
||||||
|
|
||||||
|
原始诊断 after.json 保留餐饮 55 条、林境 23 条 review,blocker 均为 0。命令仍退出 1,completionStatus 保持 unverified。manual-review.json 为全部 78 条记录保存来源审查结论与证据,不修改原报告,也不把人工审查当自动豁免。
|
||||||
|
|
||||||
|
主要审查结论:动态 trust 目标用 type 和实际 id 定位;formTargets 分别提供咨询/成功/记录页目标;工作日/周末和 pickup/delivery 动态字段都有实际声明;作品副标题由 series 与 keywords 派生;餐品数量和分类由业务列表派生,无独立重复字段;图标轮换仅为固定视觉资源。
|
||||||
|
|
||||||
|
对照原始 React 参考:餐饮位于 /home/que01/下载/阿成校园餐---微信小程序原型/,林境位于 /home/que01/下载/林境门作-·-别墅门系统高级工坊.zip。检查本次编辑标记保持统计、日程、配送及合作流程的原布局结构;没有通过 CSS 改写视觉来迁就数据。截图使用确定性本地图片 fixture,林境借用本地餐饮照片,证明布局与图片加载,不代表原型照片或像素级一致。
|
||||||
|
|
||||||
|
条件项逐行核对了可选文字/联系方式、列表、详情记录、附注分隔符等显示逻辑。浏览器验证完整内容和代表性的空区域/失败分支,未穷举所有字段为空的排列组合,也没有验证每个字段在真实微信 IDE 中的交互。当前证据不应解释为永久保证全部模板或所有未来分支无缺陷。
|
||||||
|
|
||||||
|
## 后续模板的固定验收方式
|
||||||
|
|
||||||
|
1. package manifest 自动发现,运行 template:doctor 保存基线和退出码。
|
||||||
|
2. 以视觉选区核对全部数据来源、页作用域、列表子字段和只读理由。
|
||||||
|
3. 对真实 manifest 执行画布点选及编辑器检查,不能只点侧栏。
|
||||||
|
4. 隔离数据库对 distinct binding 验证保存、草稿、发布输出及授权,不能用 mock PATCH 替代。
|
||||||
|
5. 对照原型与多宽截图,新增 wrapper 必须核查 grid/flex 直接子项。
|
||||||
|
6. 归档人工动态审查与未验证范围;新故障加入诊断器/回归与 skill。
|
||||||
|
|
||||||
|
Admin 构建的既有大于 500 kB chunk 警告仍存在。后续由 Admin 前端维护工作处理分包,本轮不提高阈值掩盖警告。浏览器 NO_COLOR/FORCE_COLOR 冲突提示来自运行环境,不影响测试结果。
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
# 模板完成度规则
|
||||||
|
|
||||||
|
## 区域与数据层级
|
||||||
|
|
||||||
|
直接编辑区域须提供全部展示变量,名称与边界一致。主理人卡片不能只有标签字段。共享姓名、头像等允许多个入口,但指向唯一权威值并说明影响范围。
|
||||||
|
|
||||||
|
组合区域仅导航、不承载字段;子区可独立点选,父容器不能吞掉点击。详情页为动态记录预览,选择记录并链接业务编辑入口。访客输入和系统状态只读并说明原因。
|
||||||
|
|
||||||
|
列表支持每项编辑、增删和必要排序;数量和布局由模板约束决定,不把四项、两列强加给所有模板。
|
||||||
|
|
||||||
|
## 完成门槛
|
||||||
|
|
||||||
|
| 层次 | 需要证明 | 历史问题 |
|
||||||
|
| ---------- | -------------------------------------------------- | ----------------------------------------- |
|
||||||
|
| 数据来源 | 每个展示变量有真实绑定或只读理由 | description/slogan、未消费的 brandPromise |
|
||||||
|
| 区域覆盖 | 选中边界内所有变量可修改 | 主理人只剩标签、统计只有介绍标题 |
|
||||||
|
| 层级与记录 | 最近目标点选,导航与画布一致,页面和 recordId 正确 | 自定义 trust 目标找不到记录 |
|
||||||
|
| 编辑闭环 | 独特值修改、预览变化、正确请求、重载保留 | 只验证输入框出现 |
|
||||||
|
| 发布隔离 | 草稿不影响公开内容、发布生效、品牌隔离 | 旧快照、跨品牌污染 |
|
||||||
|
| 视觉 | 原型对照、行列、宽度、按钮、滚动、多屏宽 | wrapper 使 2×2 变 1×4 |
|
||||||
|
| 异常 | 空值仍可配置、失败保留输入、重试、切页保护 | 无记录无入口、部分失败仍提示成功 |
|
||||||
|
|
||||||
|
## 自动诊断边界
|
||||||
|
|
||||||
|
运行 pnpm template:doctor,自动扫描 packages/template-*/template.json 和 Taro renderer;支持 --template packageKey、--output path 输出 JSON。每个问题包含 code、page、target、binding、位置和修复方向。
|
||||||
|
|
||||||
|
staticStatus 只代表支持范围内的静态检查。completionStatus 保持 unverified,直到交互、隔离数据库保存发布、视觉证据经过审阅。退出 1 表示存在 blocker、未登记 review 或执行后的登记校验失败,退出 2 表示执行故障。
|
||||||
|
|
||||||
|
已逐条完成源码审阅的 review 可登记在 `.codex-tasks/template-audit-execution/raw/manual-review.json`。登记必须使用和诊断报告一致的 `file/page/target/binding/line/message`,并保留结论与证据;doctor 只把精确匹配的 review 标记为 `source-reviewed`,不改变 `completionStatus`。未匹配的新 review 和全部 blocker 仍会让命令失败。
|
||||||
|
|
||||||
|
AST 解析可追踪 workspace.brand、presentation、object 和局部别名。动态路径、跨组件和间接映射等未知情况标为 review,不能猜测为通过。诊断器包含正反故障注入测试。
|
||||||
|
|
||||||
|
## 修复闭环
|
||||||
|
|
||||||
|
1. 保留真实 manifest、renderer、原型、失败截图和只读报告。
|
||||||
|
2. 按 code/page/target/binding 聚合同根问题,先修共享逻辑,再修声明;测试必须使用真实 manifest。
|
||||||
|
3. 先补失败回归。确定性格式化、catalog 生成可自动执行;业务字段归属、迁移、视觉调整按证据判断,不能自动猜测覆盖用户数据。
|
||||||
|
4. 小批修复,优先原 DOM 加标记;新增 wrapper 必查 grid/flex 直接子项和 CSS 选择器。
|
||||||
|
5. 重跑诊断及修改、保存、重载、公开输出;跨来源保存检查部分失败,mock 成功不能替代数据库证据。
|
||||||
|
6. 保留剩余项;连续 3 次同类失败重新审查原始数据链和测试输入,禁止删断言或弱化规则求绿。
|
||||||
|
7. 新故障加入诊断规则、测试和文档;skill 引用统一规则,不复制两套标准。
|
||||||
|
|
||||||
|
## 验收证据
|
||||||
|
|
||||||
|
归档 Git commit/未提交 diff、模板版本、命令结果、页面区域字段覆盖、原型与截图、隔离数据来源、保存重载发布测试定位和剩余项。状态为 pass/fail/unverified/not-applicable,最后一种必须附原因,不记录凭证和客户私密数据。
|
||||||
|
|
||||||
|
CI 可执行 pnpm test:template-doctor 和诊断命令。新模板自动扫描。现有缺口或动态证据未验证时不得声称模板全部完成。
|
||||||
|
|
||||||
|
## 共享绑定回归补充
|
||||||
|
|
||||||
|
同一绑定出现在多个区域时,修改任一入口后其他入口必须同步。未挂载字段不得以 undefined 覆盖已有配置;保存当前区域也不能清空其他区域。回归必须至少覆盖首页修改、主理人页修改、保存及重载,不能只使用单字段 fixture。
|
||||||
|
|
||||||
|
## 保存与预览补充
|
||||||
|
|
||||||
|
保存请求仅包含允许修改的字段及新配置。禁止在新 config 后展开带旧 config 的完整品牌对象,禁止内容编辑携带 visualTemplateKey 触发模板切换权限。共享表单保存须保留跨区域修改。
|
||||||
|
|
||||||
|
Admin 预览读取当前品牌的草稿 Runtime,公开接口读取已发布快照。两者共用投影逻辑;保存后预览、重新加载预览、发布后公开读取必须分别测试。不得用 mock 返回最新数据掩盖真实预览接口仍读旧发布快照。
|
||||||
|
|
||||||
|
templateFields 按各自 page 分组;预览同步 templateData。列表审计必须核对 itemFields 的每个实际展示子字段,列表 binding 存在不代表子字段完整。缺少记录的区域仍须提供配置入口。
|
||||||
|
|
||||||
|
## 旧配置与标准列优先级
|
||||||
|
|
||||||
|
Runtime 合并标准品牌列和模板 config 时,标准列是共享品牌事实的权威值。同名旧 config 不得覆盖标准列;标准列主动清空为 null 时,旧 slogan、phone、wechat、studioAddress 等别名也不能恢复旧内容。回归须注入冲突值及清空值,验证草稿和公开投影一致,不依赖清洗数据库掩盖优先级错误。
|
||||||
|
|
||||||
|
画布点选测试必须点击实际区域内部的叶子内容,并验证目标和记录 ID;侧栏定位通过不能代替画布可点击。应避开圆角透明角落,不能用强制点击或 dispatchEvent 掩盖真实命中问题。
|
||||||
@@ -15,16 +15,17 @@ This document records where template-controlled content is stored and how it rea
|
|||||||
|
|
||||||
## Food Schedule Example
|
## Food Schedule Example
|
||||||
|
|
||||||
The food template declares the schedule type for the `home` and `service` pages. Its Admin fields map directly to existing database columns:
|
餐饮模板的日程在 service 页展示,使用 TrustContent.config 的浅层字段:
|
||||||
|
|
||||||
- `adminFields.title` edits `TrustContent.title`.
|
- title 编辑日程区块标题。
|
||||||
- `adminFields.summary` edits the primary weekday schedule in `TrustContent.summary`.
|
- weekdayLabel、weekdayTag、weekdayDetail、weekdayHours 编辑工作日卡片。
|
||||||
- `adminFields.content` edits the weekend and supplementary schedule in `TrustContent.content`.
|
- weekendLabel、weekendTag、weekendDetail、weekendHours 编辑周末卡片。
|
||||||
- The public workspace returns those values as a `RuntimeTrustItem`; the home and service page renderers read `item.summary` and `item.content`.
|
- status 编辑日程状态。summary 和 content 已在该类型声明中隐藏,不参与日程渲染。
|
||||||
|
- 配送范围与流程分别使用 coverage 和 process 类型的配置字段,不能把摘要或正文作为第二套结构化数据入口。
|
||||||
|
|
||||||
No schedule-specific Prisma migration is needed. Different templates can choose different field labels while retaining the shared trust-content storage contract.
|
编辑器区域列表和 renderer 的 slot 均优先使用带结构化配置的记录。页面点选传递真实 recordId;没有记录时提供内容管理入口。保存只影响品牌草稿,发布后公开 Runtime 才更新。模板样例仍属于包,不作为数据库注册目录。
|
||||||
|
|
||||||
The Admin editor lists the selected template's declared trust types and uses their `adminFields` labels, help, and placeholders. In the food workspace, the service page links directly to the trust-content editor, so the schedule is configured under **内容管理 → 信任内容 → 出摊安排**. Saving changes the brand's draft content; the Mini Program sees the new values after the next publication.
|
详情页中的业务记录只提供选择预览;公共标题和按钮文案通过品牌配置区域编辑,影响全部详情页,不复制到每条业务记录。
|
||||||
|
|
||||||
## Inquiry Field Runtime Mapping
|
## Inquiry Field Runtime Mapping
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# 可视化编辑后续任务
|
||||||
|
|
||||||
|
## 当前基线
|
||||||
|
|
||||||
|
Admin 直接复用 Taro renderer,模板原始 CSS 按 750 设计宽度转换为预览容器单位,模板图片经 Vite 打包。已有区域点击、选中样式、品牌字段筛选、即时草稿和显式保存;保留 H5 iframe 作为回退。当前不代表所有页面、记录与字段均已完成编辑闭环。
|
||||||
|
|
||||||
|
## 1. 统一选区契约
|
||||||
|
|
||||||
|
- 统一 selection 为模板、页面、targetKey、实体类型、recordId;重复餐品和信任卡片必须带记录标识。
|
||||||
|
- 从 manifest 解析中文名称、binding、编辑能力,不在 Admin 中新增行业条件分支。
|
||||||
|
- 校验 target 存在、binding 可解析、页面归属正确;切页、删记录和换模板清理无效选区。
|
||||||
|
- 验收:嵌套区块选最近目标,重复卡片准确选中对应记录,未知目标不打开错误表单。
|
||||||
|
|
||||||
|
## 2. 完成点选与高亮交互
|
||||||
|
|
||||||
|
- 区分浏览模式与编辑模式;编辑模式阻止咨询提交、导航等真实操作。
|
||||||
|
- 使用独立覆盖层显示悬停边框、选中边框及中文区域名,避免改变模板背景、尺寸和布局。
|
||||||
|
- 覆盖层随滚动、容器尺寸、图片加载和字段换行更新;支持空白取消、Escape 取消及键盘选择。
|
||||||
|
- 验收:320/390 画布、长页面、滚动及图片加载后边框仍准确,不遮挡按钮和表单。
|
||||||
|
|
||||||
|
## 3. 打通绑定值编辑
|
||||||
|
|
||||||
|
- 右侧固定显示区域名称、数据来源、对应字段、未保存状态;点字段时定位关联区域。
|
||||||
|
- 品牌配置、业务记录、信任内容、咨询表单使用各自现有 API 和验证规则;记录 ID 由选区携带。
|
||||||
|
- 把当前仅跳转管理页的记录区域接入对应编辑器,复用原有表单与 mutation。
|
||||||
|
- 图片、列表、条件字段按模板声明渲染;空值、默认值、继承值明确区分。
|
||||||
|
- 验收:改值即时预览;保存后重新读取仍一致;失败保留输入并可重试;未保存切页给出明确选择。
|
||||||
|
|
||||||
|
## 4. 自动化验收和部署
|
||||||
|
|
||||||
|
- 按模板包自动发现 renderer、页面与资源,去掉现有 renderer 注册的手工二选一;未知模板明确显示不支持。
|
||||||
|
- 对每个模板覆盖首页、列表、详情、信任区及表单:选择→字段→草稿→保存→重载。
|
||||||
|
- 覆盖非空真实结构数据、嵌套/重复目标、授权失败、图片实际解码、样式尺寸和溢出;仅 DOM 存在不能作为视觉通过。
|
||||||
|
- 校验发布前后隔离:草稿不影响公开页面,发布后访客读取新值;受保护接口覆盖无凭证、错误角色及成功路径。
|
||||||
|
- 验收生产静态构建及子路径部署,不按模板新增 Vite 服务。
|
||||||
|
|
||||||
|
## 推进顺序
|
||||||
|
|
||||||
|
以下计划以 feat/admin-component-preview / 541304a 为基线。已有交互仅部分通过测试,不能视为逐页完成。实施状态以 `.codex-tasks/visual-editor-closure/SUBTASKS.csv` 为准,旧任务记录保留。
|
||||||
|
|
||||||
|
### 第一阶段:覆盖清单与绑定修复
|
||||||
|
|
||||||
|
1. 逐页盘点餐饮、林境模板,建立 coverage.csv:模板、页面、区域、实际读取字段、声明 binding、实体来源、记录定位、编辑入口、缺陷和验证证据。区分业务内容、访客输入、导航及装饰;空数据区域也纳入。
|
||||||
|
2. 优先复现首页身份区域缺少点选标记、咨询区域标为 inquiry 却包含 brand 文案导致字段过滤、咨询字段缺少独立目标。继续逐页排查,不将这些示例视为全部缺陷。
|
||||||
|
3. 补充 ADR 0020 后统一解析:区域表示页面位置,binding 决定字段来源;记录用稳定 ID,咨询字段用表单 ID 与字段 key。混合来源不能依赖 section.target 单一分类。模板包声明,Admin 通用解析。
|
||||||
|
4. 修复嵌套目标、重复记录、无效选区与空区域新增入口;模板和 renderer 从包目录发现,建立可主动检出缺失映射的契约测试。
|
||||||
|
|
||||||
|
验收:所有声明页面进入清单;首页身份、咨询文案和重复卡片可准确定位;有意破坏映射时测试失败。
|
||||||
|
|
||||||
|
### 第二阶段:区域编辑面板
|
||||||
|
|
||||||
|
- 显示页面、区域、具体记录和未保存状态。未选择时显示区域导航,选中后只显示对应字段。
|
||||||
|
- 普通字段默认单列,图片有预览与替换入口,列表支持逐项增删排序。依据面板宽度安排布局,消除强制双列和固定空白,不堆叠重复卡片。
|
||||||
|
- 字段焦点与选区双向定位,高亮随滚动、图片加载、长文本更新且不改变模板布局。
|
||||||
|
- 保存范围明确;失败保留值并可重试;有草稿时切区域、页面或品牌提供保存、放弃、取消选择。
|
||||||
|
|
||||||
|
验收:窄面板无溢出,长表单操作可达;图片、长文本、列表及保存失败、切换路径均有浏览器验证。
|
||||||
|
|
||||||
|
### 第三阶段:咨询表单编辑
|
||||||
|
|
||||||
|
- 区分页面文案、表单结构和访客试填。点击具体字段后编辑标题、提示、必填、类型及适用选项,复用现有验证规则。
|
||||||
|
- 支持增删排序、空表单创建及条件显隐配置,检查条件引用有效性。
|
||||||
|
- 复用 InquiryForm API、版本与发布语义;类型变更和删除不得破坏历史提交快照。预览不创建真实咨询、不读取客户记录。
|
||||||
|
|
||||||
|
验收:修改即时展示且保存重载一致;选择题、日期、长文本、条件字段、空状态均覆盖。接口若有变更,必须覆盖授权、品牌隔离、校验失败及成功持久化。
|
||||||
|
|
||||||
|
### 第四阶段:全页面与部署验收
|
||||||
|
|
||||||
|
- 按清单逐项验证点选、字段、草稿、保存、刷新;结合自动发现的契约检查与关键浏览器场景,不仅检查 DOM 存在。
|
||||||
|
- 使用隔离品牌验证真实 API 保存、草稿与公开内容隔离、发布后读取一致,不覆盖用户开发数据。
|
||||||
|
- 对照两套模板视觉;验证 320/390 画布、图片解码、页脚、表单;运行 H5 和小程序构建检查共享组件回归。
|
||||||
|
- 运行 format:check、lint、相关 typecheck、validate:templates、Admin tests/build、浏览器测试及涉及的 API/API Client 测试。生产静态与子路径部署可用,无按模板单独运行服务需求。
|
||||||
|
|
||||||
|
验收:本轮覆盖项都有通过证据;未完成项保持显式状态。按依赖提交可运行单元,提供预览与验证记录,合并仍等待用户确认。
|
||||||
|
|
||||||
|
## 本轮边界
|
||||||
|
|
||||||
|
本次先制定计划,功能实施尚未开始。聚焦内容编辑,不做任意拖拽布局或 HTML 入库。保留模板视觉和 H5 回退;不重置数据库或 seed,必要结构调整先制定兼容迁移。
|
||||||
@@ -12,6 +12,7 @@ export default tseslint.config(
|
|||||||
"apps/api/test/**/*.test.js",
|
"apps/api/test/**/*.test.js",
|
||||||
"apps/api/test/**/*.cjs",
|
"apps/api/test/**/*.cjs",
|
||||||
"apps/admin/test/**/*.test.mjs",
|
"apps/admin/test/**/*.test.mjs",
|
||||||
|
"apps/admin/public/**",
|
||||||
"packages/types/test/**/*.test.mjs",
|
"packages/types/test/**/*.test.mjs",
|
||||||
"apps/taro/test/**/*.test.mjs",
|
"apps/taro/test/**/*.test.mjs",
|
||||||
"apps/taro/src/assets/**",
|
"apps/taro/src/assets/**",
|
||||||
@@ -53,4 +54,8 @@ export default tseslint.config(
|
|||||||
"@typescript-eslint/require-await": "off",
|
"@typescript-eslint/require-await": "off",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
...tseslint.configs.disableTypeChecked,
|
||||||
|
files: ["apps/admin/template-preview-css.mjs"],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
+5
-1
@@ -26,8 +26,12 @@
|
|||||||
"clean": "turbo run clean && rimraf node_modules .turbo",
|
"clean": "turbo run clean && rimraf node_modules .turbo",
|
||||||
"preview:food": "pnpm --filter @personal-brand/taro dev:h5",
|
"preview:food": "pnpm --filter @personal-brand/taro dev:h5",
|
||||||
"preview:linjing": "TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5",
|
"preview:linjing": "TEMPLATE_KEY=linjing-editorial PREVIEW_PORT=3003 pnpm --filter @personal-brand/taro dev:h5",
|
||||||
|
"preview:templates": "pnpm --filter @personal-brand/taro dev:preview",
|
||||||
|
"build:admin:preview": "PREVIEW_ALL_TEMPLATES=true API_BASE_URL=/api PREVIEW_PUBLIC_PATH=/template-preview/ pnpm --filter @personal-brand/taro build:preview && node scripts/package-template-preview.cjs && VITE_APP_BASE_PATH=/admin/ VITE_API_BASE_URL=/api pnpm --filter @personal-brand/admin build",
|
||||||
"build:taro:food": "pnpm --filter @personal-brand/taro build:h5 && pnpm --filter @personal-brand/taro build:weapp",
|
"build:taro:food": "pnpm --filter @personal-brand/taro build:h5 && pnpm --filter @personal-brand/taro build:weapp",
|
||||||
"build:taro:linjing": "TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5 && TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp"
|
"build:taro:linjing": "TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:h5 && TEMPLATE_KEY=linjing-editorial pnpm --filter @personal-brand/taro build:weapp",
|
||||||
|
"template:doctor": "node scripts/template-doctor.mjs",
|
||||||
|
"test:template-doctor": "node --test scripts/test/template-doctor.test.mjs"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
|
|||||||
@@ -8,13 +8,19 @@ import type {
|
|||||||
RuntimeCapability,
|
RuntimeCapability,
|
||||||
RuntimeInquiryForm,
|
RuntimeInquiryForm,
|
||||||
RuntimeOffering,
|
RuntimeOffering,
|
||||||
|
RuntimeWorkspace,
|
||||||
RuntimeTrustItem,
|
RuntimeTrustItem,
|
||||||
ThemeManifest,
|
ThemeManifest,
|
||||||
} from "@personal-brand/types";
|
} from "@personal-brand/types";
|
||||||
|
export { projectBrandAliases, projectTrustPresentation } from "@personal-brand/types";
|
||||||
export type { PublicOffering } from "@personal-brand/types";
|
export type { PublicOffering } from "@personal-brand/types";
|
||||||
export type { BookingStatus } from "@personal-brand/types";
|
export type { BookingStatus } from "@personal-brand/types";
|
||||||
export type { BrandTemplateKey } from "@personal-brand/types";
|
export type { BrandTemplateKey } from "@personal-brand/types";
|
||||||
export type { EditorPreviewFrameMessage, EditorPreviewHostMessage } from "@personal-brand/types";
|
export type {
|
||||||
|
EditorPreviewFrameMessage,
|
||||||
|
EditorPreviewHostMessage,
|
||||||
|
RuntimeWorkspace,
|
||||||
|
} from "@personal-brand/types";
|
||||||
|
|
||||||
export interface BrandProfile {
|
export interface BrandProfile {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -102,7 +108,12 @@ export interface TemplateAdminSection {
|
|||||||
description: string;
|
description: string;
|
||||||
page: string;
|
page: string;
|
||||||
target: "brand" | "offering" | "trust" | "inquiry";
|
target: "brand" | "offering" | "trust" | "inquiry";
|
||||||
previewTargets?: Array<{ key: string; label: string }>;
|
previewTargets?: Array<{
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
composite?: boolean;
|
||||||
|
children?: string[];
|
||||||
|
}>;
|
||||||
fields: TemplateAdminField[];
|
fields: TemplateAdminField[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,6 +137,7 @@ export interface AdminTemplateContent {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
configFields?: TemplateAdminField[];
|
configFields?: TemplateAdminField[];
|
||||||
|
previewTargets?: Array<{ key: string; label: string; page?: string }>;
|
||||||
maxPublishedItems?: number;
|
maxPublishedItems?: number;
|
||||||
hideStandardFields?: Array<"summary" | "content">;
|
hideStandardFields?: Array<"summary" | "content">;
|
||||||
}>;
|
}>;
|
||||||
@@ -688,6 +700,9 @@ export class ApiClient {
|
|||||||
}> {
|
}> {
|
||||||
return this.request("/admin/workspace");
|
return this.request("/admin/workspace");
|
||||||
}
|
}
|
||||||
|
getAdminPreviewWorkspace(): Promise<RuntimeWorkspace> {
|
||||||
|
return this.request("/admin/workspace/preview");
|
||||||
|
}
|
||||||
listAdminReleases(): Promise<BrandReleaseSummary[]> {
|
listAdminReleases(): Promise<BrandReleaseSummary[]> {
|
||||||
return this.request("/admin/releases");
|
return this.request("/admin/releases");
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -6,7 +6,8 @@ import { navigate } from "../../../apps/taro/src/runtime/navigation";
|
|||||||
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
import { presentation, offering, slot, text, rows } from "../../../apps/taro/src/runtime/content";
|
||||||
import type { RuntimeWorkspace } from "@personal-brand/types";
|
import type { RuntimeWorkspace } from "@personal-brand/types";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
const asset = (name: string) => `/assets/${name}`;
|
const asset = (name: string) =>
|
||||||
|
`/assets/${PREVIEW_ALL_TEMPLATES ? "acheng-campus-food/" : ""}${name}`;
|
||||||
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||||
const brand = workspace.brand;
|
const brand = workspace.brand;
|
||||||
const p = presentation(workspace, "home");
|
const p = presentation(workspace, "home");
|
||||||
@@ -14,8 +15,8 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
return (
|
return (
|
||||||
<View className="food-home">
|
<View className="food-home">
|
||||||
<View className="page">
|
<View className="page">
|
||||||
<View className="brand-card">
|
<View className="brand-card" data-editor-target="food.home.brand-card">
|
||||||
<View className="identity">
|
<View className="identity" data-editor-target="food.home.identity">
|
||||||
{text(brand.avatarUrl) && <Image src={text(brand.avatarUrl)} mode="aspectFill" />}
|
{text(brand.avatarUrl) && <Image src={text(brand.avatarUrl)} mode="aspectFill" />}
|
||||||
<View>
|
<View>
|
||||||
<Text className="name">{text(brand.founder)}</Text>
|
<Text className="name">{text(brand.founder)}</Text>
|
||||||
@@ -28,12 +29,12 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<Text>{text(brand.address)}</Text>
|
<Text>{text(brand.address)}</Text>
|
||||||
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
{p.stallTime && <Text className="notice-time">{p.stallTime}</Text>}
|
||||||
</View>
|
</View>
|
||||||
<View className="actions">
|
<View className="actions" data-editor-target="food.home.actions">
|
||||||
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
<Button className="home-action" onClick={() => navigate("inquiry")}>
|
||||||
咨询 / 预订
|
{p.primaryAction || "咨询 / 预订"}
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="home-action muted" onClick={() => navigate("offerings")}>
|
<Button className="home-action muted" onClick={() => navigate("offerings")}>
|
||||||
查看餐品
|
{p.secondaryAction || "查看餐品"}
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@@ -56,7 +57,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<Text className="heading">{p.worksTitle || "可选餐品"}</Text>
|
<Text className="heading">{p.worksTitle || "可选餐品"}</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text className="more" onClick={() => navigate("offerings")}>
|
<Text className="more" onClick={() => navigate("offerings")}>
|
||||||
查看全部 ›
|
{p.moreAction || "查看全部"} ›
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className="dish-grid">
|
<View className="dish-grid">
|
||||||
@@ -64,6 +65,8 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View
|
<View
|
||||||
className="dish"
|
className="dish"
|
||||||
key={item.id}
|
key={item.id}
|
||||||
|
data-editor-target="acheng-campus-food.home.offering"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
onClick={() => navigate("detail", { id: item.id })}
|
onClick={() => navigate("detail", { id: item.id })}
|
||||||
>
|
>
|
||||||
<Image src={item.image} mode="aspectFill" />
|
<Image src={item.image} mode="aspectFill" />
|
||||||
@@ -81,7 +84,12 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
{workspace.trustItems
|
{workspace.trustItems
|
||||||
.filter((item) => ["promise", "case"].includes(item.type))
|
.filter((item) => ["promise", "case"].includes(item.type))
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<View className="promise" key={item.id}>
|
<View
|
||||||
|
className="promise"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target={`trust:${item.type}`}
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<Text className="eyebrow light">{item.title}</Text>
|
<Text className="eyebrow light">{item.title}</Text>
|
||||||
{item.summary && <Text className="promise-title">{item.summary}</Text>}
|
{item.summary && <Text className="promise-title">{item.summary}</Text>}
|
||||||
<Text className="quote">{item.content}</Text>
|
<Text className="quote">{item.content}</Text>
|
||||||
@@ -115,10 +123,14 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
].filter((row) => row.title && row.detail);
|
].filter((row) => row.title && row.detail);
|
||||||
const steps = rows(process?.config.steps).filter((step) => step.title && step.detail);
|
const steps = rows(process?.config.steps).filter((step) => step.title && step.detail);
|
||||||
return (
|
return (
|
||||||
<View className="food-service">
|
<View className="food-service" data-editor-target="acheng-campus-food.service.service">
|
||||||
<View className="page service-page">
|
<View className="page service-page">
|
||||||
{schedule && scheduleRows.length > 0 && (
|
{schedule && scheduleRows.length > 0 && (
|
||||||
<View className="service-card schedule-card">
|
<View
|
||||||
|
className="service-card schedule-card"
|
||||||
|
data-editor-target="trust:schedule"
|
||||||
|
data-editor-record-id={schedule.id}
|
||||||
|
>
|
||||||
<View className="card-head">
|
<View className="card-head">
|
||||||
<View className="head-title">
|
<View className="head-title">
|
||||||
<Image className="icon" src={asset("service/clock.png")} />
|
<Image className="icon" src={asset("service/clock.png")} />
|
||||||
@@ -151,7 +163,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{c && text(c.config.pickupDetail) && text(c.config.deliveryDetail) && (
|
{c && text(c.config.pickupDetail) && text(c.config.deliveryDetail) && (
|
||||||
<View className="service-card coverage-card">
|
<View
|
||||||
|
className="service-card coverage-card"
|
||||||
|
data-editor-target="trust:coverage"
|
||||||
|
data-editor-record-id={c.id}
|
||||||
|
>
|
||||||
<View className="simple-title">
|
<View className="simple-title">
|
||||||
<Image className="icon" src={asset("service/bike.png")} />
|
<Image className="icon" src={asset("service/bike.png")} />
|
||||||
<Text>{c.title}</Text>
|
<Text>{c.title}</Text>
|
||||||
@@ -175,7 +191,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{process && steps.length > 0 && (
|
{process && steps.length > 0 && (
|
||||||
<View className="service-card process-card">
|
<View
|
||||||
|
className="service-card process-card"
|
||||||
|
data-editor-target="trust:process"
|
||||||
|
data-editor-record-id={process.id}
|
||||||
|
>
|
||||||
<View className="simple-title">
|
<View className="simple-title">
|
||||||
<Image className="icon" src={asset("service/list.png")} />
|
<Image className="icon" src={asset("service/list.png")} />
|
||||||
<Text>{process.title}</Text>
|
<Text>{process.title}</Text>
|
||||||
@@ -202,7 +222,11 @@ function Service({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
)}
|
)}
|
||||||
<Text>{text(process.config.refundNote)}</Text>
|
<Text>{text(process.config.refundNote)}</Text>
|
||||||
</View>
|
</View>
|
||||||
<Button className="process-action" onClick={() => navigate("inquiry")}>
|
<Button
|
||||||
|
data-editor-target="food.service.process-action"
|
||||||
|
className="process-action"
|
||||||
|
onClick={() => navigate("inquiry")}
|
||||||
|
>
|
||||||
{p.processAction || "立即咨询"} →
|
{p.processAction || "立即咨询"} →
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
@@ -220,7 +244,7 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
const p = presentation(workspace, "profile");
|
const p = presentation(workspace, "profile");
|
||||||
const credentials = workspace.trustItems.filter((item) => item.type === "credential");
|
const credentials = workspace.trustItems.filter((item) => item.type === "credential");
|
||||||
return (
|
return (
|
||||||
<View className="food-profile">
|
<View className="food-profile" data-editor-target="acheng-campus-food.profile.identity">
|
||||||
<View className="page">
|
<View className="page">
|
||||||
<View className="profile-card">
|
<View className="profile-card">
|
||||||
<View className="portrait">
|
<View className="portrait">
|
||||||
@@ -236,7 +260,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
{text(brand.description) && <Text className="bio">{text(brand.description)}</Text>}
|
{text(brand.description) && <Text className="bio">{text(brand.description)}</Text>}
|
||||||
{credentials.map((item) =>
|
{credentials.map((item) =>
|
||||||
rows(item.config.standards).length ? (
|
rows(item.config.standards).length ? (
|
||||||
<View className="standards" key={item.id}>
|
<View
|
||||||
|
className="standards"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target="trust:credential"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
{rows(item.config.standards).map((standard, index) => (
|
{rows(item.config.standards).map((standard, index) => (
|
||||||
<View className="standard" key={index}>
|
<View className="standard" key={index}>
|
||||||
<Image
|
<Image
|
||||||
@@ -251,7 +280,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
) : (
|
) : (
|
||||||
<View className="credential-copy" key={item.id}>
|
<View
|
||||||
|
className="credential-copy"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target="trust:credential"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<Text className="credential-title">{item.title}</Text>
|
<Text className="credential-title">{item.title}</Text>
|
||||||
{item.summary && <Text className="bio">{item.summary}</Text>}
|
{item.summary && <Text className="bio">{item.summary}</Text>}
|
||||||
<Text className="bio">{item.content}</Text>
|
<Text className="bio">{item.content}</Text>
|
||||||
@@ -263,7 +297,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
{workspace.trustItems
|
{workspace.trustItems
|
||||||
.filter((item) => item.type === "case")
|
.filter((item) => item.type === "case")
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<View className="case-card" key={item.id}>
|
<View
|
||||||
|
className="case-card"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target="trust:case"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<View className="section-heading">
|
<View className="section-heading">
|
||||||
<Image className="heading-icon" src={asset("owner/handshake.png")} />
|
<Image className="heading-icon" src={asset("owner/handshake.png")} />
|
||||||
<Text>{item.title}</Text>
|
<Text>{item.title}</Text>
|
||||||
@@ -290,7 +329,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
{workspace.trustItems
|
{workspace.trustItems
|
||||||
.filter((item) => item.type === "promise")
|
.filter((item) => item.type === "promise")
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<View className="promise-card" key={item.id}>
|
<View
|
||||||
|
className="promise-card"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target="trust:promise"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<View className="section-heading">
|
<View className="section-heading">
|
||||||
<Image className="promise-icon" src={asset("owner/clock.png")} />
|
<Image className="promise-icon" src={asset("owner/clock.png")} />
|
||||||
<Text>{item.title}</Text>
|
<Text>{item.title}</Text>
|
||||||
@@ -340,13 +384,22 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const formTargets: Record<string, string> = {
|
||||||
|
inquiry: "acheng-campus-food.inquiry.booking",
|
||||||
|
success: "acheng-campus-food.success.successCopy",
|
||||||
|
records: "acheng-campus-food.records.recordsCopy",
|
||||||
|
};
|
||||||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||||||
if (page === "home") return <Home workspace={workspace} />;
|
if (page === "home") return <Home workspace={workspace} />;
|
||||||
if (page === "service") return <Service workspace={workspace} />;
|
if (page === "service") return <Service workspace={workspace} />;
|
||||||
if (page === "profile") return <Profile workspace={workspace} />;
|
if (page === "profile") return <Profile workspace={workspace} />;
|
||||||
if (page === "offerings") return <OfferingList workspace={workspace} />;
|
if (page === "offerings") return <OfferingList workspace={workspace} />;
|
||||||
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
||||||
return <View className="food-forms">{children}</View>;
|
return (
|
||||||
|
<View className="food-forms" data-editor-target={formTargets[page]}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||||
const p = presentation(workspace, "offerings");
|
const p = presentation(workspace, "offerings");
|
||||||
@@ -363,7 +416,7 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
.includes(query.trim().toLowerCase()),
|
.includes(query.trim().toLowerCase()),
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<View className="food-list">
|
<View className="food-list" data-editor-target="acheng-campus-food.offerings.menu">
|
||||||
<View className="page">
|
<View className="page">
|
||||||
<View className="filters">
|
<View className="filters">
|
||||||
<Button
|
<Button
|
||||||
@@ -399,6 +452,8 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View
|
<View
|
||||||
className="offering-card"
|
className="offering-card"
|
||||||
key={item.id}
|
key={item.id}
|
||||||
|
data-editor-target="acheng-campus-food.offerings.item"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
onClick={() => navigate("detail", { id: item.id })}
|
onClick={() => navigate("detail", { id: item.id })}
|
||||||
>
|
>
|
||||||
<View className="dish-media">
|
<View className="dish-media">
|
||||||
@@ -410,7 +465,9 @@ function OfferingList({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<Text className="subtitle">{item.desc}</Text>
|
<Text className="subtitle">{item.desc}</Text>
|
||||||
<View className="dish-bottom">
|
<View className="dish-bottom">
|
||||||
<Text className="price">{item.priceRange}</Text>
|
<Text className="price">{item.priceRange}</Text>
|
||||||
<Text className="more">{p.detailAction || "查看详情 ›"}</Text>
|
<Text className="more" data-editor-target="acheng-campus-food.offerings.action">
|
||||||
|
{p.detailAction || "查看详情 ›"}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@@ -437,7 +494,11 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
const item = offering(found);
|
const item = offering(found);
|
||||||
const p = presentation(workspace, "detail");
|
const p = presentation(workspace, "detail");
|
||||||
return (
|
return (
|
||||||
<View className="food-detail">
|
<View
|
||||||
|
className="food-detail"
|
||||||
|
data-editor-target="acheng-campus-food.detail.dishDetail"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<View className="detail">
|
<View className="detail">
|
||||||
<View className="hero-wrap">
|
<View className="hero-wrap">
|
||||||
<Image
|
<Image
|
||||||
@@ -454,7 +515,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
<Text>{item.series}</Text>
|
<Text>{item.series}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="content">
|
<View className="content" data-editor-target="acheng-campus-food.detail.detailCopy">
|
||||||
<View className="price-card">
|
<View className="price-card">
|
||||||
<View>
|
<View>
|
||||||
<Text>{p.priceLabel || "参考价格"}</Text>
|
<Text>{p.priceLabel || "参考价格"}</Text>
|
||||||
@@ -505,7 +566,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="bar">
|
<View className="bar" data-editor-target="acheng-campus-food.detail.action">
|
||||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||||
{p.inquiryAction || "咨询 / 提前预订"}
|
{p.inquiryAction || "咨询 / 提前预订"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -144,7 +144,8 @@
|
|||||||
"label": "主理人姓名",
|
"label": "主理人姓名",
|
||||||
"input": "text",
|
"input": "text",
|
||||||
"required": true,
|
"required": true,
|
||||||
"placeholder": "例如:阿成"
|
"placeholder": "例如:阿成",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "title",
|
"key": "title",
|
||||||
@@ -152,33 +153,119 @@
|
|||||||
"label": "你的身份",
|
"label": "你的身份",
|
||||||
"help": "例如:校园餐饮主理人。",
|
"help": "例如:校园餐饮主理人。",
|
||||||
"input": "text",
|
"input": "text",
|
||||||
"required": true
|
"required": true,
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "badge",
|
"key": "badge",
|
||||||
"binding": "brand.config.visualPresentation.profile.badge",
|
"binding": "brand.config.visualPresentation.profile.badge",
|
||||||
"label": "写真角标",
|
"label": "写真角标",
|
||||||
"input": "text",
|
"input": "text",
|
||||||
"help": "显示在主理人写真上,可填写经验或服务定位。"
|
"help": "显示在主理人写真上,可填写经验或服务定位。",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "storyLead",
|
"key": "storyLead",
|
||||||
"binding": "brand.config.visualPresentation.profile.storyLead",
|
"binding": "brand.config.visualPresentation.profile.storyLead",
|
||||||
"label": "故事引言",
|
"label": "故事引言",
|
||||||
"input": "textarea",
|
"input": "textarea",
|
||||||
"help": "故事开头的强调段落,下面的正文使用品牌简介。"
|
"help": "故事开头的强调段落,下面的正文使用品牌简介。",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "recordsTitle",
|
"key": "recordsTitle",
|
||||||
"binding": "brand.config.visualPresentation.profile.recordsTitle",
|
"binding": "brand.config.visualPresentation.profile.recordsTitle",
|
||||||
"label": "记录入口文案",
|
"label": "记录入口文案",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "recordsCountUnit",
|
"key": "recordsCountUnit",
|
||||||
"binding": "brand.config.visualPresentation.profile.recordsCountUnit",
|
"binding": "brand.config.visualPresentation.profile.recordsCountUnit",
|
||||||
"label": "记录数量单位",
|
"label": "记录数量单位",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food_profile_identity_avatarUrl",
|
||||||
|
"binding": "brand.avatarUrl",
|
||||||
|
"label": "主理人头像",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food_profile_identity_name",
|
||||||
|
"binding": "brand.name",
|
||||||
|
"label": "品牌名称",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food_profile_identity_description",
|
||||||
|
"binding": "brand.description",
|
||||||
|
"label": "主理人简介",
|
||||||
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.profile.identity",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.profile.identity",
|
||||||
|
"label": "摊位与主理人"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "homeOffering",
|
||||||
|
"title": "首页业务卡片",
|
||||||
|
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||||
|
"page": "home",
|
||||||
|
"target": "offering",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "name",
|
||||||
|
"binding": "offering.name",
|
||||||
|
"label": "名称",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.home.offering"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "summary",
|
||||||
|
"binding": "offering.summary",
|
||||||
|
"label": "简介",
|
||||||
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.home.offering"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "priceText",
|
||||||
|
"binding": "offering.priceText",
|
||||||
|
"label": "价格说明",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.home.offering"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "coverUrl",
|
||||||
|
"binding": "offering.coverUrl",
|
||||||
|
"label": "封面图片",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.home.offering"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "detailHero",
|
||||||
|
"binding": "offering.config.detailHero",
|
||||||
|
"label": "详情主图",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.home.offering",
|
||||||
|
"help": "此图优先用于卡片和详情;未填写时使用封面图片。"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.home.offering",
|
||||||
|
"label": "首页业务卡片"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -189,12 +276,52 @@
|
|||||||
"page": "home",
|
"page": "home",
|
||||||
"target": "brand",
|
"target": "brand",
|
||||||
"previewTargets": [
|
"previewTargets": [
|
||||||
{ "key": "food.home.location", "label": "服务地点" },
|
{
|
||||||
{ "key": "food.home.hero", "label": "出摊现场图片" },
|
"key": "food.home.brand-card",
|
||||||
{ "key": "food.home.offerings-heading", "label": "餐品区域标题" },
|
"label": "品牌信息区",
|
||||||
{ "key": "food.home.promise-heading", "label": "出餐承诺标题" }
|
"composite": true,
|
||||||
|
"children": ["food.home.identity", "food.home.location", "food.home.actions"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.identity",
|
||||||
|
"label": "主理人身份"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.location",
|
||||||
|
"label": "服务地点"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.hero",
|
||||||
|
"label": "出摊现场图片"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.offerings-heading",
|
||||||
|
"label": "餐品区域标题"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.actions",
|
||||||
|
"label": "首页操作按钮"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.home.promise-heading",
|
||||||
|
"label": "出餐承诺标题"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "founder",
|
||||||
|
"binding": "brand.config.founder",
|
||||||
|
"label": "主理人姓名",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "food.home.identity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "title",
|
||||||
|
"binding": "brand.config.title",
|
||||||
|
"label": "身份说明",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "food.home.identity"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "stallTitle",
|
"key": "stallTitle",
|
||||||
"previewTarget": "food.home.location",
|
"previewTarget": "food.home.location",
|
||||||
@@ -234,12 +361,65 @@
|
|||||||
"label": "招牌餐品标题",
|
"label": "招牌餐品标题",
|
||||||
"input": "text"
|
"input": "text"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "moreAction",
|
||||||
|
"previewTarget": "food.home.offerings-heading",
|
||||||
|
"binding": "brand.config.visualPresentation.home.moreAction",
|
||||||
|
"label": "查看全部按钮",
|
||||||
|
"input": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "primaryAction",
|
||||||
|
"previewTarget": "food.home.actions",
|
||||||
|
"binding": "brand.config.visualPresentation.home.primaryAction",
|
||||||
|
"label": "咨询按钮",
|
||||||
|
"input": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "secondaryAction",
|
||||||
|
"previewTarget": "food.home.actions",
|
||||||
|
"binding": "brand.config.visualPresentation.home.secondaryAction",
|
||||||
|
"label": "餐品按钮",
|
||||||
|
"input": "text"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "manifestoTitle",
|
"key": "manifestoTitle",
|
||||||
"previewTarget": "food.home.promise-heading",
|
"previewTarget": "food.home.promise-heading",
|
||||||
"binding": "brand.config.visualPresentation.home.manifestoTitle",
|
"binding": "brand.config.visualPresentation.home.manifestoTitle",
|
||||||
"label": "出餐承诺标题",
|
"label": "出餐承诺标题",
|
||||||
"input": "text"
|
"input": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food_home_identity_avatarUrl",
|
||||||
|
"binding": "brand.avatarUrl",
|
||||||
|
"label": "主理人头像",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "food.home.identity",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food_home_identity_description",
|
||||||
|
"binding": "brand.description",
|
||||||
|
"label": "主理人简介",
|
||||||
|
"input": "textarea",
|
||||||
|
"previewTarget": "food.home.identity",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food_home_location_address",
|
||||||
|
"binding": "brand.address",
|
||||||
|
"label": "服务地址",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "food.home.location",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food_home_hero_name",
|
||||||
|
"binding": "brand.name",
|
||||||
|
"label": "品牌名称",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "food.home.hero",
|
||||||
|
"help": "共享品牌资料,修改后同步影响其他展示位置。"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -253,9 +433,79 @@
|
|||||||
{
|
{
|
||||||
"key": "processAction",
|
"key": "processAction",
|
||||||
"binding": "brand.config.visualPresentation.service.processAction",
|
"binding": "brand.config.visualPresentation.service.processAction",
|
||||||
"label": "流程咨询按钮",
|
"label": "咨询按钮文字",
|
||||||
"input": "text",
|
"input": "text",
|
||||||
"placeholder": "例如:立即预订"
|
"previewTarget": "food.service.process-action"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.service.service",
|
||||||
|
"label": "出摊服务页说明",
|
||||||
|
"composite": true,
|
||||||
|
"children": ["food.service.process-action"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "food.service.process-action",
|
||||||
|
"label": "咨询按钮文字"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "offeringsOffering",
|
||||||
|
"title": "业务卡片",
|
||||||
|
"description": "点选预览中的单条内容,修改对应业务记录。",
|
||||||
|
"page": "offerings",
|
||||||
|
"target": "offering",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "name",
|
||||||
|
"binding": "offering.name",
|
||||||
|
"label": "名称",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "summary",
|
||||||
|
"binding": "offering.summary",
|
||||||
|
"label": "简介",
|
||||||
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "priceText",
|
||||||
|
"binding": "offering.priceText",
|
||||||
|
"label": "价格说明",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "coverUrl",
|
||||||
|
"binding": "offering.coverUrl",
|
||||||
|
"label": "封面图片",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "detailHero",
|
||||||
|
"binding": "offering.config.detailHero",
|
||||||
|
"label": "详情主图",
|
||||||
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item",
|
||||||
|
"help": "此图优先用于卡片和详情;未填写时使用封面图片。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "categoryLabel",
|
||||||
|
"binding": "offering.config.categoryLabel",
|
||||||
|
"label": "餐品类别",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.item"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.offerings.item",
|
||||||
|
"label": "业务卡片"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -270,21 +520,30 @@
|
|||||||
"key": "title",
|
"key": "title",
|
||||||
"binding": "brand.config.visualPresentation.offerings.title",
|
"binding": "brand.config.visualPresentation.offerings.title",
|
||||||
"label": "菜单页标题",
|
"label": "菜单页标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "subtitle",
|
"key": "subtitle",
|
||||||
"binding": "brand.config.visualPresentation.offerings.subtitle",
|
"binding": "brand.config.visualPresentation.offerings.subtitle",
|
||||||
"label": "菜单页说明",
|
"label": "菜单页说明",
|
||||||
"input": "textarea",
|
"input": "textarea",
|
||||||
"maxLength": 120
|
"maxLength": 120,
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "menuTip",
|
"key": "menuTip",
|
||||||
"binding": "brand.config.visualPresentation.offerings.menuTip",
|
"binding": "brand.config.visualPresentation.offerings.menuTip",
|
||||||
"label": "菜单提示",
|
"label": "菜单提示",
|
||||||
"help": "只填写当前实际提供的取餐、加菜或定制服务。",
|
"help": "只填写当前实际提供的取餐、加菜或定制服务。",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.menu"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.offerings.menu",
|
||||||
|
"label": "菜单页说明"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -299,28 +558,38 @@
|
|||||||
"key": "title",
|
"key": "title",
|
||||||
"binding": "brand.config.visualPresentation.inquiry.title",
|
"binding": "brand.config.visualPresentation.inquiry.title",
|
||||||
"label": "预订页面标题",
|
"label": "预订页面标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "subtitle",
|
"key": "subtitle",
|
||||||
"binding": "brand.config.visualPresentation.inquiry.subtitle",
|
"binding": "brand.config.visualPresentation.inquiry.subtitle",
|
||||||
"label": "预订说明",
|
"label": "预订说明",
|
||||||
"input": "textarea",
|
"input": "textarea",
|
||||||
"maxLength": 120
|
"maxLength": 120,
|
||||||
|
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "submitLabel",
|
"key": "submitLabel",
|
||||||
"binding": "brand.config.visualPresentation.inquiry.submitLabel",
|
"binding": "brand.config.visualPresentation.inquiry.submitLabel",
|
||||||
"label": "提交按钮文字",
|
"label": "提交按钮文字",
|
||||||
"input": "text",
|
"input": "text",
|
||||||
"placeholder": "例如:提交预订需求"
|
"placeholder": "例如:提交预订需求",
|
||||||
|
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "promise",
|
"key": "promise",
|
||||||
"binding": "brand.config.visualPresentation.inquiry.promise",
|
"binding": "brand.config.visualPresentation.inquiry.promise",
|
||||||
"label": "真实服务承诺",
|
"label": "真实服务承诺",
|
||||||
"help": "仅填写能兑现的回复时间、订金和联系规则;留空则不显示。",
|
"help": "仅填写能兑现的回复时间、订金和联系规则;留空则不显示。",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.inquiry.booking"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.inquiry.booking",
|
||||||
|
"label": "预订与定制"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -335,43 +604,50 @@
|
|||||||
"key": "categoryLabel",
|
"key": "categoryLabel",
|
||||||
"binding": "offering.config.categoryLabel",
|
"binding": "offering.config.categoryLabel",
|
||||||
"label": "餐品类别",
|
"label": "餐品类别",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "detailHero",
|
"key": "detailHero",
|
||||||
"binding": "offering.config.detailHero",
|
"binding": "offering.config.detailHero",
|
||||||
"label": "详情主图",
|
"label": "详情主图",
|
||||||
"input": "image"
|
"input": "image",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "area",
|
"key": "area",
|
||||||
"binding": "offering.config.area",
|
"binding": "offering.config.area",
|
||||||
"label": "供应地点",
|
"label": "供应地点",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "series",
|
"key": "series",
|
||||||
"binding": "offering.config.series",
|
"binding": "offering.config.series",
|
||||||
"label": "套餐或系列说明",
|
"label": "套餐或系列说明",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "spaceType",
|
"key": "spaceType",
|
||||||
"binding": "offering.config.spaceType",
|
"binding": "offering.config.spaceType",
|
||||||
"label": "适合场景",
|
"label": "适合场景",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "background",
|
"key": "background",
|
||||||
"binding": "offering.config.details.background",
|
"binding": "offering.config.details.background",
|
||||||
"label": "餐品介绍",
|
"label": "餐品介绍",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "designConcept",
|
"key": "designConcept",
|
||||||
"binding": "offering.config.details.designConcept",
|
"binding": "offering.config.details.designConcept",
|
||||||
"label": "口味与分量",
|
"label": "口味与分量",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "keywords",
|
"key": "keywords",
|
||||||
@@ -384,7 +660,8 @@
|
|||||||
"key": "value",
|
"key": "value",
|
||||||
"label": "特色"
|
"label": "特色"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "crafts",
|
"key": "crafts",
|
||||||
@@ -397,7 +674,8 @@
|
|||||||
"key": "value",
|
"key": "value",
|
||||||
"label": "制作说明"
|
"label": "制作说明"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "materialsList",
|
"key": "materialsList",
|
||||||
@@ -413,7 +691,14 @@
|
|||||||
"key": "spec",
|
"key": "spec",
|
||||||
"label": "说明"
|
"label": "说明"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"previewTarget": "acheng-campus-food.detail.dishDetail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.detail.dishDetail",
|
||||||
|
"label": "餐品与服务详情"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -428,50 +713,49 @@
|
|||||||
"key": "priceLabel",
|
"key": "priceLabel",
|
||||||
"binding": "brand.config.visualPresentation.detail.priceLabel",
|
"binding": "brand.config.visualPresentation.detail.priceLabel",
|
||||||
"label": "价格说明标题",
|
"label": "价格说明标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "spaceLabel",
|
"key": "spaceLabel",
|
||||||
"binding": "brand.config.visualPresentation.detail.spaceLabel",
|
"binding": "brand.config.visualPresentation.detail.spaceLabel",
|
||||||
"label": "适合场景标题",
|
"label": "适合场景标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "backgroundTitle",
|
"key": "backgroundTitle",
|
||||||
"binding": "brand.config.visualPresentation.detail.backgroundTitle",
|
"binding": "brand.config.visualPresentation.detail.backgroundTitle",
|
||||||
"label": "餐品介绍标题",
|
"label": "餐品介绍标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "conceptTitle",
|
"key": "conceptTitle",
|
||||||
"binding": "brand.config.visualPresentation.detail.conceptTitle",
|
"binding": "brand.config.visualPresentation.detail.conceptTitle",
|
||||||
"label": "口味与分量标题",
|
"label": "口味与分量标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "craftsTitle",
|
"key": "craftsTitle",
|
||||||
"binding": "brand.config.visualPresentation.detail.craftsTitle",
|
"binding": "brand.config.visualPresentation.detail.craftsTitle",
|
||||||
"label": "制作方式标题",
|
"label": "制作方式标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "materialsTitle",
|
"key": "materialsTitle",
|
||||||
"binding": "brand.config.visualPresentation.detail.materialsTitle",
|
"binding": "brand.config.visualPresentation.detail.materialsTitle",
|
||||||
"label": "食材与搭配标题",
|
"label": "食材与搭配标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
},
|
"previewTarget": "acheng-campus-food.detail.detailCopy"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
{
|
{
|
||||||
"key": "inquiryAction",
|
"key": "acheng-campus-food.detail.detailCopy",
|
||||||
"binding": "brand.config.visualPresentation.detail.inquiryAction",
|
"label": "详情页说明"
|
||||||
"label": "咨询按钮文字",
|
|
||||||
"input": "text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "inquiryHint",
|
|
||||||
"binding": "brand.config.visualPresentation.detail.inquiryHint",
|
|
||||||
"label": "咨询后的处理说明",
|
|
||||||
"help": "只写能够兑现的联系和确认方式。",
|
|
||||||
"input": "textarea"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -486,32 +770,43 @@
|
|||||||
"key": "eyebrow",
|
"key": "eyebrow",
|
||||||
"binding": "brand.config.visualPresentation.success.eyebrow",
|
"binding": "brand.config.visualPresentation.success.eyebrow",
|
||||||
"label": "页面小标题",
|
"label": "页面小标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "title",
|
"key": "title",
|
||||||
"binding": "brand.config.visualPresentation.success.title",
|
"binding": "brand.config.visualPresentation.success.title",
|
||||||
"label": "确认标题",
|
"label": "确认标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "intro",
|
"key": "intro",
|
||||||
"binding": "brand.config.visualPresentation.success.intro",
|
"binding": "brand.config.visualPresentation.success.intro",
|
||||||
"label": "后续联系说明",
|
"label": "后续联系说明",
|
||||||
"help": "若写回复时间,请确认日常能兑现。",
|
"help": "若写回复时间,请确认日常能兑现。",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "recordsAction",
|
"key": "recordsAction",
|
||||||
"binding": "brand.config.visualPresentation.success.recordsAction",
|
"binding": "brand.config.visualPresentation.success.recordsAction",
|
||||||
"label": "查看记录按钮",
|
"label": "查看记录按钮",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "homeAction",
|
"key": "homeAction",
|
||||||
"binding": "brand.config.visualPresentation.success.homeAction",
|
"binding": "brand.config.visualPresentation.success.homeAction",
|
||||||
"label": "返回首页按钮",
|
"label": "返回首页按钮",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.success.successCopy"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.success.successCopy",
|
||||||
|
"label": "提交成功页"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -526,31 +821,94 @@
|
|||||||
"key": "title",
|
"key": "title",
|
||||||
"binding": "brand.config.visualPresentation.records.title",
|
"binding": "brand.config.visualPresentation.records.title",
|
||||||
"label": "记录页标题",
|
"label": "记录页标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "createAction",
|
"key": "createAction",
|
||||||
"binding": "brand.config.visualPresentation.records.createAction",
|
"binding": "brand.config.visualPresentation.records.createAction",
|
||||||
"label": "新增咨询按钮",
|
"label": "新增咨询按钮",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "emptyTitle",
|
"key": "emptyTitle",
|
||||||
"binding": "brand.config.visualPresentation.records.emptyTitle",
|
"binding": "brand.config.visualPresentation.records.emptyTitle",
|
||||||
"label": "暂无记录标题",
|
"label": "暂无记录标题",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "emptyDescription",
|
"key": "emptyDescription",
|
||||||
"binding": "brand.config.visualPresentation.records.emptyDescription",
|
"binding": "brand.config.visualPresentation.records.emptyDescription",
|
||||||
"label": "暂无记录说明",
|
"label": "暂无记录说明",
|
||||||
"input": "textarea"
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "emptyAction",
|
"key": "emptyAction",
|
||||||
"binding": "brand.config.visualPresentation.records.emptyAction",
|
"binding": "brand.config.visualPresentation.records.emptyAction",
|
||||||
"label": "空状态按钮",
|
"label": "空状态按钮",
|
||||||
"input": "text"
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.records.recordsCopy"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.records.recordsCopy",
|
||||||
|
"label": "咨询记录页"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "offerings_detailAction",
|
||||||
|
"title": "详情按钮文字",
|
||||||
|
"description": "此页同类按钮共用此文案。",
|
||||||
|
"page": "offerings",
|
||||||
|
"target": "brand",
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.offerings.action",
|
||||||
|
"label": "详情按钮文字"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "detailAction",
|
||||||
|
"binding": "brand.config.visualPresentation.offerings.detailAction",
|
||||||
|
"label": "详情按钮文字",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.offerings.action"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "detailAction",
|
||||||
|
"title": "详情页咨询入口",
|
||||||
|
"description": "公共按钮与提示,对所有业务详情生效。",
|
||||||
|
"page": "detail",
|
||||||
|
"target": "brand",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "inquiryAction",
|
||||||
|
"binding": "brand.config.visualPresentation.detail.inquiryAction",
|
||||||
|
"label": "咨询按钮文字",
|
||||||
|
"input": "text",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.action"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "inquiryHint",
|
||||||
|
"binding": "brand.config.visualPresentation.detail.inquiryHint",
|
||||||
|
"label": "咨询后的处理说明",
|
||||||
|
"help": "只写能够兑现的联系和确认方式。",
|
||||||
|
"input": "textarea",
|
||||||
|
"previewTarget": "acheng-campus-food.detail.action"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"previewTargets": [
|
||||||
|
{
|
||||||
|
"key": "acheng-campus-food.detail.action",
|
||||||
|
"label": "详情页咨询入口"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,13 @@ export type TemplateAdminSection = {
|
|||||||
page: TemplatePageKey;
|
page: TemplatePageKey;
|
||||||
target: "brand" | "offering" | "trust" | "inquiry";
|
target: "brand" | "offering" | "trust" | "inquiry";
|
||||||
/** Visual regions rendered by this section's page. */
|
/** Visual regions rendered by this section's page. */
|
||||||
previewTargets?: Array<{ key: string; label: string }>;
|
previewTargets?: Array<{
|
||||||
|
key: string;
|
||||||
|
label: string;
|
||||||
|
/** 组合区域只负责承载和导航,不重复声明可编辑字段。 */
|
||||||
|
composite?: boolean;
|
||||||
|
children?: string[];
|
||||||
|
}>;
|
||||||
fields: TemplateAdminField[];
|
fields: TemplateAdminField[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +116,7 @@ export type TemplateTrustContentType = {
|
|||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
configFields?: TemplateAdminField[];
|
configFields?: TemplateAdminField[];
|
||||||
|
previewTargets?: Array<{ key: string; label: string; page?: string }>;
|
||||||
maxPublishedItems?: number;
|
maxPublishedItems?: number;
|
||||||
hideStandardFields?: Array<"summary" | "content">;
|
hideStandardFields?: Array<"summary" | "content">;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -169,7 +169,12 @@ test("shared brand facts have one editor and template-specific offering detail b
|
|||||||
const bindings = manifest.admin.sections.flatMap((section) =>
|
const bindings = manifest.admin.sections.flatMap((section) =>
|
||||||
section.fields.map((field) => field.binding),
|
section.fields.map((field) => field.binding),
|
||||||
);
|
);
|
||||||
assert.ok(!bindings.some((binding) => sharedBrandBindings.has(binding)), key);
|
for (const field of manifest.admin.sections.flatMap((section) => section.fields)) {
|
||||||
|
if (sharedBrandBindings.has(field.binding)) {
|
||||||
|
assert.ok(field.previewTarget, key + ": shared facts need visual targets");
|
||||||
|
assert.ok(!field.binding.includes(".config."), "Shared facts must use canonical columns");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const foodRoot = path.join(packageRoot, "template-acheng-campus-food");
|
const foodRoot = path.join(packageRoot, "template-acheng-campus-food");
|
||||||
const food = JSON.parse(fs.readFileSync(path.join(foodRoot, "template.json"), "utf8"));
|
const food = JSON.parse(fs.readFileSync(path.join(foodRoot, "template.json"), "utf8"));
|
||||||
|
|||||||
@@ -24,32 +24,110 @@ for (const directory of templateDirectories) {
|
|||||||
const targets = sections.flatMap((section) =>
|
const targets = sections.flatMap((section) =>
|
||||||
(section.previewTargets ?? []).map((target) => ({ ...target, page: section.page, section })),
|
(section.previewTargets ?? []).map((target) => ({ ...target, page: section.page, section })),
|
||||||
);
|
);
|
||||||
|
for (const declaration of manifest.trustContentTypes ?? [])
|
||||||
|
for (const target of declaration.previewTargets ?? [])
|
||||||
|
targets.push({
|
||||||
|
...target,
|
||||||
|
page: declaration.pages?.[0] ?? "home",
|
||||||
|
section: { fields: declaration.configFields ?? [] },
|
||||||
|
});
|
||||||
const keys = targets.map((target) => target.key);
|
const keys = targets.map((target) => target.key);
|
||||||
assert.equal(new Set(keys).size, keys.length, "preview target keys must be unique");
|
assert.equal(new Set(keys).size, keys.length, "preview target keys must be unique");
|
||||||
|
|
||||||
for (const { section } of targets) {
|
for (const section of sections) {
|
||||||
for (const field of section.fields) {
|
for (const field of section.fields) {
|
||||||
if (field.previewTarget)
|
assert.ok(field.binding, `${section.key}.${field.key} must have an editable binding`);
|
||||||
assert.ok(
|
assert.ok(field.previewTarget, `${section.key}.${field.key} must map to a visual region`);
|
||||||
section.previewTargets.some((target) => target.key === field.previewTarget),
|
assert.ok(
|
||||||
`${section.key}.${field.key} references an undeclared previewTarget`,
|
targets.some((target) => target.key === field.previewTarget),
|
||||||
);
|
`${section.key}.${field.key} references an undeclared previewTarget`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
for (const target of section.previewTargets ?? []) {
|
||||||
|
if (target.composite) {
|
||||||
|
assert.ok(
|
||||||
|
Array.isArray(target.children) && target.children.length > 0,
|
||||||
|
`${target.key} composite target must declare child targets`,
|
||||||
|
);
|
||||||
|
for (const child of target.children)
|
||||||
|
assert.ok(
|
||||||
|
targets.some((candidate) => candidate.key === child && !candidate.composite) ||
|
||||||
|
(child.startsWith("trust:") &&
|
||||||
|
(manifest.trustContentTypes ?? []).some(
|
||||||
|
(declaration) => `trust:${declaration.type}` === child,
|
||||||
|
)),
|
||||||
|
`${target.key} references missing or composite child ${child}`,
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
!section.fields.some((field) => field.previewTarget === target.key),
|
||||||
|
`${target.key} composite target must not duplicate editable fields`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const field of manifest.templateFields ?? []) {
|
||||||
|
assert.ok(field.binding, `templateFields.${field.key} must have an editable binding`);
|
||||||
|
assert.ok(field.previewTarget, `templateFields.${field.key} must map to a visual region`);
|
||||||
|
assert.ok(
|
||||||
|
targets.some((target) => target.key === field.previewTarget),
|
||||||
|
`templateFields.${field.key} references an undeclared previewTarget`,
|
||||||
|
);
|
||||||
|
assert.ok(rendererPath && fs.existsSync(rendererPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const target of targets)
|
for (const target of targets)
|
||||||
assert.ok(
|
if (!target.composite)
|
||||||
target.section.fields.some((field) => field.previewTarget === target.key),
|
assert.ok(
|
||||||
`${target.key} must map to at least one editable field`,
|
target.section.fields.some((field) => field.previewTarget === target.key) ||
|
||||||
);
|
(manifest.trustContentTypes ?? []).some((declaration) =>
|
||||||
|
(declaration.configFields ?? []).some((field) => field.previewTarget === target.key),
|
||||||
|
),
|
||||||
|
`${target.key} must map to at least one editable field`,
|
||||||
|
);
|
||||||
|
|
||||||
if (!targets.length) return;
|
if (!targets.length) return;
|
||||||
assert.ok(fs.existsSync(rendererPath), "templates with preview targets need a Taro renderer");
|
assert.ok(fs.existsSync(rendererPath), "templates with preview targets need a Taro renderer");
|
||||||
const renderer = fs.readFileSync(rendererPath, "utf8");
|
const renderer = fs.readFileSync(rendererPath, "utf8");
|
||||||
for (const target of targets)
|
for (const target of targets)
|
||||||
assert.ok(
|
assert.ok(
|
||||||
renderer.includes(`data-editor-target="${target.key}"`),
|
renderer.includes(`data-editor-target="${target.key}"`) ||
|
||||||
|
renderer.includes(`data-editor-target={\`${target.key}`) ||
|
||||||
|
renderer.includes(`data-editor-target={formTargets[`),
|
||||||
`renderer is missing data-editor-target ${target.key}`,
|
`renderer is missing data-editor-target ${target.key}`,
|
||||||
);
|
);
|
||||||
|
assert.ok(renderer.includes("data-editor-target"), "renderer must expose editor targets");
|
||||||
|
|
||||||
|
const hasDynamicTrustTarget = /data-editor-target=\{`trust:\$\{item\.type\}`\}/.test(renderer);
|
||||||
|
const literalRendererTargets = new Set(
|
||||||
|
[...renderer.matchAll(/data-editor-target="([^"]+)"/g)]
|
||||||
|
.map((match) => match[1])
|
||||||
|
.filter((key) => !key.startsWith("trust:")),
|
||||||
|
);
|
||||||
|
for (const renderedKey of literalRendererTargets)
|
||||||
|
assert.ok(
|
||||||
|
keys.includes(renderedKey),
|
||||||
|
`renderer target ${renderedKey} is missing from manifest`,
|
||||||
|
);
|
||||||
|
const concreteTrustTypes = new Set(
|
||||||
|
[...literalRendererTargets]
|
||||||
|
.filter((key) => key.startsWith("trust:"))
|
||||||
|
.map((key) => key.slice("trust:".length)),
|
||||||
|
);
|
||||||
|
for (const type of concreteTrustTypes) {
|
||||||
|
const key = `trust:${type}`;
|
||||||
|
assert.ok(
|
||||||
|
(manifest.trustContentTypes ?? []).some((item) => item.type === type),
|
||||||
|
`renderer trust target ${key} has no trust type declaration`,
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
targets.some((target) => target.key === key),
|
||||||
|
`renderer trust target ${key} is missing from Admin declarations`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (hasDynamicTrustTarget)
|
||||||
|
assert.ok(
|
||||||
|
manifest.trustContentTypes?.length,
|
||||||
|
"dynamic trust targets need trust type declarations",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
const credential = slot(workspace, "credential");
|
const credential = slot(workspace, "credential");
|
||||||
const t = workspace.trustPresentation;
|
const t = workspace.trustPresentation;
|
||||||
return (
|
return (
|
||||||
<View className="editorial-home">
|
<View className="editorial-home" data-editor-target="linjing-editorial.home.home">
|
||||||
<View className="page">
|
<View className="page">
|
||||||
<View className="founder-card" data-editor-target="editorial.home.identity">
|
<View className="founder-card" data-editor-target="editorial.home.identity">
|
||||||
{text(b.avatarUrl) && (
|
{text(b.avatarUrl) && (
|
||||||
@@ -53,8 +53,18 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View className="intro" data-editor-target="editorial.home.proof">
|
<View className="intro" data-editor-target="editorial.home.proof">
|
||||||
<Text className="eyebrow dark">{p.proofEyebrow}</Text>
|
<Text className="eyebrow dark">{p.proofEyebrow}</Text>
|
||||||
<Text className="section-title">{p.proofTitle}</Text>
|
<Text className="section-title">{p.proofTitle}</Text>
|
||||||
<Text className="body">{credential?.content}</Text>
|
<Text
|
||||||
<View className="stats">
|
className="body"
|
||||||
|
data-editor-target="trust:credential"
|
||||||
|
data-editor-record-id={credential?.id}
|
||||||
|
>
|
||||||
|
{credential?.content}
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
className="stats"
|
||||||
|
data-editor-target="editorial.home.proof.stats"
|
||||||
|
data-editor-record-id={credential?.id}
|
||||||
|
>
|
||||||
{t.stats?.map((item, index) => (
|
{t.stats?.map((item, index) => (
|
||||||
<View key={index}>
|
<View key={index}>
|
||||||
<Text className="stat-value">{item.value}</Text>
|
<Text className="stat-value">{item.value}</Text>
|
||||||
@@ -67,12 +77,18 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View className="trust" data-editor-target="editorial.home.manifesto">
|
<View className="trust" data-editor-target="editorial.home.manifesto">
|
||||||
<Text className="eyebrow">{p.manifestoEyebrow}</Text>
|
<Text className="eyebrow">{p.manifestoEyebrow}</Text>
|
||||||
<Text className="section-title light">{p.manifestoTitle}</Text>
|
<Text className="section-title light">{p.manifestoTitle}</Text>
|
||||||
{t.pillars?.map((item, index) => (
|
<View
|
||||||
<View className="pillar" key={index}>
|
className="pillars-content"
|
||||||
<Text className="pillar-title">{item.title}</Text>
|
data-editor-target="editorial.home.manifesto.pillars"
|
||||||
<Text className="pillar-desc">{item.desc}</Text>
|
data-editor-record-id={credential?.id}
|
||||||
</View>
|
>
|
||||||
))}
|
{t.pillars?.map((item, index) => (
|
||||||
|
<View className="pillar" key={index}>
|
||||||
|
<Text className="pillar-title">{item.title}</Text>
|
||||||
|
<Text className="pillar-desc">{item.desc}</Text>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="section">
|
<View className="section">
|
||||||
<View className="section-head" data-editor-target="editorial.home.works">
|
<View className="section-head" data-editor-target="editorial.home.works">
|
||||||
@@ -88,6 +104,8 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<View
|
<View
|
||||||
className="work-card"
|
className="work-card"
|
||||||
key={item.id}
|
key={item.id}
|
||||||
|
data-editor-target="linjing-editorial.home.offering"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
onClick={() => navigate("detail", { id: item.id })}
|
onClick={() => navigate("detail", { id: item.id })}
|
||||||
>
|
>
|
||||||
<Image src={item.image} mode="aspectFill" />
|
<Image src={item.image} mode="aspectFill" />
|
||||||
@@ -103,10 +121,14 @@ function Home({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
<View className="flow">
|
<View className="flow" data-editor-target="editorial.home.flow">
|
||||||
<Text className="flow-eyebrow">{p.flowEyebrow}</Text>
|
<Text className="flow-eyebrow">{p.flowEyebrow}</Text>
|
||||||
<Text className="flow-title">{p.flowTitle}</Text>
|
<Text className="flow-title">{p.flowTitle}</Text>
|
||||||
<View className="flow-grid">
|
<View
|
||||||
|
className="flow-grid"
|
||||||
|
data-editor-target="editorial.home.flow.steps"
|
||||||
|
data-editor-record-id={credential?.id}
|
||||||
|
>
|
||||||
{t.serviceFlow?.map((step, index) => (
|
{t.serviceFlow?.map((step, index) => (
|
||||||
<View className="flow-item" key={index}>
|
<View className="flow-item" key={index}>
|
||||||
<Text className="flow-step">{step.step}</Text>
|
<Text className="flow-step">{step.step}</Text>
|
||||||
@@ -125,9 +147,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
const p = presentation(workspace, "profile");
|
const p = presentation(workspace, "profile");
|
||||||
const config = object(b.profilePresentation);
|
const config = object(b.profilePresentation);
|
||||||
return (
|
return (
|
||||||
<View className="editorial-profile">
|
<View
|
||||||
|
className="editorial-profile"
|
||||||
|
data-editor-target="linjing-editorial.profile.profileDetails"
|
||||||
|
>
|
||||||
<View className="profile">
|
<View className="profile">
|
||||||
<View className="founder-card">
|
<View className="founder-card" data-editor-target="linjing-editorial.profile.identity">
|
||||||
<View className="identity">
|
<View className="identity">
|
||||||
{text(b.avatarUrl) && (
|
{text(b.avatarUrl) && (
|
||||||
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
|
<Image className="avatar" src={text(b.avatarUrl)} mode="aspectFill" />
|
||||||
@@ -172,7 +197,11 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="records-card" onClick={() => navigate("records")}>
|
<View
|
||||||
|
className="records-card"
|
||||||
|
data-editor-target="linjing-editorial.profile.records"
|
||||||
|
onClick={() => navigate("records")}
|
||||||
|
>
|
||||||
<View className="entry-copy">
|
<View className="entry-copy">
|
||||||
<Text>{p.recordsTitle || "我的咨询记录"}</Text>
|
<Text>{p.recordsTitle || "我的咨询记录"}</Text>
|
||||||
<Text>{p.recordsSubtitle}</Text>
|
<Text>{p.recordsSubtitle}</Text>
|
||||||
@@ -180,7 +209,7 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<Text>查看 ›</Text>
|
<Text>查看 ›</Text>
|
||||||
</View>
|
</View>
|
||||||
{rows(config.coverage).length > 0 && (
|
{rows(config.coverage).length > 0 && (
|
||||||
<View className="info-card">
|
<View className="info-card" data-editor-target="linjing-editorial.profile.coverage">
|
||||||
<View className="card-title">{p.coverageTitle}</View>
|
<View className="card-title">{p.coverageTitle}</View>
|
||||||
{rows(config.coverage).map((item, index) => (
|
{rows(config.coverage).map((item, index) => (
|
||||||
<View className="note" key={index}>
|
<View className="note" key={index}>
|
||||||
@@ -191,7 +220,7 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{Array.isArray(config.warranty) && config.warranty.length > 0 && (
|
{Array.isArray(config.warranty) && config.warranty.length > 0 && (
|
||||||
<View className="info-card">
|
<View className="info-card" data-editor-target="linjing-editorial.profile.warranty">
|
||||||
<View className="card-title">{p.warrantyTitle}</View>
|
<View className="card-title">{p.warrantyTitle}</View>
|
||||||
{config.warranty.map((item, index) => (
|
{config.warranty.map((item, index) => (
|
||||||
<View className="warranty" key={index}>
|
<View className="warranty" key={index}>
|
||||||
@@ -202,7 +231,12 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{workspace.trustItems.map((item) => (
|
{workspace.trustItems.map((item) => (
|
||||||
<View className="info-card trust-card" key={item.id}>
|
<View
|
||||||
|
className="info-card trust-card"
|
||||||
|
key={item.id}
|
||||||
|
data-editor-target={`trust:${item.type}`}
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<View className="card-title">{item.title}</View>
|
<View className="card-title">{item.title}</View>
|
||||||
{item.summary && <Text className="trust-summary">{item.summary}</Text>}
|
{item.summary && <Text className="trust-summary">{item.summary}</Text>}
|
||||||
<Text>{item.content}</Text>
|
<Text>{item.content}</Text>
|
||||||
@@ -215,15 +249,17 @@ function Profile({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
||||||
const p = presentation(workspace, "offerings");
|
const p = presentation(workspace, "offerings");
|
||||||
return (
|
return (
|
||||||
<View className="editorial-list">
|
<View className="editorial-list" data-editor-target="linjing-editorial.offerings.cases">
|
||||||
<View className="page">
|
<View className="page">
|
||||||
<Text className="eyebrow">{p.eyebrow}</Text>
|
<Text className="eyebrow">{p.worksEyebrow}</Text>
|
||||||
<Text className="section-title">{p.title || "作品与服务"}</Text>
|
<Text className="section-title">{p.worksTitle || "作品与服务"}</Text>
|
||||||
<Text className="subtitle">{p.subtitle}</Text>
|
<Text className="subtitle">{p.subtitle}</Text>
|
||||||
{workspace.offerings.map(offering).map((item) => (
|
{workspace.offerings.map(offering).map((item) => (
|
||||||
<View
|
<View
|
||||||
className="work-card"
|
className="work-card"
|
||||||
key={item.id}
|
key={item.id}
|
||||||
|
data-editor-target="linjing-editorial.offerings.item"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
onClick={() => navigate("detail", { id: item.id })}
|
onClick={() => navigate("detail", { id: item.id })}
|
||||||
>
|
>
|
||||||
<Image src={item.image} mode="aspectFill" />
|
<Image src={item.image} mode="aspectFill" />
|
||||||
@@ -234,7 +270,9 @@ function List({ workspace }: { workspace: RuntimeWorkspace }) {
|
|||||||
<Text className="work-name">{item.name}</Text>
|
<Text className="work-name">{item.name}</Text>
|
||||||
<Text className="work-desc">{item.desc}</Text>
|
<Text className="work-desc">{item.desc}</Text>
|
||||||
<Text className="work-price">{item.priceRange}</Text>
|
<Text className="work-price">{item.priceRange}</Text>
|
||||||
<Text className="more">{p.detailAction || "了解详情 →"}</Text>
|
<Text className="more" data-editor-target="linjing-editorial.offerings.action">
|
||||||
|
{p.detailAction || "了解详情 →"}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
@@ -255,7 +293,11 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
const item = offering(found);
|
const item = offering(found);
|
||||||
const p = presentation(workspace, "detail");
|
const p = presentation(workspace, "detail");
|
||||||
return (
|
return (
|
||||||
<View className="editorial-detail">
|
<View
|
||||||
|
className="editorial-detail"
|
||||||
|
data-editor-target="linjing-editorial.detail.projectDetail"
|
||||||
|
data-editor-record-id={item.id}
|
||||||
|
>
|
||||||
<View className="detail">
|
<View className="detail">
|
||||||
<View className="hero-wrap">
|
<View className="hero-wrap">
|
||||||
<Image
|
<Image
|
||||||
@@ -272,7 +314,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
<Text>{item.series}</Text>
|
<Text>{item.series}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="content">
|
<View className="content" data-editor-target="linjing-editorial.detail.detailCopy">
|
||||||
<View className="price-card">
|
<View className="price-card">
|
||||||
<View>
|
<View>
|
||||||
<Text>{p.priceLabel}</Text>
|
<Text>{p.priceLabel}</Text>
|
||||||
@@ -323,7 +365,7 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View className="bar">
|
<View className="bar" data-editor-target="linjing-editorial.detail.action">
|
||||||
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
<Button onClick={() => navigate("inquiry", { offeringId: item.id })}>
|
||||||
{p.inquiryAction}
|
{p.inquiryAction}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -333,10 +375,19 @@ function Detail({ workspace, id }: { workspace: RuntimeWorkspace; id?: string })
|
|||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const formTargets: Record<string, string> = {
|
||||||
|
inquiry: "linjing-editorial.inquiry.consultation",
|
||||||
|
success: "linjing-editorial.success.successCopy",
|
||||||
|
records: "linjing-editorial.records.recordsCopy",
|
||||||
|
};
|
||||||
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
export function TemplatePage({ workspace, page, children, offeringId }: TemplateProps) {
|
||||||
if (page === "home") return <Home workspace={workspace} />;
|
if (page === "home") return <Home workspace={workspace} />;
|
||||||
if (page === "offerings") return <List workspace={workspace} />;
|
if (page === "offerings") return <List workspace={workspace} />;
|
||||||
if (page === "profile" || page === "service") return <Profile workspace={workspace} />;
|
if (page === "profile" || page === "service") return <Profile workspace={workspace} />;
|
||||||
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
if (page === "detail") return <Detail workspace={workspace} id={offeringId} />;
|
||||||
return <View className="editorial-forms">{children}</View>;
|
return (
|
||||||
|
<View className="editorial-forms" data-editor-target={formTargets[page]}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,12 @@
|
|||||||
import type { RuntimeWorkspace } from "./runtime-workspace.js";
|
import type { RuntimeWorkspace } from "./runtime-workspace.js";
|
||||||
|
|
||||||
export type EditorPreviewHostMessage =
|
export type EditorPreviewHostMessage =
|
||||||
|
| {
|
||||||
|
protocol: "personal-brand-editor-preview";
|
||||||
|
version: 1;
|
||||||
|
type: "workspaceDraft";
|
||||||
|
workspace: RuntimeWorkspace;
|
||||||
|
}
|
||||||
| {
|
| {
|
||||||
protocol: "personal-brand-editor-preview";
|
protocol: "personal-brand-editor-preview";
|
||||||
version: 1;
|
version: 1;
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ export function runtimeContractForBinding(binding: string): RuntimeBindingContra
|
|||||||
kind: "offering",
|
kind: "offering",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
binding.startsWith("offering.") &&
|
||||||
|
["name", "summary", "priceText", "coverUrl"].includes(binding.slice("offering.".length))
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
binding,
|
||||||
|
runtimePath: `workspace.offerings[].${binding.slice("offering.".length)}`,
|
||||||
|
kind: "offering",
|
||||||
|
};
|
||||||
|
}
|
||||||
if (binding === "trust.title" || binding === "trust.summary" || binding === "trust.content") {
|
if (binding === "trust.title" || binding === "trust.summary" || binding === "trust.content") {
|
||||||
return {
|
return {
|
||||||
binding,
|
binding,
|
||||||
@@ -96,11 +106,31 @@ export function projectBrandAliases(
|
|||||||
return {
|
return {
|
||||||
...brand,
|
...brand,
|
||||||
...config,
|
...config,
|
||||||
|
// 标准品牌事实不能被旧模板 config 中同名残留覆盖。
|
||||||
|
...Object.fromEntries(
|
||||||
|
[
|
||||||
|
"id",
|
||||||
|
"slug",
|
||||||
|
"name",
|
||||||
|
"templateKey",
|
||||||
|
"tagline",
|
||||||
|
"description",
|
||||||
|
"avatarUrl",
|
||||||
|
"coverUrl",
|
||||||
|
"hours",
|
||||||
|
"address",
|
||||||
|
"deliveryNote",
|
||||||
|
"contactPhone",
|
||||||
|
"contactWechat",
|
||||||
|
]
|
||||||
|
.filter((key) => Object.prototype.hasOwnProperty.call(brand, key))
|
||||||
|
.map((key) => [key, brand[key]]),
|
||||||
|
),
|
||||||
...(typeof brand.tagline === "string" ? { tagline: brand.tagline } : {}),
|
...(typeof brand.tagline === "string" ? { tagline: brand.tagline } : {}),
|
||||||
...(typeof brand.description === "string" ? { slogan: brand.description } : {}),
|
...(Object.hasOwn(brand, "description") ? { slogan: brand.description ?? "" } : {}),
|
||||||
...(typeof brand.contactPhone === "string" ? { phone: brand.contactPhone } : {}),
|
...(Object.hasOwn(brand, "contactPhone") ? { phone: brand.contactPhone ?? "" } : {}),
|
||||||
...(typeof brand.contactWechat === "string" ? { wechat: brand.contactWechat } : {}),
|
...(Object.hasOwn(brand, "contactWechat") ? { wechat: brand.contactWechat ?? "" } : {}),
|
||||||
...(typeof brand.address === "string" ? { studioAddress: brand.address } : {}),
|
...(Object.hasOwn(brand, "address") ? { studioAddress: brand.address ?? "" } : {}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export interface CapabilityPluginManifest {
|
|||||||
export interface RuntimeWorkspace {
|
export interface RuntimeWorkspace {
|
||||||
schemaVersion: string;
|
schemaVersion: string;
|
||||||
publication?: {
|
publication?: {
|
||||||
status: "published" | "unpublished";
|
status: "published" | "unpublished" | "draft";
|
||||||
version: number | null;
|
version: number | null;
|
||||||
publishedAt?: string;
|
publishedAt?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import {
|
|||||||
} from "../src/runtime-content-contract.ts";
|
} from "../src/runtime-content-contract.ts";
|
||||||
|
|
||||||
test("runtime contract resolves canonical paths", () => {
|
test("runtime contract resolves canonical paths", () => {
|
||||||
|
assert.equal(
|
||||||
|
runtimeContractForBinding("offering.name").runtimePath,
|
||||||
|
"workspace.offerings[].name",
|
||||||
|
);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
runtimeContractForBinding("offering.config.details.background").runtimePath,
|
runtimeContractForBinding("offering.config.details.background").runtimePath,
|
||||||
"workspace.offerings[].presentation.details.background",
|
"workspace.offerings[].presentation.details.background",
|
||||||
@@ -108,3 +112,34 @@ test("legacy profile configuration cannot shadow the declared credential editor"
|
|||||||
);
|
);
|
||||||
assert.deepEqual(result, { stats });
|
assert.deepEqual(result, { stats });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("标准品牌列和清空值不会被旧 config 同名字段覆盖", () => {
|
||||||
|
const result = projectBrandAliases(
|
||||||
|
{
|
||||||
|
name: "标准名称",
|
||||||
|
avatarUrl: "标准头像",
|
||||||
|
contactPhone: "新电话",
|
||||||
|
description: "新简介",
|
||||||
|
address: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "旧名称",
|
||||||
|
avatarUrl: "旧头像",
|
||||||
|
contactPhone: "旧电话",
|
||||||
|
description: "旧简介",
|
||||||
|
address: "旧地址",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert.equal(result.name, "标准名称");
|
||||||
|
assert.equal(result.avatarUrl, "标准头像");
|
||||||
|
assert.equal(result.contactPhone, "新电话");
|
||||||
|
assert.equal(result.description, "新简介");
|
||||||
|
assert.equal(result.address, null);
|
||||||
|
assert.equal(result.studioAddress, "");
|
||||||
|
const cleared = projectBrandAliases(
|
||||||
|
{ contactPhone: null, description: null },
|
||||||
|
{ phone: "旧电话", slogan: "旧简介" },
|
||||||
|
);
|
||||||
|
assert.equal(cleared.phone, "");
|
||||||
|
assert.equal(cleared.slogan, "");
|
||||||
|
});
|
||||||
@@ -0,0 +1,409 @@
|
|||||||
|
import ts from "typescript";
|
||||||
|
|
||||||
|
// 静态检查不推断运行时成功;未知表达式保留为 review。
|
||||||
|
export function diagnoseTemplate(manifest, source, file = "taro/index.tsx") {
|
||||||
|
const issues = [];
|
||||||
|
const regions = [];
|
||||||
|
const targets = [];
|
||||||
|
const fields = [];
|
||||||
|
const add = (code, context, message, severity = "blocker") =>
|
||||||
|
issues.push({ code, severity, file, ...context, message });
|
||||||
|
for (const section of manifest.admin?.sections ?? []) {
|
||||||
|
for (const target of section.previewTargets ?? []) {
|
||||||
|
const owned = (section.fields ?? []).filter((field) => field.previewTarget === target.key);
|
||||||
|
// 与 PresentationEditor.previewTargetSource 的优先级一致。
|
||||||
|
const source =
|
||||||
|
["offering", "trust", "brand"].find((kind) =>
|
||||||
|
owned.some((field) => field.binding?.startsWith(kind + ".")),
|
||||||
|
) ?? section.target;
|
||||||
|
targets.push({ ...target, page: section.page, source });
|
||||||
|
}
|
||||||
|
for (const field of section.fields ?? []) fields.push({ ...field, page: section.page });
|
||||||
|
}
|
||||||
|
for (const field of manifest.templateFields ?? []) fields.push(field);
|
||||||
|
for (const declaration of manifest.trustContentTypes ?? []) {
|
||||||
|
for (const page of declaration.pages ?? []) {
|
||||||
|
const key = "trust:" + declaration.type;
|
||||||
|
targets.push({ key, page, source: "trust", implicit: true });
|
||||||
|
for (const name of ["title", "summary", "content"])
|
||||||
|
if (!declaration.hideStandardFields?.includes(name))
|
||||||
|
fields.push({ binding: "trust." + name, previewTarget: key, page });
|
||||||
|
for (const field of (declaration.configFields ?? []).filter((field) => {
|
||||||
|
const target = declaration.previewTargets?.find(
|
||||||
|
(target) => target.key === field.previewTarget,
|
||||||
|
);
|
||||||
|
return !target?.page || target.page === page;
|
||||||
|
}))
|
||||||
|
fields.push({ ...field, previewTarget: field.previewTarget ?? key, page });
|
||||||
|
}
|
||||||
|
for (const target of declaration.previewTargets ?? []) {
|
||||||
|
if (!target.page)
|
||||||
|
add(
|
||||||
|
"TARGET_PAGE_UNSPECIFIED",
|
||||||
|
{ target: target.key },
|
||||||
|
"信任子区域需要明确展示页面,不能自动出现在该类型的全部页面。",
|
||||||
|
);
|
||||||
|
targets.push({ ...target, page: target.page ?? declaration.pages?.[0], source: "trust" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const matching = (key, page) => targets.find((t) => t.key === key && t.page === page);
|
||||||
|
for (const field of fields) {
|
||||||
|
const target = matching(field.previewTarget, field.page);
|
||||||
|
const context = { page: field.page, target: field.previewTarget, binding: field.binding };
|
||||||
|
if (!target) add("FIELD_TARGET_MISSING", context, "字段必须绑定同页已声明区域。");
|
||||||
|
else if (target.composite)
|
||||||
|
add("COMPOSITE_HAS_FIELDS", context, "组合区域应导航到字段所属子区。");
|
||||||
|
else if (field.binding?.split(".")[0] !== target.source)
|
||||||
|
add(
|
||||||
|
"TARGET_SOURCE_MISMATCH",
|
||||||
|
context,
|
||||||
|
"区域来源与字段不一致,现有单记录编辑器无法完整保存。",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (const target of targets) {
|
||||||
|
const context = { page: target.page, target: target.key };
|
||||||
|
if (targets.filter((t) => t.key === target.key && t.page === target.page).length > 1)
|
||||||
|
add("DUPLICATE_TARGET", context, "同页区域标识必须唯一。");
|
||||||
|
if (target.composite) {
|
||||||
|
if (!target.children?.length) add("COMPOSITE_EMPTY", context, "组合区域必须有子区。");
|
||||||
|
for (const child of target.children ?? [])
|
||||||
|
if (!matching(child, target.page) || matching(child, target.page)?.composite)
|
||||||
|
add("COMPOSITE_CHILD_INVALID", context, "子区必须是同页直接区域:" + child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const ast = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
||||||
|
for (const diagnostic of ast.parseDiagnostics)
|
||||||
|
add("RENDERER_PARSE_ERROR", {}, ts.flattenDiagnosticMessageText(diagnostic.messageText, " "));
|
||||||
|
const standardBrand = new Set([
|
||||||
|
"name",
|
||||||
|
"tagline",
|
||||||
|
"description",
|
||||||
|
"avatarUrl",
|
||||||
|
"contactPhone",
|
||||||
|
"contactWechat",
|
||||||
|
"address",
|
||||||
|
"hours",
|
||||||
|
"deliveryNote",
|
||||||
|
"coverUrl",
|
||||||
|
]);
|
||||||
|
const normalize = (path) => {
|
||||||
|
if (
|
||||||
|
path.startsWith("brand.") &&
|
||||||
|
!path.startsWith("brand.config.") &&
|
||||||
|
!standardBrand.has(path.split(".")[1])
|
||||||
|
)
|
||||||
|
return path.replace("brand.", "brand.config.");
|
||||||
|
return path;
|
||||||
|
};
|
||||||
|
function inspectFunction(fn) {
|
||||||
|
const aliases = new Map([["workspace", "workspace"]]);
|
||||||
|
const offeringAliases = {
|
||||||
|
image: "offering.config.detailHero",
|
||||||
|
desc: "offering.summary",
|
||||||
|
priceRange: "offering.priceText",
|
||||||
|
category: "offering.config.categoryLabel",
|
||||||
|
area: "offering.config.area",
|
||||||
|
series: "offering.config.series",
|
||||||
|
keywords: "offering.config.keywords",
|
||||||
|
details: "offering.config.details",
|
||||||
|
};
|
||||||
|
const resolve = (node) => {
|
||||||
|
if (!node) return undefined;
|
||||||
|
if (ts.isIdentifier(node)) return aliases.get(node.text);
|
||||||
|
if (ts.isPropertyAccessExpression(node)) {
|
||||||
|
const base = resolve(node.expression);
|
||||||
|
if (!base) return undefined;
|
||||||
|
if (base === "offering" && offeringAliases[node.name.text])
|
||||||
|
return offeringAliases[node.name.text];
|
||||||
|
if (base === "offering.presentation") return "offering.config." + node.name.text;
|
||||||
|
const path = base + "." + node.name.text;
|
||||||
|
if (path === "workspace.brand") return "brand";
|
||||||
|
if (path === "workspace.templateData") return "brand.config.templateData";
|
||||||
|
if (path === "workspace.trustPresentation") return "trust.config";
|
||||||
|
if (path === "workspace.offerings") return "offering[]";
|
||||||
|
if (path === "workspace.trustItems") return "trust[]";
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
if (ts.isCallExpression(node) && ["object", "rows"].includes(node.expression.getText(ast)))
|
||||||
|
return resolve(node.arguments[0]);
|
||||||
|
if (ts.isCallExpression(node) && node.expression.getText(ast) === "offering")
|
||||||
|
return "offering";
|
||||||
|
if (ts.isCallExpression(node) && node.expression.getText(ast) === "slot") return "trust";
|
||||||
|
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
|
||||||
|
const base = resolve(node.expression.expression);
|
||||||
|
if (["filter", "slice"].includes(node.expression.name.text)) return base;
|
||||||
|
if (node.expression.name.text === "find") return base?.replace(/\[\]$/, "");
|
||||||
|
if (node.expression.name.text === "map" && node.arguments[0]?.getText(ast) === "offering")
|
||||||
|
return "offering[]";
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
ts.isCallExpression(node) &&
|
||||||
|
node.expression.getText(ast) === "presentation" &&
|
||||||
|
node.arguments[1] &&
|
||||||
|
ts.isStringLiteral(node.arguments[1])
|
||||||
|
)
|
||||||
|
return "brand.config.visualPresentation." + node.arguments[1].text;
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
function collect(node) {
|
||||||
|
if (node !== fn && ts.isFunctionDeclaration(node)) return;
|
||||||
|
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
||||||
|
const path = resolve(node.initializer);
|
||||||
|
if (path) aliases.set(node.name.text, path);
|
||||||
|
}
|
||||||
|
ts.forEachChild(node, collect);
|
||||||
|
}
|
||||||
|
collect(fn);
|
||||||
|
function visit(node, active) {
|
||||||
|
if (
|
||||||
|
ts.isCallExpression(node) &&
|
||||||
|
ts.isPropertyAccessExpression(node.expression) &&
|
||||||
|
node.expression.name.text === "map"
|
||||||
|
) {
|
||||||
|
const collection = resolve(node.expression.expression);
|
||||||
|
const callback = node.arguments[0];
|
||||||
|
if (
|
||||||
|
collection &&
|
||||||
|
callback &&
|
||||||
|
ts.isArrowFunction(callback) &&
|
||||||
|
callback.parameters[0] &&
|
||||||
|
ts.isIdentifier(callback.parameters[0].name)
|
||||||
|
) {
|
||||||
|
const name = callback.parameters[0].name.text;
|
||||||
|
const previous = aliases.get(name);
|
||||||
|
aliases.set(name, collection.replace(/\[\]$/, ""));
|
||||||
|
visit(callback.body, active);
|
||||||
|
if (previous) aliases.set(name, previous);
|
||||||
|
else aliases.delete(name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ts.isConditionalExpression(node)) {
|
||||||
|
add(
|
||||||
|
"CONDITIONAL_RENDER_REVIEW",
|
||||||
|
{
|
||||||
|
target: active?.target,
|
||||||
|
line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1,
|
||||||
|
},
|
||||||
|
"条件显示需验证全部分支与空数据入口。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
visit(node.whenTrue, active);
|
||||||
|
visit(node.whenFalse, active);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
ts.isBinaryExpression(node) &&
|
||||||
|
node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken
|
||||||
|
) {
|
||||||
|
add(
|
||||||
|
"CONDITIONAL_RENDER_REVIEW",
|
||||||
|
{
|
||||||
|
target: active?.target,
|
||||||
|
line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1,
|
||||||
|
},
|
||||||
|
"条件显示需验证全部分支与空数据入口。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
visit(node.right, active);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
||||||
|
const opening = ts.isJsxElement(node) ? node.openingElement : node;
|
||||||
|
const attrs = opening.attributes.properties;
|
||||||
|
const attr = attrs.find(
|
||||||
|
(a) => ts.isJsxAttribute(a) && a.name.getText(ast) === "data-editor-target",
|
||||||
|
);
|
||||||
|
if (attr) {
|
||||||
|
if (attr.initializer && ts.isStringLiteral(attr.initializer)) {
|
||||||
|
const key = attr.initializer.text;
|
||||||
|
const candidates = targets.filter((t) => t.key === key);
|
||||||
|
active = {
|
||||||
|
target: key,
|
||||||
|
page: candidates[0]?.page,
|
||||||
|
line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1,
|
||||||
|
bindings: new Set(),
|
||||||
|
};
|
||||||
|
regions.push(active);
|
||||||
|
if (!candidates.length)
|
||||||
|
add("RENDER_TARGET_UNDECLARED", active, "renderer 区域没有声明。");
|
||||||
|
if (
|
||||||
|
candidates.some((t) => ["trust", "offering"].includes(t.source)) &&
|
||||||
|
!attrs.some(
|
||||||
|
(a) => ts.isJsxAttribute(a) && a.name.getText(ast) === "data-editor-record-id",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
add(
|
||||||
|
"RECORD_ID_MISSING",
|
||||||
|
{ target: key, page: active.page, line: active.line },
|
||||||
|
"记录区域必须携带实际记录 ID。",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
add(
|
||||||
|
"DYNAMIC_TARGET_REVIEW",
|
||||||
|
{ line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1 },
|
||||||
|
"动态目标需用真实 manifest 和实际记录验证分支。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
active = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 属性中的事件和 recordId 不属于展示变量,只检查图片等展示属性。
|
||||||
|
for (const a of attrs)
|
||||||
|
if (
|
||||||
|
ts.isJsxAttribute(a) &&
|
||||||
|
["src", "title", "placeholder", "value"].includes(a.name.getText(ast)) &&
|
||||||
|
a.initializer
|
||||||
|
)
|
||||||
|
visit(a.initializer, active);
|
||||||
|
if (ts.isJsxElement(node)) for (const child of node.children) visit(child, active);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ts.isPropertyAccessExpression(node) && !ts.isPropertyAccessExpression(node.parent)) {
|
||||||
|
if (ts.isElementAccessExpression(node.parent) && node.parent.expression === node) return;
|
||||||
|
const path = resolve(node);
|
||||||
|
if (path && /^(brand|trust|offering)\./.test(path)) {
|
||||||
|
const binding = normalize(path);
|
||||||
|
if (active) active.bindings.add(binding);
|
||||||
|
else
|
||||||
|
add(
|
||||||
|
"UNSCOPED_RENDER_VALUE",
|
||||||
|
{ binding, line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1 },
|
||||||
|
"展示变量没有可证明的编辑区域。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
} else if (active)
|
||||||
|
add(
|
||||||
|
"UNRESOLVED_RENDER_VALUE",
|
||||||
|
{
|
||||||
|
target: active.target,
|
||||||
|
page: active.page,
|
||||||
|
expression: node.getText(ast),
|
||||||
|
line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1,
|
||||||
|
},
|
||||||
|
"需要核对循环项或间接映射,不能视为已覆盖。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (ts.isElementAccessExpression(node) && active)
|
||||||
|
add(
|
||||||
|
"DYNAMIC_VALUE_REVIEW",
|
||||||
|
{ target: active.target, page: active.page, expression: node.getText(ast) },
|
||||||
|
"动态索引必须验证实际分支。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
ts.forEachChild(node, (child) => visit(child, active));
|
||||||
|
}
|
||||||
|
// 只从 JSX 开始,避免把数据准备和事件中的读取当成展示值。
|
||||||
|
function roots(node) {
|
||||||
|
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) return visit(node, undefined);
|
||||||
|
ts.forEachChild(node, roots);
|
||||||
|
}
|
||||||
|
roots(fn);
|
||||||
|
}
|
||||||
|
for (const statement of ast.statements) {
|
||||||
|
if (ts.isFunctionDeclaration(statement)) inspectFunction(statement);
|
||||||
|
else {
|
||||||
|
const check = (node) => {
|
||||||
|
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
||||||
|
add(
|
||||||
|
"UNSUPPORTED_COMPONENT_REVIEW",
|
||||||
|
{ line: ast.getLineAndCharacterOfPosition(node.getStart(ast)).line + 1 },
|
||||||
|
"非函数声明组件需扩展解析器或补真实交互验证,不能静态认定覆盖。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ts.forEachChild(node, check);
|
||||||
|
};
|
||||||
|
check(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const region of regions) {
|
||||||
|
const context = { page: region.page, target: region.target, line: region.line };
|
||||||
|
const declared = fields.filter(
|
||||||
|
(f) => f.previewTarget === region.target && f.page === region.page,
|
||||||
|
);
|
||||||
|
for (const binding of region.bindings)
|
||||||
|
if (
|
||||||
|
!(
|
||||||
|
region.page === "detail" && binding.startsWith("offering.")
|
||||||
|
? fields.filter((f) => f.binding?.startsWith("offering."))
|
||||||
|
: declared
|
||||||
|
).some((f) => f.binding === binding || binding.startsWith(f.binding + "."))
|
||||||
|
)
|
||||||
|
add(
|
||||||
|
"REGION_FIELD_MISSING",
|
||||||
|
{ ...context, binding },
|
||||||
|
"选区实际展示该变量但当前面板没有对应字段;补真实绑定或明确只读模式。",
|
||||||
|
);
|
||||||
|
for (const binding of region.bindings) {
|
||||||
|
const field = declared.find((f) => f.input === "list" && binding.startsWith(f.binding + "."));
|
||||||
|
if (!field || field.itemValueKey) continue;
|
||||||
|
const child = binding.slice(field.binding.length + 1).split(".")[0];
|
||||||
|
if (["map", "slice", "length", "filter", "join"].includes(child)) continue;
|
||||||
|
if (!field.itemFields?.some((item) => item.key === child))
|
||||||
|
add(
|
||||||
|
"LIST_FIELD_MISSING",
|
||||||
|
{ ...context, binding },
|
||||||
|
"列表展示的子字段必须在 itemFields 中提供编辑入口。",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const target of targets)
|
||||||
|
if (!target.implicit && !regions.some((r) => r.target === target.key))
|
||||||
|
add(
|
||||||
|
"TARGET_RENDER_UNVERIFIED",
|
||||||
|
{ page: target.page, target: target.key },
|
||||||
|
"未找到字面量区域,需验证动态目标或组件路径。",
|
||||||
|
"review",
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
template: manifest.packageKey,
|
||||||
|
staticStatus: issues.length ? "fail" : "pass",
|
||||||
|
completionStatus: "unverified",
|
||||||
|
requiredEvidence: [
|
||||||
|
"real-manifest-interaction",
|
||||||
|
"save-reload-publish-isolation",
|
||||||
|
"visual-reference",
|
||||||
|
"empty-error-branches",
|
||||||
|
],
|
||||||
|
regions: regions.map((r) => ({ ...r, bindings: [...r.bindings] })),
|
||||||
|
issues,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const REVIEW_KEY_FIELDS = ["file", "page", "target", "binding", "line", "message"];
|
||||||
|
|
||||||
|
function reviewKey(item) {
|
||||||
|
return JSON.stringify(
|
||||||
|
Object.fromEntries(REVIEW_KEY_FIELDS.map((key) => [key, item[key] ?? null])),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function applyManualReview(reports, reviews, reviewScope) {
|
||||||
|
if (reviewScope !== "人工映射审查,保留原诊断,不是自动豁免或全条件组合证明")
|
||||||
|
throw new Error("Manual review registry has an unsupported scope");
|
||||||
|
const byKey = new Map();
|
||||||
|
for (const item of reviews) {
|
||||||
|
if (item.severity !== "review" || item.reviewStatus !== "source-reviewed" || !item.decision)
|
||||||
|
throw new Error("Manual review registry contains an invalid entry");
|
||||||
|
byKey.set(reviewKey(item), item);
|
||||||
|
}
|
||||||
|
for (const report of reports) {
|
||||||
|
let unresolved = 0;
|
||||||
|
report.issues.forEach((issue) => {
|
||||||
|
const reviewed = issue.severity === "review" && byKey.get(reviewKey(issue));
|
||||||
|
if (reviewed) issue.reviewStatus = "source-reviewed";
|
||||||
|
else unresolved++;
|
||||||
|
});
|
||||||
|
report.reviewedIssues = report.issues.length - unresolved;
|
||||||
|
report.unresolvedIssues = unresolved;
|
||||||
|
report.staticStatus = report.issues.some(
|
||||||
|
(issue) => issue.severity === "blocker" || issue.reviewStatus !== "source-reviewed",
|
||||||
|
)
|
||||||
|
? "fail"
|
||||||
|
: "pass";
|
||||||
|
}
|
||||||
|
return reports;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
const fs = require("node:fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
|
||||||
|
const root = path.resolve(__dirname, "..");
|
||||||
|
const source = path.join(root, "apps/taro/dist/template-preview/h5");
|
||||||
|
const destination = path.join(root, "apps/admin/public/template-preview");
|
||||||
|
|
||||||
|
if (!fs.existsSync(path.join(source, "index.html"))) {
|
||||||
|
throw new Error("Unified template preview build is missing; run build:preview first.");
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.rmSync(destination, { recursive: true, force: true });
|
||||||
|
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
||||||
|
fs.cpSync(source, destination, { recursive: true });
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { applyManualReview, diagnoseTemplate } from "./lib/template-doctor.mjs";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const options = {};
|
||||||
|
for (let i = 0; i < args.length; i += 2) {
|
||||||
|
if (!["--template", "--output"].includes(args[i]) || !args[i + 1])
|
||||||
|
throw new Error("Usage: template-doctor [--template key] [--output path]");
|
||||||
|
options[args[i]] = args[i + 1];
|
||||||
|
}
|
||||||
|
const reports = [];
|
||||||
|
for (const dir of fs.readdirSync(path.join(root, "packages")).sort()) {
|
||||||
|
const manifestPath = path.join(root, "packages", dir, "template.json");
|
||||||
|
if (!dir.startsWith("template-") || !fs.existsSync(manifestPath)) continue;
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||||
|
if (options["--template"] && manifest.packageKey !== options["--template"]) continue;
|
||||||
|
const renderer = path.join(root, "packages", dir, "taro/index.tsx");
|
||||||
|
if (!fs.existsSync(renderer)) throw new Error("Missing renderer: " + renderer);
|
||||||
|
reports.push(
|
||||||
|
diagnoseTemplate(manifest, fs.readFileSync(renderer, "utf8"), path.relative(root, renderer)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!reports.length) throw new Error("No matching templates found");
|
||||||
|
const registryPath = path.join(
|
||||||
|
root,
|
||||||
|
".codex-tasks/template-audit-execution/raw/manual-review.json",
|
||||||
|
);
|
||||||
|
const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"));
|
||||||
|
applyManualReview(reports, registry.items, registry.scope);
|
||||||
|
const report = { schemaVersion: 1, completionStatus: "unverified", templates: reports };
|
||||||
|
const output = JSON.stringify(report, null, 2) + "\n";
|
||||||
|
if (options["--output"]) {
|
||||||
|
fs.mkdirSync(path.dirname(path.resolve(options["--output"])), { recursive: true });
|
||||||
|
fs.writeFileSync(options["--output"], output);
|
||||||
|
}
|
||||||
|
process.stdout.write(output);
|
||||||
|
process.exitCode = reports.some((r) => r.staticStatus === "fail") ? 1 : 0;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message);
|
||||||
|
process.exitCode = 2;
|
||||||
|
}
|
||||||
@@ -0,0 +1,340 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import test from "node:test";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { applyManualReview, diagnoseTemplate } from "../lib/template-doctor.mjs";
|
||||||
|
|
||||||
|
test("真实模板自动发现并读取完整声明,生成可追溯区域报告", () => {
|
||||||
|
const root = new URL("../../packages/", import.meta.url);
|
||||||
|
const dirs = fs
|
||||||
|
.readdirSync(root)
|
||||||
|
.filter(
|
||||||
|
(dir) => dir.startsWith("template-") && fs.existsSync(new URL(dir + "/template.json", root)),
|
||||||
|
);
|
||||||
|
assert.ok(dirs.length > 0);
|
||||||
|
for (const dir of dirs) {
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(new URL(dir + "/template.json", root), "utf8"));
|
||||||
|
const source = fs.readFileSync(new URL(dir + "/taro/index.tsx", root), "utf8");
|
||||||
|
const report = diagnoseTemplate(manifest, source);
|
||||||
|
assert.equal(report.template, manifest.packageKey);
|
||||||
|
assert.ok(report.regions.length > 0);
|
||||||
|
assert.equal(report.completionStatus, "unverified");
|
||||||
|
for (const region of report.regions) {
|
||||||
|
for (const binding of region.bindings) {
|
||||||
|
const fields = [
|
||||||
|
...manifest.admin.sections.flatMap((s) => s.fields),
|
||||||
|
...(manifest.templateFields ?? []),
|
||||||
|
...(manifest.trustContentTypes ?? []).flatMap((t) =>
|
||||||
|
(t.configFields ?? []).map((f) => ({
|
||||||
|
...f,
|
||||||
|
previewTarget: f.previewTarget ?? "trust:" + t.type,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
...(manifest.trustContentTypes ?? []).flatMap((t) =>
|
||||||
|
["title", "summary", "content"]
|
||||||
|
.filter((name) => !t.hideStandardFields?.includes(name))
|
||||||
|
.map((name) => ({ binding: "trust." + name, previewTarget: "trust:" + t.type })),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
assert.ok(
|
||||||
|
fields.some(
|
||||||
|
(f) =>
|
||||||
|
(f.previewTarget === region.target ||
|
||||||
|
(region.page === "detail" && f.binding.startsWith("offering."))) &&
|
||||||
|
(f.binding === binding || binding.startsWith(f.binding + ".")),
|
||||||
|
) ||
|
||||||
|
report.issues.some(
|
||||||
|
(i) =>
|
||||||
|
i.code === "REGION_FIELD_MISSING" &&
|
||||||
|
i.target === region.target &&
|
||||||
|
i.binding === binding,
|
||||||
|
),
|
||||||
|
`${manifest.packageKey}: ${region.target} ${binding}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("CLI 自动发现全部模板,问题退出 1,未知模板退出 2", () => {
|
||||||
|
const cli = new URL("../template-doctor.mjs", import.meta.url);
|
||||||
|
const all = spawnSync(process.execPath, [cli.pathname], { encoding: "utf8" });
|
||||||
|
const report = JSON.parse(all.stdout);
|
||||||
|
assert.equal(all.status, report.templates.some((t) => t.staticStatus === "fail") ? 1 : 0);
|
||||||
|
assert.ok(report.templates.length > 0);
|
||||||
|
const missing = spawnSync(
|
||||||
|
process.execPath,
|
||||||
|
[cli.pathname, "--template", "missing-template-fixture"],
|
||||||
|
{ encoding: "utf8" },
|
||||||
|
);
|
||||||
|
assert.equal(missing.status, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("人工审阅登记只能匹配真实 review,新问题仍会失败", () => {
|
||||||
|
const report = {
|
||||||
|
template: "fixture",
|
||||||
|
staticStatus: "pass",
|
||||||
|
completionStatus: "unverified",
|
||||||
|
issues: [],
|
||||||
|
};
|
||||||
|
const reviewed = {
|
||||||
|
file: "taro/index.tsx",
|
||||||
|
page: "home",
|
||||||
|
target: "identity",
|
||||||
|
binding: null,
|
||||||
|
line: 20,
|
||||||
|
message: "条件显示需验证全部分支与空数据入口。",
|
||||||
|
severity: "review",
|
||||||
|
reviewStatus: "source-reviewed",
|
||||||
|
decision: "已核对空数据分支。",
|
||||||
|
};
|
||||||
|
const clone = (issue) => structuredClone({ ...report, issues: issue ? [issue] : [] });
|
||||||
|
const issue = {
|
||||||
|
code: "CONDITIONAL_RENDER_REVIEW",
|
||||||
|
file: "taro/index.tsx",
|
||||||
|
page: "home",
|
||||||
|
target: "identity",
|
||||||
|
line: 20,
|
||||||
|
message: "条件显示需验证全部分支与空数据入口。",
|
||||||
|
severity: "review",
|
||||||
|
};
|
||||||
|
const empty = applyManualReview(
|
||||||
|
[clone()],
|
||||||
|
[],
|
||||||
|
"人工映射审查,保留原诊断,不是自动豁免或全条件组合证明",
|
||||||
|
);
|
||||||
|
assert.equal(empty[0].staticStatus, "pass");
|
||||||
|
assert.equal(
|
||||||
|
applyManualReview(
|
||||||
|
[clone(issue)],
|
||||||
|
[reviewed],
|
||||||
|
"人工映射审查,保留原诊断,不是自动豁免或全条件组合证明",
|
||||||
|
)[0].staticStatus,
|
||||||
|
"pass",
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
applyManualReview(
|
||||||
|
[clone(issue)],
|
||||||
|
[],
|
||||||
|
"人工映射审查,保留原诊断,不是自动豁免或全条件组合证明",
|
||||||
|
)[0].staticStatus,
|
||||||
|
"fail",
|
||||||
|
);
|
||||||
|
assert.throws(() =>
|
||||||
|
applyManualReview(
|
||||||
|
[clone(issue)],
|
||||||
|
[{ ...reviewed, severity: "blocker" }],
|
||||||
|
"人工映射审查,保留原诊断,不是自动豁免或全条件组合证明",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert.throws(() =>
|
||||||
|
applyManualReview(
|
||||||
|
[clone(issue)],
|
||||||
|
[{ ...reviewed, reviewStatus: "verified" }],
|
||||||
|
"人工映射审查,保留原诊断,不是自动豁免或全条件组合证明",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert.throws(() => applyManualReview([clone(issue)], [reviewed], "unsupported scope"));
|
||||||
|
});
|
||||||
|
|
||||||
|
const manifest = () => ({
|
||||||
|
packageKey: "independent-template",
|
||||||
|
admin: {
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
page: "home",
|
||||||
|
target: "brand",
|
||||||
|
previewTargets: [{ key: "identity", label: "人物介绍" }],
|
||||||
|
fields: [
|
||||||
|
{ binding: "brand.config.visualPresentation.home.badge", previewTarget: "identity" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const renderer =
|
||||||
|
'function Home({workspace}) { const b = workspace.brand; const p = presentation(workspace, "home"); return <View data-editor-target="identity"><Text>{b.founder}</Text><Text>{p.badge}</Text></View>; }';
|
||||||
|
test("整卡仅有标签字段不能通过,报告具体缺失变量", () => {
|
||||||
|
const result = diagnoseTemplate(manifest(), renderer);
|
||||||
|
assert.equal(result.staticStatus, "fail");
|
||||||
|
assert.ok(
|
||||||
|
result.issues.some(
|
||||||
|
(i) => i.code === "REGION_FIELD_MISSING" && i.binding === "brand.config.founder",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("完整字段通过静态检查但不能被宣称模板完成", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].fields.push({
|
||||||
|
binding: "brand.config.founder",
|
||||||
|
previewTarget: "identity",
|
||||||
|
});
|
||||||
|
const result = diagnoseTemplate(input, renderer);
|
||||||
|
assert.equal(result.staticStatus, "pass");
|
||||||
|
assert.equal(result.completionStatus, "unverified");
|
||||||
|
});
|
||||||
|
test("嵌套子区独立检查,父区字段不能遮蔽子区缺失", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].previewTargets.push({ key: "child", label: "姓名" });
|
||||||
|
input.admin.sections[0].fields.push({
|
||||||
|
binding: "brand.config.founder",
|
||||||
|
previewTarget: "identity",
|
||||||
|
});
|
||||||
|
const result = diagnoseTemplate(
|
||||||
|
input,
|
||||||
|
renderer.replace(
|
||||||
|
"<Text>{b.founder}</Text>",
|
||||||
|
'<Text data-editor-target="child">{b.founder}</Text>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert.ok(result.issues.some((i) => i.code === "REGION_FIELD_MISSING" && i.target === "child"));
|
||||||
|
});
|
||||||
|
test("组合根上的模板字段同样算误绑", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].previewTargets[0].composite = true;
|
||||||
|
input.templateFields = [
|
||||||
|
{ page: "home", binding: "brand.config.templateData.method", previewTarget: "identity" },
|
||||||
|
];
|
||||||
|
const result = diagnoseTemplate(input, renderer);
|
||||||
|
assert.ok(
|
||||||
|
result.issues.some((i) => i.code === "COMPOSITE_HAS_FIELDS" && i.binding.endsWith(".method")),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("跨页目标不能作为合法字段入口", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.templateFields = [
|
||||||
|
{ page: "profile", binding: "brand.config.templateData.method", previewTarget: "identity" },
|
||||||
|
];
|
||||||
|
assert.ok(
|
||||||
|
diagnoseTemplate(input, renderer).issues.some((i) => i.code === "FIELD_TARGET_MISSING"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("信任子目标必须声明页面,品牌字段不可归给 trust 记录编辑器", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.trustContentTypes = [
|
||||||
|
{
|
||||||
|
type: "credential",
|
||||||
|
pages: ["home", "profile"],
|
||||||
|
previewTargets: [{ key: "stats" }],
|
||||||
|
configFields: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
input.admin.sections[0].fields.push({ binding: "brand.description", previewTarget: "stats" });
|
||||||
|
const result = diagnoseTemplate(input, renderer);
|
||||||
|
assert.ok(result.issues.some((i) => i.code === "TARGET_PAGE_UNSPECIFIED"));
|
||||||
|
assert.ok(result.issues.some((i) => i.code === "TARGET_SOURCE_MISMATCH"));
|
||||||
|
});
|
||||||
|
test("动态路径保留 review,不能静默绿色", () => {
|
||||||
|
const result = diagnoseTemplate(manifest(), renderer.replace("b.founder", "b[key]"));
|
||||||
|
assert.ok(
|
||||||
|
result.issues.some((i) => i.code === "DYNAMIC_VALUE_REVIEW" && i.severity === "review"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("记录区域缺失 recordId 会报告", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].target = "offering";
|
||||||
|
input.admin.sections[0].fields = [{ binding: "offering.name", previewTarget: "identity" }];
|
||||||
|
assert.ok(diagnoseTemplate(input, renderer).issues.some((i) => i.code === "RECORD_ID_MISSING"));
|
||||||
|
});
|
||||||
|
test("section 为 inquiry 但字段全是品牌时按运行时推导品牌来源", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].target = "inquiry";
|
||||||
|
input.admin.sections[0].fields.push({
|
||||||
|
binding: "brand.config.founder",
|
||||||
|
previewTarget: "identity",
|
||||||
|
});
|
||||||
|
assert.equal(diagnoseTemplate(input, renderer).staticStatus, "pass");
|
||||||
|
});
|
||||||
|
test("同一区域混合记录和品牌字段不能豁免", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].fields.push({ binding: "offering.name", previewTarget: "identity" });
|
||||||
|
assert.ok(
|
||||||
|
diagnoseTemplate(input, renderer).issues.some((i) => i.code === "TARGET_SOURCE_MISMATCH"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("箭头组件不能被跳过而静默通过", () => {
|
||||||
|
assert.ok(
|
||||||
|
diagnoseTemplate(
|
||||||
|
manifest(),
|
||||||
|
'const Home = () => <View data-editor-target="identity">{brand.founder}</View>',
|
||||||
|
).issues.some((i) => i.code === "UNSUPPORTED_COMPONENT_REVIEW"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test("条件只控制子区显示时不误判成父区展示字段", () => {
|
||||||
|
const input = manifest();
|
||||||
|
const source =
|
||||||
|
'function Home({workspace}) { const b=workspace.brand; return <View data-editor-target="identity">{b.avatarUrl && <Text>头像</Text>}</View>; }';
|
||||||
|
const result = diagnoseTemplate(input, source);
|
||||||
|
assert.ok(result.issues.some((i) => i.code === "CONDITIONAL_RENDER_REVIEW"));
|
||||||
|
assert.ok(!result.issues.some((i) => i.code === "REGION_FIELD_MISSING"));
|
||||||
|
});
|
||||||
|
test("JSON 合法但 TSX 损坏不能通过诊断", () => {
|
||||||
|
assert.ok(
|
||||||
|
diagnoseTemplate(manifest(), "function Home( { return <View>").issues.some(
|
||||||
|
(i) => i.code === "RENDERER_PARSE_ERROR",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("循环业务卡片追踪实际字段,删除字段会失败", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].target = "offering";
|
||||||
|
input.admin.sections[0].fields = [{ binding: "offering.name", previewTarget: "identity" }];
|
||||||
|
const source =
|
||||||
|
'function Home({workspace}) { return <View>{workspace.offerings.map(offering).map(item => <View data-editor-target="identity" data-editor-record-id={item.id}>{item.name}{item.area}</View>)}</View>; }';
|
||||||
|
const result = diagnoseTemplate(input, source);
|
||||||
|
assert.ok(
|
||||||
|
result.issues.some(
|
||||||
|
(i) => i.code === "REGION_FIELD_MISSING" && i.binding === "offering.config.area",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
input.admin.sections[0].fields.push({
|
||||||
|
binding: "offering.config.area",
|
||||||
|
previewTarget: "identity",
|
||||||
|
});
|
||||||
|
assert.ok(!diagnoseTemplate(input, source).issues.some((i) => i.code === "REGION_FIELD_MISSING"));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("结构化信任列表追踪子字段,不跨循环混用别名", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].target = "trust";
|
||||||
|
input.admin.sections[0].fields = [{ binding: "trust.config.stats", previewTarget: "identity" }];
|
||||||
|
const source =
|
||||||
|
'function Home({workspace}) { const t=workspace.trustPresentation; return <View data-editor-target="identity" data-editor-record-id="fixture">{t.stats.map(item => <Text>{item.value}</Text>)}</View>; }';
|
||||||
|
const result = diagnoseTemplate(input, source);
|
||||||
|
assert.ok(result.regions[0].bindings.includes("trust.config.stats.value"));
|
||||||
|
assert.ok(!result.issues.some((i) => i.code === "REGION_FIELD_MISSING"));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("动态索引保留待核查,但不把容器对象误当可编辑字段", () => {
|
||||||
|
const input = manifest();
|
||||||
|
const source =
|
||||||
|
'function Home({workspace}) { const b=workspace.brand; return <View data-editor-target="identity">{b.config[key]}</View>; }';
|
||||||
|
const result = diagnoseTemplate(input, source);
|
||||||
|
assert.ok(result.issues.some((i) => i.code === "DYNAMIC_VALUE_REVIEW"));
|
||||||
|
assert.ok(
|
||||||
|
!result.issues.some((i) => i.code === "REGION_FIELD_MISSING" && i.binding === "brand.config"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("列表声明存在仍须检查每个展示子字段", () => {
|
||||||
|
const input = manifest();
|
||||||
|
input.admin.sections[0].target = "trust";
|
||||||
|
input.admin.sections[0].fields = [
|
||||||
|
{
|
||||||
|
binding: "trust.config.stats",
|
||||||
|
previewTarget: "identity",
|
||||||
|
input: "list",
|
||||||
|
itemFields: [{ key: "value" }],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const source =
|
||||||
|
'function Home({workspace}) { const t=workspace.trustPresentation; return <View data-editor-target="identity" data-editor-record-id="fixture">{t.stats.map(item => <Text>{item.value}{item.sub}</Text>)}</View>; }';
|
||||||
|
assert.ok(
|
||||||
|
diagnoseTemplate(input, source).issues.some(
|
||||||
|
(i) => i.code === "LIST_FIELD_MISSING" && i.binding === "trust.config.stats.sub",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
input.admin.sections[0].fields[0].itemFields.push({ key: "sub" });
|
||||||
|
assert.ok(!diagnoseTemplate(input, source).issues.some((i) => i.code === "LIST_FIELD_MISSING"));
|
||||||
|
});
|
||||||
Reference in new issue
Block a user