685c7b51d1
- 账号体系:修改密码(/account + PATCH /api/auth/password)、自助删除账号 (DELETE /api/auth/me)、订阅退订(token + /unsubscribe 页) - 前台/SEO:RSS 订阅 /feed.xml、作品详情分享、canonical URL、 文章 Article JSON-LD、品牌化错误页(i18n) - 后台增强:图片管理 /admin/uploads、操作审计日志 /admin/audit(含清空)、 联系消息已读标记、评论列表分页 - 工程:vitest 测试(密码哈希/内容校验器/种子完整性,12 例)+ pnpm test - DB 迁移:contacts.read、subscribers.token、audit_logs(老库 ALTER 兼容) - 密码逻辑抽为 server/utils/password.ts 供测试
278 lines
9.7 KiB
Vue
278 lines
9.7 KiB
Vue
<template>
|
||
<main class="min-h-screen">
|
||
<!-- 返回按钮 -->
|
||
<div class="fixed top-28 left-4 md:left-8 z-30">
|
||
<NuxtLink
|
||
to="/news"
|
||
class="inline-flex items-center gap-2 px-4 py-2.5 rounded-full bg-white/90 backdrop-blur-sm shadow-lg hover:shadow-xl transition-all duration-300 text-sm font-semibold text-black hover:-translate-x-1"
|
||
>
|
||
<Icon name="ph:arrow-left" class="w-5 h-5" />
|
||
{{ t('news.backToList') }}
|
||
</NuxtLink>
|
||
</div>
|
||
|
||
<!-- 文章 Hero -->
|
||
<section class="relative h-[50vh] md:h-[60vh] overflow-hidden">
|
||
<img
|
||
:src="article.image || ''"
|
||
:alt="title"
|
||
class="w-full h-full object-cover"
|
||
/>
|
||
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent"></div>
|
||
<div class="absolute bottom-0 left-0 right-0 p-8 md:p-16">
|
||
<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="categoryBadge[article.category]"
|
||
>
|
||
{{ t(`news.categories.${article.category}`) }}
|
||
</span>
|
||
<h1 class="text-3xl md:text-5xl lg:text-6xl font-bold text-white mb-4 tracking-tight">
|
||
{{ title }}
|
||
</h1>
|
||
<div class="flex items-center gap-4 text-white/80 text-sm md:text-base">
|
||
<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>
|
||
<span class="flex items-center gap-1.5">
|
||
<Icon name="ph:user" class="w-4 h-4" />
|
||
{{ article.author }}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</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">
|
||
<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
|
||
v-else-if="block.type === 'heading'"
|
||
class="text-2xl md:text-3xl font-bold text-black mb-6 mt-12"
|
||
>
|
||
{{ block.text }}
|
||
</h2>
|
||
|
||
<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>
|
||
|
||
<img
|
||
v-else-if="block.type === 'image'"
|
||
:src="block.text"
|
||
:alt="title"
|
||
class="my-10 rounded-2xl w-full h-auto"
|
||
/>
|
||
</template>
|
||
</article>
|
||
|
||
<!-- 分享按钮(真实动作) -->
|
||
<div class="mt-16 pt-8 border-t border-gray-200">
|
||
<div class="flex items-center justify-between flex-wrap gap-4">
|
||
<p class="text-sm text-gray-500">{{ t('share.article') }}</p>
|
||
<div class="flex gap-3">
|
||
<button
|
||
@click="shareToX"
|
||
class="w-10 h-10 rounded-full bg-gray-100 hover:bg-black hover:text-white flex items-center justify-center transition-all duration-300"
|
||
:title="'X'"
|
||
aria-label="Share on X"
|
||
>
|
||
<Icon name="ph:x-logo" class="w-5 h-5" />
|
||
</button>
|
||
<button
|
||
@click="shareToLinkedIn"
|
||
class="w-10 h-10 rounded-full bg-gray-100 hover:bg-black hover:text-white flex items-center justify-center transition-all duration-300"
|
||
:title="'LinkedIn'"
|
||
aria-label="Share on LinkedIn"
|
||
>
|
||
<Icon name="ph:linkedin-logo" class="w-5 h-5" />
|
||
</button>
|
||
<button
|
||
@click="copyLink"
|
||
class="w-10 h-10 rounded-full bg-gray-100 hover:bg-black hover:text-white flex items-center justify-center transition-all duration-300"
|
||
:title="t('share.copy')"
|
||
aria-label="Copy link"
|
||
>
|
||
<Icon name="ph:link" class="w-5 h-5" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<p v-if="copyFeedback" class="text-sm mt-3 text-green-600">{{ copyFeedback }}</p>
|
||
</div>
|
||
|
||
<!-- 评论区 -->
|
||
<CommentSection :news-slug="slug" />
|
||
</section>
|
||
|
||
<!-- 相关文章 -->
|
||
<section class="bg-gray-50 py-16 md:py-24">
|
||
<div class="max-w-[1200px] mx-auto px-6 md:px-10">
|
||
<h2 class="text-2xl md:text-3xl font-bold text-black mb-10 text-center">{{ t('news.detail.relatedArticles') }}</h2>
|
||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||
<NuxtLink
|
||
v-for="related in relatedArticles"
|
||
:key="related.slug"
|
||
:to="`/news/${related.slug}`"
|
||
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="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">
|
||
{{ locText(related.titleZh, related.titleEn) }}
|
||
</h3>
|
||
</div>
|
||
</NuxtLink>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, ref } from 'vue'
|
||
import { useRoute } from 'vue-router'
|
||
import { useI18n } from 'vue-i18n'
|
||
import { useSeoMeta, useHead, useRuntimeConfig, createError } from '#imports'
|
||
|
||
const { t, locale } = useI18n()
|
||
const route = useRoute()
|
||
const slug = route.params.slug as string
|
||
|
||
interface Block {
|
||
type: 'paragraph' | 'heading' | 'quote' | 'image'
|
||
text: string
|
||
}
|
||
|
||
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 article = computed<ArticleItem>(() => data.value!.article)
|
||
|
||
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: () => locText(article.value.excerptZh, article.value.excerptEn),
|
||
})
|
||
|
||
// 文章 JSON-LD(Article schema,利于搜索引擎富摘要)
|
||
const { public: publicCfg } = useRuntimeConfig()
|
||
const siteBase = String(publicCfg.siteUrl || '').replace(/\/$/, '')
|
||
useHead({
|
||
script: [
|
||
{
|
||
type: 'application/ld+json',
|
||
innerHTML: JSON.stringify({
|
||
'@context': 'https://schema.org',
|
||
'@type': 'Article',
|
||
headline: title.value,
|
||
description: locText(article.value.excerptZh, article.value.excerptEn),
|
||
image: article.value.image || undefined,
|
||
datePublished: article.value.date || undefined,
|
||
author: { '@type': 'Organization', name: 'ArcticNewOne' },
|
||
mainEntityOfPage: {
|
||
'@type': 'WebPage',
|
||
'@id': siteBase ? `${siteBase}/news/${slug}` : undefined,
|
||
},
|
||
}),
|
||
},
|
||
],
|
||
})
|
||
|
||
// ---- 分享(真实动作) ----
|
||
const copyFeedback = ref('')
|
||
|
||
const shareUrl = () => (typeof window !== 'undefined' ? window.location.href : '')
|
||
const shareText = () => title.value
|
||
|
||
const shareToX = () => {
|
||
const url = `https://twitter.com/intent/tweet?url=${encodeURIComponent(shareUrl())}&text=${encodeURIComponent(shareText())}`
|
||
window.open(url, '_blank', 'noopener,noreferrer,width=600,height=480')
|
||
}
|
||
|
||
const shareToLinkedIn = () => {
|
||
const url = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl())}`
|
||
window.open(url, '_blank', 'noopener,noreferrer,width=600,height=480')
|
||
}
|
||
|
||
const copyLink = async () => {
|
||
try {
|
||
await navigator.clipboard.writeText(shareUrl())
|
||
copyFeedback.value = t('share.copied')
|
||
} catch {
|
||
// 剪贴板不可用时回退到 prompt 复制
|
||
window.prompt(t('share.copyFailed'), shareUrl())
|
||
}
|
||
setTimeout(() => (copyFeedback.value = ''), 3000)
|
||
}
|
||
</script>
|