mirror of
https://github.com/PlayEdu/backend
synced 2025-06-09 00:44:08 +08:00
Merge branch 'dev' of https://gitee.com/playeduxyz/backend into dev
This commit is contained in:
commit
cb1aa1e2d3
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
MailOutlined,
|
MailOutlined,
|
||||||
SettingOutlined,
|
SettingOutlined,
|
||||||
@ -6,7 +6,7 @@ import {
|
|||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { Menu } from "antd";
|
import { Menu } from "antd";
|
||||||
//导出路由跳转hooks函数
|
//导出路由跳转hooks函数
|
||||||
import { useNavigate, Link } from "react-router-dom";
|
import { useNavigate, Link, useLocation } from "react-router-dom";
|
||||||
import styles from "./index.module.less";
|
import styles from "./index.module.less";
|
||||||
import logo from "../../assets/logo.png";
|
import logo from "../../assets/logo.png";
|
||||||
|
|
||||||
@ -56,18 +56,32 @@ const items = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const LeftMenu: React.FC = () => {
|
export const LeftMenu: React.FC = () => {
|
||||||
//展开的subMenu
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
// 默认展开的subMenu
|
||||||
const [openKeys, setOpenKeys] = useState(["1"]);
|
const [openKeys, setOpenKeys] = useState(["1"]);
|
||||||
|
// 默认选中的menu
|
||||||
|
const [selectedKeys, setSelectedKeys] = useState(["/"]);
|
||||||
//点击subMenu的回调函数
|
//点击subMenu的回调函数
|
||||||
const onOpenChange = (keys: any) => {
|
const onOpenChange = (keys: any) => {
|
||||||
setOpenKeys(keys);
|
setOpenKeys(keys);
|
||||||
};
|
};
|
||||||
//路由跳转的函数
|
|
||||||
const navigate = useNavigate();
|
|
||||||
//点击每一项
|
|
||||||
const onClick = (e: any) => {
|
const onClick = (e: any) => {
|
||||||
navigate(e.key);
|
navigate(e.key);
|
||||||
};
|
};
|
||||||
|
const onSelect = (e: any) => {
|
||||||
|
setSelectedKeys(e.selectedKeys);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 监听菜单变化如果通过非直接点击『主面板』菜单进入到首页的话
|
||||||
|
// 则重置菜单的选择状态
|
||||||
|
useEffect(() => {
|
||||||
|
if (location.pathname === "/") {
|
||||||
|
setSelectedKeys(["/"]);
|
||||||
|
}
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles["left-menu"]}>
|
<div className={styles["left-menu"]}>
|
||||||
<Link style={{ textDecoration: "none" }} to={`/`}>
|
<Link style={{ textDecoration: "none" }} to={`/`}>
|
||||||
@ -79,10 +93,13 @@ export const LeftMenu: React.FC = () => {
|
|||||||
width: 200,
|
width: 200,
|
||||||
background: "#ffffff",
|
background: "#ffffff",
|
||||||
}}
|
}}
|
||||||
|
defaultSelectedKeys={["/"]}
|
||||||
|
selectedKeys={selectedKeys}
|
||||||
openKeys={openKeys}
|
openKeys={openKeys}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
mode="inline"
|
mode="inline"
|
||||||
items={items}
|
items={items}
|
||||||
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user