feat: 后台管理系统(Admin Backend + 全量 CMS)
- 内容迁入数据库:articles/works 表(中英双语 + 内容块), server/utils/seed.ts 灌入现有 6 动态 + 6 作品,站点初始内容不变 - 前台内容 API:/api/news、/api/work(列表/详情,仅已发布), 页面/首页组件改为 useFetch 拉取并按 locale 选 zh/en 字段 - 后台管理 /admin(admin 中间件守卫): - Dashboard 统计、动态/作品增删改(块编辑器、图片上传 /api/admin/upload) - 用户管理(角色切换/删除)、评论审核、联系/订阅管理(导出 CSV) - 预置管理员:NUXT_ADMIN_INITIAL_PASSWORD 首次初始化创建 admin 账号 - 图片自托管:上传存 PVC /data/uploads,/uploads/[...] 路由服务 - sitemap 改查 DB;i18n 移除内容键(305 键对齐);删除 app/data 冗余模块 - 角色以数据库为准(后台可切换);admin 中间件 + 客户端会话恢复插件
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 后台 Dashboard:渲染 /api/admin/stats 统计卡片。
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
|
||||
useHead({ title: 'Dashboard' })
|
||||
|
||||
interface Stats {
|
||||
articles: number
|
||||
works: number
|
||||
publishedArticles: number
|
||||
publishedWorks: number
|
||||
users: number
|
||||
comments: number
|
||||
contacts: number
|
||||
subscribers: number
|
||||
favorites: number
|
||||
}
|
||||
|
||||
const stats = ref<Stats | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
|
||||
const loadStats = async () => {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
stats.value = await $fetch<Stats>('/api/admin/stats')
|
||||
} catch (err: any) {
|
||||
error.value = err?.data?.message || '统计加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadStats)
|
||||
|
||||
const cards = computed(() => [
|
||||
{
|
||||
label: '动态文章',
|
||||
value: stats.value?.articles,
|
||||
sub: () => `已发布 ${stats.value?.publishedArticles ?? 0}`,
|
||||
icon: 'ph:newspaper',
|
||||
to: '/admin/news',
|
||||
},
|
||||
{
|
||||
label: '作品',
|
||||
value: stats.value?.works,
|
||||
sub: () => `已发布 ${stats.value?.publishedWorks ?? 0}`,
|
||||
icon: 'ph:image-square',
|
||||
to: '/admin/work',
|
||||
},
|
||||
{ label: '注册用户', value: stats.value?.users, sub: () => '全部用户', icon: 'ph:users-three', to: '/admin/users' },
|
||||
{ label: '评论', value: stats.value?.comments, sub: () => '全部评论', icon: 'ph:chat-circle-text', to: '/admin/comments' },
|
||||
{ label: '联系留言', value: stats.value?.contacts, sub: () => '表单留言', icon: 'ph:envelope-simple', to: '/admin/contacts' },
|
||||
{ label: '订阅邮箱', value: stats.value?.subscribers, sub: () => 'Newsletter', icon: 'ph:paper-plane-tilt', to: '/admin/subscribers' },
|
||||
{ label: '收藏', value: stats.value?.favorites, sub: () => '作品收藏', icon: 'ph:bookmark-simple', to: '/admin/work' },
|
||||
])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- 页头 -->
|
||||
<div class="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-4 mb-8">
|
||||
<div>
|
||||
<h1 class="text-2xl md:text-3xl font-bold text-black tracking-tight">Dashboard</h1>
|
||||
<p class="mt-1 text-sm text-gray-500">站点内容与数据概览</p>
|
||||
</div>
|
||||
<div class="flex gap-3">
|
||||
<NuxtLink
|
||||
to="/admin/news"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
|
||||
>
|
||||
<Icon name="ph:plus" class="w-4 h-4" /> 新建动态
|
||||
</NuxtLink>
|
||||
<NuxtLink
|
||||
to="/admin/work"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors"
|
||||
>
|
||||
<Icon name="ph:plus" class="w-4 h-4" /> 新建作品
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 加载态 -->
|
||||
<div v-if="loading" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-5">
|
||||
<div
|
||||
v-for="i in 8"
|
||||
:key="i"
|
||||
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-6 h-32 animate-pulse"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<!-- 错误态 -->
|
||||
<div
|
||||
v-else-if="error"
|
||||
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-10 text-center"
|
||||
>
|
||||
<Icon name="ph:warning-circle" class="w-10 h-10 text-gray-300 mx-auto mb-4" />
|
||||
<p class="text-gray-500 mb-4">{{ error }}</p>
|
||||
<button
|
||||
type="button"
|
||||
@click="loadStats"
|
||||
class="px-5 py-2 rounded-lg bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
|
||||
>
|
||||
重新加载
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 统计卡片 -->
|
||||
<div v-else class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-5">
|
||||
<NuxtLink
|
||||
v-for="card in cards"
|
||||
:key="card.label"
|
||||
:to="card.to"
|
||||
class="group rounded-2xl bg-white border border-gray-100 shadow-sm p-6 hover:shadow-lg transition-all duration-300 hover:-translate-y-1"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-5">
|
||||
<div
|
||||
class="w-11 h-11 rounded-xl bg-gray-100 text-gray-600 flex items-center justify-center group-hover:bg-black group-hover:text-white transition-colors duration-300"
|
||||
>
|
||||
<Icon :name="card.icon" class="w-5 h-5" />
|
||||
</div>
|
||||
<Icon name="ph:arrow-up-right" class="w-4 h-4 text-gray-300 group-hover:text-gray-500 transition-colors" />
|
||||
</div>
|
||||
<p class="text-3xl font-bold text-black">{{ card.value ?? 0 }}</p>
|
||||
<p class="mt-1 text-sm font-semibold text-gray-800">{{ card.label }}</p>
|
||||
<p class="mt-0.5 text-xs text-gray-400">{{ card.sub() }}</p>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user