From 2b453785da22dceee625b8da97c387b20b9835b5 Mon Sep 17 00:00:00 2001 From: jingrow Date: Wed, 18 Jun 2025 17:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SwiperItems=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/page.jsx | 11 +- components/homes/home-15/CategoryItems.jsx | 24 +- components/homes/home-15/SwiperItems.jsx | 253 +++++++++++++++++++++ 3 files changed, 284 insertions(+), 4 deletions(-) create mode 100644 components/homes/home-15/SwiperItems.jsx diff --git a/app/page.jsx b/app/page.jsx index 41bb75b..f3c148d 100644 --- a/app/page.jsx +++ b/app/page.jsx @@ -41,8 +41,15 @@ export default function Page() {
- - +
diff --git a/components/homes/home-15/CategoryItems.jsx b/components/homes/home-15/CategoryItems.jsx index 0af6ca2..243548e 100644 --- a/components/homes/home-15/CategoryItems.jsx +++ b/components/homes/home-15/CategoryItems.jsx @@ -6,7 +6,7 @@ import Link from "next/link"; import Image from "next/image"; import PropTypes from "prop-types"; -export default function CategoryItems({ pagetype = "", category = "", category_slug = "" , count = 8, columns = 4 }) { +export default function CategoryItems({ pagetype = "", category = "", category_slug = "" , count = 8, columns = 4, title = "", subtitle = "" }) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(false); @@ -133,7 +133,14 @@ export default function CategoryItems({ pagetype = "", category = "", category_s } return ( -
+
+ {/* 新增模块标题和副标题显示 */} + {(title || subtitle) && ( +
+ {title &&

{title}

} + {subtitle &&

{subtitle}

} +
+ )}
{loading ? (
加载中...
@@ -212,6 +219,17 @@ export default function CategoryItems({ pagetype = "", category = "", category_s )) )}
+ {/* 底部更多按钮 */} + {category_slug && ( +
+ + 更多 + +
+ )}
); } @@ -225,4 +243,6 @@ CategoryItems.propTypes = { ]), columns: PropTypes.number, category_slug: PropTypes.string, + title: PropTypes.string, + subtitle: PropTypes.string, }; diff --git a/components/homes/home-15/SwiperItems.jsx b/components/homes/home-15/SwiperItems.jsx new file mode 100644 index 0000000..a202b30 --- /dev/null +++ b/components/homes/home-15/SwiperItems.jsx @@ -0,0 +1,253 @@ +"use client"; +import { useEffect, useState } from "react"; +import { Swiper, SwiperSlide } from "swiper/react"; +import { Navigation, Pagination, Grid } from "swiper/modules"; +import Link from "next/link"; +import Image from "next/image"; +import PropTypes from "prop-types"; + +export default function SwiperItems({ pagetype = "", category = "", category_slug = "" , count = 8, columns = 4, rows = 1 }) { + const [posts, setPosts] = useState([]); + const [loading, setLoading] = useState(false); + + useEffect(() => { + async function fetchData() { + setLoading(true); + try { + const params = new URLSearchParams({ pagetype }); + if (category) params.append("category", category); + if (count !== undefined && count !== null) params.append("count", count); + const res = await fetch(`/api/get-listview-data?${params.toString()}`); + const json = await res.json(); + if (Array.isArray(json.data)) { + setPosts(json.data); + } else { + setPosts([]); + } + } catch (e) { + setPosts([]); + } + setLoading(false); + } + fetchData(); + }, [pagetype, category, count]); + + // 渲染卡片内容 + function renderCardImage(post, idx) { + // 多图轮播 + if (Array.isArray(post.images) && post.images.length > 1) { + return ( + + {post.images.map((img, i) => ( + + {post.title + + ))} + + ); + } + // 视频 + if (post.video_src || post.videoId) { + if (post.video_src && (post.video_src.endsWith('.mp4') || post.video_src.startsWith('/files/'))) { + return ( + + ); + } + const vid = post.videoId || (post.video_src && post.video_src.includes('youtube') ? post.video_src.split('embed/')[1] : null); + if (vid) { + return ( +