"use client"; import React, { useEffect } from "react"; import { TabBar, Toast, Badge } from "antd-mobile"; import "./index.css"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import WebSocketComponent from "../Websocket"; import { changeNoticeCount, changeInviter } from "@/store/actions"; import { connect } from "react-redux"; import { get } from "@/utils/storeInfo"; import requireAPI from "@/utils/requireAPI"; import OwnIcon from "../OwnIcon"; import OwnImage from "../OwnImage"; function BottomNav({ changeNoticeCount, changeInviter, noticeCount }) { const searchParams = useSearchParams(); const pathname = usePathname(); const router = useRouter(); useEffect(() => { const currentInviter = searchParams.get("inviter"); if (currentInviter) { // console.log("Current Inviter: " + currentInviter); changeInviter(currentInviter); } }, [pathname]); useEffect(() => { const getDtata = async () => { try { const { mid } = get("account"); const body = { mid, }; const _data = await requireAPI( "POST", "/api/notification/get_unread_count", { body, } ); if (_data.ret === -1) { return; } changeNoticeCount(_data.data.total); } catch (error) {} }; getDtata(); return () => {}; }, [noticeCount, pathname]); const setRouteActive = (value) => { router.replace(value); }; const tabs = [ { key: "/", title: "广场", icon: , activeIcon: ( ), }, { key: "/space", title: "空间", icon: , activeIcon: ( ), }, { key: "/noticeDetail", title: "消息", icon: (
{!!noticeCount && ( 99 ? "99+" : noticeCount} className="absolute top-0 right-0 z-10" /> )}
), activeIcon: (
{!!noticeCount && ( 99 ? "99+" : noticeCount} className="absolute top-0 right-0 z-10" /> )}
), }, { key: "/my", title: "我的", icon: , activeIcon: , }, ]; const checkPath = () => { const pathnames = ["/", "/space", "/noticeDetail", "/my"]; const isActive = pathnames.some((path) => path === pathname); return isActive; }; const handleGetWebsocketData = (data) => { if (data.d.unread_cnt > 0) { changeNoticeCount(data.d.unread_cnt); const { n_type, title } = data.d.notif; Toast.show({ type: "info", maskClassName: "notice-toast", content: (

{`收到一条${ n_type === 0 ? "系统" : n_type === 1 ? "审核" : n_type === 2 ? "付费" : "活动" }通知`}

{title}

), position: "top", duration: 5000, }); } }; return ( <> setRouteActive(value)} className={!checkPath() ? "hidden" : ""} > {tabs.map((item) => ( ))} ); } const mapStateToProps = ({ reducer }) => { return { noticeCount: reducer.noticeCount, }; }; const mapDispatchToProps = { changeNoticeCount, changeInviter, }; export default connect(mapStateToProps, mapDispatchToProps)(BottomNav);