Commit ca9e3cf5 authored by 左玲玲's avatar 左玲玲 😬

1452

parent c5029e04
...@@ -25,6 +25,21 @@ function strToHump(str) { ...@@ -25,6 +25,21 @@ function strToHump(str) {
return res + 'Outlined'; return res + 'Outlined';
} }
function getChildren(data) {
let arr = [];
function loop(data) {
data.map(it => {
if (it.routes?.length > 0) {
loop(it.routes);
} else {
arr.push(it);
}
});
}
loop(data);
return arr;
}
export async function getInitialState() { export async function getInitialState() {
let token = localStorage.getItem('TOKENES'); let token = localStorage.getItem('TOKENES');
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
...@@ -152,10 +167,28 @@ export const layout = ({ initialState, setInitialState }) => { ...@@ -152,10 +167,28 @@ export const layout = ({ initialState, setInitialState }) => {
noFound: <div>noFound</div>, noFound: <div>noFound</div>,
// 增加一个 loading 的状态 // 增加一个 loading 的状态
childrenRender: (children, props) => { childrenRender: (children, props) => {
let home, items = getChildren(initialState?.newMenu?.userHavePermList ?? []);
items?.unshift({
path: "/welcome",
name: "首页",
icon: "smile",
component: "./Welcome",
haveChildren: false,
key: "000000",
parentKey: "0",
routes: [],
children: null,
title: null,
});
if (history.location.pathname != "/welcome" && history.location.pathname != "/") {
home = history.location.pathname
} else {
home = items?.length > 0 ? items[0].path.indexOf("/") > -1 ? items[0].path : items[0]?.children?.length > 0 ? items[0]?.children[0]?.path : "" : "";
}
return ( return (
<> <>
{initialState?.currentUser && location.pathname !== loginPath ? ( {initialState?.currentUser && location.pathname !== loginPath ? (
<TagView home='/welcome'>{children}</TagView> <TagView home={home}>{children}</TagView>
) : ( ) : (
children children
)} )}
......
...@@ -85,7 +85,7 @@ const Tags = ({ tagList, closeTag, closeAllTag, closeOtherTag, refreshTag, home ...@@ -85,7 +85,7 @@ const Tags = ({ tagList, closeTag, closeAllTag, closeOtherTag, refreshTag, home
> >
刷新 刷新
</li> </li>
{currentTag.path != home && currentTag.currentIndex != 0 && ( {currentTag.path != home && (
<li <li
onClick={() => { onClick={() => {
setMenuVisible(false); setMenuVisible(false);
......
...@@ -30,10 +30,7 @@ const TagView = ({ home }) => { ...@@ -30,10 +30,7 @@ const TagView = ({ home }) => {
// console.log(routeContext); // console.log(routeContext);
const { menuData } = routeContext; const { menuData } = routeContext;
if (tagList.length === 0 && menuData) { if (tagList.length === 0 && menuData) {
const allarr = []; const allarr = getChildren(menuData);
treeForeach(menuData, (node) => {
allarr.push(node);
});
const firstTag = allarr.filter((el) => el.path === home)[0]; const firstTag = allarr.filter((el) => el.path === home)[0];
if (firstTag) { if (firstTag) {
const title = firstTag.name; const title = firstTag.name;
...@@ -144,6 +141,20 @@ const TagView = ({ home }) => { ...@@ -144,6 +141,20 @@ const TagView = ({ home }) => {
setTagList(tagsCopy); setTagList(tagsCopy);
}, 10); }, 10);
}; };
function getChildren(data) {
let arr = [];
function loop(data) {
data.map(it => {
if (it.children?.length > 0) {
loop(it.children);
} else {
arr.push(it);
}
});
}
loop(data);
return arr;
}
return ( return (
<> <>
<RouteContext.Consumer> <RouteContext.Consumer>
......
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