"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 (