Browse Source

scrollTo不兼容报错问题

zhuth 6 years ago
parent
commit
cd48483d28

+ 8 - 7
src/components/chart/list.jsx

@@ -55,7 +55,8 @@ class ChartList extends React.Component {
         this.setState({
             page: chart.page || 1
         });
-        this.bodyRef.current.parentNode.scrollTo(0, chart.listScrollTop)
+        let parent = this.bodyRef.current.parentNode;
+        parent.scrollTo && parent.scrollTo(0, chart.listScrollTop)
         window.addEventListener('resize', this.setBodyWidth);
     }
 
@@ -201,7 +202,7 @@ class ChartList extends React.Component {
                             this.setState({
                                 page: 1
                             }, () => {
-                                this.bodyRef.current.parentNode.scrollTo(0, 0)
+                                this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                             })
                         }}>{g.label}</span>
                         <GroupSelector
@@ -221,7 +222,7 @@ class ChartList extends React.Component {
                                 this.setState({
                                     page: 1
                                 }, () => {
-                                    this.bodyRef.current.parentNode.scrollTo(0, 0)
+                                    this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                                 })
                             }}
                         >
@@ -391,7 +392,7 @@ class ChartList extends React.Component {
                         // this.setState({
                         //     page: 1
                         // }, () => {
-                        //     this.bodyRef.current.parentNode.scrollTo(0, 0)
+                        //     this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                         // })
                     }}
                 >
@@ -405,7 +406,7 @@ class ChartList extends React.Component {
                     // this.setState({
                     //     page: 1
                     // }, () => {
-                    //     this.bodyRef.current.parentNode.scrollTo(0, 0)
+                    //     this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                     // })
                 }}>{selectedRecord.groupCode === t.code ? <span className='current' style={{ fontWeight: 'bold' }}>{t.label}</span> : t.label}</Menu.Item>
             }
@@ -436,7 +437,7 @@ class ChartList extends React.Component {
         this.setState({
             page: pageNumber
         }, () => {
-            this.bodyRef.current.parentNode.scrollTo(0, 0)
+            this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
         })
     }
 
@@ -458,7 +459,7 @@ class ChartList extends React.Component {
                                         noGroup: e.target.checked,
                                         page: 1
                                     }, () => {
-                                        this.bodyRef.current.parentNode.scrollTo(0, 0)
+                                        this.bodyRef.current.parentNode.scrollTo && this.bodyRef.current.parentNode.scrollTo(0, 0)
                                     })
                                 }}><span className="nogroup">未分组</span></Checkbox>
                                 { this.generateGroupTags() }

+ 2 - 1
src/components/dashboard/list.jsx

@@ -42,7 +42,8 @@ class DashboardList extends React.Component {
         }else {
             // dispatch({ type: 'dashboard/fetchList' });
         }
-        document.getElementsByClassName('ant-table-body')[0].scrollTo(0, dashboard.listScrollTop);
+        let tableBody = document.getElementsByClassName('ant-table-body')[0];
+        tableBody.scrollTo && tableBody.scrollTo(0, dashboard.listScrollTop);
     }
 
     componentWillUnmount() {

+ 1 - 1
src/components/dashboardDesigner/chooseChartBox.jsx

@@ -65,7 +65,7 @@ class ChooseChartBox extends React.Component {
             setTimeout(() => {
                 // 滚动到最底部
                 let viewScrollContent = document.querySelector('.viewlayout');
-                viewScrollContent.scrollTo(0, viewScrollContent.scrollHeight - viewScrollContent.clientHeight);
+                viewScrollContent.scrollTo && viewScrollContent.scrollTo(0, viewScrollContent.scrollHeight - viewScrollContent.clientHeight);
             }, 500);
         }else {
             message.warning('请选择需要添加的图表');

+ 1 - 1
src/components/dashboardDesigner/configSider.jsx

@@ -65,7 +65,7 @@ class ConfigSider extends React.Component {
                 setTimeout(() => {
                     // 滚动到最底部
                     let viewScrollContent = document.querySelector('.viewlayout');
-                    viewScrollContent.scrollTo(0, viewScrollContent.scrollHeight - viewScrollContent.clientHeight);
+                    viewScrollContent.scrollTo && viewScrollContent.scrollTo(0, viewScrollContent.scrollHeight - viewScrollContent.clientHeight);
                 }, 500);
             }}>
                 <Icon type='book'/>

+ 2 - 1
src/components/dataSource/list.jsx

@@ -38,7 +38,8 @@ class DataSource extends React.Component {
         this.setScrollTableHeight();
         dispatch({ type: 'dataSource/fetchList' });
         dispatch({ type: 'dataSource/remoteGroupList' });
-        document.getElementsByClassName('ant-table-body')[0].scrollTo(0, dataSource.listScrollTop);
+        let tableBody = document.getElementsByClassName('ant-table-body')[0];
+        tableBody.scrollTo && tableBody.scrollTo(0, dataSource.listScrollTop);
     }
     componentWillUnmount() {
         const { dispatch } = this.props;