import React from 'react' import { Layout, Button, Icon, Input, Menu, Dropdown, Card, Col, Row } from 'antd' import { connect } from 'dva' import { dateFormat } from '../../utils/baseUtils' import Ellipsis from 'ant-design-pro/lib/Ellipsis' import DistributeBox from './distributeBox' import TransferBox from '../common/selectUserBox'; import 'ant-design-pro/dist/ant-design-pro.css' import Thumbnail from './thumbnail' import './list.less' import DeleteBox from '../common/deleteBox' const { Content } = Layout const { Search } = Input const CardGrid = Card.Grid class DashboardList extends React.Component { constructor(props) { super(props); this.state = { selectedRecord: null, visibleChooseDataSourceBox: false, visibleDistributeBox: false, visibleTransferBox: false, visibleGroupMenu: false, // 显示分组菜单 visibleDeleteBox: false } } componentDidMount() { const { dispatch } = this.props; this.setBodyWidth(); dispatch({ type: 'dashboard/fetchList' }); } /** * 设置卡片容器宽度 = 每行最大卡片数量 * 卡片宽度 */ setBodyWidth() { const chartBody = document.getElementsByClassName('dashboard-body')[0]; // 卡片容器 const parent = chartBody.parentNode; // 父级容器 const pWidth = parent.offsetWidth; // 父级容器宽度 const pPadding = 10 + 10; // 父级容器左右padding const cWidth = 512; // 每个卡片宽度 const cMargin = 5 + 5; // 每个卡片左右margin const pTrueWidth = pWidth - pPadding; // 父容器实际可用宽度 const cTrueWidth = cWidth + cMargin; // 卡片实际占用宽度 const count = Math.floor(pTrueWidth/cTrueWidth); // 每行最大卡片数量 chartBody.style.width = count * cTrueWidth + 'px'; } generateCard() { const { dashboard, dispatch } = this.props; const list = dashboard.list; const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符 let filterLabel = dashboard.filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号 const operationMenu = ( { this.setState({visibleDistributeBox: true}) }}> 分发 { this.setState({ visibleTransferBox: true}) }} > 移交 { this.setState({ visibleDeleteBox: true}) }} > 删除 ) let cards = list.filter(l => { let reg = new RegExp('(' + filterLabel + '){1}', 'ig'); return (l.name || '').search(reg) !== -1 || (l.description || '').search(reg) !== -1; }).sort((a, b) => { return new Date(b.createTime) - new Date(a.createTime) }).map( (l, i) => ( { this.setState({ selectedRecord: l }) }}> { filterLabel ? ((l.name || '').split(new RegExp(`(${filterLabel})`, 'i')).map((fragment, i) => { return ( fragment.toLowerCase().replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') === filterLabel.toLowerCase() ? {fragment} : fragment ) } )) : l.name } } cover={ { dispatch({ type: 'dashboardDesigner/reset' }); dispatch({ type: 'main/redirect', path: '/dashboard/' + l.code }); }}> 16} lines={2}>{ { filterLabel ? ((l.description || '').split(new RegExp(`(${filterLabel})`, 'i')).map((fragment, i) => { return ( fragment.toLowerCase().replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') === filterLabel.toLowerCase() ? {fragment} : fragment ) } )) : l.description } } {l.creator} {dateFormat(l.createTime, 'yyyy-MM-dd')} } > )); if(cards.length === 0) { cards =
暂无数据
} return cards; } handleVisibleChange = (flag) => { this.setState({ visibleGroupMenu: flag }); } hideGroupMenu = () => { this.setState({ visibleGrouMenu: false }); } render() { const { dispatch, dashboard } = this.props; const { visibleDistributeBox, visibleTransferBox, visibleDeleteBox, selectedRecord } = this.state return ( { dispatch({ type: 'dashboard/setFilterLabel', label: e.target.value }); }} /> }>
{ this.generateCard() }
{ this.setState({ visibleDistributeBox: false }); }} /> { dispatch({ type: 'dashboard/transfer', dashboardCode: this.state.selectedRecord.code, userCode: user.code }); }} hideBox={() => { this.setState({ visibleTransferBox: false }) }} /> { this.setState({ visibleDeleteBox: false }) }} selectedRecord={selectedRecord} onOk={() => { dispatch({ type: 'dashboard/remoteDelete', code: this.state.selectedRecord.code }) }} />
) } } function mapStateToProps({ present: { dashboard } }) { return { dashboard } } export default connect(mapStateToProps)(DashboardList)