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 { history } from '@umijs/max';
import Tags from './Tags';
import styles from './index.less';
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 [tagList, setTagList] = useState([]);
......@@ -24,9 +29,13 @@ const TagView = ({ children, home }) => {
const initTags = (routeContext) => {
const { menuData } = routeContext;
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) {
const title = '首页';
const title = firstTag.name;
const path = firstTag.path;
history.push({ pathname: firstTag.path, query: firstTag.query });
setTagList([
......@@ -155,14 +164,9 @@ const TagView = ({ children, home }) => {
>
{tagList.map((item) => {
return (
<div
key={item.path}
style={{ display: item.active ? 'block' : 'none', height: '100%' }}
>
<div key={item.refresh} style={{ height: '100%' }}>
<div style={{ display: item.active ? 'block' : 'none', height: '100%' }}>
{children}
</div>
</div>
);
})}
</Scrollbars>
......
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