import React, { Component, Suspense } from 'react'; import { connect } from 'dva'; import { Row, Col, Icon, Menu, Dropdown } from 'antd'; import { RangePickerValue } from 'antd/lib/date-picker/interface'; import { getTimeDistance } from './utils/utils'; import styles from './style.less'; import PageLoading from './components/PageLoading'; import { Dispatch } from 'redux'; import { IAnalysisData } from './data.d'; import { RadioChangeEvent } from 'antd/lib/radio'; import { GridContent } from '@ant-design/pro-layout'; const IntroduceRow = React.lazy(() => import('./components/IntroduceRow')); const SalesCard = React.lazy(() => import('./components/SalesCard')); const TopSearch = React.lazy(() => import('./components/TopSearch')); const ProportionSales = React.lazy(() => import('./components/ProportionSales')); const OfflineData = React.lazy(() => import('./components/OfflineData')); interface BLOCK_NAME_CAMEL_CASEProps { BLOCK_NAME_CAMEL_CASE: IAnalysisData; dispatch: Dispatch; loading: boolean; } interface BLOCK_NAME_CAMEL_CASEState { salesType: 'all' | 'online' | 'stores'; currentTabKey: string; rangePickerValue: RangePickerValue; } @connect( ({ BLOCK_NAME_CAMEL_CASE, loading, }: { BLOCK_NAME_CAMEL_CASE: any; loading: { effects: { [key: string]: boolean }; }; }) => ({ BLOCK_NAME_CAMEL_CASE, loading: loading.effects['BLOCK_NAME_CAMEL_CASE/fetch'], }) ) class PAGE_NAME_UPPER_CAMEL_CASE extends Component< BLOCK_NAME_CAMEL_CASEProps, BLOCK_NAME_CAMEL_CASEState > { state: BLOCK_NAME_CAMEL_CASEState = { salesType: 'all', currentTabKey: '', rangePickerValue: getTimeDistance('year'), }; reqRef!: number; timeoutId!: number; componentDidMount() { const { dispatch } = this.props; this.reqRef = requestAnimationFrame(() => { dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/fetch', }); }); } componentWillUnmount() { const { dispatch } = this.props; dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/clear', }); cancelAnimationFrame(this.reqRef); clearTimeout(this.timeoutId); } handleChangeSalesType = (e: RadioChangeEvent) => { this.setState({ salesType: e.target.value, }); }; handleTabChange = (key: string) => { this.setState({ currentTabKey: key, }); }; handleRangePickerChange = (rangePickerValue: RangePickerValue) => { const { dispatch } = this.props; this.setState({ rangePickerValue, }); dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/fetchSalesData', }); }; selectDate = (type: 'today' | 'week' | 'month' | 'year') => { const { dispatch } = this.props; this.setState({ rangePickerValue: getTimeDistance(type), }); dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/fetchSalesData', }); }; isActive = (type: 'today' | 'week' | 'month' | 'year') => { const { rangePickerValue } = this.state; const value = getTimeDistance(type); if (!rangePickerValue[0] || !rangePickerValue[1]) { return ''; } if ( rangePickerValue[0].isSame(value[0], 'day') && rangePickerValue[1].isSame(value[1], 'day') ) { return styles.currentDate; } return ''; }; render() { const { rangePickerValue, salesType, currentTabKey } = this.state; const { BLOCK_NAME_CAMEL_CASE, loading } = this.props; const { visitData, visitData2, salesData, searchData, offlineData, offlineChartData, salesTypeData, salesTypeDataOnline, salesTypeDataOffline, } = BLOCK_NAME_CAMEL_CASE; let salesPieData; if (salesType === 'all') { salesPieData = salesTypeData; } else { salesPieData = salesType === 'online' ? salesTypeDataOnline : salesTypeDataOffline; } const menu = ( 操作一 操作二 ); const dropdownGroup = ( ); const activeKey = currentTabKey || (offlineData[0] && offlineData[0].name); return ( }> ); } } export default PAGE_NAME_UPPER_CAMEL_CASE;