Browse Source

导航

release_0.0.1
deartibers 3 years ago
parent
commit
f5bda27f5e
  1. 118
      web/client/src/layout/components/sider/index.jsx
  2. 19
      web/client/src/layout/containers/layout/index.jsx
  3. 4
      web/client/src/sections/auth/containers/login.jsx
  4. 12
      web/client/src/sections/example/nav-item.jsx
  5. 12
      web/client/src/sections/example1/nav-item.jsx

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

@ -9,56 +9,57 @@ import "./index.less";
let scrollbar = null
const homePath = '/example/e1/c1'
const Sider = (props) => {
const { collapsed, clientHeight, dispatch, pathname,leftItems,leftChange } = props
const { collapsed, clientHeight, dispatch, pathname, leftItems, leftChange } = props
const [items, setItems] = useState([])
const [selectedKeys, setSelectedKeys] = useState([])
const [openKeys, setOpenKeys] = useState([])
useEffect(() => {
const { sections, dispatch, user } = props;
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_) {
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: []
}
}
// 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)
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))
}
}
// 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 });
if (pathname == '/') {
@ -68,38 +69,21 @@ const Sider = (props) => {
let routeSelectedKey = [useLocation().pathname.split('/')[1]]//
let routeSelectedKeys = [useLocation().pathname.split('/')[2]]//
let routeSelectedKeyss = [useLocation().pathname.split('/')[3]]//
useEffect(()=>{
let pathname_ = pathname == '/' ? homePath : pathname
const initKeys = (items, lastKeys) => {
for (let it of items) {
if (it.to && it.to == pathname_) {
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
}
if(routeSelectedKeyss[0]){
useEffect(() => {
if (routeSelectedKeyss[0]) {
setSelectedKeys(routeSelectedKeyss)
}
else if(routeSelectedKeys[0]){
else if (routeSelectedKeys[0]) {
setSelectedKeys(routeSelectedKeys)
}
else{
else {
setSelectedKeys(routeSelectedKey)
}
const lastOpenKeys = localStorage.getItem('vcmp_open_sider')
if (lastOpenKeys) {
setOpenKeys(JSON.parse(lastOpenKeys))
}
},[window.localStorage.vcmp_open_sider,window.localStorage.vcmp_selected_sider,leftChange])
}, [window.localStorage.vcmp_open_sider, window.localStorage.vcmp_selected_sider, leftChange])
useEffect(() => {
if (scrollbar) {
@ -107,9 +91,9 @@ const Sider = (props) => {
}
})
return (
<div id={'page-slider'} style={{ height: clientHeight, position: 'relative',background:'#101531',width:180 }}>
<div id={'page-slider'} style={{ height: clientHeight, position: 'relative', background: '#101531', width: 180 }}>
<Nav
style={{background:'#101531',width:180,padding:0}}
style={{ background: '#101531', width: 180, padding: 0 }}
selectedKeys={selectedKeys}
openKeys={openKeys}

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

@ -38,7 +38,7 @@ const LayoutContainer = props => {
document.getElementById('PomsApp').clientWidth - (collapsed ? 120 : 240)
));
}
function deepCopy(data) {//
function deepCopy (data) {//
//string,number,bool,null,undefined,symbol
//object,array,date
if (data && typeof data === "object") {
@ -94,11 +94,11 @@ const LayoutContainer = props => {
if (item) {
nextItems.push.apply(nextItems, item)
if (item.length > 0) {
let itm = deepCopy(item[0]);
let itms=deepCopy(item[0]);
for (let j = 0; j < item.length; j++) {
let itm = deepCopy(item[j]);
if (itm.hasOwnProperty('items')) {
// siderItems.push.apply(siderItems, itms.items)
for (let i = 0; i < itm.items.length; i++) {
itm.items[i].fatherKey=itm.itemKey
delete itm.items[i].items
}
topItems.push(itm)
@ -110,6 +110,7 @@ const LayoutContainer = props => {
}
}
}
}
setLeftShow(false)
setAllItems(nextItems)
setHeaderItems(topItems)
@ -198,15 +199,15 @@ const LayoutContainer = props => {
history={history}
tochange={(val) => {
setLeftChange(!leftChange)
if(val.fatherKey){
if (val.fatherKey) {
for (let i = 0; i < allItems.length; i++) {
if(val.fatherKey==allItems[i].itemKey){
if (val.fatherKey == allItems[i].itemKey) {
setLeftItems(allItems[i].items)
}
}
setLeftShow(true)
}
else{
else {
setLeftShow(false)
}
history.push(val.to);
@ -214,7 +215,7 @@ const LayoutContainer = props => {
/>
</Layout.Header>
<Layout style={{ height: 'calc(100% - 60px)' }}>
{leftShow?(<Layout.Sider>
{leftShow ? (<Layout.Sider>
<Sider
sections={sections}
leftItems={leftItems}
@ -224,7 +225,7 @@ const LayoutContainer = props => {
pathname={location.pathname}
collapsed={collapsed}
/>
</Layout.Sider>):('')}
</Layout.Sider>) : ('')}
<Layout.Content>
<div style={{
margin: '12px 12px 0px',

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

@ -20,9 +20,7 @@ const Login = props => {
useEffect(() => {
if (user && user.authorized) {
dispatch(push('/example/e1/c1'));
localStorage.setItem('vcmp_selected_sider', JSON.stringify(['nvr']))
localStorage.setItem('vcmp_open_sider', JSON.stringify(['equipmentWarehouse']))
dispatch(push('/console'));
}
}, [user])

12
web/client/src/sections/example/nav-item.jsx

@ -14,7 +14,6 @@ export function getNavItem (user, dispatch) {
text: '举个棒子1',
icon: <IconCode />,
to: '/example/e1/c1',
fatherKey:'example',
items: [{
itemKey: 'c1', to: '/example/e1/c1', text: '举个锤子1'
}]
@ -23,7 +22,6 @@ export function getNavItem (user, dispatch) {
text: '举个棒子2',
icon: <IconCode />,
to: '/example/e2/c2',
fatherKey:'example',
items: [{
itemKey: 'c2', to: '/example/e2/c2', text: '举个锤子2'
}]
@ -31,15 +29,5 @@ export function getNavItem (user, dispatch) {
]
},
]
// ,[
// {
// itemKey: 'equipmentWarehouse', text: '', icon:<iconpark-icon style={{width:20,height:20}} name="she-1"></iconpark-icon>,
// items: [
// { itemKey: 'nvr', to: '/equipmentWarehouse/nvr', text: 'NVR' },
// { itemKey: 'camera', to: '/equipmentWarehouse/camera', text: '' },
// { itemKey: 'recycle', to: '/equipmentWarehouse/recycle', text: '' },
// ]
// },
// ]
);
}

12
web/client/src/sections/example1/nav-item.jsx

@ -14,7 +14,6 @@ export function getNavItem (user, dispatch) {
text: '举个棒子3',
icon: <IconCode />,
to: '/example/e3/c3',
fatherKey:'example1',
items: [{
itemKey: 'c3', to: '/example/e3/c3', text: '举个锤子3'
}]
@ -23,7 +22,6 @@ export function getNavItem (user, dispatch) {
text: '举个棒子4',
icon: <IconCode />,
to: '/example/e4/c4',
fatherKey:'example1',
items: [{
itemKey: 'c4', to: '/example/e4/c4', text: '举个锤子4'
}]
@ -31,15 +29,5 @@ export function getNavItem (user, dispatch) {
]
},
]
// ,[
// {
// itemKey: 'equipmentWarehouse', text: '', icon:<iconpark-icon style={{width:20,height:20}} name="she-1"></iconpark-icon>,
// items: [
// { itemKey: 'nvr', to: '/equipmentWarehouse/nvr', text: 'NVR' },
// { itemKey: 'camera', to: '/equipmentWarehouse/camera', text: '' },
// { itemKey: 'recycle', to: '/equipmentWarehouse/recycle', text: '' },
// ]
// },
// ]
);
}
Loading…
Cancel
Save