d67849a311
- 内容迁入数据库: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 中间件 + 客户端会话恢复插件
212 lines
7.7 KiB
Vue
212 lines
7.7 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('work.title') }}</h1>
|
|
<p ref="descRef" class="text-base md:text-lg text-gray-600 max-w-2xl">{{ t('work.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(`work.categories.${category}`) }}
|
|
</button>
|
|
</div>
|
|
|
|
<!-- 空结果 -->
|
|
<p v-if="!visibleWork.length" class="text-center text-gray-500 py-16">
|
|
{{ t('search.empty') }}
|
|
</p>
|
|
|
|
<!-- 作品列表 -->
|
|
<div
|
|
v-else
|
|
ref="projectsWrapRef"
|
|
class="grid grid-cols-1 md:grid-cols-2 gap-6 md:gap-8"
|
|
>
|
|
<NuxtLink
|
|
v-for="project in visibleWork"
|
|
:key="project.slug"
|
|
:to="`/work/${project.slug}`"
|
|
class="work-card group relative block rounded-2xl md:rounded-3xl overflow-hidden cursor-pointer hover:shadow-2xl transition-all duration-500"
|
|
>
|
|
<div class="relative aspect-[4/3] overflow-hidden bg-gray-100">
|
|
<img
|
|
:src="project.image || ''"
|
|
:alt="locText(project.titleZh, project.titleEn)"
|
|
:loading="'lazy'"
|
|
class="w-full h-full object-cover transition-transform duration-700 group-hover:scale-110"
|
|
/>
|
|
<div class="absolute inset-0 bg-gradient-to-t from-black/60 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"></div>
|
|
</div>
|
|
|
|
<div class="p-6 md:p-8 bg-white">
|
|
<div class="flex items-start justify-between mb-3">
|
|
<h3 class="text-xl md:text-2xl font-bold text-black group-hover:text-gray-700 transition-colors duration-300">
|
|
{{ locText(project.titleZh, project.titleEn) }}
|
|
</h3>
|
|
<div class="w-9 h-9 md:w-10 md:h-10 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 flex-shrink-0 ml-3">
|
|
<Icon name="ph:arrow-up-right" class="w-4 h-4 md:w-5 md:h-5" />
|
|
</div>
|
|
</div>
|
|
<p class="text-sm md:text-base text-gray-600 mb-4">{{ locText(project.descriptionZh, project.descriptionEn) }}</p>
|
|
<div class="flex flex-wrap gap-2">
|
|
<span
|
|
v-for="tag in project.tags"
|
|
:key="tag"
|
|
class="px-3 py-1 text-xs md:text-sm bg-gray-50 text-gray-700 rounded-full"
|
|
>
|
|
{{ tag }}
|
|
</span>
|
|
</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="filteredWork.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 WorkItem {
|
|
slug: string
|
|
category: 'webDesign' | 'branding' | 'development'
|
|
titleZh: string
|
|
titleEn: string
|
|
descriptionZh: string
|
|
descriptionEn: string
|
|
year: string
|
|
tags: string[]
|
|
image: string | null
|
|
}
|
|
|
|
// 内容 API(仅已发布)
|
|
const { data } = await useFetch<{ works: WorkItem[] }>('/api/work')
|
|
const works = computed(() => data.value?.works ?? [])
|
|
|
|
// 双语选择:切换语言即时生效
|
|
const locText = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
|
|
|
|
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 projectsWrapRef = ref<HTMLElement | null>(null)
|
|
const activeCategory = ref('all')
|
|
const keyword = ref('')
|
|
const visibleCount = ref(0)
|
|
|
|
const PAGE_SIZE = 4
|
|
|
|
const categories = ['all', 'webDesign', 'branding', 'development']
|
|
|
|
// 分类 + 搜索过滤(标题/描述按当前语言文案匹配)
|
|
const filteredWork = computed(() => {
|
|
const kw = keyword.value.trim().toLowerCase()
|
|
return works.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 desc = locText(item.descriptionZh, item.descriptionEn).toLowerCase()
|
|
return title.includes(kw) || desc.includes(kw)
|
|
})
|
|
})
|
|
|
|
const visibleWork = computed(() => filteredWork.value.slice(0, visibleCount.value))
|
|
const hasMore = computed(() => visibleCount.value < filteredWork.value.length)
|
|
|
|
const setCategory = (category: string) => {
|
|
activeCategory.value = category
|
|
visibleCount.value = PAGE_SIZE
|
|
}
|
|
|
|
const loadMore = () => {
|
|
visibleCount.value = Math.min(visibleCount.value + PAGE_SIZE, filteredWork.value.length)
|
|
}
|
|
|
|
useSeoMeta({
|
|
title: () => t('work.title'),
|
|
description: () => t('work.description'),
|
|
})
|
|
|
|
const playPageIntro = async () => {
|
|
await nextTick()
|
|
if (!headerWrapRef.value || !titleRef.value || !descRef.value || !filterWrapRef.value || !projectsWrapRef.value) return
|
|
|
|
const filterButtons = gsap.utils.toArray<HTMLElement>('button', filterWrapRef.value!)
|
|
const projectCards = gsap.utils.toArray<HTMLElement>('.work-card', projectsWrapRef.value!)
|
|
|
|
gsap.set([titleRef.value, descRef.value, searchWrapRef.value, ...filterButtons, ...projectCards], {
|
|
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(projectCards, { 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>
|