157 lines
12 KiB
PHP
157 lines
12 KiB
PHP
<?php
|
|
use App\Content\Buttons;
|
|
use App\Content\Database;
|
|
use App\Content\DesignLibrary;
|
|
use App\Content\View;
|
|
|
|
$e = View::escape(...);
|
|
$data = $item['payload'];
|
|
$action = $data['action'][0] ?? [];
|
|
$provider = $data['provider'] ?? [];
|
|
$errorId = static fn (string $name): string => 'design-error-' . View::escape($name);
|
|
$describe = static fn (string $name): string => ' aria-describedby="' . $errorId($name) . '"'
|
|
. ($field === $name ? ' aria-invalid="true"' : '');
|
|
$fieldError = static function (string $name) use ($errorId, $field, $error, $e): void {
|
|
$invalid = $field === $name;
|
|
?>
|
|
<small class="design-field-error" id="<?= $errorId($name) ?>" data-field-error="<?= $e($name) ?>" role="alert" tabindex="-1"<?= $invalid ? '' : ' hidden' ?>><?= $invalid ? $e($error) : '' ?></small>
|
|
<?php
|
|
};
|
|
?>
|
|
<a class="back-link" href="/admin/design">返回站点设计</a>
|
|
<header class="admin-heading">
|
|
<h1><?= $e(['header' => '页头组件', 'footer' => '页脚组件', 'palette' => '配色方案'][$kind]) ?></h1>
|
|
<?php if ($key !== 'new'): ?><a class="button button-outline" href="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>/preview" target="_blank" rel="noopener noreferrer">预览已保存的配置</a><?php endif ?>
|
|
</header>
|
|
<?= View::fragment('admin-feedback', ['error' => $field === '' ? $error : '', 'saved' => $saved]) ?>
|
|
<form class="admin-form<?= $layoutEditor ? ' design-editor' : ' admin-panel' ?>" method="post"
|
|
action="/admin/design/<?= $e($kind) ?>/<?= $e($key) ?>"<?= $layoutEditor ? ' data-layout-editor="' . $e($kind) . '" data-site-name="' . $e($siteName) . '"' : '' ?>>
|
|
<input type="hidden" name="csrf" value="<?= $e($token) ?>">
|
|
<input type="hidden" name="version" value="<?= $e($item['version']) ?>">
|
|
<?php if ($kind === 'palette'): ?>
|
|
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
|
<input type="hidden" name="preset" value="custom">
|
|
<?php $fieldError('preset'); ?>
|
|
<div class="palette-fields">
|
|
<?php foreach (DesignLibrary::COLORS as $color => [$label, $fallback]): ?>
|
|
<label><?= $e($label) ?><input type="<?= $field === $color ? 'text' : 'color' ?>" name="<?= $e($color) ?>" value="<?= $e($data[$color] ?? $fallback) ?>"<?= $describe($color) ?>><?php $fieldError($color); ?></label>
|
|
<?php endforeach ?>
|
|
</div>
|
|
<div class="form-submit"><button type="submit" class="button button-primary">保存配置</button></div>
|
|
<?php else: ?>
|
|
<div class="admin-panel design-editor-bar">
|
|
<label>配置名称<input name="name" maxlength="100" value="<?= $e($item['name']) ?>" required<?= $describe('name') ?>><?php $fieldError('name'); ?></label>
|
|
<label><input type="checkbox" name="make_default" value="1" <?= $default ? 'checked' : '' ?>> 用作站点默认<?= $kind === 'header' ? '页头' : '页脚' ?></label>
|
|
<button type="submit" class="button button-primary">保存配置</button>
|
|
</div>
|
|
<div class="design-editor-grid">
|
|
<div class="design-editor-main">
|
|
<section class="admin-panel design-canvas" data-layout-workspace hidden aria-labelledby="design-canvas-title">
|
|
<div class="admin-heading compact">
|
|
<h2 id="design-canvas-title">编辑画布</h2>
|
|
<div class="preview-selector" role="group" aria-label="预览尺寸">
|
|
<button type="button" class="button button-outline" data-layout-viewport="desktop" aria-pressed="true">桌面</button>
|
|
<button type="button" class="button button-outline" data-layout-viewport="phone" aria-pressed="false">手机</button>
|
|
</div>
|
|
</div>
|
|
<div class="design-canvas-stage">
|
|
<div class="design-canvas-viewport">
|
|
<iframe data-layout-frame sandbox="allow-same-origin" title="可编辑的<?= $kind === 'header' ? '页头' : '页脚' ?>画布"
|
|
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => array_key_first(DesignLibrary::PRESETS[$kind]), 'layoutEditor' => true])) ?>"></iframe>
|
|
</div>
|
|
<p class="field-note" data-layout-empty hidden>勾选组件,添加到画布。</p>
|
|
</div>
|
|
<p class="field-note">点击画布中的文字可直接修改。链接、图片和用户区在组件面板设置。</p>
|
|
</section>
|
|
<fieldset class="admin-panel design-templates"<?= $describe('preset') ?>>
|
|
<legend>布局模板</legend>
|
|
<div class="design-template-grid">
|
|
<?php foreach (DesignLibrary::PRESETS[$kind] as $preset => $label): ?>
|
|
<label class="design-template-choice">
|
|
<span class="design-template-image">
|
|
<iframe aria-hidden="true" tabindex="-1" inert title="<?= $e($label) ?>缩略预览" sandbox
|
|
srcdoc="<?= $e(View::fragment('design-layout-document', ['kind' => $kind, 'preset' => $preset, 'layoutEditor' => false])) ?>"></iframe>
|
|
</span>
|
|
<span class="design-template-caption"><input type="radio" name="preset" value="<?= $e($preset) ?>" data-layout-preset required <?= $preset === $item['preset'] ? 'checked' : '' ?>><?= $e($label) ?></span>
|
|
</label>
|
|
<?php endforeach ?>
|
|
</div>
|
|
<?php $fieldError('preset'); ?>
|
|
</fieldset>
|
|
</div>
|
|
<aside class="admin-panel design-editor-inspector" aria-label="组件和属性">
|
|
<fieldset class="admin-options design-component-panel"<?= $describe('components') ?>>
|
|
<legend>组件</legend>
|
|
<ul class="admin-list layout-components" data-layout-components>
|
|
<?php foreach (array_unique([...$data['components'], ...array_keys(DesignLibrary::COMPONENTS[$kind])]) as $component): ?>
|
|
<li data-layout-layer="<?= $e($component) ?>">
|
|
<label><input type="checkbox" name="components[]" value="<?= $e($component) ?>" <?= in_array($component, $data['components'], true) ? 'checked' : '' ?>><?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?></label>
|
|
<div class="actions">
|
|
<button type="button" class="button button-outline" data-layout-select="<?= $e($component) ?>" aria-label="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="编辑<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" hidden><?= View::fragment('studio-icon', ['icon' => 'edit']) ?></button>
|
|
<button type="button" class="button button-outline" data-component-move="-1" aria-label="上移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="上移">↑</button>
|
|
<button type="button" class="button button-outline" data-component-move="1" aria-label="下移<?= $e(DesignLibrary::COMPONENTS[$kind][$component]) ?>" title="下移">↓</button>
|
|
</div>
|
|
</li>
|
|
<?php endforeach ?>
|
|
</ul>
|
|
<?php $fieldError('components'); ?>
|
|
</fieldset>
|
|
<fieldset class="admin-options design-properties" data-layout-panel="brand">
|
|
<legend>站点标识</legend>
|
|
<label>品牌名称<input name="brand" maxlength="100" value="<?= $e($data['brand']) ?>"<?= $describe('brand') ?>><?php $fieldError('brand'); ?></label>
|
|
<div>
|
|
<?= View::fragment('studio-asset-field', ['name' => 'logo', 'label' => '品牌图片', 'value' => $data['logo'],
|
|
'describedBy' => $errorId('logo'), 'invalid' => $field === 'logo']) ?>
|
|
<?php $fieldError('logo'); ?>
|
|
</div>
|
|
</fieldset>
|
|
<fieldset class="admin-options design-properties" data-layout-panel="links"<?= $describe('links') ?>>
|
|
<legend><?= $kind === 'header' ? '导航链接' : '页脚链接' ?></legend>
|
|
<label data-layout-legacy-links>链接列表<textarea name="links" rows="4"<?= $describe('links') ?>><?= $e($links) ?></textarea><small>每行填写「名称 | 链接」。</small></label>
|
|
<input type="hidden" name="canvas_links" value="<?= $e(Database::json($data['links'] ?? [])) ?>" disabled>
|
|
<div data-layout-link-editor hidden>
|
|
<div class="design-link-rows" data-layout-link-rows></div>
|
|
<button class="button button-outline" type="button" data-layout-link-add>添加链接</button>
|
|
<template data-layout-link-template>
|
|
<div class="design-link-row">
|
|
<label>文案<input maxlength="70" data-layout-link-field="1"></label>
|
|
<label>地址<input maxlength="1000" data-layout-link-field="0" placeholder="/articles"></label>
|
|
<div class="design-link-controls">
|
|
<button class="button button-outline" type="button" data-layout-link-move="-1" title="上移链接" aria-label="上移链接">↑</button>
|
|
<button class="button button-outline" type="button" data-layout-link-move="1" title="下移链接" aria-label="下移链接">↓</button>
|
|
<button class="button button-outline" type="button" data-layout-link-remove title="删除链接" aria-label="删除链接"><?= View::fragment('studio-icon', ['icon' => 'delete']) ?></button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
<?php $fieldError('links'); ?>
|
|
</fieldset>
|
|
<?php if ($kind === 'header'): ?>
|
|
<fieldset class="admin-options design-properties" data-layout-panel="action"<?= $describe('action') ?>>
|
|
<legend>行动按钮</legend>
|
|
<label>文案<input name="action_label" maxlength="70" value="<?= $e($action[1] ?? '') ?>"></label>
|
|
<label>链接<input name="action_url" maxlength="1000" value="<?= $e($action[0] ?? '') ?>"></label>
|
|
<label>样式<select name="action_style"><?php foreach (Buttons::STYLES as $style => $label): ?>
|
|
<option value="<?= $e($style) ?>" <?= ($action[2] ?? 'outline') === $style ? 'selected' : '' ?>><?= $e($label) ?></option>
|
|
<?php endforeach ?></select></label>
|
|
<label><input type="checkbox" name="action_blank" value="1" <?= !empty($action[3]) ? 'checked' : '' ?>> 在新标签页打开</label>
|
|
<?php $fieldError('action'); ?>
|
|
</fieldset>
|
|
<div data-layout-panel="account">
|
|
<?= View::fragment('design-provider-fields', compact('item', 'provider', 'e', 'describe', 'fieldError', 'reenterSecret', 'field') + ['components' => $data['components']]) ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<fieldset class="admin-options design-properties" data-layout-panel="text">
|
|
<legend>说明文字</legend>
|
|
<label>内容<textarea name="text" rows="3" maxlength="1200"<?= $describe('text') ?>><?= $e($data['text']) ?></textarea><?php $fieldError('text'); ?></label>
|
|
</fieldset>
|
|
<fieldset class="admin-options design-properties" data-layout-panel="legal">
|
|
<legend>版权文字</legend>
|
|
<label>内容<input name="legal" maxlength="300" value="<?= $e($data['legal']) ?>"<?= $describe('legal') ?>><?php $fieldError('legal'); ?></label>
|
|
</fieldset>
|
|
<?php endif ?>
|
|
</aside>
|
|
</div>
|
|
<?php endif ?>
|
|
</form>
|