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
+48 -10
View File
@@ -36,11 +36,11 @@
</div>
<h3 class="text-xl md:text-3xl font-bold mb-3 line-clamp-2">
{{ t(`news.items.${item.slug}.title`) }}
{{ locText(item.titleZh, item.titleEn) }}
</h3>
<p v-if="item.showDescription" class="text-white/90 text-sm md:text-base line-clamp-3">
{{ t(`news.items.${item.slug}.excerpt`) }}
{{ locText(item.excerptZh, item.excerptEn) }}
</p>
</div>
@@ -70,16 +70,25 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
import { ref, onMounted, onUnmounted, nextTick, watch, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
import { newsItems, formatNewsDate } from '~/data/news'
gsap.registerPlugin(ScrollTrigger)
const { t, locale } = useI18n()
interface ArticleItem {
slug: string
category: 'insights' | 'projects' | 'announcements'
titleZh: string
titleEn: string
excerptZh: string
excerptEn: string
date: string | null
}
const rootRef = ref<HTMLElement | null>(null)
const headerRef = ref<HTMLElement | null>(null)
const cardElements = ref<(HTMLElement | null)[]>([])
@@ -89,6 +98,23 @@ const setCardRef = (el: any, index: number) => {
if (el) cardElements.value[index] = el
}
// 内容 API(仅已发布,date 降序)
const { data } = await useFetch<{ articles: ArticleItem[] }>('/api/news')
const articles = computed(() => data.value?.articles ?? [])
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)
}
// Bento 布局(与动态数据一一对应;分类图标/渐变/跨度)
const layout = [
{ categoryIcon: 'ph:article', gradient: 'bg-gradient-to-br from-blue-500 via-purple-500 to-pink-500', gridClass: 'col-span-12 md:col-span-6 md:row-span-2', showDescription: true },
@@ -100,10 +126,12 @@ const layout = [
] as const
// 取前 6 条动态,绑定布局
const updates = newsItems.slice(0, 6).map((item, i) => ({
...item,
...layout[i],
}))
const updates = computed(() =>
articles.value.slice(0, 6).map((item, i) => ({
...item,
...layout[i],
})),
)
// 卡片悬浮效果
const handleCardHover = (index: number, isHover: boolean) => {
@@ -120,9 +148,10 @@ const handleCardHover = (index: number, isHover: boolean) => {
})
}
onMounted(async () => {
const playIntro = async () => {
if (!rootRef.value || !headerRef.value || cardElements.value.length === 0) return
await nextTick()
if (!rootRef.value || !headerRef.value) return
if (ctx) ctx.revert()
ctx = gsap.context(() => {
// 初始状态
@@ -152,8 +181,17 @@ onMounted(async () => {
animation: tl,
})
}, rootRef.value)
}
onMounted(() => {
playIntro()
})
// 若数据异步到达(纯客户端首帧),卡片渲染后补跑入场动画
watch(updates, () => {
if (!ctx) playIntro()
}, { flush: 'post' })
onUnmounted(() => {
ctx?.revert()
})