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:
+88
-40
@@ -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),
|
||||
})
|
||||
|
||||
// ---- 分享(真实动作) ----
|
||||
|
||||
+47
-10
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user