import React, { memo, useState, useEffect } from 'react'; import { Tabs, Button, Row } from 'antd'; import { DownOutlined } from '@ant-design/icons'; import { tabsType } from './type'; import './pro-table-header.less'; const { TabPane } = Tabs; interface HeaderProps { title: string; tabs?: tabsType; firstTabsChange: ( key: string | number | undefined, value: string | number | undefined, ) => void; secondTabsChange: ( key: string | number | undefined, value: string | number | undefined, ) => void; } export default memo(function (props: HeaderProps) { const { title, tabs, firstTabsChange, secondTabsChange } = props; const [firstTab, setFirstTab] = useState(tabs?.firstTabs?.defaultKey || '1'); // 一级菜单active const [secondTab, setSecondTab] = useState(tabs?.secondTabs?.defaultKey || 1); // 二级菜单active const [rotate, setRotate] = useState(tabs?.secondTabs?.defaultOpen ? 0.5 : 0); // 旋转角度 useEffect(() => { /// 实现动态修改 二级defaultKey 后不刷新的问题 if(tabs?.secondTabs && tabs?.secondTabs?.defaultKey !== secondTab){ setSecondTab(tabs?.secondTabs.defaultKey || 1);// 避免ts报错 } if(tabs?.firstTabs && tabs?.firstTabs?.defaultKey !== secondTab){ setFirstTab(tabs?.firstTabs.defaultKey || '1');// 避免ts报错 } }, [tabs]) /** * 一级tabs切换 * @param key */ const tabFirstTabsChange = (key, value) => { //该处为解决 antd 默认将 activeKey转成string型 if (typeof tabs?.firstTabs?.defaultKey === 'number') { value = parseFloat(value); } firstTabsChange(key, value); setFirstTab(value+''); // console.log(value); // console.log('一级切换111', tabs?.secondTabs?.defaultKey); setSecondTab(tabs?.secondTabs?.defaultKey || 1); }; /** * 二级tabs切换 * @param key */ const tabSecondTabsChange = (key, value) => { secondTabsChange(key, value); setSecondTab(value); }; // console.log('tabs.firstTabs.defaultKey', tabs?.firstTabs.defaultKey); return (

{title || ''}

{tabs && tabs.firstTabs && (
tabFirstTabsChange(tabs?.firstTabs?.key, e)} > {tabs.firstTabs.data.map(item => ( ))}
)} {tabs && tabs.secondTabs && (
{tabs.secondTabs.title}: {tabs.secondTabs.data.map((item, index) => { if (rotate) { return ( ); } else { return ( ); } })}
{/*
*/}
)}
); });