463 lines
11 KiB
Svelte
463 lines
11 KiB
Svelte
<script lang="ts">
|
|
import type { PageData, ActionData } from './$types';
|
|
import { enhance } from '$app/forms';
|
|
import { addToast } from '$lib/stores/toast.svelte';
|
|
import Tabs from '$lib/components/admin/Tabs.svelte';
|
|
import ImagePicker from '$lib/components/admin/FeaturedImagePicker.svelte';
|
|
import { untrack } from 'svelte';
|
|
|
|
let { data, form }: { data: PageData; form: ActionData } = $props();
|
|
const initialData = $state.snapshot(untrack(() => data));
|
|
let activeTab = $state('basic');
|
|
|
|
let avatarEnabled = $state(initialData.settings['site.avatar_enabled'] !== 'false');
|
|
let avatarUrl = $state(initialData.settings['site.avatar_url'] || '');
|
|
|
|
$effect(() => {
|
|
if (form?.success) {
|
|
addToast('设置保存成功!', 'success');
|
|
} else if (form?.error) {
|
|
addToast(form.error, 'error');
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<div class="admin-page-header">
|
|
<h2>系统设置</h2>
|
|
</div>
|
|
|
|
<Tabs
|
|
tabs={[
|
|
{ id: 'basic', label: '基础信息' },
|
|
{ id: 'appearance', label: '外观与主页' },
|
|
{ id: 'terms', label: '术语设定' },
|
|
{ id: 'system', label: '系统与安全' }
|
|
]}
|
|
bind:activeTab
|
|
/>
|
|
|
|
<div class="settings-container">
|
|
{#if activeTab === 'basic'}
|
|
<div class="settings-card full-width">
|
|
<h3>站点基础信息</h3>
|
|
<p class="desc">设置您的网站名称和一句话描述,这些信息将展示在首页和浏览器标题中。</p>
|
|
|
|
<form
|
|
method="POST"
|
|
action="?/updateSiteInfo"
|
|
use:enhance={() => {
|
|
return async ({ update }) => {
|
|
update({ reset: false });
|
|
};
|
|
}}
|
|
class="alias-form"
|
|
>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="site_title">网站标题</label>
|
|
<input
|
|
type="text"
|
|
id="site_title"
|
|
name="site_title"
|
|
value={data.settings['site.title'] || 'BlogFlare'}
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="site_description">站点描述</label>
|
|
<input
|
|
type="text"
|
|
id="site_description"
|
|
name="site_description"
|
|
value={data.settings['site.description'] ||
|
|
'A high-performance blog powered by Cloudflare D1, R2, and KV.'}
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="r2_public_domain">R2 自定义域名 (用于访问附件)</label>
|
|
<input
|
|
type="text"
|
|
id="r2_public_domain"
|
|
name="r2_public_domain"
|
|
value={data.settings['r2.public_domain'] || 'https://assets.yourdomain.com'}
|
|
placeholder="例如: https://assets.mydomain.com"
|
|
/>
|
|
<small class="form-hint">请确保不要以斜杠 / 结尾</small>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="site_launch_date">建站日期</label>
|
|
<input
|
|
type="date"
|
|
id="site_launch_date"
|
|
name="site_launch_date"
|
|
value={data.settings['site.launch_date'] || ''}
|
|
/>
|
|
<small class="form-hint">用于在底栏显示"感谢陪伴 X 天 X 小时"</small>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">保存</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if activeTab === 'appearance'}
|
|
<div class="settings-card full-width">
|
|
<h3>首页顶部主图与外观偏好</h3>
|
|
<p class="desc">
|
|
针对站点的主页展现风貌(如顶部站点头像/主图的开启或关闭、自定义挑选等)进行专属配置。
|
|
</p>
|
|
|
|
<form
|
|
method="POST"
|
|
action="?/updateAppearance"
|
|
use:enhance={() => {
|
|
return async ({ update }) => {
|
|
update({ reset: false });
|
|
};
|
|
}}
|
|
class="alias-form"
|
|
>
|
|
<div class="form-group">
|
|
<label class="toggle-label">
|
|
<input type="checkbox" name="site_avatar_enabled_cb" bind:checked={avatarEnabled} />
|
|
<input
|
|
type="hidden"
|
|
name="site_avatar_enabled"
|
|
value={avatarEnabled ? 'true' : 'false'}
|
|
/>
|
|
<span class="toggle-text">在网站首页顶部标题栏显示主图 / 站点头像</span>
|
|
</label>
|
|
</div>
|
|
|
|
{#if avatarEnabled}
|
|
<div class="form-group">
|
|
<label for="picker">主页显示图片</label>
|
|
<div class="picker-container">
|
|
<ImagePicker
|
|
bind:cover={avatarUrl}
|
|
title=""
|
|
inputName="site_avatar_url"
|
|
aspectRatio="1/1"
|
|
/>
|
|
</div>
|
|
</div>
|
|
{:else}
|
|
<input type="hidden" name="site_avatar_url" value={avatarUrl} />
|
|
{/if}
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">保存外观偏好</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if activeTab === 'system'}
|
|
<div class="settings-card">
|
|
<h3>系统信息</h3>
|
|
<div class="info-row">
|
|
<span class="label">主题风格</span>
|
|
<span class="value">Typecho Theme VOID</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">驱动框架</span>
|
|
<span class="value">SvelteKit 5 + Cloudflare</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="settings-card">
|
|
<h3>安全与环境</h3>
|
|
<div class="info-row">
|
|
<span class="label">当前管理员</span>
|
|
<span class="value">{data.user?.email || '未知用户'}</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">数据库绑定</span>
|
|
<span class="value"><span class="badge">{data.platformEnv}</span></span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="label">鉴权模式</span>
|
|
<span class="value">Cloudflare Access (Zero Trust)</span>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if activeTab === 'terms'}
|
|
<div class="settings-card full-width">
|
|
<h3>个性化术语设定</h3>
|
|
<p class="desc">
|
|
您可以根据部署场景(如教学系统、文档库)自定义后台各模块的显示名称,例如将“文章”改为“实验手册”。
|
|
</p>
|
|
|
|
<form
|
|
method="POST"
|
|
action="?/updateAliases"
|
|
use:enhance={() => {
|
|
return async ({ update }) => {
|
|
update({ reset: false });
|
|
};
|
|
}}
|
|
class="alias-form"
|
|
>
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="alias_post">文章</label>
|
|
<input
|
|
type="text"
|
|
id="alias_post"
|
|
name="alias_post"
|
|
value={data.settings['alias.post'] || '文章'}
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="alias_page">页面</label>
|
|
<input
|
|
type="text"
|
|
id="alias_page"
|
|
name="alias_page"
|
|
value={data.settings['alias.page'] || '页面'}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label for="alias_category">分类</label>
|
|
<input
|
|
type="text"
|
|
id="alias_category"
|
|
name="alias_category"
|
|
value={data.settings['alias.category'] || '分类'}
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="alias_tag">标签</label>
|
|
<input
|
|
type="text"
|
|
id="alias_tag"
|
|
name="alias_tag"
|
|
value={data.settings['alias.tag'] || '标签'}
|
|
required
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="alias_series">系列</label>
|
|
<input
|
|
type="text"
|
|
id="alias_series"
|
|
name="alias_series"
|
|
value={data.settings['alias.series'] || '系列'}
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn btn-primary">保存</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
<style>
|
|
.admin-page-header {
|
|
margin-bottom: 25px;
|
|
border-bottom: 2px solid var(--text-color);
|
|
padding-bottom: 12px;
|
|
}
|
|
|
|
.admin-page-header h2 {
|
|
margin: 0;
|
|
font-size: 2rem;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.settings-container {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
|
gap: 25px;
|
|
align-items: stretch;
|
|
}
|
|
|
|
.full-width {
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.settings-card {
|
|
border: 2px solid var(--text-color);
|
|
padding: 24px;
|
|
background: transparent;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.settings-card h3 {
|
|
margin: 0 0 12px 0;
|
|
font-size: 1.2rem;
|
|
border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
|
|
padding-bottom: 10px;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.settings-card .desc {
|
|
font-size: 0.9rem;
|
|
color: var(--text-muted, rgba(0, 0, 0, 0.6));
|
|
margin-bottom: 24px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.info-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 14px 0;
|
|
border-bottom: 1px dashed var(--border-color, rgba(0, 0, 0, 0.08));
|
|
font-size: 0.95rem;
|
|
gap: 15px;
|
|
}
|
|
|
|
.info-row:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.info-row .label {
|
|
color: var(--text-muted, rgba(0, 0, 0, 0.6));
|
|
font-weight: 500;
|
|
white-space: nowrap;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.info-row .value {
|
|
color: var(--text-color);
|
|
font-weight: 600;
|
|
text-align: right;
|
|
word-break: break-word;
|
|
}
|
|
|
|
.alias-form {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
|
|
.form-row {
|
|
display: flex;
|
|
gap: 20px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.form-row {
|
|
flex-direction: column;
|
|
gap: 20px;
|
|
}
|
|
}
|
|
|
|
.form-group {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
|
|
.form-group label {
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.form-group input {
|
|
padding: 10px 14px;
|
|
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
background: rgba(0, 0, 0, 0.02);
|
|
font-size: 1rem;
|
|
color: var(--text-color);
|
|
border-radius: 0;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: var(--accent-color, #419b38);
|
|
box-shadow: 0 0 0 2px rgba(65, 155, 56, 0.1);
|
|
}
|
|
|
|
/* 抹除浏览器原生日期选择器的特殊样式,保持与项目其他输入框一致 */
|
|
.form-group input[type='date'] {
|
|
appearance: none;
|
|
-webkit-appearance: none;
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
color-scheme: light;
|
|
}
|
|
|
|
.form-group input[type='date']::-webkit-calendar-picker-indicator {
|
|
filter: invert(0.4);
|
|
cursor: pointer;
|
|
padding: 0;
|
|
margin-left: 4px;
|
|
}
|
|
|
|
.form-actions {
|
|
margin-top: 10px;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.btn {
|
|
display: inline-block;
|
|
padding: 10px 24px;
|
|
text-decoration: none;
|
|
font-size: 0.95rem;
|
|
font-weight: 600;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
border: 2px solid var(--text-color);
|
|
background-color: transparent;
|
|
color: var(--text-color);
|
|
font-family: inherit;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: var(--text-color);
|
|
color: var(--bg-color, #ffffff);
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: var(--accent-color, #419b38);
|
|
border-color: var(--accent-color, #419b38);
|
|
color: white;
|
|
}
|
|
|
|
.toggle-label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
font-size: 0.95rem;
|
|
font-weight: 600;
|
|
color: var(--text-color);
|
|
}
|
|
|
|
.toggle-label input[type='checkbox'] {
|
|
width: 18px;
|
|
height: 18px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.picker-container {
|
|
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
padding: 20px;
|
|
background: rgba(0, 0, 0, 0.01);
|
|
margin-top: 5px;
|
|
}
|
|
</style>
|