|
@@ -1,22 +1,63 @@
|
|
|
-import React from 'react';
|
|
|
|
|
-import { Outlet } from 'react-router-dom';
|
|
|
|
|
-import { Layout, Typography } from 'antd';
|
|
|
|
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
|
|
+import { Link, Outlet, useLocation, useNavigate } from 'react-router-dom';
|
|
|
|
|
+import { Layout, Row, Col, Typography, Button, Result } from 'antd';
|
|
|
|
|
+import { ArrowLeftOutlined } from '@ant-design/icons';
|
|
|
|
|
+import { useAuth } from '../apis/AuthProvider';
|
|
|
|
|
+import UserDrawer from '../components/UserDrawer';
|
|
|
import styles from './PageLayout.module.css';
|
|
import styles from './PageLayout.module.css';
|
|
|
|
|
|
|
|
const { Header, Content } = Layout;
|
|
const { Header, Content } = Layout;
|
|
|
const { Text } = Typography;
|
|
const { Text } = Typography;
|
|
|
|
|
|
|
|
-const PageLayout: React.FC = () => (
|
|
|
|
|
- <Layout className={styles.layout}>
|
|
|
|
|
- <Header className={styles.header}>
|
|
|
|
|
- <Text className={styles.title} strong>
|
|
|
|
|
- Woord
|
|
|
|
|
- </Text>
|
|
|
|
|
- </Header>
|
|
|
|
|
- <Content className={styles.content}>
|
|
|
|
|
- <Outlet />
|
|
|
|
|
- </Content>
|
|
|
|
|
- </Layout>
|
|
|
|
|
-);
|
|
|
|
|
|
|
+const PageLayout: React.FC = () => {
|
|
|
|
|
+ const [open, setOpen] = useState(false);
|
|
|
|
|
+
|
|
|
|
|
+ const { pathname } = useLocation();
|
|
|
|
|
+ const navigate = useNavigate();
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (pathname === '/') {
|
|
|
|
|
+ navigate('/dicts');
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [pathname, navigate]);
|
|
|
|
|
+
|
|
|
|
|
+ const { user } = useAuth();
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Layout>
|
|
|
|
|
+ <Header className={styles.header}>
|
|
|
|
|
+ <Row gutter={8}>
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ <Link to={pathname.slice(0, pathname.lastIndexOf('/'))}>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="link"
|
|
|
|
|
+ icon={<ArrowLeftOutlined />}
|
|
|
|
|
+ disabled={pathname === '/dicts'}
|
|
|
|
|
+ />
|
|
|
|
|
+ </Link>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col flex={1}>
|
|
|
|
|
+ <Text className={styles.title} strong>
|
|
|
|
|
+ Woord
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ {user ? (
|
|
|
|
|
+ user.name
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Button shape="round" onClick={() => setOpen(true)}>
|
|
|
|
|
+ 登录
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ </Header>
|
|
|
|
|
+ <Content className={styles.content}>
|
|
|
|
|
+ {user ? <Outlet /> : <Result status="403" subTitle="请先登录" />}
|
|
|
|
|
+ </Content>
|
|
|
|
|
+ <UserDrawer open={open} onClose={() => setOpen(false)} />
|
|
|
|
|
+ </Layout>
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
export default PageLayout;
|
|
export default PageLayout;
|