Files
arcticnewone/app/pages/news/index.vue
T
virtheart 337eb4f05a feat: 登录改为 Casdoor 统一身份认证(SSO),重建用户体系
- 移除内置密码注册/登录/改密/删号/头像,统一走 Casdoor OIDC 授权码
- 服务端 casdoor-nodejs-sdk:code 换 token + 证书公钥验签 + get-account 补齐资料
- 用户表重建为 provider+provider_id(Casdoor sub 为准),邮箱不再唯一
- 管理员由 Casdoor token 的 isAdmin/IsAdmin 字段或 admin 角色判定,删除角色切换接口
- 前端登录弹窗改为申统认证跳转,注册去 Casdoor;后台用户列表只读角色
- 会话沿用 an_session httpOnly Cookie,requireUser/requireAdmin 守卫保留
- 配置注入 deploy.sh/.env.example;新增 casdoor 单测,删除 password 单测
2026-08-09 00:18:47 +08:00

247 lines
9.0 KiB
Vue

<template>
<main class="page-container min-h-screen pt-32 pb-20 px-4 md:px-8 mx-auto max-w-[1200px]">
<div
ref="headerWrapRef"
class="flex flex-col items-center justify-center text-center mb-10 md:mb-16"
>
<h1 ref="titleRef" class="text-3xl md:text-5xl font-bold mb-4 md:mb-6 tracking-tight text-black">{{ t('news.title') }}</h1>
<p ref="descRef" class="text-base md:text-lg text-gray-600 max-w-2xl">{{ t('news.description') }}</p>
</div>
<!-- 搜索框 -->
<div ref="searchWrapRef" class="flex justify-center mb-8">
<div class="relative w-full max-w-md">
<Icon name="ph:magnifying-glass" class="w-5 h-5 text-gray-400 absolute left-4 top-1/2 -translate-y-1/2" />
<input
v-model="keyword"
type="text"
:placeholder="t('search.placeholder')"
class="w-full pl-12 pr-4 py-3 rounded-full border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 text-sm md:text-base"
/>
</div>
</div>
<!-- 分类筛选 -->
<div
ref="filterWrapRef"
class="flex justify-center gap-3 md:gap-4 mb-10 md:mb-14 flex-wrap"
>
<button
v-for="category in categories"
:key="category"
@click="setCategory(category)"
class="px-5 md:px-6 py-2 md:py-2.5 rounded-full text-sm md:text-base font-semibold transition-all duration-300"
:class="activeCategory === category
? 'bg-black text-white shadow-lg'
: 'bg-gray-100 text-gray-700 hover:bg-gray-200'"
>
{{ t(`news.categories.${category}`) }}
</button>
</div>
<!-- 空结果 -->
<p v-if="!visibleNews.length" class="text-center text-gray-500 py-16">
{{ t('search.empty') }}
</p>
<!-- 文章列表 -->
<div
v-else
ref="articlesWrapRef"
class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 md:gap-8"
>
<NuxtLink
v-for="article in visibleNews"
:key="article.slug"
:to="`/news/${article.slug}`"
class="news-card group relative flex flex-col rounded-2xl md:rounded-3xl overflow-hidden bg-white border border-gray-100 hover:shadow-xl transition-all duration-500 cursor-pointer hover:-translate-y-2"
>
<div class="relative aspect-[16/10] overflow-hidden bg-gray-100">
<CoverImage
:src="article.image"
:alt="locText(article.titleZh, article.titleEn)"
:title="locText(article.titleZh, article.titleEn)"
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="categoryBadge[article.category]"
>
{{ t(`news.categories.${article.category}`) }}
</span>
</div>
</div>
<div class="flex flex-col flex-grow p-5 md:p-6">
<div class="flex items-center gap-3 text-xs md:text-sm text-gray-500 mb-3">
<span class="flex items-center gap-1.5">
<Icon name="ph:calendar-blank" class="w-4 h-4" />
{{ formatNewsDate(article.date, locale) }}
</span>
<span class="flex items-center gap-1.5">
<Icon name="ph:clock" class="w-4 h-4" />
{{ article.readTime }} {{ t('news.minutes') }}
</span>
</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">
{{ locText(article.titleZh, article.titleEn) }}
</h3>
<p class="text-sm md:text-base text-gray-600 mb-4 flex-grow line-clamp-3">
{{ locText(article.excerptZh, article.excerptEn) }}
</p>
<div class="flex items-center justify-between pt-3 border-t border-gray-100">
<span class="text-sm font-semibold text-black group-hover:text-gray-700 transition-colors duration-300">
{{ t('news.readMore') }}
</span>
<div class="w-8 h-8 rounded-full flex items-center justify-center bg-gray-50 text-gray-400 group-hover:bg-black group-hover:text-white transition-all duration-300">
<Icon name="ph:arrow-right" class="w-4 h-4" />
</div>
</div>
</div>
</NuxtLink>
</div>
<!-- 加载更多 -->
<div v-if="hasMore" class="flex justify-center mt-12">
<button
@click="loadMore"
class="px-8 py-3.5 rounded-full bg-black text-white font-semibold hover:bg-gray-800 transition-all duration-300 flex items-center gap-2"
>
<Icon name="ph:plus" class="w-5 h-5" />
{{ t('pagination.loadMore') }}
</button>
</div>
<p v-else-if="filteredNews.length > PAGE_SIZE" class="text-center text-gray-400 text-sm mt-8">
{{ t('pagination.noMore') }}
</p>
</main>
</template>
<script setup lang="ts">
import { nextTick, onMounted, ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useSeoMeta } from '#imports'
import gsap from 'gsap'
import { useAppStore } from '~/stores/app'
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)
const searchWrapRef = ref<HTMLElement | null>(null)
const filterWrapRef = ref<HTMLElement | null>(null)
const articlesWrapRef = ref<HTMLElement | null>(null)
const activeCategory = ref('all')
const keyword = ref('')
const visibleCount = ref(0)
const PAGE_SIZE = 6
const categories = ['all', 'insights', 'projects', 'announcements']
// 分类 + 搜索过滤(标题/摘要按当前语言文案匹配)
const filteredNews = computed(() => {
const kw = keyword.value.trim().toLowerCase()
return articles.value.filter((item) => {
if (activeCategory.value !== 'all' && item.category !== activeCategory.value) return false
if (!kw) return true
const title = locText(item.titleZh, item.titleEn).toLowerCase()
const excerpt = locText(item.excerptZh, item.excerptEn).toLowerCase()
return title.includes(kw) || excerpt.includes(kw)
})
})
const visibleNews = computed(() => filteredNews.value.slice(0, visibleCount.value))
const hasMore = computed(() => visibleCount.value < filteredNews.value.length)
const setCategory = (category: string) => {
activeCategory.value = category
visibleCount.value = PAGE_SIZE
}
const loadMore = () => {
visibleCount.value = Math.min(visibleCount.value + PAGE_SIZE, filteredNews.value.length)
}
useSeoMeta({
title: () => t('news.title'),
description: () => t('news.description'),
})
const playPageIntro = async () => {
await nextTick()
if (!headerWrapRef.value || !titleRef.value || !descRef.value || !filterWrapRef.value || !articlesWrapRef.value) return
const filterButtons = gsap.utils.toArray<HTMLElement>('button', filterWrapRef.value!)
const newsCards = gsap.utils.toArray<HTMLElement>('.news-card', articlesWrapRef.value!)
gsap.set([titleRef.value, descRef.value, searchWrapRef.value, ...filterButtons, ...newsCards], {
autoAlpha: 0, y: 30,
})
const tl = gsap.timeline({ defaults: { ease: 'power2.out' } })
tl.to(titleRef.value, { autoAlpha: 1, y: 0, duration: 0.5 })
tl.to(descRef.value, { autoAlpha: 1, y: 0, duration: 0.4 }, '-=0.3')
tl.to(searchWrapRef.value, { autoAlpha: 1, y: 0, duration: 0.4 }, '-=0.2')
tl.to(filterButtons, { autoAlpha: 1, y: 0, duration: 0.4, stagger: 0.05 }, '-=0.2')
tl.to(newsCards, { autoAlpha: 1, y: 0, duration: 0.5, stagger: 0.08 }, '-=0.2')
}
onMounted(() => {
visibleCount.value = PAGE_SIZE
if (!appStore.isAppLoading) {
playPageIntro()
} else {
window.addEventListener('app-loading-done', playPageIntro, { once: true })
}
})
</script>
<style scoped>
p { word-break: break-word; }
</style>