Sidebar.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. "use client";
  2. import { ContactType, getContactsApi, getSidebarActivitiesApi } from "@/api/config";
  3. import { BannerRep, GroupType } from "@/api/home";
  4. import Box from "@/components/Box";
  5. import dialogManage from "@/dialog/manager";
  6. import { Link, usePathname, useRouter } from "@/i18n/routing";
  7. import { useProviderStore } from "@/stores/useProvider";
  8. import { useSystemStore } from "@/stores/useSystemStore";
  9. import { useWalletStore } from "@/stores/useWalletStore";
  10. import { server } from "@/utils/client";
  11. import clsx from "clsx";
  12. import { useLocale } from "next-intl";
  13. import Image from "next/image";
  14. import React, { FC, PropsWithChildren, useEffect, useMemo, useRef, useState } from "react";
  15. import styles from "./style.module.scss";
  16. const getGames = async () => {
  17. return server
  18. .request<GroupType[]>({
  19. url: "/v1/api/front/game_list",
  20. method: "POST",
  21. })
  22. .then((res) => {
  23. if (res.code === 200) return res.data;
  24. return [];
  25. });
  26. };
  27. const registePromoClick = (activity_id: number) => {
  28. return server
  29. .request({
  30. url: "/v1/api/front/activity_promotion_click",
  31. method: "post",
  32. data: { activity_id },
  33. })
  34. .then((res) => {
  35. if (res.code === 200) return res.data;
  36. return [];
  37. });
  38. };
  39. interface Props {}
  40. const tabs = [
  41. { name: "casino", id: 1, icon: "pro-niuyouguo" },
  42. { name: "promocoes", id: 2, icon: "pro-shengriliwu" },
  43. ];
  44. enum PageEnum {
  45. "home",
  46. "sports",
  47. "help",
  48. "promo",
  49. "deposit",
  50. "download",
  51. "none",
  52. "profile",
  53. "gameList2",
  54. "withdraw",
  55. "Vip",
  56. }
  57. const PageEnumMap = new Map<PageEnum, { url: string }>([
  58. [PageEnum.home, { url: "/" }],
  59. [PageEnum.sports, { url: "/promo" }],
  60. [PageEnum.help, { url: "/help" }],
  61. [PageEnum.Vip, { url: "/vip" }],
  62. [PageEnum.promo, { url: "/promo" }],
  63. [PageEnum.deposit, { url: "/deposit" }],
  64. [PageEnum.withdraw, { url: "/deposit?target=2" }],
  65. [PageEnum.download, { url: "/download" }],
  66. [PageEnum.profile, { url: "/profile" }],
  67. ]);
  68. const Sidebar: FC<PropsWithChildren<Props>> = (props) => {
  69. // const t = useTranslations("Sidebar");
  70. const { providers, setProviders } = useProviderStore();
  71. const { wallet } = useWalletStore();
  72. const locale = useLocale();
  73. // const swiper = useSwiper();
  74. const router = useRouter();
  75. const tab = useRef<HTMLDivElement>(null);
  76. const bgRef = useRef<HTMLDivElement>(null);
  77. const [isShowAll, setIsShowAll] = useState(false);
  78. const pathname = usePathname();
  79. const { isCollapse, setCollapse, service, show_free_game, show_again_game } = useSystemStore(
  80. (state) => ({
  81. isCollapse: state.isCollapse,
  82. setCollapse: state.setCollapse,
  83. service: state.service,
  84. show_free_game: state.show_free_game,
  85. show_again_game: state.show_again_game,
  86. })
  87. );
  88. React.useEffect(() => {
  89. if (!providers || providers.length === 0) {
  90. getGames().then((res) => {
  91. const providersData = res[0].category.filter((item) => item.type === 2);
  92. if (providersData.length === 0) return [] as any;
  93. setProviders(providersData[0].game_list);
  94. });
  95. }
  96. }, [providers, setProviders]);
  97. const tabHandler = (index: PageEnum, isAction = true) => {
  98. bgRef.current?.setAttribute(
  99. "style",
  100. `transform: translateX(${tab.current?.clientWidth! * index}px)`
  101. );
  102. if (isAction) {
  103. const curToPage = PageEnumMap.get(index);
  104. if (curToPage) {
  105. router.push(curToPage.url);
  106. setCollapse(false);
  107. }
  108. }
  109. return index;
  110. };
  111. const registePromo = (id?: number) => {
  112. if (!id) return;
  113. registePromoClick(id);
  114. };
  115. useEffect(() => {
  116. if (pathname === "/") {
  117. tabHandler(PageEnum.home, false);
  118. } else {
  119. tabHandler(PageEnum.sports, false);
  120. }
  121. // eslint-disable-next-line react-hooks/exhaustive-deps
  122. }, [isCollapse]);
  123. const [contacts, setContacts] = useState<ContactType[]>();
  124. const [cardData, setCardData] = useState<BannerRep[]>([]);
  125. useEffect(() => {
  126. getContactsApi().then((res) => {
  127. setContacts(res.data.filter((item) => item.show_bar === 1));
  128. });
  129. getSidebarActivitiesApi().then((res) => {
  130. console.log(33, res.data);
  131. setCardData(res.data);
  132. });
  133. }, []);
  134. const serviceUrl: string = useMemo(() => {
  135. if (!service) return "";
  136. const result = service.filter((item) => item.status === 1);
  137. return result[0]?.url || "";
  138. }, [service]);
  139. const listCfg = useMemo(() => {
  140. return [
  141. {
  142. text: "Seleção de idioma",
  143. icon: `/sidebar/${locale}.png`,
  144. handle: () => {
  145. setCollapse(false);
  146. dialogManage.showDialog("LanguageSelect");
  147. },
  148. },
  149. {
  150. text: "Baixar APP",
  151. icon: "/sidebar/app.png",
  152. handle: () => {
  153. router.push("/download");
  154. },
  155. },
  156. {
  157. text: "atendimento ao Cliente",
  158. icon: "/sidebar/service.png",
  159. renderWrap: (children: any) =>
  160. serviceUrl ? <Link href={serviceUrl}>{children}</Link> : "",
  161. },
  162. {
  163. text: "VIP",
  164. icon: "/sidebar/vip.png",
  165. handle: () => tabHandler(PageEnum.Vip),
  166. },
  167. {
  168. text: "FAQ",
  169. icon: "/sidebar/faq.png",
  170. handle: () => tabHandler(PageEnum.help),
  171. },
  172. {
  173. text: "Envie-nos um e-mail",
  174. icon: "/sidebar/email.png",
  175. noRender: !(contacts && contacts?.length > 0),
  176. handle: () => {
  177. if (contacts) {
  178. const a = document.createElement("a");
  179. a.href = `mailto:${contacts[0].email}`;
  180. a.target = "email";
  181. a.click();
  182. }
  183. },
  184. },
  185. ];
  186. // eslint-disable-next-line react-hooks/exhaustive-deps
  187. }, [serviceUrl, locale]);
  188. const walletCfg = useMemo(() => {
  189. const result: any = [
  190. {
  191. text: "Saldo",
  192. icon: "/sidebar/saldo.png",
  193. textStyle: { fontSize: ".12rem" },
  194. value: wallet.score || 0,
  195. },
  196. {
  197. text: "Bônus",
  198. icon: "/sidebar/bonus.png",
  199. textStyle: { fontSize: ".12rem" },
  200. value: wallet.point || 0,
  201. },
  202. ];
  203. if (show_free_game === 1) {
  204. result.push({
  205. text: "Carteira grátis",
  206. icon: "/sidebar/free.png",
  207. value: wallet.free_score || 0,
  208. });
  209. }
  210. if (show_again_game === 1) {
  211. result.push({
  212. text: "Carteira duplicada",
  213. icon: "/sidebar/money.png",
  214. textStyle: { fontSize: ".09rem" },
  215. value: wallet.lose_score || 0,
  216. });
  217. }
  218. return result;
  219. }, [wallet, show_free_game, show_again_game]);
  220. const todoHandler = (item: any) => {
  221. setCollapse(false);
  222. router.push({
  223. pathname: `/gameList2?provider_id=${item.id}`,
  224. });
  225. };
  226. const promotionHandle = (item: any) => {
  227. setCollapse(false);
  228. // router.push({
  229. // pathname: `/gameList2?provider_id=${item.id}`,
  230. // });
  231. };
  232. return (
  233. <Box pt={false} className={"h-[100%] bg-[#1e252b] px-[0px]"}>
  234. <div className={"relative flex h-[100%] flex-col"}>
  235. <div className={"sticky top-[0] px-[.12rem]"}>
  236. <div className={"mb-[.1rem] flex items-center pt-[10px]"}>
  237. <div
  238. onClick={() => tabHandler(PageEnum.none)}
  239. className="mr-[.06rem] rounded-[.06rem] bg-[#121617] px-[.08rem] py-[.06rem]"
  240. >
  241. <i className="iconfont icon-zhankai1 text-[.16rem] text-[#fff]"></i>
  242. </div>
  243. <div className={"flex-1"}>
  244. <Image src={"/logo2.png"} alt={"logo"} width={130} height={110} />
  245. </div>
  246. </div>
  247. </div>
  248. <div className="flex-1 overflow-scroll px-[.12rem]">
  249. <div className={styles.providerBox}>
  250. {providers?.map((item, idx) => {
  251. if (idx === 8 && !isShowAll) {
  252. return (
  253. <div
  254. className={styles.providerItem}
  255. onClick={() => setIsShowAll(true)}
  256. key={item.id}
  257. >
  258. <img src="/sidebar/more.png" alt="" />
  259. </div>
  260. );
  261. }
  262. if (idx > 8 && !isShowAll) return null;
  263. return (
  264. <div
  265. className={styles.providerItem}
  266. onClick={() => todoHandler(item)}
  267. key={item.id}
  268. >
  269. <img src={item.game_icon} alt="" />
  270. </div>
  271. );
  272. })}
  273. </div>
  274. <div className={clsx(styles.sideTitle, "mt-[.06rem]")}>
  275. <i
  276. className={clsx("iconfont icon-qianbao11 text-[.26rem]", styles.icon)}
  277. ></i>
  278. <span>Carteira</span>
  279. </div>
  280. <div className={styles.qianbao}>
  281. {walletCfg.map((item: any) => {
  282. return (
  283. <div key={item.text} className={styles.qianbaoItem}>
  284. <img className="mr-[.06rem] w-[.3rem]" src={item.icon} alt="" />
  285. <div>
  286. <div className="text-[.16rem] leading-[1.2]">
  287. {item.value}R
  288. </div>
  289. <div
  290. className="text-[.1rem] leading-[1]"
  291. style={{ ...(item.textStyle || {}) }}
  292. >
  293. {item.text}
  294. </div>
  295. </div>
  296. </div>
  297. );
  298. })}
  299. </div>
  300. {cardData.length > 0 && (
  301. <div className={clsx(styles.sideTitle, "my-[.06rem]")}>
  302. <i
  303. className={clsx("iconfont icon-liwu text-[.24rem]", styles.icon)}
  304. ></i>
  305. <span>Promoções</span>
  306. </div>
  307. )}
  308. <div className={styles.promotionBox}>
  309. {cardData.map((item) => {
  310. return (
  311. <Box
  312. key={item.id}
  313. action={item.action_type}
  314. actionData={item.action_params}
  315. className={styles.promoItem}
  316. onBeforeHandler={() => registePromo(item.id)}
  317. >
  318. <div
  319. key={item.id}
  320. className={styles.promotionItem}
  321. onClick={() => promotionHandle(item)}
  322. >
  323. <img src={item.content} alt="" />
  324. </div>
  325. </Box>
  326. );
  327. })}
  328. {/* <div className={styles.promotionItem}>
  329. <img src="/sidebar/promotion.png" alt="" />
  330. </div>
  331. <div className={styles.promotionItem}>
  332. <img src="/sidebar/promotion.png" alt="" />
  333. </div>
  334. <div className={styles.promotionItem}>
  335. <img src="/sidebar/promotion.png" alt="" />
  336. </div>
  337. <div className={styles.promotionItem}>
  338. <img src="/sidebar/promotion.png" alt="" />
  339. </div> */}
  340. </div>
  341. {listCfg.map((item) => {
  342. if (item.noRender) return null;
  343. if (item.renderWrap) {
  344. const Wrapper = item.renderWrap;
  345. if (React.isValidElement(Wrapper)) {
  346. return (
  347. <Wrapper key={item.text}>
  348. <div className={styles.signalItem}>
  349. <img src={item.icon} alt="" />
  350. <div>{item.text}</div>
  351. </div>
  352. </Wrapper>
  353. );
  354. }
  355. return null;
  356. }
  357. return (
  358. <div
  359. className={styles.signalItem}
  360. key={item.text}
  361. onClick={item.handle}
  362. >
  363. <img src={item.icon} alt="" />
  364. <div>{item.text}</div>
  365. </div>
  366. );
  367. })}
  368. </div>
  369. <div
  370. className={clsx(
  371. "flex items-center justify-between bg-[#2b363f] p-[.1rem]",
  372. styles.footer
  373. )}
  374. >
  375. <button onClick={() => tabHandler(PageEnum.deposit)}>Depósito</button>
  376. <button onClick={() => tabHandler(PageEnum.withdraw)}>Sacar</button>
  377. </div>
  378. {/* card*/}
  379. {/* <div className={"mt-[0.2rem] grid grid-cols-1 gap-[0.0833rem]"}>
  380. {cardData.map((item, index) => {
  381. return (
  382. <Box
  383. className={"shadow-md"}
  384. none={true}
  385. key={index}
  386. onBeforeHandler={() => {
  387. // 关闭侧边栏按钮
  388. setCollapse(false);
  389. // 关闭swiper
  390. // swiper.slideNext();
  391. }}
  392. action={item.action_type}
  393. actionData={item.action_params}
  394. >
  395. <div className="mb-[.1rem] flex h-[0.5556rem] justify-center overflow-hidden rounded-[0.1rem] border-[1px] border-[#eba9ff]">
  396. <img
  397. src={item.content}
  398. alt=""
  399. className={"h-[100%] w-[100%]"}
  400. />
  401. </div>
  402. </Box>
  403. );
  404. })}
  405. </div> */}
  406. {/* gift */}
  407. {/*<section*/}
  408. {/* onClick={() => tabHandler(PageEnum.promo)}*/}
  409. {/* className={"my-[0.11rem] flex items-center text-[0.15rem]" + " text-[#fff]"}*/}
  410. {/*>*/}
  411. {/* <div className={"flex-1"}>*/}
  412. {/* <span*/}
  413. {/* className={*/}
  414. {/* "iconfont icon-liwulipinjiangpin mr-[0.0694rem]" +*/}
  415. {/* " text-[0.16rem] text-[#999]"*/}
  416. {/* }*/}
  417. {/* ></span>*/}
  418. {/* <span> {t("promocoes")} </span>*/}
  419. {/* </div>*/}
  420. {/* /!*<span className={"iconfont icon-xiangyou1"}></span>*!/*/}
  421. {/*</section>*/}
  422. {/* <section
  423. onClick={() => tabHandler(PageEnum.deposit)}
  424. className={"my-[0.16rem] flex items-center text-[0.15rem]" + " text-[#fff]"}
  425. >
  426. <div className={"flex-1"}>
  427. <span
  428. className={
  429. "iconfont icon-qianbao3 mr-[0.0694rem] text-[0.16rem] text-[#fff]"
  430. }
  431. ></span>
  432. <span> {t("deposit")} </span>
  433. </div>
  434. </section>
  435. <section
  436. onClick={() => tabHandler(PageEnum.help)}
  437. className={"my-[0.16rem] flex items-center text-[0.15rem]" + " text-[#fff]"}
  438. >
  439. <div className={"flex-1"}>
  440. <span
  441. className={
  442. "iconfont icon-bangzhu mr-[0.0694rem] text-[0.16rem] text-[#fff]"
  443. }
  444. ></span>
  445. <span> {t("ajude")} </span>
  446. </div>
  447. </section>
  448. <section
  449. onClick={() => tabHandler(PageEnum.download)}
  450. className={"my-[0.16rem] flex items-center text-[0.15rem]" + " text-[#fff]"}
  451. >
  452. <div className={"flex-1"}>
  453. <span
  454. className={
  455. "iconfont icon-header-18 mr-[0.0694rem] text-[0.16rem] text-[#fff]"
  456. }
  457. ></span>
  458. <span> {t("download")} </span>
  459. </div>
  460. </section>
  461. <section className={"text-[0.15rem]" + " text-[#fff]"}>
  462. {contacts?.map((item, index) => (
  463. <a
  464. key={index}
  465. href={`mailto:${item.email}`}
  466. className={"my-[0.16rem] flex items-center text-[#fff]"}
  467. >
  468. <span
  469. className={
  470. "iconfont icon-duanxinguanli mr-[0.09rem] text-[0.16rem] text-[#fff]"
  471. }
  472. ></span>
  473. <span> {t("email")} </span>
  474. </a>
  475. ))}
  476. </section>
  477. <section className={"mt-[0.11rem] text-[#fff]"}>{t("coumnidade")}</section> */}
  478. </div>
  479. </Box>
  480. );
  481. };
  482. export default Sidebar;