|
@@ -1,35 +1,83 @@
|
|
|
"use client";
|
|
|
+import { GroupType } from "@/api/home";
|
|
|
+import Box from "@/components/Box";
|
|
|
import { useRouter } from "@/i18n";
|
|
|
import { Toast } from "antd-mobile";
|
|
|
import clsx from "clsx";
|
|
|
import { useTranslations } from "next-intl";
|
|
|
-import { FC } from "react";
|
|
|
+import { FC, useState } from "react";
|
|
|
import { Swiper, SwiperSlide } from "swiper/react";
|
|
|
+import HomeGames from "./HomeGames";
|
|
|
|
|
|
const buttonGroup = [
|
|
|
- { icon: "icon-liwulipinjiangpin", title: "first", isHot: true, url: "/gameList/99" },
|
|
|
- { icon: "icon-mofang", title: "second", isHot: false, url: "/gameList/110" },
|
|
|
- { icon: "icon-zuqiu2", title: "third", isHot: false, url: "/gameList/110" },
|
|
|
- { icon: "icon-icons_video", title: "fourth", isHot: false, url: "/gameList/112" },
|
|
|
- { icon: "icon-header-18", title: "Fifth", isHot: false, url: "/gameList/110" },
|
|
|
+ {
|
|
|
+ icon: "icon-liwulipinjiangpin",
|
|
|
+ category_name: "first",
|
|
|
+ isHot: true,
|
|
|
+ url: "/gameList/99",
|
|
|
+ locale: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "icon-mofang",
|
|
|
+ category_name: "second",
|
|
|
+ isHot: false,
|
|
|
+ url: "/gameList/110",
|
|
|
+ locale: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "icon-zuqiu2",
|
|
|
+ category_name: "third",
|
|
|
+ isHot: false,
|
|
|
+ url: "/gameList/110",
|
|
|
+ locale: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "icon-icons_video",
|
|
|
+ category_name: "fourth",
|
|
|
+ isHot: false,
|
|
|
+ url: "/gameList/112",
|
|
|
+ locale: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "icon-header-18",
|
|
|
+ category_name: "Fifth",
|
|
|
+ isHot: false,
|
|
|
+ url: "/gameList/110",
|
|
|
+ locale: true,
|
|
|
+ },
|
|
|
];
|
|
|
|
|
|
-type TabItemType = (typeof buttonGroup)[number];
|
|
|
-const TabItem = ({ item }: { item: TabItemType }) => {
|
|
|
+type TabItemType = (typeof buttonGroup)[number] & GroupType;
|
|
|
+const TabItem = ({
|
|
|
+ item,
|
|
|
+ active,
|
|
|
+ onClick,
|
|
|
+}: {
|
|
|
+ item: TabItemType;
|
|
|
+ active?: boolean;
|
|
|
+ onClick?: (item: TabItemType) => void;
|
|
|
+}) => {
|
|
|
const router = useRouter();
|
|
|
const t = useTranslations("ButtonGroup");
|
|
|
const handler = (item: TabItemType) => {
|
|
|
- // router.push(item.url);
|
|
|
- Toast.show("it is under development.");
|
|
|
+ if (item.locale) {
|
|
|
+ Toast.show("it is under development.");
|
|
|
+ } else {
|
|
|
+ onClick && onClick(item);
|
|
|
+ }
|
|
|
};
|
|
|
const cls = clsx("iconfont text-[0.14rem]", item.icon);
|
|
|
+ const rootCls = clsx(
|
|
|
+ "relative mr-[0.06rem] flex h-[0.3rem] bg-[#3a3a3a] flex-1 cursor-pointer items-center" +
|
|
|
+ " rounded-[0.05rem] px-[0.08rem] py-[0.03rem] text-[0.12rem] text-[#fff]",
|
|
|
+ { "bg-primary-color": active }
|
|
|
+ );
|
|
|
return (
|
|
|
- <div
|
|
|
- className={`relative mr-[0.06rem] flex h-[0.3rem] flex-1 cursor-pointer items-center rounded-[0.05rem] bg-[#3a3a3a] px-[0.08rem] py-[0.03rem] text-[0.12rem] text-[#fff]`}
|
|
|
- onClick={() => handler(item)}
|
|
|
- >
|
|
|
+ <div className={rootCls} onClick={() => handler(item)}>
|
|
|
<span className={cls}></span>
|
|
|
- <span className={"ml-[0.03rem] truncate"}>{t(item.title)}</span>
|
|
|
+ <span className={"ml-[0.03rem] truncate"}>
|
|
|
+ {item.locale ? t(item.category_name) : item.category_name}
|
|
|
+ </span>
|
|
|
{item.isHot && (
|
|
|
<img
|
|
|
className={"absolute -top-[0.12rem] right-0 h-[0.21rem] w-[0.21rem]"}
|
|
@@ -40,15 +88,36 @@ const TabItem = ({ item }: { item: TabItemType }) => {
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
|
-const Tabs: FC = () => {
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ tabs: GroupType[];
|
|
|
+}
|
|
|
+const Tabs: FC<Props> = (props) => {
|
|
|
+ const { tabs } = props;
|
|
|
+ const tabData = [...tabs, ...buttonGroup];
|
|
|
+ const [active, setActive] = useState<number>(0);
|
|
|
+ const selectHandler = (item: TabItemType, index: number) => {
|
|
|
+ setActive(index);
|
|
|
+ };
|
|
|
+ const groupGames = tabs[active].category;
|
|
|
return (
|
|
|
- <Swiper slidesPerView={3.5} centeredSlidesBounds>
|
|
|
- {buttonGroup?.map((group, index) => (
|
|
|
- <SwiperSlide key={index} className={"pt-[0.1389rem]"}>
|
|
|
- <TabItem item={group}></TabItem>
|
|
|
- </SwiperSlide>
|
|
|
- ))}
|
|
|
- </Swiper>
|
|
|
+ <>
|
|
|
+ <Box>
|
|
|
+ <Swiper slidesPerView={3.5} centeredSlidesBounds>
|
|
|
+ {tabData?.map((group, index) => (
|
|
|
+ <SwiperSlide key={index} className={"pt-[0.1389rem]"}>
|
|
|
+ <TabItem
|
|
|
+ item={group as TabItemType}
|
|
|
+ active={index === active}
|
|
|
+ onClick={(event) => selectHandler(event, index)}
|
|
|
+ ></TabItem>
|
|
|
+ </SwiperSlide>
|
|
|
+ ))}
|
|
|
+ </Swiper>
|
|
|
+ </Box>
|
|
|
+
|
|
|
+ <HomeGames groupGames={groupGames} />
|
|
|
+ </>
|
|
|
);
|
|
|
};
|
|
|
|