import React from 'react' import { Layout, Tabs, Dropdown, Menu } from 'antd' import { connect } from 'dva' import MenuLayout from './sider' import DashboardViewToolbar from './toolbar' import DashboardView from './view' import EmptyContent from '../common/emptyContent/index' import CusIcon from '../common/cusIcon/index' import './index.less' const { Sider, Content } = Layout const TabPane = Tabs.TabPane class Home extends React.Component { componentDidMount() { const { home, dispatch } = this.props; dispatch({ type: 'home/getFixedDashboard' }).then(data => { if(data && home.tabs.length === 0) { dispatch({ type: 'home/openTab', tab: data }) } }); } // componentWillUnmount() { // const { home, dispatch } = this.props; // const { tabs } = home; // // 离开页面后将报表中的图表配置移除,以保证下次进入时触发自动刷新 // tabs.forEach(t => { // t.config = null; // }); // dispatch({ type: 'home/setField', name: 'tabs', value: tabs }); // } generateTabs() { const { home } = this.props; const { tabs, fixedDashboard } = home; return tabs.map(t => ( {/* {t.name}} key={t.code}> */} )); } generateTabTitle = (text, tabKey) => ( {text} ) generateMenu = (tabKey) => { const { fixedDashboard } = this.props.home return { // 点击菜单项后触发tab的切换事件,这里将其事件阻断 e.domEvent.stopPropagation(); this.remove(tabKey); }}>关闭当前 { // 点击菜单项后触发tab的切换事件,这里将其事件阻断 e.domEvent.stopPropagation(); this.removeOther(tabKey); }}>关闭其他 { // 点击菜单项后触发tab的切换事件,这里将其事件阻断 e.domEvent.stopPropagation(); this.removeAll(); }}>关闭所有 } onChange = (activeKey) => { const { dispatch, home } = this.props; const { selectedTab, tabs } = home; let tab = tabs.find(t => t.code === activeKey); dispatch({ type: 'home/saveCurrentTabDashboardConfig', code: selectedTab.code }); dispatch({ type: 'home/changeTab', tab }); } onEdit = (targetKey, action) => { this[action](targetKey); } remove = (targetKey) => { const { dispatch, home } = this.props; const { tabs: allTabs } = home; let tab = allTabs.find(t => t.code === targetKey); dispatch({ type: 'home/closeTab', tab }); } removeOther = (targetKey) => { const { dispatch, home } = this.props; const { tabs: allTabs, fixedDashboard } = home; let tabs = allTabs.filter(t => (t.code !== targetKey && (!fixedDashboard || t.code !== fixedDashboard.code) )); let tab = allTabs.find(t => t.code === targetKey); dispatch({ type: 'home/closeTabs', tabs }); dispatch({ type: 'home/changeTab', tab }); } removeAll = () => { const { dispatch } = this.props; dispatch({ type: 'home/closeAllTabs' }); } render() { const { home } = this.props; const { tabs, selectedTab } = home; return {tabs.length > 0 ? { this.generateTabs() } : } } } export default connect(({ present: { home, dashboard } }) => ({ home, dashboard }))(Home)