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
+47 -10
View File
@@ -58,15 +58,15 @@
>
<div class="relative aspect-[16/10] overflow-hidden bg-gray-100">
<img
:src="article.image"
:alt="t(`news.items.${article.slug}.title`)"
:src="article.image || ''"
:alt="locText(article.titleZh, article.titleEn)"
:loading="'lazy'"
class="w-full h-full object-cover transition-transform duration-700 group-hover:scale-110"
/>
<div class="absolute top-4 left-4">
<span
class="px-3 py-1.5 text-xs md:text-sm font-semibold rounded-full shadow-sm"
:class="article.badge"
:class="categoryBadge[article.category]"
>
{{ t(`news.categories.${article.category}`) }}
</span>
@@ -86,11 +86,11 @@
</div>
<h3 class="text-lg md:text-xl font-bold text-black mb-3 group-hover:text-gray-700 transition-colors duration-300 line-clamp-2">
{{ t(`news.items.${article.slug}.title`) }}
{{ locText(article.titleZh, article.titleEn) }}
</h3>
<p class="text-sm md:text-base text-gray-600 mb-4 flex-grow line-clamp-3">
{{ t(`news.items.${article.slug}.excerpt`) }}
{{ locText(article.excerptZh, article.excerptEn) }}
</p>
<div class="flex items-center justify-between pt-3 border-t border-gray-100">
@@ -127,11 +127,48 @@ import { useI18n } from 'vue-i18n'
import { useSeoMeta } from '#imports'
import gsap from 'gsap'
import { useAppStore } from '~/stores/app'
import { newsItems, formatNewsDate, getNewsCategories } from '~/data/news'
const { t, locale } = useI18n()
const appStore = useAppStore()
interface ArticleItem {
slug: string
category: 'insights' | 'projects' | 'announcements'
titleZh: string
titleEn: string
excerptZh: string
excerptEn: string
image: string | null
date: string | null
readTime: number
author: string
}
// 内容 API(仅已发布,date 降序)
const { data } = await useFetch<{ articles: ArticleItem[] }>('/api/news')
const articles = computed(() => data.value?.articles ?? [])
// 双语选择:切换语言即时生效(内容双字段已在 API 返回,无需重新请求)
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)
}
// 分类徽章样式(insights=紫、projects=蓝、announcements=绿)
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 headerWrapRef = ref<HTMLElement | null>(null)
const titleRef = ref<HTMLElement | null>(null)
const descRef = ref<HTMLElement | null>(null)
@@ -144,16 +181,16 @@ const visibleCount = ref(0)
const PAGE_SIZE = 6
const categories = ['all', ...getNewsCategories()]
const categories = ['all', 'insights', 'projects', 'announcements']
// 分类 + 搜索过滤(标题/摘要按当前语言文案匹配)
const filteredNews = computed(() => {
const kw = keyword.value.trim().toLowerCase()
return newsItems.filter((item) => {
return articles.value.filter((item) => {
if (activeCategory.value !== 'all' && item.category !== activeCategory.value) return false
if (!kw) return true
const title = t(`news.items.${item.slug}.title`).toLowerCase()
const excerpt = t(`news.items.${item.slug}.excerpt`).toLowerCase()
const title = locText(item.titleZh, item.titleEn).toLowerCase()
const excerpt = locText(item.excerptZh, item.excerptEn).toLowerCase()
return title.includes(kw) || excerpt.includes(kw)
})
})