|
|
@ -5,6 +5,7 @@ import { DownOutlined } from '@ant-design/icons';
|
|
|
|
import 'antd/dist/reset.css';
|
|
|
|
import 'antd/dist/reset.css';
|
|
|
|
import AppLogo from '@/assets/logo-gh.png';
|
|
|
|
import AppLogo from '@/assets/logo-gh.png';
|
|
|
|
import { isEmpty } from '@/utils/commons';
|
|
|
|
import { isEmpty } from '@/utils/commons';
|
|
|
|
|
|
|
|
import { appendRequestParams } from '@/utils/request'
|
|
|
|
import Language from '../i18n/LanguageSwitcher';
|
|
|
|
import Language from '../i18n/LanguageSwitcher';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import zhLocale from 'antd/locale/zh_CN';
|
|
|
|
import zhLocale from 'antd/locale/zh_CN';
|
|
|
@ -24,38 +25,34 @@ function App() {
|
|
|
|
const [password, setPassword] = useState('');
|
|
|
|
const [password, setPassword] = useState('');
|
|
|
|
const { notification } = AntApp.useApp();
|
|
|
|
const { notification } = AntApp.useApp();
|
|
|
|
|
|
|
|
|
|
|
|
const loginUser = useAuthStore((state) => state.loginUser)
|
|
|
|
const [loginUser, validateUserPassword] = useAuthStore((state) => state.loginUser, state.validateUserPassword)
|
|
|
|
|
|
|
|
|
|
|
|
const { loginToken } = useStorage()
|
|
|
|
const { loginToken } = useStorage()
|
|
|
|
|
|
|
|
|
|
|
|
const noticeUnRead = useNoticeStore((state) => state.noticeUnRead);
|
|
|
|
const noticeUnRead = useNoticeStore((state) => state.noticeUnRead)
|
|
|
|
const href = useHref();
|
|
|
|
const href = useHref();
|
|
|
|
const navigate = useNavigate()
|
|
|
|
const navigate = useNavigate()
|
|
|
|
const location = useLocation()
|
|
|
|
const location = useLocation()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 除了路由 /p...以外都需要登陆系统
|
|
|
|
|
|
|
|
const needToLogin = href !== '/login' && isEmpty(loginToken)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!needToLogin) {
|
|
|
|
|
|
|
|
appendRequestParams('token', loginToken)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (href !== '/login' && isEmpty(loginToken)) {
|
|
|
|
if (needToLogin) {
|
|
|
|
navigate('/login');
|
|
|
|
navigate('/login')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [href]);
|
|
|
|
}, [href])
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
window.gtag('event', 'page_view', { page_location: window.location.href });
|
|
|
|
window.gtag('event', 'page_view', { page_location: window.location.href });
|
|
|
|
}, [location]);
|
|
|
|
}, [location]);
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = () => {
|
|
|
|
const onSubmit = () => {
|
|
|
|
authStore.valdateUserPassword(loginUser.username, password)
|
|
|
|
valdateUserPassword(loginUser.username, password)
|
|
|
|
.then(() => {
|
|
|
|
|
|
|
|
authStore.fetchUserDetail()
|
|
|
|
|
|
|
|
.catch(ex => {
|
|
|
|
|
|
|
|
notification.error({
|
|
|
|
|
|
|
|
message: `Notification`,
|
|
|
|
|
|
|
|
description: 'Failed to get user information.',
|
|
|
|
|
|
|
|
placement: 'top',
|
|
|
|
|
|
|
|
duration: 4,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(ex => {
|
|
|
|
.catch(ex => {
|
|
|
|
notification.error({
|
|
|
|
notification.error({
|
|
|
|
message: `Notification`,
|
|
|
|
message: `Notification`,
|
|
|
@ -181,7 +178,7 @@ function App() {
|
|
|
|
minHeight: 280,
|
|
|
|
minHeight: 280,
|
|
|
|
background: colorBgContainer,
|
|
|
|
background: colorBgContainer,
|
|
|
|
}}>
|
|
|
|
}}>
|
|
|
|
<Outlet />
|
|
|
|
{needToLogin ? <>login...</> : <Outlet />}
|
|
|
|
</Content>
|
|
|
|
</Content>
|
|
|
|
<Footer></Footer>
|
|
|
|
<Footer></Footer>
|
|
|
|
</Layout>
|
|
|
|
</Layout>
|
|
|
|