Browse Source

列表过滤组件设计

zhuth 6 years ago
parent
commit
0e4e3f12be

+ 112 - 33
src/components/chart/chooseDataSourceBox.jsx

@@ -1,19 +1,39 @@
 import React from 'react'
-import { Modal, Table, Radio, message, Input, Row, Col } from 'antd'
+import { Modal, Table, Radio, message, Row, Col } from 'antd'
 import { connect } from 'dva'
 import './chooseDataSourceBox.less'
 import { dateFormat } from '../../utils/baseUtils'
-const { Search } = Input
+import ListFilter from '../common/listFilter/index'
 
 class ChooseDataSourceBox extends React.Component {
     constructor(props) {
         super(props);
         this.state = {
+            filterItem: { name: 'name', label: '名称', type: 'string' },
             filterLabel: '',
-            selectedRecord: null
+            selectedRecord: null,
+            screenWidth: document.documentElement.clientWidth || document.body.clientWidth,
+            screenHeight: document.documentElement.clientHeight || document.body.clientHeight
         }
     }
 
+    componentDidMount() {
+        const { dispatch } = this.props;
+        dispatch({ type: 'dataSource/fetchList' });
+        window.addEventListener('resize', this.onWindowResize);
+    }
+
+    componentWillUnmount() {
+        window.removeEventListener('resize', this.onWindowResize);
+    }
+
+    onWindowResize = () => {
+        this.setState({
+            screenWidth: document.documentElement.clientWidth || document.body.clientWidth,
+            screenHeight: document.documentElement.clientHeight || document.body.clientHeight
+        });
+    }
+
     changeSelected = (record) => {
         this.setState({
             selectedRecord: Object.assign({}, record)
@@ -31,12 +51,48 @@ class ChooseDataSourceBox extends React.Component {
         }
     }
 
+    onSearch = (list) => {
+        const { filterItem, filterLabel: stateFilterLabel } = this.state;
+        const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
+        let filterLabel = stateFilterLabel ? (stateFilterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
+        let filterReg = new RegExp('('+ filterLabel +'){1}', 'ig');
+
+        return list.map(l => {
+            let o = Object.assign({}, l);
+
+            if(filterItem.type === 'date') {
+                if(filterLabel===""){
+                    return o;
+                }else if(filterLabel.indexOf('#')>-1){
+                    let start = filterLabel.split('#')[0]
+                    let end = filterLabel.split('#')[1]
+                    let nowTime = o[filterItem.name].getTime();
+                    if(nowTime>=start && nowTime<=end){
+                        return o;
+                    }
+                    return null 
+                }else{
+                    return null 
+                }
+            }else {
+                let arr = filterItem.name.split('.');
+                let v = o;
+                for(let i = 0; i < arr.length; i++) {
+                    v = v[arr[i]]
+                }
+                return ((v + '').search(filterReg) > -1) ? o : null
+            }
+        }).filter(a => a!==null);
+    }
+
     render() {
-        const { selectedRecord } = this.state;
         const { dataSource, visibleChooseDataSourceBox, hideBox } = this.props
-
+        const { filterItem, filterLabel: stateFilterLabel, selectedRecord, screenWidth, screenHeight } = this.state;
+        const tableBodyWidth = screenWidth * 0.8 - 10 - 10 - 18;
+        const tableBodyHeight = screenHeight * 0.8 - 65 - 53 - 38 - 130;
+        const tableRowHeight = 38;
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
-        let filterLabel = this.state.filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
+        let filterLabel = stateFilterLabel ? (stateFilterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
         
         const columns = [{
             title: '选择',
@@ -55,7 +111,7 @@ class ChooseDataSourceBox extends React.Component {
                     <div className={`datasource-type type-${record.type.key}`}></div>
                     <div>
                         <span>
-                            { filterLabel ?
+                            { (filterItem.name === 'name' && filterLabel) ?
                                 (text.split(new RegExp(`(${filterLabel})`, 'i')).map((fragment, i) => {
                                     return (
                                         fragment.toLowerCase().replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') === filterLabel.toLowerCase() ?
@@ -69,11 +125,35 @@ class ChooseDataSourceBox extends React.Component {
                     </div>
                 </div>
             }
+        }, {
+            title: '数据链接',
+            dataIndex: 'dbConfig.name',
+            key: 'dbConfig.name',
+            width: 100
         }, {
             title: '创建人',
             dataIndex: 'creatorName',
             key: 'creatorName',
-            width: 100
+            width: 100,
+            render: (text, record) => {
+                return <div className='datasource-name'>
+                    <div className={`datasource-type type-${record.type.key}`}></div>
+                    <div>
+                        <span>
+                            { (filterItem.name === 'creatorName' && filterLabel) ?
+                                (text.split(new RegExp(`(${filterLabel})`, 'i')).map((fragment, i) => {
+                                    return (
+                                        fragment.toLowerCase().replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') === filterLabel.toLowerCase() ?
+                                        <span key={i} style={{fontWeight: 'bold', color: 'red'}} className="highlight">{fragment}</span> :
+                                        fragment
+                                    )
+                                }
+                                )) : text
+                            }
+                        </span>
+                    </div>
+                </div>
+            }
         }, {
             title: '创建时间',
             dataIndex: 'createTime',
@@ -88,7 +168,7 @@ class ChooseDataSourceBox extends React.Component {
             render: (text, record) => {
                 return (
                     <span>
-                        { filterLabel ?
+                        { (filterItem.name === 'description' && filterLabel) ?
                             ((text || '').split(new RegExp(`(${filterLabel})`, 'i')).map((fragment, i) => {
                                 return (
                                     fragment.toLowerCase().replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') === filterLabel.toLowerCase() ?
@@ -106,19 +186,26 @@ class ChooseDataSourceBox extends React.Component {
         return (
             <Modal
                 className='choosedatasource-box'
-                title={
-                    <Row>
-                        <Col span={14}>选择数据源</Col>
-                        <Col span={8}><Search 
-                            placeholder="请输入关键字"
-                            onChange={e => {
-                                this.setState({
-                                    filterLabel: e.target.value
-                                });
-                            }}
-                        /></Col>
-                    </Row>
-                }
+                title={<Row><Col>选择数据源</Col><Col>
+                    <ListFilter
+                        modelName={null}
+                        model={{
+                            filterItems: dataSource.filterItems,
+                            filterItem, // 已选过滤字段
+                            filterLabel: stateFilterLabel,
+                        }}
+                        onChangeFilterItem={(filterItem) => {
+                            this.setState({
+                                filterItem
+                            });
+                        }}
+                        onChangeFilterValue={(filterLabel) => {
+                            this.setState({
+                                filterLabel
+                            });
+                        }}
+                    />
+                </Col></Row>}
                 visible={visibleChooseDataSourceBox}
                 onOk={this.okHandler}
                 onCancel={hideBox}
@@ -128,18 +215,10 @@ class ChooseDataSourceBox extends React.Component {
                 <Table
                     className='choosedatasource-table'
                     columns={columns}
-                    dataSource={dataSource.list.filter(l => {
-                        try{
-                            let regLabel = new RegExp('(' + filterLabel + '){1}', 'ig');
-                            return (l.name || '').search(regLabel) !== -1 || (l.description || '').search(regLabel) !== -1;
-                        }catch(e) {
-                            console.log(e);
-                            return true;
-                        }
-                    })}
+                    dataSource={this.onSearch(dataSource.list)}
                     size='small'
-                    scroll={{x: false, y: 471}}
-                    pagination={false}
+                    scroll={{ x: columns ? columns.length * 100 : tableBodyWidth, y: tableBodyHeight }}
+                    pagination={{ defaultPageSize: Math.floor(tableBodyHeight/tableRowHeight) || 10 }}
                     onRow={(record) => {
                         return {
                             onClick: () => {

+ 5 - 0
src/components/chart/chooseDataSourceBox.less

@@ -1,5 +1,10 @@
 .choosedatasource-box {
     width: 800px !important;
+    .ant-modal-header {
+        .list-filter {
+            float: right;
+        }
+    }
     .ant-modal-body {
         padding: 0;
         max-height: 50vh;

+ 2 - 2
src/components/chart/list.jsx

@@ -373,11 +373,11 @@ class ChartList extends React.Component {
                                     }}>
                                         <Icon type="area-chart" />创建图表
                                     </Button>
-                                    <ChooseDataSourceBox visibleChooseDataSourceBox={visibleChooseDataSourceBox} hideBox={() => {
+                                    {visibleChooseDataSourceBox && <ChooseDataSourceBox visibleChooseDataSourceBox={visibleChooseDataSourceBox} hideBox={() => {
                                         this.setState({
                                             visibleChooseDataSourceBox: false
                                         });
-                                    }}/>
+                                    }}/>}
                                 </Col>
                             </Col>
                         </Row>

+ 19 - 9
src/components/common/listFilter/index.jsx

@@ -15,7 +15,7 @@ class ListFilter extends React.Component {
     }
 
     generateFilterItem = () => {
-        const { modelName, model, dispatch } = this.props;
+        const { modelName, model, dispatch, onChangeFilterItem, onChangeFilterValue } = this.props;
         const { filterItems, filterItem } = model;
 
         return <Select 
@@ -23,7 +23,11 @@ class ListFilter extends React.Component {
             style={{ width: 120 }}
             onChange={value => {
                 let item = filterItems.find(i => i.name === value);
-                dispatch({ type: modelName + '/setFilterItem', item });
+                modelName && dispatch({ type: modelName + '/setFilterItem', item });
+                if(typeof onChangeFilterItem === 'function') {
+                    onChangeFilterItem(item)
+                    onChangeFilterValue('');
+                }
             }}
         >
             {filterItems.map(t => <Option key={t.name}  value={t.name}>{t.label}</Option>)}
@@ -31,10 +35,11 @@ class ListFilter extends React.Component {
     }
 
     generateFilterValue = () => {
-        const { modelName, model, dispatch } = this.props;
+        const { modelName, model, dispatch, onChangeFilterValue } = this.props;
         const { fetching } = this.state;
-        const { filterItem } = model;
+        const { filterItem, filterLabel } = model;
         const { type, name } = filterItem;
+
         if(type === 'date') {
             return <RangePicker  
                 ranges={{
@@ -49,7 +54,8 @@ class ListFilter extends React.Component {
                 onChange={e => {
                     //清空时间时
                     if(e.length === 0){
-                        dispatch({ type: modelName + '/setFilterLabel', label: '' });
+                        modelName && dispatch({ type: modelName + '/setFilterLabel', label: '' });
+                        typeof onChangeFilterValue === 'function' && onChangeFilterValue('')
                     }
                 }}
                 onOk={e => {
@@ -57,7 +63,9 @@ class ListFilter extends React.Component {
                     let start = e[0]
                     let end = e[1]
                     let time = start._d.getTime() + "#" + end._d.getTime()
-                    dispatch({ type: modelName + '/setFilterLabel', label: time });
+                    modelName && dispatch({ type: modelName + '/setFilterLabel', label: time });
+                    typeof onChangeFilterValue === 'function' && onChangeFilterValue(time)
+
                 }}
             >
             </RangePicker> 
@@ -65,9 +73,10 @@ class ListFilter extends React.Component {
             return <Search
                 style={{ width: 150 }}
                 placeholder="请输入关键字"
-                value={model.filterLabel}
+                value={filterLabel}
                 onChange={e => {
-                    dispatch({ type: modelName + '/setFilterLabel', label: e.target.value });
+                    modelName && dispatch({ type: modelName + '/setFilterLabel', label: e.target.value });
+                    typeof onChangeFilterValue === 'function' && onChangeFilterValue(e.target.value)
                 }}
             />
         }else if(type === 'enum') {
@@ -77,7 +86,8 @@ class ListFilter extends React.Component {
                 value={model.filterLabel || null}
                 loading={fetching}
                 onChange={(value) => {
-                    dispatch({ type: modelName + '/setFilterLabel', label: value ? value : '' });
+                    modelName && dispatch({ type: modelName + '/setFilterLabel', label: value ? value : '' });
+                    typeof onChangeFilterValue === 'function' && onChangeFilterValue(value)
                 }}
                 onFocus={() => {
                     this.fetchData(filterItem)

+ 5 - 53
src/components/dashboard/list.jsx

@@ -1,18 +1,16 @@
 import React from 'react'
-import { Layout, Button, Icon, Input, Table, Menu, Dropdown, Card, Col, Row, Select, DatePicker } from 'antd'
+import { Layout, Button, Icon, Table, Menu, Dropdown, Card, Col, Row, Select, DatePicker } from 'antd'
 import { connect } from 'dva'
-import moment from 'moment'
 import TransferBox from '../common/selectUserBox/selectUserBox';
 import AccessObjectBox from '../common/accessObjectBox/accessObjectBox'
 import { dateFormat } from '../../utils/baseUtils'
 import DeleteBox from '../common/deleteBox/deleteBox'
 import ShareBox from './shareBox'
 import CopyBox from './copyBox'
+import ListFilter from '../common/listFilter/index'
 import './list.less'
 const { Content } = Layout
-const { Search } = Input
 const { Option } = Select
-const { RangePicker } = DatePicker
 
 
 class DashboardList extends React.Component {
@@ -92,7 +90,7 @@ class DashboardList extends React.Component {
 
     onSearch(list, dashboard) {
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
-        let filterLabel = (dashboard.filterLabel || '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
+        let filterLabel = dashboard.filterLabel ? (dashboard.filterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
         let filterItem = dashboard.filterItem;
         let filterReg = new RegExp('(' + filterLabel + '){1}', 'ig');
         return list.map(l => {
@@ -165,7 +163,7 @@ class DashboardList extends React.Component {
         const { menuTree, menuSelectedKeys, filterItem } = dashboard;
 
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
-        let filterLabel = dashboard.filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
+        let filterLabel = dashboard.filterLabel ? (dashboard.filterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
 
         const moreOperatingMenu = (
             <Menu className='menu-operation'>
@@ -312,54 +310,8 @@ class DashboardList extends React.Component {
                             <Col style={{ display: 'flex' }}>
                             </Col>
                             <Col className='search'>
-                                <Col style={{ padding: '0 1px', margin: '0 -5px' }}>
-                                    <Select 
-                                        value={dashboard.filterItem.name}
-                                        style={{ width: 120 }}
-                                        onChange={value => {
-                                            let item = dashboard.filterItems.find(i => i.name === value);
-                                            dispatch({ type: 'dashboard/setFilterItem', item });
-                                        }}
-                                    >
-                                        { this.generateFilterItems() }
-                                    </Select>
-                                </Col>
                                 <Col style={{ padding: '0 5px' }}>
-                                    {dashboard.filterItem.type === 'date' ? 
-                                        <RangePicker  
-                                            ranges={{
-                                                '今天': [moment().startOf('day'), moment().endOf('day')], 
-                                                '昨天': [moment().startOf('day').add(-1,'days'), moment().endOf('day')],
-                                                '近七天': [moment().startOf('day'),moment().endOf('day').add(6,'days')],
-                                                '本月': [moment().startOf('month'), moment().endOf('month')],
-                                                '本年': [moment().startOf('year'), moment().endOf('year')] 
-                                            }}
-                                            showTime={{ format: 'HH:mm' }}
-                                            format="YYYY-MM-DD HH:mm:ss"
-                                            onChange={e => {
-                                                //清空时间时
-                                                if(e.length === 0){
-                                                    dispatch({ type: 'dashboard/setFilterLabel', label: '' });
-                                                }
-                                            }}
-                                            onOk={e => {
-                                                //解析时间格式
-                                                let start = e[0]
-                                                let end = e[1]
-                                                let time = start._d.getTime() + "#" + end._d.getTime()
-                                                dispatch({ type: 'dashboard/setFilterLabel', label: time });
-                                            }}
-                                        >
-                                        </RangePicker> 
-                                        : 
-                                        <Search
-                                            value={dashboard.filterLabel}
-                                            placeholder="请输入关键字"
-                                            onChange={e => {
-                                                dispatch({ type: 'dashboard/setFilterLabel', label: e.target.value });
-                                            }}
-                                        />
-                                    }
+                                    <ListFilter modelName='dashboard' model={dashboard}/>
                                 </Col>
                                 <Col >
                                     <Button style={{ marginRight: '8px' }} onClick={() => {

+ 64 - 85
src/components/dashboardDesigner/chooseChartBox.jsx

@@ -1,12 +1,11 @@
 import React from 'react'
 import '../../models/dashboardDesigner'
-import { Modal, Radio, Row, Col, Table, Input, Select, message, DatePicker } from 'antd'
+import { Modal, Radio, Row, Col, Table, message } from 'antd'
 import { connect } from 'dva'
 import moment from 'moment'
 import 'braft-editor/dist/braft.css'
+import ListFilter from '../common/listFilter/index'
 import './chooseChartBox.less'
-const { Search } = Input
-const { RangePicker } = DatePicker
 
 class ChooseChartBox extends React.Component {
 
@@ -14,6 +13,7 @@ class ChooseChartBox extends React.Component {
         super(props);
         this.state = {
             filterLabel: '',
+            filterItem: { name: 'name', label: '图表名称', type: 'string' },
             selectedRecord: -1,
             screenWidth: document.documentElement.clientWidth || document.body.clientWidth,
             screenHeight: document.documentElement.clientHeight || document.body.clientHeight
@@ -54,20 +54,48 @@ class ChooseChartBox extends React.Component {
         }
     }
 
-    generateFilterItems = () => {
-        const { filterItems } = this.props.chart;
-        return filterItems.map(t => <Select.Option key={t.name}  value={t.name}>{t.label}</Select.Option>);
+    onSearch = (list) => {
+        const { filterItem, filterLabel: stateFilterLabel } = this.state;
+        const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
+        let filterLabel = stateFilterLabel ? (stateFilterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
+        let filterReg = new RegExp('('+ filterLabel +'){1}', 'ig');
+
+        return list.map(l => {
+            let o = Object.assign({}, l);
+
+            if(filterItem.type === 'date') {
+                if(filterLabel===""){
+                    return o;
+                }else if(filterLabel.indexOf('#')>-1){
+                    let start = filterLabel.split('#')[0]
+                    let end = filterLabel.split('#')[1]
+                    let nowTime = o[filterItem.name].getTime();
+                    if(nowTime>=start && nowTime<=end){
+                        return o;
+                    }
+                    return null 
+                }else{
+                    return null 
+                }
+            }else {
+                let arr = filterItem.name.split('.');
+                let v = o;
+                for(let i = 0; i < arr.length; i++) {
+                    v = v[arr[i]]
+                }
+                return ((v + '').search(filterReg) > -1) ? o : null
+            }
+        }).filter(a => a!==null);
     }
 
     render() {
-        const { main, visibleBox, hideBox, dashboardDesigner, chart, dispatch } = this.props;
-        const { selectedRecord, screenWidth, screenHeight } = this.state;
+        const { visibleBox, hideBox, dashboardDesigner, chart } = this.props;
+        const { selectedRecord, screenWidth, screenHeight, filterItem, filterLabel: stateFilterLabel } = this.state;
         const tableBodyWidth = screenWidth * 0.8 - 10 - 10 - 18;
         const tableBodyHeight = screenHeight * 0.8 - 65 - 53 - 38 - 130;
         const tableRowHeight = 38;
-        const { filterItem } = dashboardDesigner;
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
-        let filterLabel = this.state.filterLabel.replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1'); // 添加转义符号
+        let filterLabel = stateFilterLabel ? (stateFilterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
         const columns = [{
             title: '选择',
             key: 'selected',
@@ -102,6 +130,11 @@ class ChooseChartBox extends React.Component {
                     </div>
                 </div>
             }
+        }, {
+            title: '数据源',
+            dataIndex: 'dataSourceName',
+            key: 'dataSourceName',
+            width: 100,
         }, {
             title: '创建人',
             dataIndex: 'creatorName',
@@ -164,60 +197,25 @@ class ChooseChartBox extends React.Component {
                             <Col >选择图表</Col>
                         </Row>
                         <Row type='flex' justify='end'>
-                            <Col style={{ padding: '0 1px', margin: '0 -5px' }}>
-                                <Select 
-                                    value={filterItem.name}
-                                    style={{ width: 120 }}
-                                    onChange={value => {
-                                        let item = chart.filterItems.find(i => i.name === value);
-                                        dispatch({ type: 'dashboardDesigner/setFilterItem', item });
-                                    }}
-                                >
-                                    {this.generateFilterItems()}
-                                </Select>
-                            </Col>
                             <Col style={{ padding: '0 5px' }}>
-                                {filterItem.type === 'date' ? 
-                                    <RangePicker  
-                                        ranges={{
-                                            '今天': [moment().startOf('day'), moment().endOf('day')], 
-                                            '昨天': [moment().startOf('day').add(-1,'days'), moment().endOf('day')],
-                                            '近七天': [moment().startOf('day'),moment().endOf('day').add(6,'days')],
-                                            '本月': [moment().startOf('month'), moment().endOf('month')],
-                                            '本年': [moment().startOf('year'), moment().endOf('year')] 
-                                        }}
-                                        showTime={{ format: 'HH:mm' }}
-                                        format="YYYY-MM-DD HH:mm:ss"
-                                        onChange={e => {
-                                            //清空时间时
-                                            if(e.length === 0){
-                                                this.setState({
-                                                    filterLabel: ''
-                                                });
-                                            }
-                                        }}
-                                        onOk={e => {
-                                            //解析时间格式
-                                            let start = e[0]
-                                            let end = e[1]
-                                            let time = start._d.getTime() + "#" + end._d.getTime()
-                                            this.setState({
-                                                filterLabel: time
-                                            });
-                                        }}
-                                    >
-                                    </RangePicker> 
-                                    : 
-                                    <Search
-                                        placeholder="请输入关键字"
-                                        value={this.state.filterLabel}
-                                        onChange={e => {
-                                            this.setState({
-                                                filterLabel: e.target.value
-                                            });
-                                        }}
-                                    />
-                                }
+                                <ListFilter
+                                    modelName={null}
+                                    model={{
+                                        filterItems: chart.filterItems,
+                                        filterItem,
+                                        filterLabel: stateFilterLabel,
+                                    }}
+                                    onChangeFilterItem={(filterItem) => {
+                                        this.setState({
+                                            filterItem
+                                        });
+                                    }}
+                                    onChangeFilterValue={(filterLabel) => {
+                                        this.setState({
+                                            filterLabel
+                                        });
+                                    }}
+                                />
                             </Col>
                         </Row>
                     </Row>
@@ -234,26 +232,7 @@ class ChooseChartBox extends React.Component {
                         ...c,
                         width: 100
                     }))}
-                    dataSource={chart.list.map((l, i) => {
-                        let o = Object.assign({}, l);
-                        if(filterItem.type === 'date') {
-                            if(filterLabel===""){
-                                return { ...o, key: i };
-                            }else if(filterLabel.indexOf('#')>-1){
-                                let start = filterLabel.split('#')[0]
-                                let end = filterLabel.split('#')[1]
-                                let nowTime = new Date(o[filterItem.name]).getTime();
-                                if(nowTime>=start && nowTime<=end){
-                                    return { ...o, key: i};
-                                }
-                                return null 
-                            }else{
-                                return null 
-                            }
-                        }else {
-                            return ((o[filterItem.name] + '').search(new RegExp('(' + filterLabel + '){1}', 'ig')) > -1) ? { ...o, key: i } : null
-                        }
-                    }).filter(a => a!==null && a.creatorCode === main.currentUser.code)}
+                    dataSource={this.onSearch(chart.list)}
                     size='small'
                     scroll={{ x: columns ? columns.length * 100 : tableBodyWidth, y: tableBodyHeight }}
                     pagination={{ defaultPageSize: Math.floor(tableBodyHeight/tableRowHeight) || 10 }}
@@ -279,8 +258,8 @@ class ChooseChartBox extends React.Component {
 
 
 
-function mapStateToProps({ present: { main, dashboardDesigner, chart } }) {
-    return { main, dashboardDesigner, chart };
+function mapStateToProps({ present: { dashboardDesigner, chart } }) {
+    return { dashboardDesigner, chart };
 }
 
 export default connect(mapStateToProps)(ChooseChartBox)