import React from 'react' import { Layout, Tag, Icon } from 'antd' import { connect } from 'dva' import ViewLayout from './viewLayout' import FilterBox from '../common/filterBox/filterBox2' import Filter from '../common/filterBox/filter2' import ConfigSider from './configSider' const { Header, Content, Sider } = Layout class DashboardDesignerContent extends React.Component { constructor(props) { super(props); this.state = { lastContentSize: { scroll: false, width: 0, height: 0, }, visibleFilterBox: false, closeFilters: false, }; this.contentRef=React.createRef(); } componentDidMount() { // this.refreshContentSize(); const { dashboardDesigner } = this.props; const { filters } = dashboardDesigner; this.setState({ closeFilters: filters.length > 6 }); window.addEventListener("resize", this.refreshContentSize); } componentWillUnmount() { window.removeEventListener('resize', this.refreshContentSize); } showFilterBox = (e) => { this.setState({ visibleFilterBox: true }); } hideFilterBox = (e) => { this.setState({ visibleFilterBox: false, }); } /** * 重设容器宽度 */ refreshContentSize = () => { this.setState({ refresh: true }); } getContentSize = () => { const { lastContentSize } = this.state; let contentEl = this.contentRef.current; if(!contentEl) { return { width: 0, height: 0 }; } let viewcontent = contentEl.getElementsByClassName('dashboard-viewcontent')[0]; let _scroll = viewcontent.scrollHeight > viewcontent.clientHeight; let padding = 0; let width = contentEl.offsetWidth - padding * 2 - (_scroll ? 10 : 2) // 有滚动条时需要减去滚动条的宽度 if(width > 0 && width !== lastContentSize.width) { this.setState({ lastContentSize: { width, height: contentEl.clientHeight, scroll: _scroll } }); } return { width: width, height: contentEl.clientHeight } } createFilters = (filters) => { const { dispatch, afterRefresh } = this.props; dispatch({ type: 'dashboardDesigner/changeFilters', filters }).then(() => { afterRefresh && typeof afterRefresh === 'function' && afterRefresh() }); } filterUsingChange = (e) => { const key = e.target.dataset.key; const { dashboardDesigner, dispatch, afterRefresh } = this.props; const filters = dashboardDesigner.filters; let filter = filters.find(f => +f.key === +key); dispatch({ type: 'dashboardDesigner/changeFilter', filter: { ...filter, using: filter.type ? !filter.using : false} }).then(() => { afterRefresh && typeof afterRefresh === 'function' && afterRefresh() }); } changeFilterValue = (filter) => { const { dispatch, afterRefresh } = this.props; dispatch({ type: 'dashboardDesigner/changeFilter', filter }).then(() => { afterRefresh && typeof afterRefresh === 'function' && afterRefresh() }); } render() { const { dashboardDesigner, isOwner, isShareView, isShareKeyView, isViewMode } = this.props; const { dataSources, editMode, filters, relationColumns } = dashboardDesigner; const { visibleFilterBox, lastContentSize, closeFilters } = this.state; const contentSize = this.getContentSize(); return {isOwner && editMode && !isShareView && !isShareKeyView && !isViewMode && } {/** 这里直接用main标签而不用antd的Header组件是为了让ref能够定位到对应的dom元素 */}
{(editMode || (filters && filters.length > 0) )&&
{/*
*/}
{isOwner && editMode && !isShareView && !isShareKeyView && !isViewMode && } {filters.map(f => ( ))}
0 ? 'block' : 'none' }}> { this.setState({ closeFilters: !closeFilters }); }}/>
{visibleFilterBox && }
}
} } export default connect(({ present: { dashboardDesigner } }) => ({ dashboardDesigner }))(DashboardDesignerContent);