feat(app): 添加多模板关于我们页面及相关路由和404页面

- 新增404页面,优化未找到页面体验,避免被搜索引擎索引
- 增加文件代理接口,隐藏真实文件服务器地址,支持文件请求代理
- 实现/article、/case、/product及/page动态路由兼容列表与详情展示
- 添加动态CMS页面兼容入口处理旧式路径,统一路由与SEO设置
- 新增模板1、模板7、模板2、模板3关于我们页面,实现多模板支持
- 模板增强支持CMS单页内容加载及SEO信息动态设置
- 配置环境变量及Git忽略文件规则辅助开发和构建环境管理
This commit is contained in:
2026-09-08 12:13:44 +08:00
commit 2b69686795
381 changed files with 59891 additions and 0 deletions
+160
View File
@@ -0,0 +1,160 @@
<template>
<div class="bg-white">
<!-- 页头墨绿渐变色块不使用单页配图作背景 -->
<section
class="relative overflow-hidden"
style="background-image: linear-gradient(120deg, #008960 0%, #00a878 100%)"
>
<div class="absolute -top-20 -right-16 w-72 h-72 rounded-full bg-white/10 blur-3xl" />
<div class="absolute -bottom-24 left-10 w-64 h-64 rounded-full bg-black/10 blur-3xl" />
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-12 lg:py-16 relative z-10">
<nav class="text-xs text-white/70 mb-3" aria-label="面包屑">
<NuxtLink to="/" class="hover:text-white transition-colors">首页</NuxtLink>
<span class="mx-2">/</span>
<span class="text-white">{{ pageTitle }}</span>
</nav>
<h1 class="text-3xl sm:text-4xl font-bold text-white">{{ pageTitle }}</h1>
<p v-if="subTitle" class="text-white/75 mt-3 max-w-2xl leading-relaxed line-clamp-2">
{{ subTitle }}
</p>
</div>
</section>
<!-- 正文 -->
<section class="py-12 lg:py-16">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<div class="max-w-5xl mx-auto">
<div class="bg-white rounded-none shadow-sm border border-[var(--t9-border)] overflow-hidden">
<!-- 单页配图cms_page.image作为正文顶部插图 -->
<img
v-if="coverImage"
:src="coverImage"
:alt="pageTitle"
class="w-full h-56 sm:h-72 lg:h-80 object-cover"
>
<div class="p-6 sm:p-10">
<template v-if="hasContent">
<div class="flex flex-wrap items-center gap-3 mb-6 pb-6 border-b border-[var(--t9-border)]">
<span class="w-1.5 h-6 rounded-full bg-[var(--t9-primary)]" />
<h2 class="text-xl sm:text-2xl font-bold text-[var(--t9-text)]">{{ pageTitle }}</h2>
<span v-if="updateTimeText" class="sm:ml-auto text-sm text-[var(--t9-text-secondary)]">
更新于 {{ updateTimeText }}
</span>
</div>
<RichText :content="pageData?.content" />
<PageAttachments
v-if="pageData?.attachments?.length"
:attachments="pageData.attachments"
/>
</template>
<!-- 空态 / 错误态 -->
<div v-else class="text-center py-16">
<svg class="w-16 h-16 mx-auto text-[var(--t9-muted-light)] mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
</svg>
<p class="text-[var(--t9-text)] font-medium mb-2">{{ emptyState.title }}</p>
<p class="text-[var(--t9-muted-2)] text-sm leading-relaxed mb-6">{{ emptyState.desc }}</p>
<NuxtLink to="/" class="text-[var(--t9-primary)] hover:underline">返回首页</NuxtLink>
</div>
</div>
</div>
<!-- 底部 CTA -->
<div class="mt-10 rounded-none border border-[var(--t9-border)] bg-[var(--t9-primary-faint)] p-8 sm:p-10 text-center">
<h3 class="text-xl sm:text-2xl font-bold text-[var(--t9-text)] mb-3">想进一步了解我们</h3>
<p class="text-[var(--t9-text-secondary)] mb-6">
欢迎来电咨询或在线留言我们将安排专业顾问与您对接
</p>
<div class="flex flex-wrap items-center justify-center gap-4">
<NuxtLink
to="/contact"
class="inline-flex items-center px-6 py-3 bg-[var(--t9-primary)] text-white font-semibold rounded-sm hover:bg-[var(--t9-primary-dark)] transition-colors shadow-sm"
>
联系我们
</NuxtLink>
<a
v-if="siteInfo?.phone"
:href="`tel:${siteInfo.phone}`"
class="inline-flex items-center px-6 py-3 border border-[var(--t9-primary)] text-[var(--t9-primary)] font-semibold rounded-sm hover:bg-[var(--t9-primary-soft)] transition-colors"
>
{{ siteInfo.phone }}
</a>
</div>
</div>
</div>
</div>
</section>
</div>
</template>
<script setup lang="ts">
/**
* 模板 9 - 关于我们(墨绿文化出版风)
*
* 数据源:后台「单页管理」cms_page 表中 path=about 的记录。
* 链路:useFetch('/api/page/detail', { path: 'about' })
* → server/api/page/detail.get.ts 的 path 分支
* → 上游 /cms/cms-page/getByPath/about(带 TenantId
*
* 内容全部由后台维护:title / content(富文本)/ image(正文顶部插图)
* / keywords / descriptionSEO)。后台未录入时展示空态引导。
*/
import dayjs from 'dayjs'
import type { PageDetail } from '~/types'
const { siteInfo, fetchSiteInfo } = useSite()
const { fileUrl } = useFileUrl()
await fetchSiteInfo()
/** 单页详情:静态 key + 静态 query,保证 SSR 直出 */
const { data: pageData } = await useFetch<PageDetail>('/api/page/detail', {
key: 'page-about',
query: { path: 'about' }
})
const pageTitle = computed(() => pageData.value?.title?.trim() || '关于我们')
/** 正文顶部插图(cms_page.image */
const coverImage = computed(() => fileUrl(pageData.value?.photo || ''))
/** 正文是否可渲染 */
const hasContent = computed(() => Boolean(pageData.value?.hasContent && pageData.value?.content))
/** 页头副标题:优先单页 SEO 描述,其次站点简介 */
const subTitle = computed(() => {
const desc = pageData.value?.description?.trim()
if (desc) return desc
return (siteInfo.value?.comments || '').trim()
})
const updateTimeText = computed(() => {
const t = pageData.value?.updateTime
return t ? dayjs(t).format('YYYY-MM-DD') : ''
})
/** 空内容兜底文案,区分「未录入」与「接口异常」 */
const emptyState = computed(() => {
if (pageData.value?.status === 'error') {
return { title: '内容暂时无法加载', desc: '内容接口暂时不可用,请稍后再试。' }
}
return {
title: '内容尚未录入',
desc: '请前往管理后台「单页管理」补充 path 为 about 的页面正文。'
}
})
/** 用单页的 TDK 覆盖外层路由壳的默认 SEO(字段为空时自动回落站点信息) */
usePageSeo(
{
title: pageTitle.value,
path: '/about',
keywords: pageData.value?.keywords || undefined,
description: pageData.value?.description || undefined,
image: coverImage.value || undefined
},
siteInfo.value
)
</script>
@@ -0,0 +1,56 @@
<template>
<div class="min-h-screen py-16 bg-[var(--t9-bg-soft)]">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<div v-if="caseItem" class="max-w-4xl mx-auto">
<div class="mb-8">
<NuxtLink :to="`/case${caseItem?.navigationId ? '?navId=' + caseItem.navigationId : ''}`" class="text-sm text-[var(--t9-text-secondary)] hover:text-[var(--t9-primary)]"> 返回案例列表</NuxtLink>
</div>
<h1 class="text-3xl sm:text-4xl font-bold text-[var(--t9-text)] mb-4">{{ caseItem.title }}</h1>
<div class="flex flex-wrap items-center gap-4 text-sm text-[var(--t9-text-secondary)] mb-8 pb-8 border-b border-[var(--t9-border)]">
<span v-if="caseItem.clientName" class="px-3 py-1 bg-[var(--t9-primary-soft)] text-[var(--t9-primary)] rounded-full">
{{ caseItem.clientName }}
</span>
<span v-if="caseItem.projectTime">项目时间{{ caseItem.projectTime }}</span>
<span v-if="caseItem.categoryName">行业{{ caseItem.categoryName }}</span>
</div>
<div class="aspect-video bg-[var(--t9-primary-faint)] rounded-none overflow-hidden mb-10">
<img
v-if="caseItem.cover"
:src="fileUrl(caseItem.cover)"
:alt="caseItem.title"
class="w-full h-full object-cover"
>
</div>
<p v-if="caseItem.summary" class="text-lg text-[var(--t9-text-secondary)] mb-8 leading-relaxed">
{{ caseItem.summary }}
</p>
<RichText :content="caseItem.content" />
</div>
<div v-else class="text-center py-20">
<h1 class="text-2xl font-bold text-[var(--t9-text)] mb-4">案例不存在或已下架</h1>
<NuxtLink :to="`/case${caseItem?.navigationId ? '?navId=' + caseItem.navigationId : ''}`" class="text-[var(--t9-primary)] hover:underline">返回案例列表</NuxtLink>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import type { CaseItem } from '~/types'
/**
* 模板 9 - 案例详情页(墨绿文化出版风)
*/
const route = useRoute()
const id = route.params.id as string
const { fileUrl } = useFileUrl()
const { data: caseItem } = await useFetch<CaseItem | null>(`/api/case/detail?id=${id}`, {
key: `case-${id}`
})
</script>
@@ -0,0 +1,145 @@
<template>
<div class="min-h-screen bg-white pb-16">
<div class="t9-container">
<h1 class="t9-section-title">{{ pageTitle }}</h1>
<div v-if="pending" class="flex justify-center py-12">
<SiteLoading />
</div>
<SiteError v-else-if="error" message="获取列表失败" />
<!-- 图书封面墙对齐原站作品集板块5 列书籍封面 -->
<div v-else class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-5 lg:gap-6">
<NuxtLink
v-for="item in cases"
:key="item.id"
:to="`/case/${item.id}`"
class="group"
>
<div class="w-full aspect-[19/23] overflow-hidden bg-[var(--t9-bg-gray)]">
<img
:src="itemImage(item)"
:alt="item.title"
class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"
loading="lazy"
@error="onImgError"
>
</div>
<p
class="mt-2.5 text-sm text-center leading-snug t9-clamp-2 transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-muted-2)"
>{{ item.title }}</p>
</NuxtLink>
</div>
<!-- 空状态 -->
<div v-if="!pending && !error && cases.length === 0" class="text-center py-20">
<svg class="w-16 h-16 mx-auto mb-4" style="color: var(--t9-muted-light)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
</svg>
<p style="color: var(--t9-text-secondary)">暂无内容</p>
</div>
<!-- 分页 -->
<div v-if="totalPages > 1" class="flex justify-center mt-12">
<nav class="flex items-center gap-1.5 flex-wrap justify-center">
<button
v-for="p in totalPages"
:key="p"
class="min-w-[36px] h-9 px-2 text-sm border transition-colors"
:style="p === currentPage
? 'background-color: var(--t9-primary); border-color: var(--t9-primary); color: #fff'
: 'background-color: #fff; border-color: var(--t9-border); color: var(--t9-text)'"
@click="currentPage = p"
>
{{ p }}
</button>
</nav>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import type { CaseItem, PageResult } from '~/types'
import { collectDescendantNavIds } from '~/utils/nav-tree'
import { getCompressedImageUrl } from '~/utils/image'
/**
* 模板 9 - 案例列表页(墨绿文化出版风)
*/
const route = useRoute()
const { allNavigations, fetchSiteInfo } = useSite()
// 确保导航数据已加载(用于栏目标题与分类判定)
await fetchSiteInfo()
// 列表(栏目)入口 /case/{navigationId} 时按分类过滤;/case 根目录展示全部案例
const navigationId = computed<number | undefined>(() => {
const id = route.params.id
return id ? Number(id) : undefined
})
// 聚合:父栏目访问时递归收集自身 + 所有后代栏目 navigationId,交给后端 IN 查询
const categoryIds = computed<string | undefined>(() => {
const ids = collectDescendantNavIds(navigationId.value, allNavigations.value || [])
return ids.length ? ids.join(',') : undefined
})
const currentPage = ref(1)
const limit = 12
const { data, pending, error } = await useFetch<PageResult<CaseItem>>('/api/case/list', {
key: `case-list-${categoryIds.value ?? navigationId.value ?? 'all'}-p${currentPage.value}`,
query: {
page: currentPage,
limit,
...(categoryIds.value
? { categoryIds: categoryIds.value }
: (navigationId.value ? { navigationId: navigationId.value } : {}))
},
watch: [currentPage, categoryIds, navigationId]
})
const cases = computed(() => data.value?.list || [])
const totalCount = computed(() => data.value?.count ?? 0)
const totalPages = computed(() => Math.max(1, Math.ceil(totalCount.value / limit)))
// 切换栏目时回到第 1 页
watch([categoryIds, navigationId], () => {
currentPage.value = 1
})
// 栏目标题:命中导航取导航标题,否则用模块默认名
const pageTitle = computed(() => {
const id = navigationId.value
if (id == null) return '图书速递'
const navs = (allNavigations.value || []) as any[]
const find = (items: any[]): any => {
for (const it of items) {
if (it.navigationId === id) return it
if (it.children?.length) {
const f = find(it.children)
if (f) return f
}
}
return undefined
}
return find(navs)?.title || '图书速递'
})
/** 封面图:兼容 cover / image / photo / images[0] */
const FALLBACK_IMAGE = '/images/template-09/news-default.jpg'
function itemImage(item: CaseItem): string {
const anyItem = item as Record<string, unknown>
const raw = (anyItem.cover || anyItem.image || anyItem.photo
|| (Array.isArray(anyItem.images) ? (anyItem.images as string[])[0] : '')) as string
return raw ? getCompressedImageUrl(raw, { width: 800 }) : FALLBACK_IMAGE
}
function onImgError(e: Event) {
const el = e.target as HTMLImageElement
if (el && !el.src.endsWith(FALLBACK_IMAGE)) el.src = FALLBACK_IMAGE
}
</script>
@@ -0,0 +1,90 @@
<template>
<div class="min-h-screen py-16 bg-[var(--t9-bg-soft)]">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<div class="max-w-6xl mx-auto">
<div class="text-center mb-12">
<span class="inline-block px-3 py-1 rounded-full bg-[var(--t9-primary-soft)] text-[var(--t9-primary)] text-sm font-semibold mb-4">联系我们</span>
<h1 class="text-3xl font-bold text-[var(--t9-text)] mb-4">期待与您相遇</h1>
<p class="text-[var(--t9-text-secondary)] max-w-2xl mx-auto">有任何问题或合作意向欢迎随时与我们联系</p>
</div>
<div class="grid lg:grid-cols-2 gap-10">
<!-- 联系信息 -->
<div class="bg-white rounded-none p-8 shadow-sm border border-[var(--t9-border)]">
<h2 class="text-xl font-bold text-[var(--t9-text)] mb-6">联系方式</h2>
<div class="space-y-6">
<div class="flex items-start gap-4">
<div class="w-10 h-10 rounded-sm bg-[var(--t9-primary-soft)] flex items-center justify-center flex-shrink-0">
<svg class="w-5 h-5 text-[var(--t9-primary)]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z" />
</svg>
</div>
<div>
<h3 class="font-medium text-[var(--t9-text)]">电话咨询</h3>
<p class="text-[var(--t9-text-secondary)] mt-1">{{ siteInfo?.phone || '400-000-0000' }}</p>
</div>
</div>
<div class="flex items-start gap-4">
<div class="w-10 h-10 rounded-sm bg-[var(--t9-primary-soft)] flex items-center justify-center flex-shrink-0">
<svg class="w-5 h-5 text-[var(--t9-primary)]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
</div>
<div>
<h3 class="font-medium text-[var(--t9-text)]">电子邮箱</h3>
<p class="text-[var(--t9-text-secondary)] mt-1">{{ siteInfo?.email || 'contact@example.com' }}</p>
</div>
</div>
<div class="flex items-start gap-4">
<div class="w-10 h-10 rounded-sm bg-[var(--t9-primary-soft)] flex items-center justify-center flex-shrink-0">
<svg class="w-5 h-5 text-[var(--t9-primary)]" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
</div>
<div>
<h3 class="font-medium text-[var(--t9-text)]">公司地址</h3>
<p class="text-[var(--t9-text-secondary)] mt-1">{{ siteInfo?.address || '请填写公司地址' }}</p>
</div>
</div>
</div>
</div>
<!-- 在线表单 -->
<div class="bg-white rounded-none p-8 shadow-sm border border-[var(--t9-border)]">
<h2 class="text-xl font-bold text-[var(--t9-text)] mb-6">在线留言</h2>
<ContactForm
input-class="w-full px-4 py-2.5 border border-[var(--t9-border)] rounded-sm focus:outline-none focus:border-[var(--t9-primary)] bg-[var(--t9-bg-soft)] placeholder-[var(--t9-muted)]"
submit-class="w-full px-6 py-3 bg-[var(--t9-primary)] text-white font-semibold rounded-sm hover:bg-[var(--t9-primary-dark)] transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
label-class="block text-sm font-medium text-[var(--t9-text)] mb-1"
:accent="config.themeConfig.primaryColor"
/>
</div>
</div>
</div>
</div>
<PageAttachments
v-if="contactAttachments.length"
:attachments="contactAttachments"
class="mt-10"
/>
</div>
</template>
<script setup lang="ts">
import type { PageDetail, PageAttachment } from '~/types'
import config from '../config'
/**
* 模板 9 - 联系我们页(墨绿文化出版风)
*/
const { siteInfo, fetchSiteInfo } = useSite()
await fetchSiteInfo()
// 联系页附件(CMS「单页管理」按 path=contact 维护)
const { data: contactPage } = await useFetch<PageDetail>('/api/page/detail', { query: { path: 'contact' } })
const contactAttachments = computed<PageAttachment[]>(() => contactPage.value?.attachments || [])
</script>
+434
View File
@@ -0,0 +1,434 @@
<template>
<div class="bg-white">
<HeroSection />
<!-- 数据统计栏三组数字 -->
<section v-if="statsItems.length" class="bg-white pt-8">
<div class="t9-container">
<div class="grid grid-cols-1 sm:grid-cols-3 gap-6 sm:gap-4">
<div
v-for="(s, i) in statsItems"
:key="'stat-' + i"
class="flex items-center justify-center gap-3"
>
<span
class="w-14 h-14 rounded-full flex items-center justify-center flex-shrink-0"
style="background-color: var(--t9-primary-soft)"
>
<!-- 作家 -->
<svg v-if="i === 0" class="w-7 h-7" style="color: var(--t9-primary)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
</svg>
<!-- 书籍 -->
<svg v-else-if="i === 1" class="w-7 h-7" style="color: var(--t9-primary)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
</svg>
<!-- 读者 -->
<svg v-else class="w-7 h-7" style="color: var(--t9-primary)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
</svg>
</span>
<div class="leading-tight">
<div class="text-2xl font-bold" style="color: var(--t9-primary)">{{ s.value }}</div>
<div class="text-sm mt-1" style="color: var(--t9-muted)">{{ s.label }}</div>
</div>
</div>
</div>
</div>
</section>
<!-- 出版社简介 -->
<section v-if="introText" class="bg-white pt-8 pb-2">
<div class="t9-container">
<p class="text-[15px] leading-8 text-justify indent-8" style="color: var(--t9-text)">
{{ introText }}
</p>
</div>
</section>
<!-- 新闻中心左大图 + 右列表 -->
<section v-if="newsList.length" class="bg-white">
<div class="t9-container">
<h2 class="t9-section-title">{{ newsNav?.title || '新闻中心' }}</h2>
<div class="grid lg:grid-cols-2 gap-8 lg:gap-10 pb-8">
<!-- 头条大图 -->
<div v-if="featuredNews">
<NuxtLink :to="detailLink(newsNav?.model, featuredNews)" class="block group">
<div class="overflow-hidden bg-[var(--t9-bg-gray)] h-[240px] sm:h-[280px]">
<img
:src="itemImage(featuredNews)"
:alt="featuredNews.title"
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
loading="lazy"
@error="onImgError"
>
</div>
<div class="pt-4">
<div class="flex items-start justify-between gap-4">
<h3
class="text-base t9-ellipsis flex-1 transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-muted)"
>{{ featuredNews.title }}</h3>
<span class="text-sm flex-shrink-0" style="color: var(--t9-muted)">
{{ formatDate(featuredNews.publishTime || featuredNews.createTime) }}
</span>
</div>
<p class="mt-3 text-sm leading-7 t9-clamp-3" style="color: var(--t9-muted)">
{{ summaryOf(featuredNews) }}
</p>
</div>
</NuxtLink>
</div>
<!-- 列表 -->
<ul class="flex flex-col">
<li
v-for="item in restNews"
:key="item.id || item.articleId"
class="border-b"
style="border-color: var(--t9-border-2)"
>
<NuxtLink
:to="detailLink(newsNav?.model, item)"
class="flex items-center justify-between gap-4 py-[14px] group"
>
<span class="flex items-center gap-2 min-w-0 flex-1">
<span class="w-1.5 h-1.5 rounded-full flex-shrink-0" style="background-color: var(--t9-primary)"></span>
<span
class="t9-ellipsis text-[15px] transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-text)"
>{{ item.title }}</span>
</span>
<span class="text-sm flex-shrink-0" style="color: var(--t9-muted)">
{{ formatDate(item.publishTime || item.createTime) }}
</span>
</NuxtLink>
</li>
</ul>
</div>
</div>
</section>
<!-- 图书速递横向滚动封面 -->
<section v-if="carouselBooks.length" class="bg-white">
<div class="t9-container">
<h2 class="t9-section-title">{{ bookNav?.title || '图书速递' }}</h2>
<div class="relative pb-8">
<div
ref="scrollerRef"
class="t9-scroll-x flex gap-5 overflow-x-auto pb-3 scroll-smooth"
>
<NuxtLink
v-for="item in carouselBooks"
:key="'book-' + (item.id || item.articleId)"
:to="detailLink(bookNav?.model, item)"
class="flex-shrink-0 w-[150px] group"
>
<div class="w-[150px] h-[210px] overflow-hidden bg-[var(--t9-bg-gray)]">
<img
:src="itemImage(item)"
:alt="item.title"
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
loading="lazy"
@error="onImgError"
>
</div>
<p
class="mt-2 text-sm text-center t9-ellipsis transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-muted-2)"
>{{ item.title }}</p>
</NuxtLink>
</div>
<!-- 左右滚动按钮 -->
<button
v-if="carouselBooks.length > 6"
type="button" aria-label="向左滚动"
class="hidden lg:flex absolute -left-4 top-[85px] w-9 h-9 rounded-full items-center justify-center text-white shadow-md transition-opacity hover:opacity-90"
style="background-color: var(--t9-primary)"
@click="scrollBy(-600)"
>
<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" /></svg>
</button>
<button
v-if="carouselBooks.length > 6"
type="button" aria-label="向右滚动"
class="hidden lg:flex absolute -right-4 top-[85px] w-9 h-9 rounded-full items-center justify-center text-white shadow-md transition-opacity hover:opacity-90"
style="background-color: var(--t9-primary)"
@click="scrollBy(600)"
>
<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" /></svg>
</button>
</div>
</div>
</section>
<!-- 名家经典圆形头像网格 -->
<section v-if="masterList.length" class="bg-white">
<div class="t9-container">
<h2 class="t9-section-title">{{ masterNav?.title || '名家经典' }}</h2>
<div class="flex flex-wrap justify-center gap-x-6 gap-y-7 pb-8">
<NuxtLink
v-for="item in masterList"
:key="'master-' + (item.id || item.productId)"
:to="detailLink(masterNav?.model, item)"
class="w-[104px] sm:w-[120px] group"
>
<div
class="w-[104px] h-[104px] sm:w-[120px] sm:h-[120px] rounded-full overflow-hidden bg-[var(--t9-bg-gray)] border-2 border-transparent transition-colors group-hover:border-[var(--t9-primary)]"
>
<img
:src="itemImage(item)"
:alt="masterName(item)"
class="w-full h-full object-cover"
loading="lazy"
@error="onImgError"
>
</div>
<p
class="mt-2 text-[13px] text-center leading-snug t9-clamp-2 transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-text)"
>{{ masterName(item) }}</p>
</NuxtLink>
</div>
</div>
</section>
<!-- 作品集书籍封面墙 + 查看更多 -->
<section v-if="worksBooks.length" class="bg-white">
<div class="t9-container">
<h2 class="t9-section-title">作品集</h2>
<div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-5 lg:gap-6">
<NuxtLink
v-for="item in worksBooks"
:key="'work-' + (item.id || item.articleId)"
:to="detailLink(bookNav?.model, item)"
class="group"
>
<div class="w-full aspect-[19/23] overflow-hidden bg-[var(--t9-bg-gray)]">
<img
:src="itemImage(item)"
:alt="item.title"
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
@error="onImgError"
>
</div>
<p
class="mt-2 text-sm text-center t9-ellipsis transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-muted-2)"
>{{ item.title }}</p>
</NuxtLink>
</div>
<div class="text-center py-10">
<NuxtLink
:to="bookNav ? getNavLink(bookNav) : '/article'"
class="inline-block px-8 py-2 text-sm border transition-colors hover:text-white"
style="color: var(--t9-text); border-color: var(--t9-border-2)"
@mouseenter="onMoreEnter"
@mouseleave="onMoreLeave"
>
查看更多 More
</NuxtLink>
</div>
</div>
</section>
<!-- 兜底全部板块无数据时展示关于我们 -->
<AboutSection
v-if="!newsList.length && !carouselBooks.length && !masterList.length"
title-color="var(--t9-text-strong)"
accent-color="var(--t9-primary)"
summary-color="var(--t9-text-secondary)"
link-color="var(--t9-primary)"
container-class="t9-container grid lg:grid-cols-2 gap-10 items-center"
image-bg-color="var(--t9-bg-gray)"
image-object-fit="object-cover"
/>
</div>
</template>
<script setup lang="ts">
/**
* 模板 9 - 首页(墨绿文化出版风,对齐漓江出版社官网)
*
* 板块顺序:Banner → 数据统计 → 简介 → 新闻中心(左大图右列表)
* → 图书速递(横向滚动封面)→ 名家经典(圆形头像)→ 作品集(封面墙)
*
* 数据来源自适应导航:
* - newsNav :第 1 个 article 模型顶层栏目
* - bookNav case 模型栏目,缺省回退到第 2 个 article 栏目
* - masterNav product 模型顶层栏目(渲染为圆形头像)
*/
import dayjs from 'dayjs'
import HeroSection from '../components/HeroSection.vue'
import type { CmsNavigation, Article, Product, CaseItem, PageResult, ApiEnvelope } from '~/types'
import { collectDescendantNavIds } from '~/utils/nav-tree'
import { getNavLink, stripHtml } from '~/utils'
import { getCompressedImageUrl } from '~/utils/image'
type ContentItem = Article | Product | CaseItem
const { siteInfo, navigations, allNavigations, fetchSiteInfo } = useSite()
await fetchSiteInfo()
/** 顶层栏目:
* 优先取顶部主菜单(useSite.navigations,即 top===1 的权威顶部菜单),
* 避免把页脚链接(如「核销业务」「资质荣誉」)误当成首页内容板块的数据源;
* 顶部菜单为空时才回退到全部导航的顶层节点。 */
const topNavs = computed<CmsNavigation[]>(() => {
const primary = (navigations.value || []).filter((n) => (n.parentId || 0) === 0)
if (primary.length) return primary
return (allNavigations.value || []).filter((n) => (n.parentId || 0) === 0)
})
/** 新闻栏目:第 1 个 article 模型 */
const newsNav = computed<CmsNavigation | undefined>(() =>
topNavs.value.filter((n) => n.model === 'article')[0]
)
/** 图书栏目:case 模型优先,其次第 2 个 article 栏目 */
const bookNav = computed<CmsNavigation | undefined>(() =>
topNavs.value.find((n) => n.model === 'case')
|| topNavs.value.filter((n) => n.model === 'article')[1]
)
/** 名家栏目:product 模型 */
const masterNav = computed<CmsNavigation | undefined>(() =>
topNavs.value.find((n) => n.model === 'product')
)
/** 通用列表拉取
* 先按栏目(含所有后代栏目)过滤;若该栏目下暂无内容,回退为不限栏目再取一次,
* 兼容后台内容尚未归类到具体栏目的站点,避免首页板块整块空白。 */
async function fetchList(nav: CmsNavigation | undefined, limit: number): Promise<ContentItem[]> {
if (!nav) return []
const api = nav.model === 'product'
? '/api/product/list'
: nav.model === 'case'
? '/api/case/list'
: '/api/article/list'
const ids = collectDescendantNavIds(nav.navigationId, allNavigations.value || [])
const load = async (categoryIds?: string): Promise<ContentItem[]> => {
try {
const res = await $fetch<ApiEnvelope<PageResult<ContentItem>> | PageResult<ContentItem>>(api, {
query: { categoryIds, page: 1, limit }
})
return ((res as ApiEnvelope<PageResult<ContentItem>>)?.data?.list
?? (res as PageResult<ContentItem>)?.list
?? []) as ContentItem[]
} catch {
return []
}
}
const scoped = ids.length ? ids.join(',') : undefined
const list = await load(scoped)
if (list.length || !scoped) return list
return load(undefined)
}
/** SSR 并发拉取三类数据 */
const [newsList, bookList, masterList] = await Promise.all([
fetchList(newsNav.value, 7),
fetchList(bookNav.value, 27),
fetchList(masterNav.value, 21)
])
/** 新闻头条与列表 */
const featuredNews = computed<ContentItem | undefined>(() => newsList[0])
const restNews = computed<ContentItem[]>(() => newsList.slice(1, 7))
/** 图书速递(前 12 条横滚)与作品集(后续 15 条封面墙) */
const carouselBooks = computed<ContentItem[]>(() => bookList.slice(0, 12))
const worksBooks = computed<ContentItem[]>(() => bookList.slice(12, 27))
/** 数据统计栏:优先后台 config.stats(JSON 数组),否则用实际内容数量兜底 */
const statsItems = computed<{ value: string, label: string }[]>(() => {
const raw = (siteInfo.value?.config as Record<string, unknown> | undefined)?.stats
let parsed: unknown = raw
if (typeof raw === 'string') {
try { parsed = JSON.parse(raw) } catch { parsed = null }
}
if (Array.isArray(parsed) && parsed.length) {
return (parsed as { value?: string | number, label?: string }[])
.filter((s) => s && (s.value !== undefined || s.label))
.slice(0, 3)
.map((s) => ({ value: String(s.value ?? ''), label: String(s.label ?? '') }))
}
const items: { value: string, label: string }[] = []
if (masterList.length) items.push({ value: `${masterList.length}+`, label: `${masterNav.value?.title || '名家'}` })
if (bookList.length) items.push({ value: `${bookList.length}+`, label: `${bookNav.value?.title || '作品'}` })
if (newsList.length) items.push({ value: `${newsList.length}+`, label: `${newsNav.value?.title || '资讯'}` })
return items.length === 3 ? items : []
})
/** 简介文案 */
const introText = computed(() =>
stripHtml(String(siteInfo.value?.comments || (siteInfo.value as Record<string, unknown> | null)?.content || '')) || ''
)
/** 默认封面图(文章/图书无图时使用) */
const FALLBACK_IMAGE = '/images/template-09/news-default.jpg'
/** 内容封面图:兼容 image / cover / photo / images[0] */
function itemImage(item: ContentItem): string {
const anyItem = item as Record<string, unknown>
const raw = (anyItem.image || anyItem.cover || anyItem.photo
|| (Array.isArray(anyItem.images) ? (anyItem.images as string[])[0] : '')) as string
if (!raw) return FALLBACK_IMAGE
return getCompressedImageUrl(raw, { width: 800 })
}
/** 图片加载失败回退 */
function onImgError(e: Event) {
const el = e.target as HTMLImageElement
if (el && !el.src.endsWith(FALLBACK_IMAGE)) el.src = FALLBACK_IMAGE
}
/** 名家/产品名称:兼容 productName / title */
function masterName(item: ContentItem): string {
const anyItem = item as Record<string, unknown>
return String(anyItem.productName || anyItem.title || '')
}
/** 摘要 */
function summaryOf(item: ContentItem): string {
const anyItem = item as Record<string, unknown>
const s = (anyItem.summary || anyItem.description || anyItem.content || '') as string
return stripHtml(s).slice(0, 120)
}
/** 详情链接 */
function detailLink(model: string | undefined, item: ContentItem): string {
const anyItem = item as Record<string, unknown>
const id = anyItem.id || anyItem.articleId || anyItem.productId
if (model === 'product') return `/product/${id}`
if (model === 'case') return `/case/${id}`
return `/article/${id}`
}
function formatDate(date?: unknown) {
if (!date) return ''
return dayjs(String(date)).format('YYYY-MM-DD')
}
/** 图书速递横向滚动 */
const scrollerRef = ref<HTMLElement | null>(null)
function scrollBy(delta: number) {
scrollerRef.value?.scrollBy({ left: delta, behavior: 'smooth' })
}
/** 「查看更多」按钮 hover 主色填充 */
function onMoreEnter(e: Event) {
const el = e.target as HTMLElement
el.style.backgroundColor = 'var(--t9-primary)'
el.style.borderColor = 'var(--t9-primary)'
el.style.color = '#ffffff'
}
function onMoreLeave(e: Event) {
const el = e.target as HTMLElement
el.style.backgroundColor = ''
el.style.borderColor = 'var(--t9-border-2)'
el.style.color = 'var(--t9-text)'
}
</script>
@@ -0,0 +1,84 @@
<template>
<div class="min-h-screen bg-white py-10">
<div class="t9-container">
<div v-if="article" class="max-w-4xl mx-auto">
<!-- 面包屑 -->
<div class="mb-6 text-sm" style="color: var(--t9-muted)">
<NuxtLink to="/" class="hover:text-[var(--t9-primary)] transition-colors">首页</NuxtLink>
<span class="mx-2">&gt;</span>
<NuxtLink :to="`/article${article?.navigationId ? '?navId=' + article.navigationId : ''}`" class="hover:text-[var(--t9-primary)] transition-colors">
{{ article.categoryName || '新闻中心' }}
</NuxtLink>
<span class="mx-2">&gt;</span>
<span>正文</span>
</div>
<h1 class="text-2xl sm:text-[28px] font-bold leading-relaxed text-center" style="color: var(--t9-text-strong)">
{{ article.title }}
</h1>
<div
class="flex flex-wrap items-center justify-center gap-5 text-sm mt-5 pb-5 border-b"
style="color: var(--t9-muted); border-color: var(--t9-border)"
>
<span>{{ formatDate(article.publishTime || article.createTime) }}</span>
<span v-if="article.author">作者{{ article.author }}</span>
<span v-if="article.source">来源{{ article.source }}</span>
<span v-if="article.categoryName" style="color: var(--t9-primary)">{{ article.categoryName }}</span>
</div>
<div v-if="article.image || article.cover" class="mt-8 overflow-hidden bg-[var(--t9-bg-gray)]">
<img
:src="fileUrl(article.image || article.cover)"
:alt="article.title"
class="w-full h-auto object-cover"
>
</div>
<div class="mt-8">
<RichText :content="article.content" />
<PageAttachments
v-if="article?.files?.length"
:attachments="article.files"
/>
</div>
<div class="mt-10 pt-6 border-t" style="border-color: var(--t9-border)">
<NuxtLink
:to="`/article${article?.navigationId ? '?navId=' + article.navigationId : ''}`"
class="inline-block px-6 py-2 text-sm border transition-colors hover:text-white hover:bg-[var(--t9-primary)] hover:border-[var(--t9-primary)]"
style="color: var(--t9-text); border-color: var(--t9-border-2)"
>
返回列表
</NuxtLink>
</div>
</div>
<div v-else class="text-center py-20">
<h1 class="text-2xl font-bold mb-4" style="color: var(--t9-text-strong)">文章不存在或已下架</h1>
<NuxtLink :to="`/article${article?.navigationId ? '?navId=' + article.navigationId : ''}`" class="hover:underline" style="color: var(--t9-primary)">返回新闻列表</NuxtLink>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import dayjs from 'dayjs'
import type { Article } from '~/types'
/**
* 模板 9 - 新闻详情页(墨绿文化出版风)
*/
const route = useRoute()
const id = route.params.id as string
const { fileUrl } = useFileUrl()
const { data: article } = await useFetch<Article | null>(`/api/article/detail?id=${id}`, {
key: `article-${id}`
})
function formatDate(date?: string) {
if (!date) return ''
return dayjs(date).format('YYYY-MM-DD')
}
</script>
@@ -0,0 +1,206 @@
<template>
<div class="min-h-screen bg-white pb-16">
<div class="t9-container">
<!-- 栏目标题 -->
<h1 class="t9-section-title">{{ pageTitle }}</h1>
<div v-if="pending" class="flex justify-center py-12">
<SiteLoading />
</div>
<div v-else-if="error" class="text-center py-12">
<SiteError message="获取新闻列表失败" />
</div>
<template v-else>
<!-- 列表式左缩略图 + 右标题摘要日期 -->
<ul v-if="articles.length > 0" class="border-t" style="border-color: var(--t9-border)">
<li
v-for="item in articles"
:key="item.id || item.articleId"
class="border-b"
style="border-color: var(--t9-border)"
>
<NuxtLink
:to="`/article/${item.id || item.articleId}`"
class="flex gap-5 py-6 group"
>
<div class="w-[200px] h-[132px] flex-shrink-0 overflow-hidden bg-[var(--t9-bg-gray)] hidden sm:block">
<img
:src="itemImage(item)"
:alt="item.title"
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
loading="lazy"
@error="onImgError"
>
</div>
<div class="flex-1 min-w-0 flex flex-col">
<h2
class="text-[17px] font-medium t9-clamp-2 transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-text-strong)"
>{{ item.title }}</h2>
<p class="mt-3 text-sm leading-7 t9-clamp-2 flex-1" style="color: var(--t9-muted)">
{{ stripHtml(item.summary || item.content || '') }}
</p>
<div class="mt-3 flex items-center gap-4 text-xs" style="color: var(--t9-muted)">
<span>{{ formatDate(item.publishTime || item.createTime) }}</span>
<span v-if="item.categoryName" style="color: var(--t9-primary)">{{ item.categoryName }}</span>
</div>
</div>
</NuxtLink>
</li>
</ul>
<!-- 空状态 -->
<div v-else class="text-center py-20">
<svg class="w-16 h-16 mx-auto mb-4" style="color: var(--t9-muted-light)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
</svg>
<p style="color: var(--t9-text-secondary)">暂无新闻内容</p>
</div>
<!-- 分页 -->
<div v-if="totalPages > 1" class="flex justify-center mt-10">
<nav class="flex items-center gap-1.5 flex-wrap justify-center">
<button
v-for="p in totalPages"
:key="p"
class="min-w-[36px] h-9 px-2 text-sm border transition-colors"
:style="p === currentPage
? 'background-color: var(--t9-primary); border-color: var(--t9-primary); color: #fff'
: 'background-color: #fff; border-color: var(--t9-border); color: var(--t9-text)'"
@click="currentPage = p"
>
{{ p }}
</button>
</nav>
</div>
</template>
</div>
</div>
</template>
<script setup lang="ts">
/**
* 模板 9 - 新闻列表页(墨绿文化出版风)
*/
import dayjs from 'dayjs'
import type { Article, PageResult, ApiEnvelope, CmsNavigation } from '~/types'
import { collectDescendantNavIds } from '~/utils/nav-tree'
import { getCompressedImageUrl } from '~/utils/image'
const { navigations, allNavigations, fetchSiteInfo } = useSite()
const route = useRoute()
await fetchSiteInfo()
/** 从路由参数、查询参数或导航中获取栏目 navigationId
*
* 优先级(2026-07-21 修正):
* 1. route.query.navId(查询参数 ?navId=xxx,优先——导航子分类下拉切换时通过此方式传入,
* 必须高于 route.params.id,否则 /article/4277?navId=4278 会因 params.id=4277 先命中而忽略 navId
* 2. route.params.id(路由参数 /article/:navigationId
* 3. navigations 中 model=article 的第一个栏目(兜底)
*/
const navigationId = computed<number | undefined>(() => {
// 1. 查询参数优先(导航子分类下拉切换时传入)
const queryNavId = route.query.navId as string
if (queryNavId) {
const num = Number(queryNavId)
if (!Number.isNaN(num)) return num
}
// 2. 路由参数
const routeId = route.params.id as string
if (routeId) {
const num = Number(routeId)
if (!Number.isNaN(num)) return num
}
// 3. 兜底:优先顶部主菜单(top===1)中的 article 栏目,避免命中页脚链接;顶部没有再退回全部导航
const isArticleNav = (n: CmsNavigation) =>
n.model === 'article' || (n.path || '').split('/').filter(Boolean)[0] === 'article'
const nav = (navigations.value || []).find(isArticleNav)
|| (allNavigations.value || []).find(isArticleNav)
return nav?.navigationId
})
/** 聚合:父栏目访问时递归收集自身 + 所有后代栏目 navigationId,交给后端 IN 查询 */
const categoryIds = computed<string | undefined>(() => {
const ids = collectDescendantNavIds(navigationId.value, allNavigations.value || [])
return ids.length ? ids.join(',') : undefined
})
/** 页面标题 */
const pageTitle = computed(() => {
const navs = allNavigations.value || []
const findNav = (items: CmsNavigation[]): CmsNavigation | undefined => {
for (const item of items) {
if (item.navigationId === navigationId.value) return item
if (item.children?.length) {
const found = findNav(item.children)
if (found) return found
}
}
return undefined
}
if (keywords.value) return `搜索:"${keywords.value}"`
return findNav(navs)?.title || '新闻资讯'
})
/** 搜索关键词(来自 Header 搜索框提交的 ?keywords= */
const keywords = computed(() => ((route.query.keywords as string) || '').trim())
const currentPage = ref(1)
const limit = 12
// 响应式 query + watch 选项触发翻页/换栏目的重新请求;
// key 带页码,保证每一页独立缓存、翻页必然重新拉取(避免共用 key 被缓存返回第 1 页)。
// keywords 变化时同样触发重新请求,关键词搜索忽略栏目、全局检索。
const { data, pending, error } = await useFetch<
ApiEnvelope<PageResult<Article>> | PageResult<Article>
>('/api/article/list', {
key: `news-list-${keywords.value || 'all'}-${categoryIds.value ?? navigationId.value ?? 'default'}-p${currentPage.value}`,
query: {
categoryIds: keywords.value ? undefined : categoryIds.value,
keywords: keywords.value || undefined,
page: currentPage,
limit
},
watch: [currentPage, navigationId, categoryIds, keywords]
})
const articles = computed<Article[]>(() => {
const envelope = data.value as ApiEnvelope<PageResult<Article>>
const direct = data.value as PageResult<Article>
return envelope?.data?.list || direct?.list || []
})
const totalCount = computed(() => {
const envelope = data.value as ApiEnvelope<PageResult<Article>>
const direct = data.value as PageResult<Article>
return envelope?.data?.count || envelope?.data?.total || direct?.count || direct?.total || 0
})
const totalPages = computed(() => {
return Math.ceil(totalCount.value / limit)
})
// 栏目切换 / 关键词变化时回到第 1 页(watch 选项已负责重新请求)
watch([navigationId, keywords], () => {
currentPage.value = 1
})
function formatDate(date?: string) {
if (!date) return ''
return dayjs(date).format('YYYY-MM-DD')
}
/** 列表缩略图:兼容 image / cover / photo,缺省用本地兜底图 */
const FALLBACK_IMAGE = '/images/template-09/news-default.jpg'
function itemImage(item: Article): string {
const raw = item.image || item.cover || item.photo || ''
return raw ? getCompressedImageUrl(raw, { width: 800 }) : FALLBACK_IMAGE
}
function onImgError(e: Event) {
const el = e.target as HTMLImageElement
if (el && !el.src.endsWith(FALLBACK_IMAGE)) el.src = FALLBACK_IMAGE
}
</script>
+161
View File
@@ -0,0 +1,161 @@
<template>
<div class="min-h-[60vh] bg-white pb-16">
<div class="t9-container">
<!-- 顶部栏目标题 + 自身内容 -->
<div v-if="pageTitle" class="max-w-4xl mx-auto">
<h1 class="t9-section-title">{{ pageTitle }}</h1>
<div v-if="pageData && pageData.hasContent">
<div v-if="pageData.updateTime" class="text-sm text-center mb-8" style="color: var(--t9-muted)">
更新时间{{ formatDate(pageData.updateTime) }}
</div>
<RichText :content="pageData.content" />
</div>
<PageAttachments
v-if="pageData?.attachments?.length"
:attachments="pageData.attachments"
/>
</div>
<!-- 子栏目聚合列表 -->
<div v-if="childCards.length" class="max-w-5xl mx-auto mt-14">
<h2 class="t9-section-title">子栏目</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
<NuxtLink
v-for="p in childCards"
:key="p.navigationId"
:to="`/page/${p.navigationId}`"
class="block p-6 border transition-colors hover:border-[var(--t9-primary)]"
style="border-color: var(--t9-border)"
>
<h3 class="text-lg font-semibold mb-2" style="color: var(--t9-text-strong)">{{ p.title }}</h3>
<p class="text-sm leading-7 t9-clamp-3" style="color: var(--t9-muted)">{{ excerpt(p.content) }}</p>
</NuxtLink>
</div>
</div>
<!-- 空状态 -->
<div v-if="!pageData?.hasContent && !childCards.length" class="text-center py-20">
<p class="mb-2" style="color: var(--t9-text-secondary)">{{ emptyState.title }}</p>
<p class="text-sm mb-6 leading-relaxed" style="color: var(--t9-muted-2)">
{{ emptyState.desc }}<br />
当前导航{{ currentNav?.title || pageTitle }}ID{{ navigationId }}
</p>
<NuxtLink to="/" class="hover:underline" style="color: var(--t9-primary)">返回首页</NuxtLink>
</div>
</div>
</div>
</template>
<script setup lang="ts">
/**
* 模板 9 - 通用 CMS 页面(墨绿文化出版风)
* 支持两种入口:
* 1. /page/:navigationId → CMS 导航路径(优先)
* 2. /:slug → 传统路径
*
* 父栏目聚合:当当前 page 栏目拥有子栏目时,递归收集其下所有子栏目的单页,
* 以卡片列表形式聚合展示(每个子页卡片链接到 /page/{childNavId} 详情页)。
*/
import dayjs from 'dayjs'
import type { CmsNavigation, PageDetail } from '~/types'
import { collectDescendantNavIds, isParentNavigation } from '~/utils/nav-tree'
interface ChildPage {
pageId?: number
title?: string
path?: string
content?: string
navigationId?: number
image?: string | null
}
const route = useRoute()
const { allNavigations, fetchSiteInfo } = useSite()
await fetchSiteInfo()
/** 从路由获取 navigationId */
const navigationId = computed(() => {
const id = route.params.id as string
if (id) {
const num = Number(id)
if (!Number.isNaN(num)) return num
}
return undefined
})
/** 当前栏目是否为父栏目(拥有子栏目) */
const hasChildren = computed(() => isParentNavigation(navigationId.value, allNavigations.value || []))
/** 递归收集当前栏目自身 + 所有后代 navigationId */
const descendantNavIds = computed(() =>
collectDescendantNavIds(navigationId.value, allNavigations.value || [])
)
/** 从导航中查找当前页面信息(使用 allNavigations,已做标题映射) */
const currentNav = computed<CmsNavigation | undefined>(() => {
if (!navigationId.value) return undefined
const findNav = (items: CmsNavigation[]): CmsNavigation | undefined => {
for (const item of items) {
if (item.navigationId === navigationId.value) return item
if (item.children?.length) {
const found = findNav(item.children)
if (found) return found
}
}
return undefined
}
return findNav(allNavigations.value)
})
/** 获取页面内容 */
const navId = navigationId.value
const pagePath = (() => {
const num = Number(route.params.id)
return Number.isNaN(num) ? (route.params.id as string) : undefined
})()
const { data: pageData } = await useFetch<PageDetail>('/api/page/detail', {
key: `page-${navId ?? pagePath ?? 'default'}`,
query: { navigationId: navId, path: pagePath }
})
/** 父栏目聚合:取其下所有子栏目的单页(不含父栏目自身,避免与顶部内容重复) */
const childPages = ref<ChildPage[]>([])
if (hasChildren.value && descendantNavIds.value.length) {
const { data: childrenData } = await useFetch<{ list: ChildPage[]; count: number }>('/api/page/children', {
key: `page-children-${navId}`,
query: { navigationIds: descendantNavIds.value.join(',') }
})
childPages.value = childrenData.value?.list || []
}
const childCards = computed(() => childPages.value.filter(p => p.navigationId !== navId))
const pageTitle = computed(() => {
return pageData.value?.title || currentNav.value?.title || '页面'
})
/** 空内容兜底文案,按状态区分「未录入」与「接口异常」 */
const emptyState = computed(() => {
const status = pageData.value?.status
if (status === 'error') {
return { title: '内容暂时无法加载', desc: '内容接口暂时不可用,请稍后再试。' }
}
return { title: '内容尚未录入', desc: '该页面正文尚未在 CMS 管理后台配置,请前往 CMS 后台为该导航补充内容。' }
})
/** 富文本正文截取纯文本摘要 */
function excerpt(html?: string, len = 80) {
if (!html) return ''
const text = (html || '')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;/g, ' ')
.replace(/\s+/g, ' ')
.trim()
return text.length > len ? text.slice(0, len) + '…' : text
}
function formatDate(date?: string) {
if (!date) return ''
return dayjs(date).format('YYYY-MM-DD')
}
</script>
@@ -0,0 +1,64 @@
<template>
<div class="min-h-screen py-16 bg-[var(--t9-bg-soft)]">
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
<div v-if="product" class="max-w-5xl mx-auto">
<div class="mb-8">
<NuxtLink :to="`/product${product?.navigationId ? '?navId=' + product.navigationId : ''}`" class="text-sm text-[var(--t9-text-secondary)] hover:text-[var(--t9-primary)]"> 返回产品列表</NuxtLink>
</div>
<div class="grid lg:grid-cols-2 gap-10 mb-12">
<div class="aspect-video bg-[var(--t9-primary-faint)] rounded-none overflow-hidden">
<img
v-if="product.cover"
:src="fileUrl(product.cover)"
:alt="product.productName"
class="w-full h-full object-cover"
>
</div>
<div>
<h1 class="text-3xl font-bold text-[var(--t9-text)] mb-4">{{ product.productName }}</h1>
<p v-if="product.subtitle" class="text-lg text-[var(--t9-text-secondary)] mb-6">{{ product.subtitle }}</p>
<p class="text-[var(--t9-text-secondary)] leading-relaxed mb-6">{{ stripHtml(product.description) }}</p>
<div v-if="product.price" class="text-2xl font-bold text-[var(--t9-primary)] mb-6">
{{ product.price }}
</div>
<button
type="button"
class="inline-flex items-center justify-center px-8 py-3 bg-[var(--t9-primary)] text-white font-semibold rounded-full hover:bg-[var(--t9-primary-dark)] transition-colors"
@click="openConsult({ need: `咨询产品:${product.productName}`, source: 'product-detail' })"
>
立即咨询
</button>
</div>
</div>
<div class="border-t border-[var(--t9-border)] pt-10">
<h2 class="text-2xl font-bold text-[var(--t9-text)] mb-6">产品详情</h2>
<RichText :content="product.content" />
</div>
</div>
<div v-else class="text-center py-20">
<h1 class="text-2xl font-bold text-[var(--t9-text)] mb-4">产品不存在或已下架</h1>
<NuxtLink :to="`/product${product?.navigationId ? '?navId=' + product.navigationId : ''}`" class="text-[var(--t9-primary)] hover:underline">返回产品列表</NuxtLink>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import type { Product } from '~/types'
/**
* 模板 9 - 产品详情页(墨绿文化出版风)
*/
const route = useRoute()
const id = route.params.id as string
const { fileUrl } = useFileUrl()
const { openConsult } = useConsult()
const { data: product } = await useFetch<Product | null>(`/api/product/detail?id=${id}`, {
key: `product-${id}`
})
</script>
@@ -0,0 +1,169 @@
<template>
<div class="min-h-screen bg-white pb-16">
<div class="t9-container">
<h1 class="t9-section-title">{{ pageTitle }}</h1>
<div v-if="pending" class="flex justify-center py-12">
<SiteLoading />
</div>
<SiteError v-else-if="error" message="获取产品列表失败" />
<!-- 圆形头像网格对齐原站名家经典板块 -->
<div v-else class="flex flex-wrap justify-center gap-x-7 gap-y-8">
<NuxtLink
v-for="item in products"
:key="item.id ?? item.productId"
:to="`/product/${item.id ?? item.productId}`"
class="w-[110px] sm:w-[130px] group"
>
<div
class="w-[110px] h-[110px] sm:w-[130px] sm:h-[130px] rounded-full overflow-hidden bg-[var(--t9-bg-gray)] border-2 border-transparent transition-colors group-hover:border-[var(--t9-primary)]"
>
<img
:src="itemImage(item)"
:alt="item.productName"
class="w-full h-full object-cover"
loading="lazy"
@error="onImgError"
>
</div>
<p
class="mt-2.5 text-sm text-center leading-snug t9-clamp-2 transition-colors group-hover:text-[var(--t9-primary)]"
style="color: var(--t9-text)"
>{{ item.productName }}</p>
</NuxtLink>
</div>
<!-- 空状态 -->
<div v-if="!pending && !error && products.length === 0" class="text-center py-20">
<svg class="w-16 h-16 mx-auto mb-4" style="color: var(--t9-muted-light)" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
</svg>
<p style="color: var(--t9-text-secondary)">暂无内容</p>
</div>
<!-- 分页 -->
<div v-if="totalPages > 1" class="flex justify-center mt-12">
<nav class="flex items-center gap-1.5 flex-wrap justify-center">
<button
v-for="p in totalPages"
:key="p"
class="min-w-[36px] h-9 px-2 text-sm border transition-colors"
:style="p === currentPage
? 'background-color: var(--t9-primary); border-color: var(--t9-primary); color: #fff'
: 'background-color: #fff; border-color: var(--t9-border); color: var(--t9-text)'"
@click="currentPage = p"
>
{{ p }}
</button>
</nav>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import type { Product, PageResult, ApiEnvelope, CmsNavigation } from '~/types'
import { collectDescendantNavIds } from '~/utils/nav-tree'
import { getCompressedImageUrl } from '~/utils/image'
/**
* 模板 9 - 产品列表页(墨绿文化出版风)
* 渲染为圆形头像网格,对齐原站「名家经典」板块
*/
const { allNavigations, fetchSiteInfo } = useSite()
const route = useRoute()
await fetchSiteInfo()
/**
* 栏目 navigationId:从查询参数或路由参数读取。
* 优先级(2026-07-21 修正):route.query.navId > route.params.id
* (子分类下拉切换通过 ?navId= 传入,必须优先于路径参数,否则切换不生效)
*/
const navigationId = computed<number | undefined>(() => {
// 1. 查询参数优先(导航子分类下拉切换时传入)
const qid = route.query.navId as string
if (qid) {
const n = Number(qid)
if (!Number.isNaN(n)) return n
}
// 2. 路由参数(/product/:navigationId
const pid = route.params.id as string
if (pid) {
const n = Number(pid)
if (!Number.isNaN(n)) return n
}
return undefined
})
// 聚合:父栏目访问时递归收集自身 + 所有后代栏目 navigationId,交给后端 IN 查询
const categoryIds = computed<string | undefined>(() => {
const ids = collectDescendantNavIds(navigationId.value, allNavigations.value || [])
return ids.length ? ids.join(',') : undefined
})
const currentPage = ref(1)
const limit = 12
const { data, pending, error } = await useFetch<
ApiEnvelope<PageResult<Product>> | PageResult<Product>
>('/api/product/list', {
key: `product-list-${categoryIds.value ?? navigationId.value ?? 'all'}-p${currentPage.value}`,
query: {
page: currentPage,
limit,
...(categoryIds.value
? { categoryIds: categoryIds.value }
: (navigationId.value ? { navigationId: navigationId.value } : {}))
},
watch: [currentPage, categoryIds, navigationId]
})
const products = computed<Product[]>(() => {
const envelope = data.value as ApiEnvelope<PageResult<Product>>
const direct = data.value as PageResult<Product>
return envelope?.data?.list || direct?.list || []
})
const totalCount = computed(() => {
const envelope = data.value as ApiEnvelope<PageResult<Product>>
const direct = data.value as PageResult<Product>
return envelope?.data?.count || envelope?.data?.total || direct?.count || direct?.total || 0
})
const totalPages = computed(() => Math.max(1, Math.ceil(totalCount.value / limit)))
// 切换栏目时回到第 1 页
watch([categoryIds, navigationId], () => {
currentPage.value = 1
})
/** 页面标题:取当前栏目名称,兜底「名家经典」 */
const pageTitle = computed(() => {
const navs = allNavigations.value || []
const findNav = (items: CmsNavigation[]): CmsNavigation | undefined => {
for (const item of items) {
if (item.navigationId === navigationId.value) return item
if (item.children?.length) {
const found = findNav(item.children)
if (found) return found
}
}
return undefined
}
return findNav(navs)?.title || '名家经典'
})
/** 头像图:兼容 cover / photo / image / images[0] */
const FALLBACK_IMAGE = '/images/template-09/news-default.jpg'
function itemImage(item: Product): string {
const anyItem = item as Record<string, unknown>
const raw = (anyItem.cover || anyItem.photo || anyItem.image
|| (Array.isArray(anyItem.images) ? (anyItem.images as string[])[0] : '')) as string
return raw ? getCompressedImageUrl(raw, { width: 800 }) : FALLBACK_IMAGE
}
function onImgError(e: Event) {
const el = e.target as HTMLImageElement
if (el && !el.src.endsWith(FALLBACK_IMAGE)) el.src = FALLBACK_IMAGE
}
</script>