|
|
@ -38,6 +38,49 @@ const LayoutContainer = props => { |
|
|
|
document.getElementById('PomsApp').clientWidth - (collapsed ? 120 : 240) |
|
|
|
)); |
|
|
|
} |
|
|
|
function deepCopy(data) {//深拷贝 |
|
|
|
//string,number,bool,null,undefined,symbol |
|
|
|
//object,array,date |
|
|
|
if (data && typeof data === "object") { |
|
|
|
//针对函数的拷贝 |
|
|
|
if (typeof data === "function") { |
|
|
|
let tempFunc = data.bind(null); |
|
|
|
tempFunc.prototype = deepCopy(data.prototype); |
|
|
|
return tempFunc; |
|
|
|
} |
|
|
|
|
|
|
|
switch (Object.prototype.toString.call(data)) { |
|
|
|
case "[object String]": |
|
|
|
return data.toString(); |
|
|
|
case "[object Number]": |
|
|
|
return Number(data.toString()); |
|
|
|
case "[object Boolean]": |
|
|
|
return new Boolean(data.toString()); |
|
|
|
case "[object Date]": |
|
|
|
return new Date(data.getTime()); |
|
|
|
case "[object Array]": |
|
|
|
var arr = []; |
|
|
|
for (let i = 0; i < data.length; i++) { |
|
|
|
arr[i] = deepCopy(data[i]); |
|
|
|
} |
|
|
|
return arr; |
|
|
|
|
|
|
|
//js自带对象或用户自定义类实例 |
|
|
|
case "[object Object]": |
|
|
|
var obj = {}; |
|
|
|
for (let key in data) { |
|
|
|
//会遍历原型链上的属性方法,可以用hasOwnProperty来控制 (obj.hasOwnProperty(prop) |
|
|
|
obj[key] = deepCopy(data[key]); |
|
|
|
} |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} else { |
|
|
|
//string,number,bool,null,undefined,symbol |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
const [headerItems, setHeaderItems] = useState([]) |
|
|
|
const [leftItems, setLeftItems] = useState([]) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
let topItems = []//头部导航 |
|
|
@ -47,8 +90,8 @@ const LayoutContainer = props => { |
|
|
|
let item = c.getNavItem(user, dispatch); |
|
|
|
if (item) { |
|
|
|
if (item.length > 0) { |
|
|
|
let itm = JSON.parse(JSON.stringify(item[0])); |
|
|
|
let itms = JSON.parse(JSON.stringify(item[0])); |
|
|
|
let itm = deepCopy(item[0]); |
|
|
|
let itms=deepCopy(item[0]); |
|
|
|
if (itm.hasOwnProperty('items')) { |
|
|
|
siderItems.push.apply(siderItems, itms.items) |
|
|
|
for (let i = 0; i < itm.items.length; i++) { |
|
|
@ -64,8 +107,8 @@ const LayoutContainer = props => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('siderItems', siderItems); |
|
|
|
console.log('topItems', topItems); |
|
|
|
setHeaderItems(topItems) |
|
|
|
setLeftItems(siderItems) |
|
|
|
|
|
|
|
window.addEventListener('resize', resize_); |
|
|
|
return () => { |
|
|
@ -140,6 +183,7 @@ const LayoutContainer = props => { |
|
|
|
<> |
|
|
|
<Layout.Header> |
|
|
|
<Header |
|
|
|
headerItems={headerItems} |
|
|
|
user={user} |
|
|
|
pathname={location.pathname} |
|
|
|
toggleCollapsed={() => { |
|
|
@ -153,6 +197,7 @@ const LayoutContainer = props => { |
|
|
|
<Layout.Sider> |
|
|
|
<Sider |
|
|
|
sections={sections} |
|
|
|
leftItems={leftItems} |
|
|
|
dispatch={dispatch} |
|
|
|
user={user} |
|
|
|
pathname={location.pathname} |
|
|
|