Files
arcticnewone/app/components/home/HomeUpdates.vue
T
virtheart d67849a311 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 中间件 + 客户端会话恢复插件
2026-08-06 16:27:19 +08:00

206 lines
7.3 KiB
Vue

<template>
<section ref="rootRef" class="relative bg-white min-h-screen flex flex-col items-center justify-center overflow-hidden py-20">
<div class="w-full max-w-[1400px] mx-auto px-6 md:px-10">
<!-- 标题 -->
<div ref="headerRef" class="text-center mb-16 md:mb-20">
<h2 class="text-5xl md:text-7xl font-bold tracking-tight text-black mb-6">
{{ t('home.updates.title') }}
</h2>
<p class="text-lg md:text-xl text-gray-600 max-w-2xl mx-auto">
{{ t('home.updates.subtitle') }}
</p>
</div>
<!-- Bento 网格 -->
<div class="grid grid-cols-12 gap-4 md:gap-6 auto-rows-[200px]">
<NuxtLink
v-for="(item, index) in updates"
:key="item.slug"
:to="`/news/${item.slug}`"
:ref="el => setCardRef(el, index)"
class="update-card group relative overflow-hidden rounded-3xl cursor-pointer block"
:class="item.gridClass"
:style="{ opacity: 0 }"
@mouseenter="() => handleCardHover(index, true)"
@mouseleave="() => handleCardHover(index, false)"
>
<!-- 背景渐变 -->
<div class="absolute inset-0 transition-transform duration-500 group-hover:scale-110" :class="item.gradient"></div>
<!-- 内容 -->
<div class="relative z-10 h-full p-6 md:p-8 flex flex-col justify-between text-white">
<div>
<div class="inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-white/20 backdrop-blur-sm text-xs md:text-sm font-semibold mb-4">
<Icon :name="item.categoryIcon" class="w-4 h-4" />
{{ t(`news.categories.${item.category}`) }}
</div>
<h3 class="text-xl md:text-3xl font-bold mb-3 line-clamp-2">
{{ locText(item.titleZh, item.titleEn) }}
</h3>
<p v-if="item.showDescription" class="text-white/90 text-sm md:text-base line-clamp-3">
{{ locText(item.excerptZh, item.excerptEn) }}
</p>
</div>
<div class="flex items-center justify-between">
<span class="text-xs md:text-sm text-white/80">{{ formatNewsDate(item.date, locale) }}</span>
<Icon name="ph:arrow-up-right" class="w-5 h-5 md:w-6 md:h-6 transition-transform duration-300 group-hover:translate-x-1 group-hover:-translate-y-1" />
</div>
</div>
<!-- 悬浮效果 -->
<div class="absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-300"></div>
</NuxtLink>
</div>
<!-- 查看更多 -->
<div class="flex justify-center mt-12 md:mt-16">
<NuxtLink
to="/news"
class="inline-flex items-center gap-3 px-8 py-4 rounded-full bg-black text-white font-semibold hover:shadow-2xl transition-all duration-300 hover:-translate-y-1"
>
{{ t('home.updates.viewAll') }}
<Icon name="ph:arrow-right" class="w-5 h-5" />
</NuxtLink>
</div>
</div>
</section>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted, nextTick, watch, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
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)[]>([])
let ctx: gsap.Context | null = null
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 },
{ categoryIcon: 'ph:briefcase', gradient: 'bg-gradient-to-br from-orange-500 to-red-500', gridClass: 'col-span-12 md:col-span-3 md:row-span-1', showDescription: false },
{ categoryIcon: 'ph:newspaper', gradient: 'bg-gradient-to-br from-green-500 to-emerald-500', gridClass: 'col-span-12 md:col-span-3 md:row-span-1', showDescription: false },
{ categoryIcon: 'ph:article', gradient: 'bg-gradient-to-br from-indigo-500 to-blue-500', gridClass: 'col-span-12 md:col-span-3 md:row-span-2', showDescription: true },
{ categoryIcon: 'ph:briefcase', gradient: 'bg-gradient-to-br from-pink-500 to-rose-500', gridClass: 'col-span-12 md:col-span-6 md:row-span-1', showDescription: false },
{ categoryIcon: 'ph:newspaper', gradient: 'bg-gradient-to-br from-amber-500 to-orange-500', gridClass: 'col-span-12 md:col-span-3 md:row-span-1', showDescription: false },
] as const
// 取前 6 条动态,绑定布局
const updates = computed(() =>
articles.value.slice(0, 6).map((item, i) => ({
...item,
...layout[i],
})),
)
// 卡片悬浮效果
const handleCardHover = (index: number, isHover: boolean) => {
const card = cardElements.value[index]
if (!card) return
gsap.to(card, {
y: isHover ? -8 : 0,
boxShadow: isHover
? '0 25px 50px -12px rgba(0, 0, 0, 0.25)'
: '0 10px 15px -3px rgba(0, 0, 0, 0.1)',
duration: 0.3,
ease: 'power2.out',
})
}
const playIntro = async () => {
if (!rootRef.value || !headerRef.value || cardElements.value.length === 0) return
await nextTick()
if (ctx) ctx.revert()
ctx = gsap.context(() => {
// 初始状态
gsap.set(headerRef.value, { autoAlpha: 0, y: 50 })
cardElements.value.forEach((card) => {
if (!card) return
gsap.set(card, { autoAlpha: 0, y: 60, scale: 0.9 })
})
// 入场动画:标题 + 卡片错开出现
const tl = gsap.timeline()
tl.to(headerRef.value, { autoAlpha: 1, y: 0, duration: 0.8, ease: 'power3.out' }, 0)
cardElements.value.forEach((card, index) => {
if (!card) return
tl.to(card, {
autoAlpha: 1, y: 0, scale: 1,
duration: 0.7, ease: 'power3.out',
}, 0.3 + index * 0.1)
})
ScrollTrigger.create({
trigger: rootRef.value,
start: 'top 75%',
toggleActions: 'play none none none',
animation: tl,
})
}, rootRef.value)
}
onMounted(() => {
playIntro()
})
// 若数据异步到达(纯客户端首帧),卡片渲染后补跑入场动画
watch(updates, () => {
if (!ctx) playIntro()
}, { flush: 'post' })
onUnmounted(() => {
ctx?.revert()
})
</script>
<style scoped>
.update-card {
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
will-change: transform, box-shadow, opacity;
}
</style>