import React, { useCallback, useRef } from 'react'; import { Box, Flex, useTheme } from '@chakra-ui/react'; import { useGlobalStore } from '@/store/global'; import { useRouter } from 'next/router'; import dynamic from 'next/dynamic'; import { clearToken } from '@/utils/user'; import { useUserStore } from '@/store/user'; import { useConfirm } from '@/hooks/useConfirm'; import PageContainer from '@/components/PageContainer'; import SideTabs from '@/components/SideTabs'; import Tabs from '@/components/Tabs'; import UserInfo from './components/Info'; import { serviceSideProps } from '@/utils/i18n'; import { feConfigs } from '@/store/static'; import { useTranslation } from 'react-i18next'; const Promotion = dynamic(() => import('./components/Promotion'), { ssr: false }); const BillTable = dynamic(() => import('./components/BillTable'), { ssr: false }); const PayRecordTable = dynamic(() => import('./components/PayRecordTable'), { ssr: false }); const InformTable = dynamic(() => import('./components/InformTable'), { ssr: false }); enum TabEnum { 'info' = 'info', 'promotion' = 'promotion', 'bill' = 'bill', 'pay' = 'pay', 'inform' = 'inform', 'loginout' = 'loginout' } const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => { const { t } = useTranslation(); const tabList = useRef([ { icon: 'meLight', label: t('user.Personal Information'), id: TabEnum.info }, { icon: 'billRecordLight', label: t('user.Usage Record'), id: TabEnum.bill }, ...(feConfigs?.show_userDetail ? [ { icon: 'promotionLight', label: t('user.Promotion Record'), id: TabEnum.promotion }, { icon: 'payRecordLight', label: t('user.Recharge Record'), id: TabEnum.pay } ] : []), { icon: 'informLight', label: t('user.Notice'), id: TabEnum.inform }, { icon: 'loginoutLight', label: t('user.Sign Out'), id: TabEnum.loginout } ]); const { openConfirm, ConfirmModal } = useConfirm({ content: '确认退出登录?' }); const router = useRouter(); const theme = useTheme(); const { isPc } = useGlobalStore(); const { setUserInfo } = useUserStore(); const setCurrentTab = useCallback( (tab: string) => { if (tab === TabEnum.loginout) { openConfirm(() => { clearToken(); setUserInfo(null); router.replace('/login'); })(); } else { router.replace({ query: { currentTab: tab } }); } }, [openConfirm, router, setUserInfo] ); return ( {isPc ? ( ) : ( ({ id: item.id, label: item.label }))} activeId={currentTab} onChange={setCurrentTab} /> )} {currentTab === TabEnum.info && } {currentTab === TabEnum.promotion && } {currentTab === TabEnum.bill && } {currentTab === TabEnum.pay && } {currentTab === TabEnum.inform && } ); }; export async function getServerSideProps(content: any) { return { props: { currentTab: content?.query?.currentTab || TabEnum.info, ...(await serviceSideProps(content)) } }; } export default Account;