import { Outlet, Link, useHref, useNavigate, NavLink } from 'react-router-dom'; import { useEffect, useState } from 'react'; import { Layout, Menu, ConfigProvider, theme, Dropdown, Space, Row, Col, Badge, Typography, Modal, Input, Button, App as AntApp } from 'antd'; import { DownOutlined } from '@ant-design/icons'; import 'antd/dist/reset.css'; import AppLogo from '@/assets/logo-gh.png'; import { isEmpty } from '@/utils/commons'; import { useTranslation } from 'react-i18next'; import zhLocale from 'antd/locale/zh_CN'; import enLocale from 'antd/locale/en_US'; import 'dayjs/locale/zh-cn'; import ErrorBoundary from '@/components/ErrorBoundary'; import { BUILD_VERSION, } from '@/config'; import useNoticeStore from '@/stores/Notice'; import useAuthStore from '@/stores/Auth'; import { useThemeContext } from '@/stores/ThemeContext'; import { usingStorage } from '@/hooks/usingStorage'; import { useDefaultLgc } from '@/i18n/LanguageSwitcher'; import { appendRequestParams } from '@/utils/request' import { PERM_ACCOUNT_MANAGEMENT, PERM_ROLE_NEW, PERM_OVERSEA, PERM_AIR_TICKET, PERM_PRODUCTS_MANAGEMENT } from '@/config'; const { Header, Content, Footer } = Layout; const { Title } = Typography; function App() { const { t, i18n } = useTranslation() const { colorPrimary } = useThemeContext() const [password, setPassword] = useState('') const [authenticate, tokenTimeout, isPermitted, currentUser] = useAuthStore( (state) => [state.authenticate, state.tokenTimeout, state.isPermitted, state.currentUser]) const { loginToken } = usingStorage() const noticeUnRead = useNoticeStore((state) => state.noticeUnRead) const href = useHref() const navigate = useNavigate() // 除了路由 /p...以外都需要登陆系统 const needToLogin = href !== '/login' && isEmpty(loginToken) useEffect(() => { if (needToLogin) { navigate('/login') } }, [href]) const onSubmit = () => { authenticate(currentUser?.username, password) .catch(ex => { console.error(ex) alert(t('Validation.LoginFailed')) }) setPassword('') } const splitPath = href.split('/') let defaultPath = 'notice' if (splitPath.length > 1) { defaultPath = splitPath[1] } const { language } = useDefaultLgc(); const [antdLng, setAntdLng] = useState(enLocale); useEffect(() => { setAntdLng(i18n.language === 'en' ? enLocale : zhLocale); appendRequestParams('lgc', language); }, [i18n.language]) return ( {t('LoginTimeout')}
{t('LoginTimeoutTip')}
setPassword(e.target.value)} onPressEnter={onSubmit} addonBefore={currentUser?.username} />
App logo {t('menu.Reservation')} } : null, isPermitted(PERM_OVERSEA) ? { key: 'invoice', label: {t('menu.Invoice')} } : null, isPermitted(PERM_OVERSEA) ? { key: 'feedback', label: {t('menu.Feedback')} } : null, isPermitted(PERM_OVERSEA) ? { key: 'report', label: {t('menu.Report')} } : null, isPermitted(PERM_AIR_TICKET) ? { key: 'airticket', label: {t('menu.Airticket')} } : null, isPermitted(PERM_PRODUCTS_MANAGEMENT) ? { key: 'products', label: {t('menu.Products')} } : { key: 'products', label: {t('menu.Products')} }, { key: 'notice', label: ( {t('menu.Notice')} {noticeUnRead ? : ''} ), }, ]} />

{currentUser?.travelAgencyName}

{t('ChangePassword')}, key: '0' }, { label: {t('Profile')}, key: '1' }, isPermitted(PERM_ACCOUNT_MANAGEMENT) ? { label: {t('account:accountList')}, key: '3' } : null, isPermitted(PERM_ROLE_NEW) ? { label: {t('account:roleList')}, key: '4' } : null, { type: 'divider' }, { label: {t('Logout')}, key: '99' }, ] ], }} trigger={['click']} > e.preventDefault()}>
{currentUser?.realname}
{needToLogin ? <>login... : }
) } export default App