import React, { useEffect, useState, useRef, useCallback } from "react"; import { Toast, Swiper, Image } from "antd-mobile"; import LoadingMask from "@/components/LoadingMask"; import { useRouter } from "next/navigation"; import requireAPI from "@/utils/requireAPI"; import OwnImage from "@/components/OwnImage"; import { goToPage } from "@/utils/tools"; export default function Banner() { const [bannerList, setBannerList] = useState([]); const [isLoading, setIsLoading] = useState(false); const router = useRouter(); const ref = useRef(null); useEffect(() => { const getBannerList = async () => { setIsLoading(true); try { const _data = await requireAPI( "POST", "/api/activity_banner/list", null, true ); if (_data.ret === -1) { Toast.show({ icon: "fail", content: _data.msg, position: "top", }); return; } setBannerList(_data.data.list); } catch (error) { console.error(error); } finally { setIsLoading(false); } }; getBannerList(); }, []); const items = useCallback( (item, index) => (
{ const links = item?.hyperlinks; if (links.length > 1) { router.push( links.filter((it) => it.inward_action_type === "h5")[0]?.url ); } else { router.push(links[0]?.url); } }} >
), [] ); return (
{bannerList.map((item, index) => items(item, index))}
); }