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

1452

parent c5029e04
......@@ -25,6 +25,21 @@ function strToHump(str) {
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() {
let token = localStorage.getItem('TOKENES');
const fetchUserInfo = async () => {
......@@ -152,10 +167,28 @@ export const layout = ({ initialState, setInitialState }) => {
noFound: <div>noFound</div>,
// 增加一个 loading 的状态
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 (
<>
{initialState?.currentUser && location.pathname !== loginPath ? (
<TagView home='/welcome'>{children}</TagView>
<TagView home={home}>{children}</TagView>
) : (
children
)}
......
......@@ -85,7 +85,7 @@ const Tags = ({ tagList, closeTag, closeAllTag, closeOtherTag, refreshTag, home
>
刷新
</li>
{currentTag.path != home && currentTag.currentIndex != 0 && (
{currentTag.path != home && (
<li
onClick={() => {
setMenuVisible(false);
......
......@@ -30,10 +30,7 @@ const TagView = ({ home }) => {
// console.log(routeContext);
const { menuData } = routeContext;
if (tagList.length === 0 && menuData) {
const allarr = [];
treeForeach(menuData, (node) => {
allarr.push(node);
});
const allarr = getChildren(menuData);
const firstTag = allarr.filter((el) => el.path === home)[0];
if (firstTag) {
const title = firstTag.name;
......@@ -144,6 +141,20 @@ const TagView = ({ home }) => {
setTagList(tagsCopy);
}, 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 (
<>
<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