|
@ -4,18 +4,18 @@ import { connect } from 'react-redux'; |
|
|
import { Nav } from '@douyinfe/semi-ui'; |
|
|
import { Nav } from '@douyinfe/semi-ui'; |
|
|
import { push } from 'react-router-redux'; |
|
|
import { push } from 'react-router-redux'; |
|
|
import { useLocation } from 'react-router'; |
|
|
import { useLocation } from 'react-router'; |
|
|
|
|
|
import "./index.less"; |
|
|
|
|
|
|
|
|
let scrollbar = null |
|
|
let scrollbar = null |
|
|
const homePath = '/equipmentWarehouse/nvr' |
|
|
const homePath = '/example/e1/c1' |
|
|
const Sider = props => { |
|
|
const Sider = (props) => { |
|
|
const { collapsed, clientHeight, dispatch, pathname } = props |
|
|
const { collapsed, clientHeight, dispatch, pathname,leftItems } = props |
|
|
const [items, setItems] = useState([]) |
|
|
const [items, setItems] = useState([]) |
|
|
const [selectedKeys, setSelectedKeys] = useState([]) |
|
|
const [selectedKeys, setSelectedKeys] = useState([]) |
|
|
const [openKeys, setOpenKeys] = useState([]) |
|
|
const [openKeys, setOpenKeys] = useState([]) |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
const { sections, dispatch, user } = props; |
|
|
const { sections, dispatch, user } = props; |
|
|
let nextItems = [] |
|
|
let nextItems = leftItems |
|
|
let pathname_ = pathname == '/' ? homePath : pathname |
|
|
let pathname_ = pathname == '/' ? homePath : pathname |
|
|
const initKeys = (items, lastKeys) => { |
|
|
const initKeys = (items, lastKeys) => { |
|
|
for (let it of items) { |
|
|
for (let it of items) { |
|
@ -37,17 +37,7 @@ const Sider = props => { |
|
|
openKeys: [] |
|
|
openKeys: [] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (let c of sections) { |
|
|
|
|
|
if (typeof c.getNavItem == 'function') { |
|
|
|
|
|
let item = c.getNavItem(user, dispatch); |
|
|
|
|
|
if (item) { |
|
|
|
|
|
nextItems.push.apply(nextItems, item) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
setItems(nextItems) |
|
|
setItems(nextItems) |
|
|
|
|
|
|
|
|
const { selectedKeys, openKeys } = initKeys( |
|
|
const { selectedKeys, openKeys } = initKeys( |
|
|
nextItems, |
|
|
nextItems, |
|
|
{ |
|
|
{ |
|
@ -73,7 +63,7 @@ const Sider = props => { |
|
|
if (pathname == '/') { |
|
|
if (pathname == '/') { |
|
|
dispatch(push(homePath)) |
|
|
dispatch(push(homePath)) |
|
|
} |
|
|
} |
|
|
}, []) |
|
|
}, [leftItems]) |
|
|
let routeSelectedKey = [useLocation().pathname.split('/')[1]]//没有子目录的 |
|
|
let routeSelectedKey = [useLocation().pathname.split('/')[1]]//没有子目录的 |
|
|
let routeSelectedKeys = [useLocation().pathname.split('/')[2]]//有子目录的 |
|
|
let routeSelectedKeys = [useLocation().pathname.split('/')[2]]//有子目录的 |
|
|
useEffect(()=>{ |
|
|
useEffect(()=>{ |
|
@ -113,9 +103,9 @@ const Sider = props => { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
return ( |
|
|
return ( |
|
|
<div id={'page-slider'} style={{ height: clientHeight, position: 'relative' }}> |
|
|
<div id={'page-slider'} style={{ height: clientHeight, position: 'relative',background:'#101531',width:180 }}> |
|
|
<Nav |
|
|
<Nav |
|
|
style={{}} |
|
|
style={{background:'#101531',width:180,padding:0}} |
|
|
// defaultOpenKeys={openKeys} |
|
|
// defaultOpenKeys={openKeys} |
|
|
// defaultSelectedKeys ={selectedKeys} |
|
|
// defaultSelectedKeys ={selectedKeys} |
|
|
selectedKeys={selectedKeys} |
|
|
selectedKeys={selectedKeys} |
|
|