"use client"; import React, { useEffect, useState } from "react"; import Image from "next/image"; import axios from "axios"; export default function Gallery() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { async function fetchData() { try { setLoading(true); const res = await axios.get("/api/get-component-data", { params: { component_name: "Gallery" }, }); setData(res.data.data); } catch (err) { setError("获取Gallery数据失败"); } finally { setLoading(false); } } fetchData(); }, []); if (loading) return
Loading...
; if (error || !data) return null; // 主表字段 const title = data.title || "Our Products"; const subtitle = data.subtitle || ""; const buttonText = data.button_text || "MORE"; const buttonLink = data.button_link || "#"; // 子表items const items = Array.isArray(data.items) ? data.items.slice(0, 6) : []; return (

{title}

{subtitle &&
{subtitle}
}
{buttonText}
{items.map((item, idx) => { const link = item.item_link || "#"; return ( {item.item_title
icon
{item.item_title || "-"}
); })}
); }