feat: 添加后台仪表盘及系统设置页面
This commit is contained in:
1 parent
6fb837eccd
commit
b3456b8916
4 files changed
+227
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ platform }) => {
|
||||
const db = platform?.env?.DB;
|
||||
|
||||
let postCount = 0;
|
||||
let tagCount = 0;
|
||||
|
||||
if (db) {
|
||||
try {
|
||||
const postResult = await db.prepare('SELECT COUNT(*) as count FROM posts').first();
|
||||
const tagResult = await db.prepare('SELECT COUNT(*) as count FROM tags').first();
|
||||
|
||||
postCount = (postResult?.count as number) || 0;
|
||||
tagCount = (tagResult?.count as number) || 0;
|
||||
} catch (err) {
|
||||
console.error('Error fetching admin dashboard stats:', err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
postCount,
|
||||
tagCount
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
let { data }: { data: PageData } = $props();
|
||||
</script>
|
||||
|
||||
<div class="dashboard">
|
||||
<h2>仪表盘</h2>
|
||||
<p class="welcome">欢迎回来,<strong>{data.user?.email || '管理员'}</strong>!这是您的后台概览。</p>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<h3>文章总数</h3>
|
||||
<div class="number">{data.postCount}</div>
|
||||
<a href="/admin/posts" class="action-link">管理文章 →</a>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<h3>标签总数</h3>
|
||||
<div class="number">{data.tagCount}</div>
|
||||
<a href="/admin/tags" class="action-link">管理标签 →</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.dashboard h2 {
|
||||
margin-top: 0;
|
||||
border-bottom: 2px solid var(--text-color);
|
||||
padding-bottom: 12px;
|
||||
font-size: 2rem;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.welcome {
|
||||
color: var(--text-muted, rgba(0,0,0,0.6));
|
||||
margin-bottom: 2.5rem;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 25px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: transparent;
|
||||
border: 2px solid var(--text-color);
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
transition: border-color 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
border-color: var(--accent-color, #bd6262);
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 1.1rem;
|
||||
color: var(--text-muted, rgba(0,0,0,0.6));
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-card .number {
|
||||
font-size: 3.2rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-color, rgba(0,0,0,0.86));
|
||||
margin-bottom: 18px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.action-link {
|
||||
display: inline-block;
|
||||
font-size: 0.95rem;
|
||||
color: var(--text-color);
|
||||
font-weight: 600;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.2);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.stat-card:hover .action-link {
|
||||
color: var(--accent-color, #bd6262);
|
||||
border-bottom-color: var(--accent-color, #bd6262);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ platform, locals }) => {
|
||||
return {
|
||||
user: locals.user,
|
||||
platformEnv: !!platform?.env?.DB ? 'Cloudflare D1 (Connected)' : 'Local Mock'
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,108 @@
|
||||
<script lang="ts">
|
||||
import type { PageData } from './$types';
|
||||
|
||||
let { data }: { data: PageData } = $props();
|
||||
</script>
|
||||
|
||||
<div class="admin-page-header">
|
||||
<h2>系统设置</h2>
|
||||
</div>
|
||||
|
||||
<div class="settings-container">
|
||||
<div class="settings-card">
|
||||
<h3>博客信息</h3>
|
||||
<div class="info-row">
|
||||
<span class="label">博客名称</span>
|
||||
<span class="value">BlogFlare</span>
|
||||
</div>
|
||||
<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>
|
||||
</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;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
border: 2px solid var(--text-color);
|
||||
padding: 24px;
|
||||
background: transparent;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.settings-card h3 {
|
||||
margin: 0 0 18px 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);
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user