|
|
@@ -2,7 +2,7 @@
|
|
|
* 图表列表
|
|
|
*/
|
|
|
import React from 'react'
|
|
|
-import { Layout, Button, Icon, Menu, Dropdown, Card, Col, Row, Breadcrumb, Tag, Checkbox, Pagination } from 'antd'
|
|
|
+import { Layout, Button, Icon, Menu, Dropdown, Card, Col, Row, Breadcrumb, Tag, Checkbox } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import ChooseDataSourceBox from './chooseDataSourceBox'
|
|
|
import GroupManagementBox from '../common/groupManageMentBox/box'
|
|
|
@@ -35,13 +35,7 @@ class ChartList extends React.Component {
|
|
|
visibleDeleteBox: false,
|
|
|
visibleGroupManageMentBox: false, // 显示分组管理组件
|
|
|
visibleDataPreviewBox: false,
|
|
|
-
|
|
|
noGroup: false, // 显示未分组数据
|
|
|
-
|
|
|
- page: 1, // 分页器当前页码
|
|
|
- pageSize: 25,// 每页最大展示卡片数(maxRowCards * maxRow)
|
|
|
- maxRowCards: 5, // 每行最大展示卡片数(无需自定义,有自动计算逻辑)
|
|
|
- maxRow: 5, // 每页最大行数(手动设置,也许后期可以通过判断电脑性能自动设置该值?)
|
|
|
}
|
|
|
this.bodyRef = React.createRef();
|
|
|
}
|
|
|
@@ -51,9 +45,6 @@ class ChartList extends React.Component {
|
|
|
this.setBodyWidth();
|
|
|
dispatch({ type: 'chart/fetchList' })
|
|
|
dispatch({ type: 'chart/remoteGroupList' });
|
|
|
- this.setState({
|
|
|
- page: chart.page || 1
|
|
|
- });
|
|
|
let parent = this.bodyRef.current.parentNode;
|
|
|
parent.scrollTo && parent.scrollTo(0, chart.listScrollTop)
|
|
|
window.addEventListener('resize', this.setBodyWidth);
|
|
|
@@ -64,7 +55,6 @@ class ChartList extends React.Component {
|
|
|
window.removeEventListener('resize', this.setBodyWidth);
|
|
|
dispatch({ type: 'chart/setFields', fields: [
|
|
|
{ name: 'listScrollTop', value: this.bodyRef.current.parentNode.scrollTop },
|
|
|
- { name: 'page', value: this.state.page },
|
|
|
] });
|
|
|
}
|
|
|
|
|
|
@@ -72,7 +62,6 @@ class ChartList extends React.Component {
|
|
|
* 设置卡片容器宽度 = 每行最大卡片数量 * 卡片宽度
|
|
|
*/
|
|
|
setBodyWidth = () => {
|
|
|
- const { maxRowCards, maxRow } = this.state;
|
|
|
const cardBody = this.bodyRef.current; // 卡片容器
|
|
|
const parent = cardBody.parentNode; // 父级容器
|
|
|
const pWidth = parent.offsetWidth; // 父级容器宽度
|
|
|
@@ -85,30 +74,9 @@ class ChartList extends React.Component {
|
|
|
const cardBodyWidth = count * cTrueWidth; // 考虑到滚动条,减少一个
|
|
|
|
|
|
cardBodyWidth > 0 ? cardBody.style.width = cardBodyWidth + 'px' : void(0);
|
|
|
-
|
|
|
- if(maxRowCards !== count) {
|
|
|
- this.setState({
|
|
|
- maxRowCards: count,
|
|
|
- pageSize: count * maxRow
|
|
|
- });
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- onGroup = () => {
|
|
|
- const { chart } = this.props;
|
|
|
- const { noGroup } = this.state;
|
|
|
- const { list, currentGroup } = chart;
|
|
|
-
|
|
|
- if(noGroup) {
|
|
|
- return list.filter(l => l.groupCode === '-1' );
|
|
|
- }else if(currentGroup) {
|
|
|
- return list.filter(l => l.groupCode === currentGroup.code );
|
|
|
- }else {
|
|
|
- return list;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- onFilterAndGroup = (cardList) => {
|
|
|
+ onFilterAndGroup = cardList => {
|
|
|
const { chart } = this.props;
|
|
|
const { noGroup } = this.state;
|
|
|
const { filterItem, currentGroup } = chart;
|
|
|
@@ -116,13 +84,14 @@ class ChartList extends React.Component {
|
|
|
let filterLabel = chart.filterLabel ? (chart.filterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
|
|
|
let filterReg = new RegExp('(' + filterLabel + '){1}', 'ig');
|
|
|
|
|
|
- let list = cardList.filter(l => {
|
|
|
+ let list = cardList.map(l => {
|
|
|
+ let visible = false;
|
|
|
if(filterItem.type === 'date') {
|
|
|
if(filterLabel===""){
|
|
|
if(noGroup) {
|
|
|
- return l.groupCode === '-1'
|
|
|
+ visible = l.groupCode === '-1';
|
|
|
}else {
|
|
|
- return !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
+ visible = !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
}
|
|
|
}else if(filterLabel.indexOf('#')>-1){
|
|
|
let start = filterLabel.split('#')[0]
|
|
|
@@ -130,26 +99,27 @@ class ChartList extends React.Component {
|
|
|
let nowTime = new Date(l[filterItem.name]).getTime();
|
|
|
if(nowTime>=start && nowTime<=end){
|
|
|
if(noGroup) {
|
|
|
- return l.groupCode === '-1'
|
|
|
+ visible = l.groupCode === '-1'
|
|
|
}else {
|
|
|
- return !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
+ visible = !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
}
|
|
|
}
|
|
|
- return false;
|
|
|
+ visible = false;
|
|
|
}else{
|
|
|
- return false;
|
|
|
+ visible = false;
|
|
|
}
|
|
|
}else {
|
|
|
if((l[filterItem.name] + '').search(filterReg) > -1) {
|
|
|
if(noGroup) {
|
|
|
- return l.groupCode === '-1'
|
|
|
+ visible = l.groupCode === '-1'
|
|
|
}else {
|
|
|
- return !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
+ visible = !!currentGroup ? l.groupCode === currentGroup.code : true;
|
|
|
}
|
|
|
}else {
|
|
|
- return false;
|
|
|
+ visible = false;
|
|
|
}
|
|
|
}
|
|
|
+ return { ...l, visible }
|
|
|
})
|
|
|
|
|
|
return list;
|
|
|
@@ -161,14 +131,9 @@ class ChartList extends React.Component {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- onPage = (list) => {
|
|
|
- const { page, pageSize } = this.state;
|
|
|
- return list.slice(pageSize * (page - 1), pageSize * (page - 1) + pageSize)
|
|
|
- }
|
|
|
-
|
|
|
- onReduce = () => {
|
|
|
+ onFilter = () => {
|
|
|
const { list } = this.props.chart;
|
|
|
- return this.onSort(this.onFilterAndGroup(list));
|
|
|
+ return this.onFilterAndGroup(list);
|
|
|
}
|
|
|
|
|
|
getParens = (group) => {
|
|
|
@@ -198,11 +163,7 @@ class ChartList extends React.Component {
|
|
|
<span onClick={() => {
|
|
|
let group = chart.groupList.find(group => group.code === g.code);
|
|
|
dispatch({ type: 'chart/setCurrentGroup', group: group });
|
|
|
- this.setState({
|
|
|
- page: 1
|
|
|
- }, () => {
|
|
|
- this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
- })
|
|
|
+ this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
}}>{g.label}</span>
|
|
|
<GroupSelector
|
|
|
visible={this.state['visibleGroupSelector' + g.code]}
|
|
|
@@ -218,11 +179,7 @@ class ChartList extends React.Component {
|
|
|
obj['visibleGroupSelector' + g.code] = false;
|
|
|
this.setState(obj);
|
|
|
dispatch({ type: 'chart/setCurrentGroup', group });
|
|
|
- this.setState({
|
|
|
- page: 1
|
|
|
- }, () => {
|
|
|
- this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
- })
|
|
|
+ this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
}}
|
|
|
>
|
|
|
<Icon style={{ marginLeft: '4px', fontSize: '12px' }} type="caret-down" />
|
|
|
@@ -289,9 +246,8 @@ class ChartList extends React.Component {
|
|
|
const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
|
|
|
let filterLabel = chart.filterLabel ? (chart.filterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
|
|
|
|
|
|
- console.time('generateCard');
|
|
|
let cards = list.map( (l, i) => (
|
|
|
- <CardGrid className={`chart-card`} key={i} onClick={() => {
|
|
|
+ <CardGrid className={`chart-card${l.visible ? ' visible' : ' hidden'}`} key={i} onClick={() => {
|
|
|
this.setState({ selectedRecord: l })
|
|
|
}}>
|
|
|
<Card
|
|
|
@@ -352,7 +308,6 @@ class ChartList extends React.Component {
|
|
|
</Card>
|
|
|
</CardGrid>
|
|
|
));
|
|
|
- console.timeEnd('generateCard');
|
|
|
if(cards.length === 0) {
|
|
|
return <EmptyContent />
|
|
|
}
|
|
|
@@ -401,20 +356,13 @@ class ChartList extends React.Component {
|
|
|
dispatch({ type: 'chart/remoteMoveGroup', dragCode, dropCode, dropPosition });
|
|
|
}
|
|
|
|
|
|
- onPageChange = (pageNumber) => {
|
|
|
- this.setState({
|
|
|
- page: pageNumber
|
|
|
- }, () => {
|
|
|
- this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
render() {
|
|
|
const { dispatch, chart } = this.props;
|
|
|
const { listLoading } = chart;
|
|
|
- const { visibleChooseDataSourceBox, visibleDistributeBox, visibleGroupManageMentBox, visibleTransferBox, visibleDeleteBox, selectedRecord, noGroup, pageSize, page } = this.state;
|
|
|
- let reduceList = this.onReduce();
|
|
|
- let viewList = this.onPage(reduceList);
|
|
|
+ const { visibleChooseDataSourceBox, visibleDistributeBox, visibleGroupManageMentBox, visibleTransferBox, visibleDeleteBox, selectedRecord, noGroup } = this.state;
|
|
|
+ let viewList = this.onFilter();
|
|
|
+ // let viewList = this.onPage(reduceList);
|
|
|
+ // let viewList = reduceList;
|
|
|
return (
|
|
|
<Layout className='layout-chart'>
|
|
|
<Loading visible={listLoading} />
|
|
|
@@ -425,7 +373,6 @@ class ChartList extends React.Component {
|
|
|
<Checkbox style={{ marginTop: '4px' }} checked={noGroup} onChange={(e) => {
|
|
|
this.setState({
|
|
|
noGroup: e.target.checked,
|
|
|
- page: 1
|
|
|
}, () => {
|
|
|
this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
|
|
|
})
|
|
|
@@ -467,9 +414,6 @@ class ChartList extends React.Component {
|
|
|
{ this.generateCard(viewList) }
|
|
|
</div>
|
|
|
</Card>
|
|
|
- <Pagination showQuickJumper pageSize={pageSize} current={page} total={reduceList.length} onChange={this.onPageChange}
|
|
|
- showTotal={total => `共${total}个图表`}
|
|
|
- />
|
|
|
</Content>
|
|
|
{visibleGroupManageMentBox && <GroupManagementBox
|
|
|
typeText='图表'
|