Commit 877cef33 authored by wuhao's avatar wuhao 🎯

asder

parent ab5433fa
import React, { useState, useEffect, useRef } from 'react'; /* eslint-disable react/jsx-key */
import React, { useState, useEffect, useRef, memo } from 'react';
import { RouteContext } from '@ant-design/pro-layout'; import { RouteContext } from '@ant-design/pro-layout';
import { history } from '@umijs/max'; import { history } from '@umijs/max';
import Tags from './Tags'; import Tags from './Tags';
import styles from './index.less'; import styles from './index.less';
import { Scrollbars } from 'react-custom-scrollbars'; import { Scrollbars } from 'react-custom-scrollbars';
// tree遍历
function treeForeach(tree, func) {
tree.forEach((data) => {
func(data);
data.children && treeForeach(data.children, func); // 遍历子树
});
}
/**
* @component TagView 标签页组件
*/
const TagView = ({ children, home }) => { const TagView = ({ children, home }) => {
const [tagList, setTagList] = useState([]); const [tagList, setTagList] = useState([]);
...@@ -24,9 +29,13 @@ const TagView = ({ children, home }) => { ...@@ -24,9 +29,13 @@ const TagView = ({ children, home }) => {
const initTags = (routeContext) => { const initTags = (routeContext) => {
const { menuData } = routeContext; const { menuData } = routeContext;
if (tagList.length === 0 && menuData) { if (tagList.length === 0 && menuData) {
const firstTag = menuData.filter((el) => el.path === home)[0]; const allarr = [];
treeForeach(menuData, (node) => {
allarr.push(node);
});
const firstTag = allarr.filter((el) => el.path === location?.hash?.replace('#', ''))[0];
if (firstTag) { if (firstTag) {
const title = '首页'; const title = firstTag.name;
const path = firstTag.path; const path = firstTag.path;
history.push({ pathname: firstTag.path, query: firstTag.query }); history.push({ pathname: firstTag.path, query: firstTag.query });
setTagList([ setTagList([
...@@ -155,13 +164,8 @@ const TagView = ({ children, home }) => { ...@@ -155,13 +164,8 @@ const TagView = ({ children, home }) => {
> >
{tagList.map((item) => { {tagList.map((item) => {
return ( return (
<div <div style={{ display: item.active ? 'block' : 'none', height: '100%' }}>
key={item.path} {children}
style={{ display: item.active ? 'block' : 'none', height: '100%' }}
>
<div key={item.refresh} style={{ height: '100%' }}>
{children}
</div>
</div> </div>
); );
})} })}
......
This diff is collapsed.
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