Commit f8c683d4 by zhujian

'fix'

parent ffead757
import React, { Key, useContext, useEffect, useRef, useState } from 'react';
import React, { Key, useContext, useEffect, useRef, useState, useMemo } from 'react';
import {
withRouter,
} from 'react-router-dom';
import { Menu} from 'antd';
import { Menu } from 'antd';
import { menuList } from '../../routes//config/menuList'
import { XMContext } from '../../store/context';
import Service from "@/common/js/service";
......@@ -13,13 +13,14 @@ import "./Menu.less";
const { SubMenu } = Menu;
function Aside(props: any) {
const {menuType,handleMenuType}= props
const { menuType, handleMenuType } = props
const ctx: any = useContext(XMContext);
const [selectKey, setSelectKey] = useState();
const [openKeys, setOpenKeys] = useState(['']);
const [topLogoUrl, setTopLogoUrl] = useState("")
const [collapsed, setCollapsed] = useState(false)
const rootSubmenuKeys = _.pluck(menuList, 'groupCode');
useEffect(() => {
const link = props.location.pathname;
menuList.map((item: any, index: any) => {
......@@ -36,13 +37,14 @@ function Aside(props: any) {
return item;
})
}, [props.location.pathname])
useEffect(()=> {
useEffect(() => {
getTopLeftLogo()
},[])
}, [])
function getTopLeftLogo() {
if (User.getToken()) {
StoreService.getStoreDetail({storeId:User.getStoreId()})
.then(res=> {
StoreService.getStoreDetail({ storeId: User.getStoreId() })
.then(res => {
if (_.isEmpty(res.result.logo)) {
setTopLogoUrl("https://image.xiaomaiketang.com/xm/fe4NCjr7XF.png")
} else {
......@@ -52,12 +54,14 @@ function Aside(props: any) {
})
}
}
function toggleMenu(item: any) {
window.RCHistory.push(item.link)
if (!menuType) {
setOpenKeys([])
}
}
function onOpenChange(key: Key[]) {
if (typeof key === "string") {
if (openKeys.includes(key)) {
......@@ -86,6 +90,13 @@ function Aside(props: any) {
setCollapsed(!collapsed)
}
const openKeysConstrol = useMemo(() => {
return {
[menuType ? 'openKeys ' : 'defaultOpenKeys']: openKeys
};
}, [menuType, openKeys])
return (
<div
id="left-container"
......@@ -97,7 +108,7 @@ function Aside(props: any) {
>
<div className="top-ctrl">
<div className="topLogo">
{ menuType && <img src={topLogoUrl} alt="" className="img1"></img> }
{menuType && <img src={topLogoUrl} alt="" className="img1"></img>}
</div>
<div className="menu-type-icon" onClick={handleMenu}>
{menuType ? (
......@@ -120,9 +131,10 @@ function Aside(props: any) {
<div className="nav">
<Menu
style={menuType ? { minHeight: "100%", background: '#0E1935' }:{minHeight: "100%", background: '#0E1935',width:"56px" }}
{...openKeysConstrol}
style={menuType ? { minHeight: "100%", background: '#0E1935' } : { minHeight: "100%", background: '#0E1935', width: "56px" }}
selectedKeys={selectKey}
openKeys={menuType ? openKeys : []}
onOpenChange={onOpenChange}
inlineCollapsed={collapsed}
mode={menuType ? "inline" : "vertical"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment