From 636788b65c78fe0e1cfe148cd1da01842949196e Mon Sep 17 00:00:00 2001 From: ChatGPT Date: Mon, 23 Nov 2026 20:30:11 +0800 Subject: [PATCH] Add visual header and footer layout editors --- README.md | 2 +- app/Content/DesignLibrary.php | 6 +- app/Controller/AdminController.php | 1 + app/Controller/DesignController.php | 21 ++- app/view/admin-design-edit.php | 184 +++++++++++------- app/view/admin-layout.php | 4 + app/view/admin-page.php | 5 + app/view/design-layout-document.php | 31 ++++ app/view/design-provider-fields.php | 29 +++ app/view/footer.php | 19 +- app/view/header.php | 23 ++- public/assets/admin.css | 23 ++- public/assets/admin.js | 15 +- public/assets/design-editor.css | 167 +++++++++++++++++ public/assets/design-editor.js | 277 ++++++++++++++++++++++++++++ public/assets/site.css | 2 + 16 files changed, 714 insertions(+), 95 deletions(-) create mode 100644 app/view/design-layout-document.php create mode 100644 app/view/design-provider-fields.php create mode 100644 public/assets/design-editor.css create mode 100644 public/assets/design-editor.js diff --git a/README.md b/README.md index ddefb70..d08a4bf 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ php start.php start - 选中元素可编辑四边的内外边距。选中文字后可修改字号、粗体、斜体和删除线。Enter 或 Shift+Enter 在当前元素内换行。正文用 Ctrl+Enter(macOS 上为 ⌘+Enter)或工具栏「换段」新建段落,列表中则新增列表项。 - 画布支持 Ctrl/⌘+Z 撤销和 Ctrl/⌘+Shift+Z 重做。页面设置的输入框保留浏览器原生撤销。 - 选中按钮后可复制。在「属性」中选择纯色填充、线框、下划线或无样式,并选择是否在新标签页打开。首屏支持最多八个按钮。 -- 「站点设计」中可以保存多套页头、页脚和配色。选择布局模板后,可以勾选并排序标识、导航、按钮、文字、版权或用户区组件,填入各组件内容。页头和页脚可以设为站点默认。每页可覆盖这两个默认项、选择配色,或独立隐藏页头和页脚。 +- 「站点设计」中可以保存多套页头、页脚和配色。页头页脚编辑器提供布局预览卡和桌面、手机画布。可直接修改画布文字,在组件面板开启或排序组件,设置图片、链接和用户区。页头和页脚可以设为站点默认。每页可覆盖默认项、选择配色,或独立隐藏页头和页脚。页面编辑器里的「编辑页头/编辑页脚」会打开当前方案的画布。 - 媒体库和媒体选择器只列出用户上传文件。编辑器图标、示例资产、字体、模板缩略图和产品标识随程序发布。 - 发布后的站点具备独立标题、描述、canonical、Open Graph、站点地图和 robots.txt。可在「站点设置」配置站点名称和静态资源 CDN。 diff --git a/app/Content/DesignLibrary.php b/app/Content/DesignLibrary.php index 7da8d52..d4a27a8 100644 --- a/app/Content/DesignLibrary.php +++ b/app/Content/DesignLibrary.php @@ -125,7 +125,11 @@ final class DesignLibrary } } $clean['components'] = array_values(array_unique($components)); - $clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20); + try { + $clean['links'] = Buttons::validate($data['links'] ?? $clean['links'], 20); + } catch (RuntimeException $error) { + throw new DesignFieldError('links', $error->getMessage()); + } try { $clean['action'] = Buttons::validate($data['action'] ?? []); } catch (RuntimeException $error) { diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php index 50f1fbd..afcb469 100644 --- a/app/Controller/AdminController.php +++ b/app/Controller/AdminController.php @@ -319,6 +319,7 @@ class AdminController return $this->render($request, 'admin-page', [ 'title' => '编辑 ' . $page['name'], 'page' => $page, 'categories' => $repo->categories(), 'wideAdmin' => true, 'error' => $error, 'saved' => $request->get('saved') === '1', 'pageTemplateDrawer' => true, 'designs' => DesignLibrary::all(), + 'layoutDefaults' => array_intersect_key($repo->site(), ['header_id' => true, 'footer_id' => true]), ], $error !== '' ? 422 : 200); } diff --git a/app/Controller/DesignController.php b/app/Controller/DesignController.php index 8570e3d..25fd42b 100644 --- a/app/Controller/DesignController.php +++ b/app/Controller/DesignController.php @@ -43,7 +43,8 @@ final class DesignController extends AdminController $field = ''; $secret = ''; $links = SiteDesign::linkText($item['payload']['links'] ?? []); - $default = $id !== null && ((new Repository())->site()[$kind . '_id'] ?? null) === $id; + $site = (new Repository())->site(); + $default = $id === null ? $request->get('default') === '1' : ($site[$kind . '_id'] ?? null) === $id; if ($request->method() === 'POST') { try { $savedProvider = $item['payload']['provider'] ?? []; @@ -73,10 +74,19 @@ final class DesignController extends AdminController } $secret = $this->input($request, 'provider_secret', trimValue: false); } - try { - $item['payload']['links'] = SiteDesign::parseLinks($links); - } catch (RuntimeException $ex) { - throw new DesignFieldError('links', $ex->getMessage()); + if ($request->post('canvas_links') !== null) { + $draftLinks = json_decode($this->input($request, 'canvas_links'), true); + if (!is_array($draftLinks) || !array_is_list($draftLinks) + || array_filter($draftLinks, 'is_array') !== $draftLinks) { + throw new DesignFieldError('links', '导航链接格式无效。'); + } + $item['payload']['links'] = $draftLinks; + } else { + try { + $item['payload']['links'] = SiteDesign::parseLinks($links); + } catch (RuntimeException $ex) { + throw new DesignFieldError('links', $ex->getMessage()); + } } } $id = DesignLibrary::save($kind, $id, $item['name'], $item['preset'], $item['payload'], $item['version'], $default, $secret); @@ -98,6 +108,7 @@ final class DesignController extends AdminController return $this->render($request, 'admin-design-edit', [ 'title' => '设计配置', 'kind' => $kind, 'key' => $key, 'item' => $item, 'default' => $default, 'error' => $error, 'field' => $field, 'links' => $links, 'reenterSecret' => $error !== '' && $secret !== '', + 'layoutEditor' => $kind !== 'palette', 'wideAdmin' => $kind !== 'palette', 'siteName' => $site['name'], 'saved' => $error === '' && $request->get('saved') === '1', ], $error === '' ? 200 : 422); } diff --git a/app/view/admin-design-edit.php b/app/view/admin-design-edit.php index 6cbf1fb..8b261a5 100644 --- a/app/view/admin-design-edit.php +++ b/app/view/admin-design-edit.php @@ -1,5 +1,6 @@ 预览已保存的配置 $field === '' ? $error : '', 'saved' => $saved]) ?> -
+> - - + + +
[$label, $fallback]): ?>
+
-
>组件及顺序 -
    - -
  • -
  • - -
- -
-
- -
- 'logo', 'label' => '品牌图片', 'value' => $data['logo'], - 'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?> - -
+
+ + + +
+
+
+ +
> + 布局模板 +
+ $label): ?> + + +
+ +
+
+
- - -
>行动按钮 - - - - - -
-
>用户区认证 - - - - - - - '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?> - - -

回调地址

-
- - - - - - diff --git a/app/view/admin-layout.php b/app/view/admin-layout.php index 1a64dda..dc8d04a 100644 --- a/app/view/admin-layout.php +++ b/app/view/admin-layout.php @@ -24,6 +24,10 @@ $active = match (true) { + + + + diff --git a/app/view/admin-page.php b/app/view/admin-page.php index 3c62964..ed9dac7 100644 --- a/app/view/admin-page.php +++ b/app/view/admin-page.php @@ -16,6 +16,11 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';

页面设置 + '编辑页头', 'footer' => '编辑页脚'] as $kind => $label): ?> + + + 公开页面 打开预览 diff --git a/app/view/design-layout-document.php b/app/view/design-layout-document.php new file mode 100644 index 0000000..c950846 --- /dev/null +++ b/app/view/design-layout-document.php @@ -0,0 +1,31 @@ + 0, + 'preset' => $preset, + 'payload' => array_replace(DesignLibrary::defaults($kind), [ + 'brand' => '品牌名称', + 'text' => '关于网站的一句话介绍。', + 'links' => $layoutEditor ? [] : [['/', '首页'], ['/articles', '文章']], + 'legal' => '© 品牌名称', + 'action' => [['/articles', '了解更多', 'solid', false]], + ]), +]; +?> + + + + + + + + + + $layout, 'site' => ['name' => '品牌名称'], 'showHeader' => true, 'showFooter' => true, + 'path' => '/', 'visitor' => null, 'member' => $preset === 'member', 'layoutEditor' => $layoutEditor, +]) ?> + + diff --git a/app/view/design-provider-fields.php b/app/view/design-provider-fields.php new file mode 100644 index 0000000..d1fbd42 --- /dev/null +++ b/app/view/design-provider-fields.php @@ -0,0 +1,29 @@ + +
>用户区认证 + + + + + + + '授权端点', 'token' => '令牌端点', 'userinfo' => '用户资料端点', 'subject_field' => '用户 ID 字段', 'name_field' => '名称字段', 'avatar_field' => '头像字段'] as $providerField => $label): ?> + + +

回调地址

+
diff --git a/app/view/footer.php b/app/view/footer.php index 19832b5..b7261d7 100644 --- a/app/view/footer.php +++ b/app/view/footer.php @@ -4,22 +4,25 @@ use App\Content\View; $e = View::escape(...); $data = $footer['payload']; $brand = $data['brand'] ?: $site['name']; +$layoutEditor ??= false; +$part = static fn (string $component): string => $layoutEditor ? ' data-layout-component="' . $component . '"' : ''; ?>