Browse Source

数据源、图表列表未分组记录到model

zhuth 6 years ago
parent
commit
12e053b9d4

+ 6 - 12
src/components/chart/list.jsx

@@ -35,7 +35,6 @@ class ChartList extends React.Component {
             visibleDeleteBox: false,
             visibleGroupManageMentBox: false, // 显示分组管理组件
             visibleDataPreviewBox: false,
-            noGroup: false, // 显示未分组数据
         }
         this.bodyRef = React.createRef();
     }
@@ -78,8 +77,7 @@ class ChartList extends React.Component {
 
     onFilterAndGroup = cardList => {
         const { chart } = this.props;
-        const { noGroup } = this.state;
-        const { filterItem, currentGroup } = chart;
+        const { filterItem, currentGroup, noGroup } = chart;
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
         let filterLabel = chart.filterLabel ? (chart.filterLabel + '').replace(new RegExp('(\\\\)', 'g'), '\\$1').replace(reg, '\\$1') : ''; // 添加转义符号
         let filterReg = new RegExp('(' + filterLabel + '){1}', 'ig');
@@ -148,8 +146,7 @@ class ChartList extends React.Component {
 
     generateGroupTags = () => {
         const { chart, dispatch } = this.props;
-        const { noGroup } = this.state;
-        const { currentGroup } = chart;
+        const { currentGroup, noGroup } = chart;
         const pGroups = currentGroup ? [{ code: '-1', label: '全部分组' }].concat(this.getParens(currentGroup)) : [{ code: '-1', label: '全部分组' }];
         return <Breadcrumb className={`group${noGroup ? ' nogroup' : ''}`} separator=">">
             { pGroups.map(g => (
@@ -364,8 +361,8 @@ class ChartList extends React.Component {
 
     render() {
         const { dispatch, chart } = this.props;
-        const { listLoading } = chart;
-        const { visibleChooseDataSourceBox, visibleDistributeBox, visibleGroupManageMentBox, visibleTransferBox, visibleDeleteBox, selectedRecord, noGroup } = this.state;
+        const { listLoading, noGroup } = chart;
+        const { visibleChooseDataSourceBox, visibleDistributeBox, visibleGroupManageMentBox, visibleTransferBox, visibleDeleteBox, selectedRecord } = this.state;
         let viewList =  this.onFilter();
         // let viewList = this.onPage(reduceList);
         // let viewList = reduceList;
@@ -377,11 +374,8 @@ class ChartList extends React.Component {
                         <Row className='tools' type='flex' justify='space-between'>
                             <Col className="groups" style={{ display: 'flex', width: 'calc(100% - 324px)', overflow: 'hidden' }}>
                                 <Checkbox style={{ marginTop: '4px' }} checked={noGroup} onChange={(e) => {
-                                    this.setState({
-                                        noGroup: e.target.checked,
-                                    }, () => {
-                                        this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
-                                    })
+                                    dispatch({ type: 'chart/setField', name: 'noGroup', value: e.target.checked });
+                                    this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                                 }}><span className="nogroup">未分组</span></Checkbox>
                                 { this.generateGroupTags() }
                             </Col>

+ 5 - 8
src/components/dataSource/list.jsx

@@ -27,7 +27,6 @@ class DataSource extends React.Component {
             visibleCopyBox: false,
             visibleDataPreviewBox: false, // 显示数据预览
             visibleGroupManageMentBox: false, // 显示分组管理
-            noGroup: false, // 显示未分组数据
         }
     };
     hideTransferBox = () => {
@@ -64,8 +63,7 @@ class DataSource extends React.Component {
 
     onGroup() {
         const { dataSource } = this.props;
-        const { noGroup } = this.state;
-        const { currentGroup, list } = dataSource;
+        const { currentGroup, list, noGroup } = dataSource;
         
         if(noGroup) {
             return list.filter(l => l.groupCode === '-1' );
@@ -142,8 +140,7 @@ class DataSource extends React.Component {
 
     generateGroupTags = () => {
         const { dataSource, dispatch } = this.props;
-        const { noGroup } = this.state;
-        const { currentGroup } = dataSource;
+        const { currentGroup, noGroup } = dataSource;
         const pGroups = (currentGroup) ? [{ code: '-1', label: '全部分组' }].concat(this.getParents(currentGroup)) : [{ code: '-1', label: '全部分组' }];
         return <Breadcrumb className={`group${noGroup ? ' nogroup' : ''}`} separator=">">
             { pGroups.map(g => (
@@ -232,8 +229,8 @@ class DataSource extends React.Component {
 
     render() {
         const { main, dataSource, dispatch } = this.props;
-        const { listLoading } = dataSource;
-        const { selectedRecord, visibleTransferBox, visibleGroupManageMentBox, visibleCopyBox, visibleDeleteBox, visibleDataPreviewBox, noGroup } = this.state;
+        const { listLoading, noGroup } = dataSource;
+        const { selectedRecord, visibleTransferBox, visibleGroupManageMentBox, visibleCopyBox, visibleDeleteBox, visibleDataPreviewBox } = this.state;
         const { currentUser } = main;
         const treeData = arrayToTree(dataSource.groupList, '-1', 'code', 'pcode', 'children');
         const reg = new RegExp('([+ \\- & | ! ( ) { } \\[ \\] ^ \" ~ * ? : ( ) \/])', 'g'); // 需要转义的字符
@@ -389,7 +386,7 @@ class DataSource extends React.Component {
                         <Row className='datasource-tools' type='flex' justify='space-between'>
                             <Col className="groups" style={{ display: 'flex', width: 'calc(100% - 324px)', overflow: 'hidden' }}>
                                 <Checkbox style={{ marginTop: '4px' }} checked={noGroup} onChange={(e) => {
-                                    this.setState({noGroup: e.target.checked})
+                                    dispatch({ type: 'dataSource/setField', name: 'noGroup', value: e.target.checked });
                                 }}>未分组</Checkbox>
                                 { this.generateGroupTags() }
                             </Col>

+ 1 - 0
src/models/chart.js

@@ -13,6 +13,7 @@ export default {
             typeLabel: 'name',
             groupList: [],
             currentGroup: null,
+            noGroup: false,
             filterItems: [ // 可选过滤字段
                 { name: 'name', label: '名称', type: 'string' },
                 // { name: 'description', label: '备注', type: 'string' },

+ 1 - 0
src/models/dataSource.js

@@ -12,6 +12,7 @@ export default {
             invalidSQL: false,
             groupList: [],
             currentGroup: null,
+            noGroup: false,
             filterItems: [ // 可选过滤字段
                 { name: 'name', label: '名称', type: 'string' },
                 { name: 'creatorName', label: '创建人', type: 'string' },