diff --git a/README.md b/README.md index 78e12c7..976dae2 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,9 @@ php start.php start ## 页面与站点设计 - 在「页面」新建空白草稿或从整页模板创建。画布支持编辑、媒体拖拽调整宽度、移动端预览、区块复制与删除。插入媒体时先放入占位图,双击占位图或使用「替换媒体」选择文件。 -- 在「组件」中可选择图左、图右和交错图文。大图封面、均分图文、大图与清单、故事与图注都提供两种方向。手机上图文按组件顺序堆叠。 -- 「图层」可展开到最内层的元素。以 HTML 标签标识每个元素。可拖拽调整区块及内容元素的顺序,也可用箭头在同层移动或用定位图标选中画布中的元素。生成的区块外壳和动态文章列表保留其结构。移除的首屏可通过撤销或「页面设置 → 页面显示」恢复。 +- 在「组件」里先看分类示意图,再选具体组件。大图封面、均分图文、大图与清单、故事与图注都提供两种方向。手机上图文按组件顺序堆叠。 +- 「图层」用组件类型标记顶层,下级用 HTML 标签标记。图层工具提供定位、复制、删除和设置 ID。选中画布中的元素时,图层面板会展开并高亮对应项。可拖拽或用箭头调整顺序。动态文章列表在组件层管理。 +- 要移除区块标题,点击标题图层的删除按钮。正文和组件会保留。可以撤销这次操作,也可以用区块的「编辑 HTML」重新填写标题。 - 选中最外层区块的「编辑 HTML」可修改正文、标题和简介源码。首屏还可以转为完整自定义 HTML,并随时恢复为模板首屏。应用前服务端会清理 HTML,应用后可撤销,保存页面后才会写入站点。 - 点击面包屑或目录文案可就地编辑,双击或打开属性可修改链接。「页面设置 → 首屏与目录」可管理整组链接。模板内其他导航与常规内容一起编辑。 - 「保存页面」在当前画布完成保存。使用「发布」保存并公开草稿,也可以用「转为草稿」下架页面。 diff --git a/VERSION b/VERSION index a73b432..8af85be 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.2 \ No newline at end of file +1.5.3 diff --git a/app/Content/BlockTemplates.php b/app/Content/BlockTemplates.php index 33ff769..5ec3312 100644 --- a/app/Content/BlockTemplates.php +++ b/app/Content/BlockTemplates.php @@ -71,19 +71,23 @@ final class BlockTemplates 'network' => ['按分类分组', '', '', self::NETWORK_FEED], 'list' => ['步骤列表', '
  1. 填写第一步
  2. 填写第二步
  3. 填写第三步
'], 'notice' => ['重点提示', '

填写重要提示

说明访客需要知悉的事项、条件或时间。

'], + 'policy-summary' => ['条款摘要', '

适用范围

说明这项条款适用于哪些访客或服务。

生效与联系

填写生效日期,以及有疑问时的联系方式。

'], ]], 'cover' => ['封面与横幅', [ 'cover' => ['图文封面', '

用一句话介绍你的产品

在首段说明访客能获得什么。

查看服务
'], 'banner' => ['横幅', '

用一句话介绍你的项目

简要说明项目能为访客做什么。

了解更多
'], 'two-actions' => ['双按钮横幅', '

选择下一步

介绍访客可以立即做什么。

查看服务联系我们
'], + 'announcement-banner' => ['公告横幅', '

站点公告

填写公告主题

写明变动时间和受影响的访客。

查看详情
'], ]], 'layout' => ['图文与布局', [ 'image' => ['产品图文', '

介绍主题

在这里说明图片或产品。

'], 'grid' => ['双栏网格', '

第一栏

填写主要内容。

第二栏

补充相关信息。

'], + 'before-after' => ['前后对照', '
调整前示意
调整前 · 写明原来的做法
调整后示意
调整后 · 说明改进和效果
'], ]], 'media' => ['媒体', [ 'gallery' => ['三图画廊', ''], 'video-demo' => ['视频演示', '

演示视频

说明视频涵盖的功能与操作。

'], + 'audio-episode' => ['音频节目', '
节目封面
节目名称与期数

本期节目

填写节目标题

介绍本期主题和嘉宾。

'], ]], 'features' => ['特性与口碑', [ 'features' => ['特性卡片', '

特点一

介绍这个特点。

特点二

介绍这个特点。

特点三

介绍这个特点。

'], @@ -91,6 +95,7 @@ final class BlockTemplates 'metrics' => ['关键数据', '
累计项目
100
服务覆盖
12
合作伙伴
8
'], 'testimonials' => ['用户评价', '

填写用户的评价,并说明他们获得的结果。

用户姓名 · 公司或角色

填写另一条用户评价。

用户姓名 · 公司或角色

'], 'plan-comparison' => ['两种方案对比', '

适合个人

轻量方案

适合团队

协作方案

'], + 'customer-story' => ['客户案例', '

客户案例

填写项目名称

介绍客户遇到的问题和项目结果。

用一句话说明这项改进带来的变化。

客户姓名 · 角色

'], ]], 'details' => ['表格与问答', [ 'table' => ['对比表格', '
项目说明
项目一填写说明
项目二填写说明
'], @@ -100,6 +105,7 @@ final class BlockTemplates 'changelog' => ['更新记录', '

版本 2.0

填写主要功能或改进。

版本 1.0

填写上一版本的更新内容。

'], 'pricing' => ['双方案报价', '

基础方案

填写价格

填写方案包含的服务。

咨询基础方案

进阶方案

填写价格

填写扩展服务或权益。

咨询进阶方案
'], 'reference-code' => ['说明与代码示例', '

操作示例

运行一次检查

说明命令的适用环境和执行后的结果。

curl -I https://example.com
'], + 'feature-matrix' => ['功能矩阵', '
各方案功能对照
功能基础版团队版
工作空间1 个不限
协作成员个人团队
支持方式帮助文档邮件支持
'], ]], 'actions' => ['导航与引导', [ 'service-catalog' => ['目录卡片', '', '', self::CATALOG_FEED], @@ -108,21 +114,25 @@ final class BlockTemplates 'resources' => ['资料与链接', ''], 'contact-card' => ['联系方式', '

联系团队

填写咨询范围与回复时间。

电子邮件
hello@example.com
服务时间
填写工作时间
'], 'support-channels' => ['支持渠道', '

查找自助资料

按问题类型查阅文档与最新公告。

查看帮助文章

联系支持团队

请注明当前情况、操作步骤及希望得到的帮助。

发送邮件
'], + 'download-center' => ['下载中心', ''], ]], 'events' => ['活动与场地', [ 'event-agenda' => ['当日议程', '
  1. 09:30

    签到与开场

    开放入口并介绍当天安排。

    主会场
  2. 10:30

    专题工作坊

    跟随主持人完成一次实践。

    工作区
  3. 14:00

    圆桌交流

    分享实践经验并回答问题。

    交流区
'], 'speaker-lineup' => ['嘉宾阵容', '

主题分享

嘉宾姓名

填写嘉宾的角色和主题。

工作坊

主持人姓名

介绍实践主题和适合的听众。

圆桌交流

主持人姓名

介绍本场将讨论的议题。

'], 'venue-guide' => ['到场指南', '

开放与入场

填写开放时间、预约方式和入口位置。

交通与无障碍

填写推荐交通方式和无障碍通道位置。

'], + 'opening-hours' => ['开放时间与地址', '

开放时间

周一至周五
09:00–18:00
周末
10:00–16:00

地址与入口

填写地址、楼层和入口信息。

联系场馆
'], 'event-registration' => ['活动报名', '

参加活动

预留你的席位

报名时请附上姓名和到场人数。

邮件报名
'], ]], 'commerce' => ['商品与服务', [ 'product-spotlight' => ['商品展示', '
商品展示示例

系列名称

填写商品名称

说明规格、适用场景与供货信息。

联系订购
'], 'product-specifications' => ['规格清单', '
材质
填写材料及维护方式。
尺寸
标注尺寸与单位。
交付
说明交付时间及适用范围。
'], 'service-process' => ['服务流程', '
  1. 沟通需求

    说明首次沟通需要提供哪些资料。

  2. 确认方案

    列出范围、周期和交付计划。

  3. 交付与支持

    介绍验收方式和后续跟进安排。

'], + 'delivery-and-returns' => ['配送与售后', '

配送与取货

填写配送范围、预计时效和费用。

退换与保修

填写退换货条件、保修范围和联系渠道。

'], ]], 'editorial' => ['专题与编辑部', [ 'editorial-feature' => ['专题导读', '

本期主题

写下一句概括专题观点的话。

用一段话交代来由,并指出读者可以从哪里开始。

浏览文章
'], 'reading-path' => ['阅读路径', '
  1. 01

    从背景开始

    了解这组文章要解决的问题。

  2. 02

    阅读主题文章

    按主题深入阅读,并查看相关材料。

'], + 'author-profile' => ['作者介绍', '
作者工作台示意

作者

填写作者姓名

介绍作者的写作主题和相关经历。

阅读更多文章
'], ]], ]; @@ -183,4 +193,18 @@ final class BlockTemplates return null; } + + public static function sectionType(array $section, array $presentation): string + { + $template = self::find($presentation['template'] ?? ''); + if ($template !== null) { + return $template[0]; + } + $feed = json_decode($section['feed'] ?? '{}', true); + + return match ($feed['mode'] ?? $section['style']) { + 'catalog' => '目录卡片', 'network' => '按分类分组', 'merged', 'tabs' => '分类文章', + 'layout' => '版式区块', 'hero-links' => '首屏导航', 'tinted' => '浅色区块', default => '内容区块', + }; + } } diff --git a/app/Content/CanvasStyle.php b/app/Content/CanvasStyle.php index f65ac9e..7260745 100644 --- a/app/Content/CanvasStyle.php +++ b/app/Content/CanvasStyle.php @@ -8,7 +8,7 @@ use RuntimeException; final class CanvasStyle { - public const PAGE = ['hero', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs']; + public const PAGE = ['hero', 'hero-content', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs']; public const MIN_MEDIA_SCALE = 1; public const SECTION = ['section', 'title', 'lead', 'body']; @@ -55,6 +55,10 @@ final class CanvasStyle } $styles = []; foreach ($input as $role => $style) { + if ($roles === self::SECTION && $role === 'template' && is_string($style) && BlockTemplates::find($style)) { + $styles[$role] = $style; + continue; + } if ($roles === self::PAGE && $role === 'breadcrumbLinks') { if (!is_string($style)) { throw new RuntimeException('面包屑无效。'); @@ -94,14 +98,41 @@ final class CanvasStyle } $cleanRuns[] = [self::lineBreaks($run[0]), self::classList($run[1], textOnly: true)]; } - if ($classes !== '' || $cleanRuns !== []) { - $styles[$role] = ['classes' => $classes, 'runs' => $cleanRuns]; + $id = $style['id'] ?? ''; + if (!is_string($id) || ($id !== '' && !preg_match('/^[A-Za-z][A-Za-z0-9_.:-]{0,79}$/D', $id))) { + throw new RuntimeException('元素 ID 须以英文字母开头,最长 80 个字符。'); + } + $hidden = in_array($role, ['heading', 'title'], true) && ($style['hidden'] ?? false) === true; + if ($classes !== '' || $cleanRuns !== [] || $id !== '' || $hidden) { + $styles[$role] = ['classes' => $classes, 'runs' => $cleanRuns] + + ($id !== '' ? ['id' => $id] : []) + ($hidden ? ['hidden' => true] : []); } } return $styles; } + public static function idAttributes(array $styles, string $role, bool $canvas, string $fallback = ''): string + { + $custom = $styles[$role]['id'] ?? ''; + $id = $custom !== '' ? $custom : $fallback; + + return ($id === '' ? '' : ' id="' . View::escape($id) . '"') + . ($canvas ? ' data-studio-default-id="' . View::escape($fallback) . '"' : '') + . ($canvas && $custom !== '' ? ' data-studio-layer-id="' . View::escape($custom) . '"' : ''); + } + + public static function originalAnchor(array $styles, string $role, string $original): string + { + return isset($styles[$role]['id']) && $styles[$role]['id'] !== $original + ? '' : ''; + } + + public static function hiddenTitle(array $styles, string $role, string $text, bool $canvas): string + { + return $canvas && $text === '' && !empty($styles[$role]['hidden']) ? ' hidden data-studio-layer-hidden' : ''; + } + private static function classList(mixed $value, bool $textOnly = false): string { if (!is_string($value) || strlen($value) > 1800) { diff --git a/app/Content/PageDraft.php b/app/Content/PageDraft.php index eee5202..593cec8 100644 --- a/app/Content/PageDraft.php +++ b/app/Content/PageDraft.php @@ -38,7 +38,7 @@ final class PageDraft 'actions' => [], 'quicklinks' => [], 'theme' => '', 'sections' => []]; $page['name'] = $name; foreach (['title' => 160, 'heading' => 110, 'description' => 300, 'lead' => 600, 'accent' => 110, 'image' => 1000, 'alt' => 200] as $field => $limit) { - $page[$field] = self::text($input[$field] ?? $page[$field], $limit, in_array($field, ['title', 'heading'], true)); + $page[$field] = self::text($input[$field] ?? $page[$field], $limit, $field === 'title'); } if (mb_strlen($page['heading'] . $page['accent']) > 110 || ($page['image'] !== '' && !Html::url($page['image'], true))) { throw new RuntimeException('首屏标题过长或图片地址不正确。'); @@ -106,10 +106,11 @@ final class PageDraft throw new RuntimeException('区块样式无效。'); } $sections[$key] = [ - 'key' => $key, 'title' => self::text($item['title'] ?? $preset[0] ?? '', 100, true), + 'key' => $key, 'title' => self::text($item['title'] ?? $preset[0] ?? '', 100), 'lead' => self::text($item['lead'] ?? $preset[2] ?? '', 500), 'body' => Html::sanitize(self::text($item['body'] ?? $preset[1] ?? '', 120000)), 'style' => $style, 'feed' => $preset[3] ?? null, 'version' => null, + 'presentation' => CanvasStyle::encode($preset === null ? [] : ['template' => $item['preset']]), ]; } return array_values($sections); diff --git a/app/Content/Repository.php b/app/Content/Repository.php index a14e5d4..a2bf3f4 100644 --- a/app/Content/Repository.php +++ b/app/Content/Repository.php @@ -260,10 +260,11 @@ final class Repository self::checkVersion($query->rowCount()); } - public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null, string $lead = ''): void + public function createSection(string $page, string $key, string $title, string $style, string $body, ?string $feed = null, string $lead = '', ?string $template = null): void { - Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed, $lead): void { - self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed', 'lead')); + Database::write(function (PDO $pdo) use ($page, $key, $title, $style, $body, $feed, $lead, $template): void { + $presentation = CanvasStyle::encode($template === null ? [] : ['template' => $template]); + self::insertSection($pdo, $page, $key, compact('title', 'style', 'body', 'feed', 'lead', 'presentation')); self::touchPage($pdo, $page); }); } diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php index 39fb2f5..19c005b 100644 --- a/app/Controller/AdminController.php +++ b/app/Controller/AdminController.php @@ -442,7 +442,7 @@ class AdminController if ($data['name'] === '' || mb_strlen($data['name']) > 100 || !in_array($data['status'], ['draft', 'published'], true) || $data['title'] === '' || mb_strlen($data['title']) > 160 || ($public && $data['status'] === 'published' && $data['description'] === '') || mb_strlen($data['description']) > 300 || - (($data['visibility']['hero'] ?? true) && !array_key_exists('heroHtml', $data['presentation']) && $data['heading'] === '') || mb_strlen($data['heading'] . $data['accent']) > 110 || + mb_strlen($data['heading'] . $data['accent']) > 110 || mb_strlen($data['lead']) > 600 || mb_strlen($data['alt']) > 200 || ($data['image_scale'] !== 0 && ($data['image_scale'] < CanvasStyle::MIN_MEDIA_SCALE || $data['image_scale'] > 100)) || strlen($data['image']) > 1000 || ($data['image'] !== '' && !Html::url($data['image'], true))) { @@ -580,6 +580,9 @@ class AdminController continue; } $section = $available[$key] ?? ['key' => $key, 'title' => '', 'lead' => '', 'body' => '', 'style' => 'plain']; + if ($isNew && ($change['style'] ?? null) === 'layout') { + $section['style'] = 'layout'; + } if ($isNew && isset($change['template'])) { $preset = is_string($change['template']) ? BlockTemplates::find($change['template']) : null; if ($preset === null) { @@ -591,7 +594,8 @@ class AdminController if ($isNew && isset($change['copyOf'])) { $source = $change['copyOf']['key'] ?? null; $sourceVersion = $change['copyOf']['version'] ?? null; - if (!is_string($source) || empty($available[$source]['feed']) || $sourceVersion !== (int) $available[$source]['version']) { + if (!is_string($source) || !isset($available[$source]) || $available[$source]['style'] === 'hero-links' + || $sourceVersion !== (int) $available[$source]['version']) { throw new RuntimeException('原模块已变更,请刷新画布后再复制。'); } $section = array_replace($available[$source], ['key' => $key]); @@ -647,9 +651,9 @@ class AdminController private function checkSection(array $section, string $savedStyle): void { - if ($section['title'] === '' || mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500 + if (mb_strlen($section['title']) > 100 || mb_strlen($section['lead']) > 500 || strlen($section['body']) > 300000 || !in_array($section['style'], [$savedStyle, 'plain', 'tinted'], true)) { - throw new RuntimeException('请填写区块标题,并检查说明及正文长度。'); + throw new RuntimeException('请检查区块标题、简介及正文长度。'); } } diff --git a/app/Controller/SiteController.php b/app/Controller/SiteController.php index 1c64b6b..8b62f3d 100644 --- a/app/Controller/SiteController.php +++ b/app/Controller/SiteController.php @@ -127,7 +127,7 @@ final class SiteController } return $this->renderArchive($request, $repo, $category ?? array_keys($categories), null, [ - 'headline' => $section['title'] . ($category !== null ? ' · ' . $categories[$category] : ''), + 'headline' => ($section['title'] ?: '文章与动态') . ($category !== null ? ' · ' . $categories[$category] : ''), 'description' => '查看' . implode('、', $categories) . '分类下的文章。', 'archivePath' => $category === null ? $allPath : $categoryLinks[$category], 'allPath' => $allPath, 'categoryLinks' => $categoryLinks, 'categories' => $categories, 'category' => $category, 'tag' => null, diff --git a/app/Controller/StudioController.php b/app/Controller/StudioController.php index f75df55..60d6375 100644 --- a/app/Controller/StudioController.php +++ b/app/Controller/StudioController.php @@ -123,7 +123,7 @@ final class StudioController extends AdminController if ($preset === null) { throw new RuntimeException('请选择区块类型。'); } - $repo->createSection($slug, $key, $preset[0], $preset[4] ?? 'plain', Html::sanitize($preset[1], $key), $preset[3] ?? null, $preset[2] ?? ''); + $repo->createSection($slug, $key, $preset[0], $preset[4] ?? 'plain', Html::sanitize($preset[1], $key), $preset[3] ?? null, $preset[2] ?? '', $type); return $this->success($request, "/admin/pages/$slug/$key"); } diff --git a/app/view/admin-page.php b/app/view/admin-page.php index 46d8599..39ff709 100644 --- a/app/view/admin-page.php +++ b/app/view/admin-page.php @@ -197,6 +197,7 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];

编辑属性

+ @@ -224,7 +225,7 @@ $spacingPresets = [0, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128];

模块设置

- + $categories, 'feed' => [], 'allowOff' => false]) ?> diff --git a/app/view/admin-section.php b/app/view/admin-section.php index 73ade75..a627e3c 100644 --- a/app/view/admin-section.php +++ b/app/view/admin-section.php @@ -15,7 +15,7 @@ $feed = json_decode($section['feed'] ?? '{}', true, flags: JSON_THROW_ON_ERROR); - +