Files
arcticnewone/app/pages/work/[slug].vue
T
virtheart 685c7b51d1 feat: 收官补齐全部未实现功能
- 账号体系:修改密码(/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 供测试
2026-08-06 17:26:26 +08:00

281 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<main class="min-h-screen">
<!-- 返回按钮 -->
<div class="fixed top-28 left-4 md:left-8 z-30">
<NuxtLink
to="/work"
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('work.backToList') }}
</NuxtLink>
</div>
<!-- Hero 大图 -->
<section class="relative h-[60vh] md:h-[70vh] overflow-hidden">
<img
:src="project.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-[1200px] mx-auto">
<div class="flex flex-wrap gap-2 mb-4">
<span
v-for="tag in project.tags"
:key="tag"
class="px-3 py-1 text-xs md:text-sm bg-white/20 backdrop-blur-sm text-white rounded-full"
>
{{ tag }}
</span>
</div>
<h1 class="text-4xl md:text-6xl lg:text-7xl font-bold text-white mb-4 tracking-tight">
{{ title }}
</h1>
<p class="text-lg md:text-xl text-white/80 max-w-2xl">
{{ description }}
</p>
</div>
</div>
</section>
<!-- 项目信息 -->
<section class="max-w-[1200px] mx-auto px-6 md:px-10 py-16 md:py-24">
<div class="grid grid-cols-1 lg:grid-cols-3 gap-12 lg:gap-16">
<!-- 左侧:项目详情 -->
<div class="lg:col-span-2 space-y-12">
<div>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6">{{ t('work.detail.overview') }}</h2>
<p class="text-gray-700 text-base md:text-lg leading-relaxed">
{{ locText(project.overviewZh, project.overviewEn) }}
</p>
</div>
<div>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6">{{ t('work.detail.challenge') }}</h2>
<p class="text-gray-700 text-base md:text-lg leading-relaxed">
{{ locText(project.challengeZh, project.challengeEn) }}
</p>
</div>
<div>
<h2 class="text-2xl md:text-3xl font-bold text-black mb-6">{{ t('work.detail.solution') }}</h2>
<p class="text-gray-700 text-base md:text-lg leading-relaxed">
{{ locText(project.solutionZh, project.solutionEn) }}
</p>
</div>
<!-- 项目截图 -->
<div v-if="project.gallery.length" class="space-y-6">
<h2 class="text-2xl md:text-3xl font-bold text-black">{{ t('work.detail.gallery') }}</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div
v-for="(img, index) in project.gallery"
:key="index"
class="rounded-2xl overflow-hidden shadow-lg hover:shadow-2xl transition-shadow duration-300"
>
<img :src="img" :alt="`${title} screenshot ${index + 1}`" class="w-full h-auto" />
</div>
</div>
</div>
</div>
<!-- 右侧:项目信息卡片 -->
<div class="space-y-8">
<div class="bg-gray-50 rounded-2xl p-6 md:p-8 sticky top-32">
<h3 class="text-lg font-bold text-black mb-6">{{ t('work.detail.projectInfo') }}</h3>
<div class="space-y-5">
<div>
<p class="text-sm text-gray-500 mb-1">{{ t('work.detail.client') }}</p>
<p class="text-base font-semibold text-black">{{ locText(project.clientZh, project.clientEn) }}</p>
</div>
<div>
<p class="text-sm text-gray-500 mb-1">{{ t('work.detail.year') }}</p>
<p class="text-base font-semibold text-black">{{ project.year }}</p>
</div>
<div>
<p class="text-sm text-gray-500 mb-1">{{ t('work.detail.duration') }}</p>
<p class="text-base font-semibold text-black">{{ locText(project.durationZh, project.durationEn) }}</p>
</div>
<div>
<p class="text-sm text-gray-500 mb-1">{{ t('work.detail.services') }}</p>
<div class="flex flex-wrap gap-2 mt-2">
<span
v-for="tag in project.tags"
:key="tag"
class="px-3 py-1 text-xs bg-black text-white rounded-full"
>
{{ tag }}
</span>
</div>
</div>
</div>
<div class="mt-8 space-y-3">
<!-- 访问项目(仅存在真实地址时渲染) -->
<a
v-if="project.url"
:href="project.url"
target="_blank"
rel="noopener noreferrer"
class="w-full inline-flex items-center justify-center gap-2 px-6 py-3.5 rounded-full bg-black text-white font-semibold hover:bg-gray-800 transition-colors duration-300"
>
{{ t('work.detail.visitProject') }}
<Icon name="ph:arrow-up-right" class="w-5 h-5" />
</a>
<!-- 收藏 -->
<FavoriteButton :work-slug="slug" />
</div>
<!-- 分享 -->
<div class="mt-8 pt-6 border-t border-gray-200">
<p class="text-sm text-gray-500 mb-3">{{ t('share.article') }}</p>
<div class="flex gap-3">
<button
@click="shareToX"
class="w-10 h-10 rounded-full bg-white border border-gray-200 hover:bg-black hover:text-white hover:border-black 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-white border border-gray-200 hover:bg-black hover:text-white hover:border-black 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-white border border-gray-200 hover:bg-black hover:text-white hover:border-black 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>
<p v-if="copyFeedback" class="text-sm mt-3 text-green-600">{{ copyFeedback }}</p>
</div>
</div>
</div>
</div>
</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('work.detail.relatedProjects') }}</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<NuxtLink
v-for="related in relatedProjects"
:key="related.slug"
:to="`/work/${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-[4/3] 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">
<h3 class="text-lg font-bold text-black group-hover:text-gray-600 transition-colors">{{ locText(related.titleZh, related.titleEn) }}</h3>
<p class="text-sm text-gray-500 mt-1">{{ related.tags?.[0] }}</p>
</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, createError } from '#imports'
const { t, locale } = useI18n()
const route = useRoute()
const slug = route.params.slug as string
interface WorkItem {
slug: string
category: 'webDesign' | 'branding' | 'development'
titleZh: string
titleEn: string
descriptionZh: string
descriptionEn: string
overviewZh: string
overviewEn: string
challengeZh: string
challengeEn: string
solutionZh: string
solutionEn: string
clientZh: string
clientEn: string
durationZh: string
durationEn: string
year: string
tags: string[]
image: string | null
gallery: string[]
url: string | null
}
const [{ data, error }, { data: listData }] = await Promise.all([
useFetch<{ work: WorkItem }>(`/api/work/${slug}`),
useFetch<{ works: WorkItem[] }>('/api/work'),
])
// 未发布 / 不存在 → 404
if (error.value || !data.value?.work) {
throw createError({ statusCode: 404, statusMessage: 'Project not found' })
}
const project = computed<WorkItem>(() => data.value!.work)
const locText = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
const title = computed(() => locText(project.value.titleZh, project.value.titleEn))
const description = computed(() => locText(project.value.descriptionZh, project.value.descriptionEn))
const relatedProjects = computed(() =>
(listData.value?.works ?? []).filter((p) => p.slug !== slug).slice(0, 3),
)
useSeoMeta({
title: () => `${title.value} - ${t('work.title')}`,
description: () => description.value,
})
// ---- 分享(真实动作) ----
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>