import React, { useEffect, useMemo, useCallback } from 'react'; import { useRouter } from 'next/router'; import { Box, Flex, IconButton, useTheme } from '@chakra-ui/react'; import { useUserStore } from '@/store/user'; import dynamic from 'next/dynamic'; import { defaultApp } from '@/constants/model'; import Tabs from '@/components/Tabs'; import SideTabs from '@/components/SideTabs'; import Settings from './components/Settings'; import Avatar from '@/components/Avatar'; import MyIcon from '@/components/Icon'; import PageContainer from '@/components/PageContainer'; const Share = dynamic(() => import('./components/Share'), { ssr: false }); const API = dynamic(() => import('./components/API'), { ssr: false }); enum TabEnum { 'settings' = 'settings', 'share' = 'share', 'API' = 'API' } const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => { const router = useRouter(); const theme = useTheme(); const { appId } = router.query as { appId: string }; const { appDetail = defaultApp } = useUserStore(); const setCurrentTab = useCallback( (tab: `${TabEnum}`) => { router.replace({ query: { appId, currentTab: tab } }); }, [appId, router] ); const tabList = useMemo( () => [ { label: '概览', id: TabEnum.settings, icon: 'overviewLight' }, { label: '链接分享', id: TabEnum.share, icon: 'shareLight' }, { label: 'API访问', id: TabEnum.API, icon: 'apiLight' }, { label: '立即对话', id: 'startChat', icon: 'chatLight' } ], [] ); // useEffect(() => { // window.onbeforeunload = (e) => { // e.preventDefault(); // e.returnValue = '内容已修改,确认离开页面吗?'; // }; // return () => { // window.onbeforeunload = null; // }; // }, []); return ( {/* pc tab */} {appDetail.name} { if (e === 'startChat') { router.push(`/chat?appId=${appId}`); } else { setCurrentTab(e); } }} /> router.replace('/app/list')} > } bg={'white'} boxShadow={'1px 1px 9px rgba(0,0,0,0.15)'} h={'28px'} size={'sm'} borderRadius={'50%'} aria-label={''} /> 我的应用 {/* phone tab */} {appDetail.name} { if (e === 'startChat') { router.push(`/chat?appId=${appId}`); } else { setCurrentTab(e); } }} /> {currentTab === TabEnum.settings && } {currentTab === TabEnum.API && } {currentTab === TabEnum.share && } ); }; export async function getServerSideProps(context: any) { const currentTab = context?.query?.currentTab || TabEnum.settings; return { props: { currentTab } }; } export default AppDetail;