Browse Source

导航栏联动

release_0.0.1
deartibers 2 years ago
parent
commit
fa84a546c6
  1. 1
      web/client/src/layout/components/header/index.jsx
  2. 53
      web/client/src/layout/components/sider/index.jsx
  3. 29
      web/client/src/layout/containers/layout/index.jsx
  4. 2
      web/client/src/sections/auth/containers/login.jsx
  5. 4
      web/client/src/sections/console/containers/console.jsx

1
web/client/src/layout/components/header/index.jsx

@ -42,7 +42,6 @@ const Header = (props) => {
footer={ footer={
<> <>
{headerItems.map((item,index)=>{ {headerItems.map((item,index)=>{
// console.log('item',item);
if(item.hasOwnProperty('items')){ if(item.hasOwnProperty('items')){
return( return(
<Nav.Sub <Nav.Sub

53
web/client/src/layout/components/sider/index.jsx

@ -16,51 +16,7 @@ const Sider = (props) => {
useEffect(() => { useEffect(() => {
const { sections, dispatch, user } = props; const { sections, dispatch, user } = props;
let nextItems = leftItems let nextItems = leftItems
// let pathname_ = pathname == '/' ? homePath : pathname
// const initKeys = (items, lastKeys) => {
// // console.log('1111111',items);
// for (let it of items) {
// if (it.to && it.to == pathname_) {
// // console.log('22222222222',it.itemKey);
// lastKeys.selectedKeys.push(it.itemKey)
// return lastKeys
// } else if (it.items && it.items.length) {
// const preLastKeys = JSON.parse(JSON.stringify(lastKeys))
// preLastKeys.openKeys.push(it.itemKey)
// const nextKeys = initKeys(it.items, JSON.parse(JSON.stringify(preLastKeys)))
// if (nextKeys.selectedKeys.length > preLastKeys.selectedKeys.length || nextKeys.openKeys.length > preLastKeys.openKeys.length) {
// return nextKeys
// }
// }
// }
// return lastKeys
// return {
// selectedKeys: [],
// openKeys: []
// }
// }
setItems(nextItems) setItems(nextItems)
// const { selectedKeys, openKeys } = initKeys(
// nextItems,
// {
// selectedKeys: [],
// openKeys: []
// }
// )
// if (selectedKeys.length || openKeys.length) {
// setSelectedKeys(selectedKeys)
// setOpenKeys(openKeys)
// } else {
// const lastSelectedKeys = localStorage.getItem('vcmp_selected_sider')
// if (lastSelectedKeys) {
// setSelectedKeys(JSON.parse(lastSelectedKeys))
// }
// const lastOpenKeys = localStorage.getItem('vcmp_open_sider')
// if (lastOpenKeys) {
// setOpenKeys(JSON.parse(lastOpenKeys))
// }
// }
scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true }); scrollbar = new PerfectScrollbar('#page-slider', { suppressScrollX: true });
if (pathname == '/') { if (pathname == '/') {
dispatch(push(homePath)) dispatch(push(homePath))
@ -79,11 +35,11 @@ const Sider = (props) => {
else { else {
setSelectedKeys(routeSelectedKey) setSelectedKeys(routeSelectedKey)
} }
const lastOpenKeys = localStorage.getItem('vcmp_open_sider') const lastOpenKeys = localStorage.getItem('poms_open_sider')
if (lastOpenKeys) { if (lastOpenKeys) {
setOpenKeys(JSON.parse(lastOpenKeys)) setOpenKeys(JSON.parse(lastOpenKeys))
} }
}, [window.localStorage.vcmp_open_sider, window.localStorage.vcmp_selected_sider, leftChange]) }, [window.localStorage.poms_open_sider, window.localStorage.poms_selected_sider, leftChange])
useEffect(() => { useEffect(() => {
if (scrollbar) { if (scrollbar) {
@ -102,12 +58,13 @@ const Sider = (props) => {
if (selectItem.to) { if (selectItem.to) {
dispatch(push(selectItem.to)) dispatch(push(selectItem.to))
} }
let myfatherKey = selectItem.to
localStorage.setItem('poms_selected_sider', JSON.stringify([myfatherKey.split('/')[1]]))
setSelectedKeys(selectedKeys) setSelectedKeys(selectedKeys)
localStorage.setItem('vcmp_selected_sider', JSON.stringify(selectedKeys))
}} }}
onOpenChange={({ openKeys }) => { onOpenChange={({ openKeys }) => {
setOpenKeys(openKeys) setOpenKeys(openKeys)
localStorage.setItem('vcmp_open_sider', JSON.stringify(openKeys)) localStorage.setItem('poms_open_sider', JSON.stringify(openKeys))
}} }}
items={items} items={items}
/> />

29
web/client/src/layout/containers/layout/index.jsx

@ -86,7 +86,7 @@ const LayoutContainer = props => {
const [leftShow, setLeftShow] = useState(false) const [leftShow, setLeftShow] = useState(false)
useEffect(() => { useEffect(() => {
let topItems = []// let topItems = []//
// let siderItems = []// const lastSelectedKeys = localStorage.getItem('poms_selected_sider')
let nextItems = []// let nextItems = []//
for (let c of sections) { for (let c of sections) {
if (typeof c.getNavItem == 'function') { if (typeof c.getNavItem == 'function') {
@ -111,10 +111,25 @@ const LayoutContainer = props => {
} }
} }
} }
setLeftShow(false)
setAllItems(nextItems) setAllItems(nextItems)
setHeaderItems(topItems) setHeaderItems(topItems)
// setLeftItems(siderItems) if (lastSelectedKeys) {//
for (let i = 0; i < nextItems.length; i++) {
if (JSON.parse(lastSelectedKeys)[0] == nextItems[i].itemKey) {
let openArr = []
for (let j = 0; j < nextItems[i].items.length; j++) {
openArr.push(nextItems[i].items[j].itemKey)
}
localStorage.setItem('poms_open_sider', JSON.stringify(openArr))
setLeftItems(nextItems[i].items)
}
}
setLeftShow(true)
}
else {
setLeftShow(false)
}
window.addEventListener('resize', resize_); window.addEventListener('resize', resize_);
return () => { return () => {
@ -202,12 +217,20 @@ const LayoutContainer = props => {
if (val.fatherKey) { if (val.fatherKey) {
for (let i = 0; i < allItems.length; i++) { for (let i = 0; i < allItems.length; i++) {
if (val.fatherKey == allItems[i].itemKey) { if (val.fatherKey == allItems[i].itemKey) {
let openArr = []
for (let j = 0; j < allItems[i].items.length; j++) {
openArr.push(allItems[i].items[j].itemKey)
}
localStorage.setItem('poms_selected_sider', JSON.stringify([val.fatherKey]))
localStorage.setItem('poms_open_sider', JSON.stringify(openArr))
setLeftItems(allItems[i].items) setLeftItems(allItems[i].items)
} }
} }
setLeftShow(true) setLeftShow(true)
} }
else { else {
localStorage.setItem('poms_open_sider', JSON.stringify([]))
localStorage.removeItem('poms_selected_sider')
setLeftShow(false) setLeftShow(false)
} }
history.push(val.to); history.push(val.to);

2
web/client/src/sections/auth/containers/login.jsx

@ -21,6 +21,8 @@ const Login = props => {
useEffect(() => { useEffect(() => {
if (user && user.authorized) { if (user && user.authorized) {
dispatch(push('/console')); dispatch(push('/console'));
localStorage.setItem('poms_open_sider', JSON.stringify([]))
localStorage.removeItem('poms_selected_sider')
} }
}, [user]) }, [user])

4
web/client/src/sections/console/containers/console.jsx

@ -4,7 +4,7 @@ import { Spin, Card } from '@douyinfe/semi-ui';
import '../style.less' import '../style.less'
const { Meta } = Card; const { Meta } = Card;
const Example = (props) => { const Console = (props) => {
const { dispatch, actions, user, loading, socket } = props const { dispatch, actions, user, loading, socket } = props
useEffect(() => { useEffect(() => {
@ -46,4 +46,4 @@ function mapStateToProps (state) {
}; };
} }
export default connect(mapStateToProps)(Example); export default connect(mapStateToProps)(Console);

Loading…
Cancel
Save