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:
2026-08-06 16:15:14 +08:00
parent 5c3f3bca63
commit d67849a311
67 changed files with 4909 additions and 754 deletions
+88 -40
View File
@@ -14,7 +14,7 @@
<!-- 文章 Hero -->
<section class="relative h-[50vh] md:h-[60vh] overflow-hidden">
<img
:src="article.image"
:src="article.image || ''"
:alt="title"
class="w-full h-full object-cover"
/>
@@ -23,7 +23,7 @@
<div class="max-w-[800px] mx-auto">
<span
class="inline-block px-3 py-1.5 text-xs md:text-sm font-semibold rounded-full mb-4"
:class="article.badge"
:class="categoryBadge[article.category]"
>
{{ t(`news.categories.${article.category}`) }}
</span>
@@ -48,41 +48,38 @@
</div>
</section>
<!-- 文章内容 -->
<!-- 文章内容(内容块:paragraph / heading / quote / image) -->
<section class="max-w-[800px] mx-auto px-6 md:px-10 py-16 md:py-24">
<article class="prose prose-lg max-w-none">
<p class="text-gray-700 text-lg leading-relaxed mb-8">
{{ t(`news.detail.items.${slug}.content`) }}
</p>
<template v-for="(block, index) in blocks" :key="index">
<p
v-if="block.type === 'paragraph'"
class="text-gray-700 text-lg leading-relaxed mb-8"
>
{{ block.text }}
</p>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6 mt-12">
{{ t(`news.detail.items.${slug}.section1Title`) }}
</h2>
<p class="text-gray-700 text-lg leading-relaxed mb-8">
{{ t(`news.detail.items.${slug}.section1Content`) }}
</p>
<h2
v-else-if="block.type === 'heading'"
class="text-2xl md:text-3xl font-bold text-black mb-6 mt-12"
>
{{ block.text }}
</h2>
<blockquote class="border-l-4 border-black pl-6 my-10 italic text-gray-600 text-lg">
"{{ t(`news.detail.items.${slug}.quote`) }}"
</blockquote>
<blockquote
v-else-if="block.type === 'quote'"
class="border-l-4 border-black pl-6 my-10 italic text-gray-600 text-lg"
>
"{{ block.text }}"
</blockquote>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6 mt-12">
{{ t(`news.detail.items.${slug}.section2Title`) }}
</h2>
<p class="text-gray-700 text-lg leading-relaxed mb-8">
{{ t(`news.detail.items.${slug}.section2Content`) }}
</p>
<div class="my-10 rounded-2xl overflow-hidden">
<img :src="article.image" :alt="title" class="w-full h-auto" />
</div>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6 mt-12">
{{ t(`news.detail.items.${slug}.section3Title`) }}
</h2>
<p class="text-gray-700 text-lg leading-relaxed mb-8">
{{ t(`news.detail.items.${slug}.section3Content`) }}
</p>
<img
v-else-if="block.type === 'image'"
:src="block.text"
:alt="title"
class="my-10 rounded-2xl w-full h-auto"
/>
</template>
</article>
<!-- 分享按钮(真实动作) -->
@@ -135,12 +132,12 @@
class="group block rounded-2xl overflow-hidden bg-white shadow-lg hover:shadow-xl transition-all duration-300 hover:-translate-y-1"
>
<div class="relative aspect-[16/10] overflow-hidden">
<img :src="related.image" :alt="t(`news.items.${related.slug}.title`)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
<img :src="related.image || ''" :alt="locText(related.titleZh, related.titleEn)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
</div>
<div class="p-5">
<span class="text-xs text-gray-500">{{ formatNewsDate(related.date, locale) }}</span>
<h3 class="text-lg font-bold text-black group-hover:text-gray-600 transition-colors mt-1 line-clamp-2">
{{ t(`news.items.${related.slug}.title`) }}
{{ locText(related.titleZh, related.titleEn) }}
</h3>
</div>
</NuxtLink>
@@ -155,25 +152,76 @@ import { computed, ref } from 'vue'
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useSeoMeta, createError } from '#imports'
import { newsBySlug, newsItems, formatNewsDate } from '~/data/news'
const { t, locale } = useI18n()
const route = useRoute()
const slug = route.params.slug as string
const article = newsBySlug[slug]
interface Block {
type: 'paragraph' | 'heading' | 'quote' | 'image'
text: string
}
if (!article) {
interface ArticleItem {
slug: string
category: 'insights' | 'projects' | 'announcements'
titleZh: string
titleEn: string
excerptZh: string
excerptEn: string
contentZh: Block[]
contentEn: Block[]
image: string | null
date: string | null
readTime: number
author: string
}
const [{ data, error }, { data: listData }] = await Promise.all([
useFetch<{ article: ArticleItem }>(`/api/news/${slug}`),
useFetch<{ articles: ArticleItem[] }>('/api/news'),
])
// 未发布 / 不存在 → 404
if (error.value || !data.value?.article) {
throw createError({ statusCode: 404, statusMessage: 'Article not found' })
}
const title = computed(() => t(`news.items.${slug}.title`))
const article = computed<ArticleItem>(() => data.value!.article)
const relatedArticles = newsItems.filter((a) => a.slug !== slug).slice(0, 3)
const locText = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
function formatNewsDate(date: string | null, loc: string): string {
if (!date) return ''
const d = new Date(`${date}T00:00:00`)
if (Number.isNaN(d.getTime())) return date
return new Intl.DateTimeFormat(loc === 'zh' ? 'zh-CN' : 'en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(d)
}
const categoryBadge: Record<string, string> = {
insights: 'bg-purple-100 text-purple-700',
projects: 'bg-blue-100 text-blue-700',
announcements: 'bg-green-100 text-green-700',
}
const title = computed(() => locText(article.value.titleZh, article.value.titleEn))
// 正文内容块(按当前语言选择 contentZh / contentEn)
const blocks = computed(() =>
locale.value === 'zh' ? article.value.contentZh : article.value.contentEn,
)
const relatedArticles = computed(() =>
(listData.value?.articles ?? []).filter((a) => a.slug !== slug).slice(0, 3),
)
useSeoMeta({
title: () => `${title.value} - ${t('news.title')}`,
description: () => t(`news.items.${slug}.excerpt`),
description: () => locText(article.value.excerptZh, article.value.excerptEn),
})
// ---- 分享(真实动作) ----