Fix palette choices, template drawer, and canvas layer labels
This commit is contained in:
@@ -116,7 +116,12 @@ final class DesignLibrary
|
||||
}
|
||||
$id = filter_var($value, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
|
||||
if ($id === false || !self::find($id, $kind)) {
|
||||
throw new RuntimeException('所选页头、页脚或配色方案不存在。');
|
||||
$label = match ($kind) {
|
||||
'header' => '页头',
|
||||
'footer' => '页脚',
|
||||
default => '配色方案',
|
||||
};
|
||||
throw new RuntimeException('所选' . $label . '已不可用。请保留修改,重新打开页面后再选择。');
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
@@ -11,11 +11,6 @@ final class LayoutPage
|
||||
{
|
||||
public const TYPES = ['page' => '普通页面', 'home' => '首页', 'header' => '页头', 'footer' => '页脚'];
|
||||
|
||||
public static function slug(string $kind, int $id): string
|
||||
{
|
||||
return "layout--$kind-$id";
|
||||
}
|
||||
|
||||
public static function insertPreset(PDO $pdo, string $kind, string $name): int
|
||||
{
|
||||
$pdo->prepare('INSERT INTO design_presets (kind, name, preset, payload) VALUES (?, ?, ?, ?)')
|
||||
@@ -40,7 +35,7 @@ final class LayoutPage
|
||||
$layout = $row;
|
||||
$layout['payload'] = DesignLibrary::normalize($kind, $row['preset'], json_decode($row['payload'], true, flags: JSON_THROW_ON_ERROR));
|
||||
$body = self::component($kind, $layout, $site['name']);
|
||||
Repository::insertPage($pdo, self::slug($kind, $row['id']), $row['name'], [
|
||||
Repository::insertPage($pdo, 'layout--' . $kind . '-' . $row['id'], $row['name'], [
|
||||
'visibility' => ['hero' => false],
|
||||
'sections' => [[
|
||||
'key' => 'layout-content', 'title' => DesignLibrary::PRESETS[$kind][$row['preset']], 'lead' => '',
|
||||
|
||||
@@ -143,8 +143,11 @@ final class Repository
|
||||
public function savePage(string $slug, array $data, int $version, array $sections = [], bool $replaceDraftSections = false, ?array $sectionOrder = null): array
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($slug, $data, $version, $sections, $replaceDraftSections, $sectionOrder): array {
|
||||
$existing = $this->one('SELECT pages.version, pages.page_type, pages.layout_id, d.kind AS layout_kind
|
||||
$existing = $this->one('SELECT pages.version, pages.page_type, pages.layout_id, pages.header_id, pages.footer_id, d.kind AS layout_kind
|
||||
FROM pages LEFT JOIN design_presets d ON pages.layout_id = d.id WHERE pages.slug = ?', [$slug]);
|
||||
if ($existing !== null && $existing['version'] !== $version) {
|
||||
$this->checkRemovedPageLayouts($existing, $data['originalLayoutIds'] ?? []);
|
||||
}
|
||||
self::checkVersion($existing !== null && $existing['version'] === $version ? 1 : 0);
|
||||
$target = $data['slug'] ?? $slug;
|
||||
if ($target !== $slug && $this->one('SELECT 1 FROM pages WHERE slug = ?', [$target])) {
|
||||
@@ -204,6 +207,17 @@ final class Repository
|
||||
});
|
||||
}
|
||||
|
||||
private function checkRemovedPageLayouts(array $page, array $originalIds): void
|
||||
{
|
||||
foreach (['header' => '页头', 'footer' => '页脚'] as $kind => $label) {
|
||||
$id = $originalIds[$kind] ?? 0;
|
||||
if ($id > 0 && $page[$kind . '_id'] === null
|
||||
&& !$this->one('SELECT 1 FROM design_presets WHERE id = ? AND kind = ?', [$id, $kind])) {
|
||||
throw new RuntimeException('此页面引用的' . $label . '已被移除。请保留修改,重新打开编辑器后再保存。');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePage(string $slug, int $version): bool
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($slug, $version): bool {
|
||||
|
||||
@@ -32,9 +32,9 @@ final class SiteDesign
|
||||
}
|
||||
|
||||
public static function saveGeneral(string $name, string $origin, int $version, array $systemPages, bool $maintenance,
|
||||
?string $head = null, ?string $icon = null): void
|
||||
?string $head = null, ?string $icon = null, mixed $palette = null): void
|
||||
{
|
||||
Database::write(function (PDO $pdo) use ($name, $origin, $version, $systemPages, $maintenance, $head, $icon): void {
|
||||
Database::write(function (PDO $pdo) use ($name, $origin, $version, $systemPages, $maintenance, $head, $icon, $palette): void {
|
||||
$site = json_decode((string) $pdo->query('SELECT payload FROM site_settings WHERE id = 1')->fetchColumn(), true, flags: JSON_THROW_ON_ERROR);
|
||||
if (($site['revisions']['general'] ?? 0) !== $version) {
|
||||
throw new RuntimeException('站点设置已更新,请重新打开后再保存。');
|
||||
@@ -48,6 +48,10 @@ final class SiteDesign
|
||||
if ($maintenance && !isset($systemPages['maintenance'])) {
|
||||
throw new RuntimeException('请先发布并选择维护页,再开启维护模式。');
|
||||
}
|
||||
if ($palette !== null) {
|
||||
$site['palette_id'] = DesignLibrary::selection('palette', $palette)
|
||||
?? throw new RuntimeException('请选择站点默认配色。');
|
||||
}
|
||||
$site['name'] = $name;
|
||||
$site['cdn'] = ['origin' => $origin];
|
||||
$site['system_pages'] = $systemPages;
|
||||
|
||||
Reference in New Issue
Block a user