diff --git a/components/homes/home-15/CategoryItems.jsx b/components/homes/home-15/CategoryItems.jsx
index 24b276d..616507d 100644
--- a/components/homes/home-15/CategoryItems.jsx
+++ b/components/homes/home-15/CategoryItems.jsx
@@ -4,17 +4,48 @@ import { Swiper, SwiperSlide } from "swiper/react";
import { Navigation, Pagination } from "swiper/modules";
import Link from "next/link";
import Image from "next/image";
-import PropTypes from "prop-types";
+import axios from "axios";
-export default function CategoryItems({ pagetype = "", category = "", category_slug = "" , count = 8, columns = 4, title = "", subtitle = "" }) {
+export default function CategoryItems() {
+ const [data, setData] = useState(null);
const [posts, setPosts] = useState([]);
- const [loading, setLoading] = useState(false);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState(null);
+
+ // 统一字段映射,便于团队查阅和维护
+ const title = data?.title;
+ const subtitle = data?.subtitle;
+ const pagetype = data?.t1;
+ const category = data?.t2;
+ const category_slug = data?.t3;
+ const count = data?.t4;
+ const columns = data?.t5;
+ const button_text = data?.button_text;
useEffect(() => {
- async function fetchData() {
+ async function fetchComponentData() {
+ try {
+ setLoading(true);
+ const res = await axios.get("/api/get-component-data", {
+ params: { component_name: "CategoryItems" },
+ });
+ setData(res.data.data);
+ } catch (err) {
+ setError("获取CategoryItems数据失败");
+ } finally {
+ setLoading(false);
+ }
+ }
+ fetchComponentData();
+ }, []);
+
+ useEffect(() => {
+ async function fetchPosts() {
+ if (!data) return;
setLoading(true);
try {
- const params = new URLSearchParams({ pagetype });
+ // 使用统一映射变量
+ const params = new URLSearchParams({ pagetype: 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()}`);
@@ -29,9 +60,10 @@ export default function CategoryItems({ pagetype = "", category = "", category_s
}
setLoading(false);
}
- fetchData();
- }, [pagetype, category, count]);
+ fetchPosts();
+ }, [data, pagetype, category, count]);
+ if (!data) return null;
// 渲染卡片内容
function renderCardImage(post, idx) {
// 多图轮播
@@ -133,7 +165,7 @@ export default function CategoryItems({ pagetype = "", category = "", category_s
}
return (
-
+
{/* 新增模块标题和副标题显示 */}
{(title || subtitle) && (
@@ -141,11 +173,11 @@ export default function CategoryItems({ pagetype = "", category = "", category_s
{subtitle &&
{subtitle}
}
)}
-
+
{loading ? (
-
加载中...
+
加载中...
) : posts.length === 0 ? (
-
暂无数据
+
暂无数据
) : (
posts.map((post, idx) => (
@@ -193,23 +225,10 @@ export default function CategoryItems({ pagetype = "", category = "", category_s
href={`/${category_slug}`}
className="btn btn-lg btn-fuchsia !text-white !bg-[#1A1A1A] hover:text-white hover:bg-[#1A1A1A] hover:!border-[#1A1A1A] active:text-white active:bg-[#1A1A1A] active:border-[#1A1A1A] disabled:text-white disabled:bg-[#1A1A1A] disabled:border-[#1A1A1A] !rounded-[0.8rem] mx-1"
>
- 更多
+ {button_text || "更多"}
)}
);
}
-
-CategoryItems.propTypes = {
- pagetype: PropTypes.string,
- category: PropTypes.string,
- count: PropTypes.oneOfType([
- PropTypes.string,
- PropTypes.number
- ]),
- columns: PropTypes.number,
- category_slug: PropTypes.string,
- title: PropTypes.string,
- subtitle: PropTypes.string,
-};
diff --git a/components/homes/home-15/Hero.jsx b/components/homes/home-15/Hero.jsx
index 2bd3a4f..7631a9e 100644
--- a/components/homes/home-15/Hero.jsx
+++ b/components/homes/home-15/Hero.jsx
@@ -41,7 +41,7 @@ export default function Hero() {
return (
-