|
|
@@ -10,8 +10,8 @@ class DataPreview extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
- boxW: 1, // 0 ~ 1
|
|
|
- boxH: 1, // 0 ~ 1
|
|
|
+ boxW: 0.8, // 0 ~ 1
|
|
|
+ boxH: 0.8, // 0 ~ 1
|
|
|
columnWidth: 200,
|
|
|
tableHeaderHeight: 60,
|
|
|
screenWidth: document.documentElement.clientWidth || document.body.clientWidth,
|
|
|
@@ -20,9 +20,8 @@ class DataPreview extends React.Component {
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
- const { fetchFunction } = this.props;
|
|
|
+ this.onWindowResize();
|
|
|
window.addEventListener('resize', this.onWindowResize);
|
|
|
- typeof fetchFunction === 'function' && fetchFunction();
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
@@ -32,26 +31,25 @@ class DataPreview extends React.Component {
|
|
|
}
|
|
|
|
|
|
onWindowResize = () => {
|
|
|
- const boxEl = document.getElementsByClassName('datapreview')[0];
|
|
|
- const tableHeaderEl = boxEl.getElementsByTagName('thead')[0];
|
|
|
+ const { fetchFunction } = this.props;
|
|
|
+ let tableBodyHeight = document.body.clientHeight * this.state.boxH - 64 - 24 * 2 - 40 - 40 - 2;
|
|
|
|
|
|
- this.setState({
|
|
|
- screenWidth: document.documentElement.clientWidth || document.body.clientWidth, // 屏幕宽
|
|
|
- screenHeight: document.documentElement.clientHeight || document.body.clientHeight, // 屏幕高
|
|
|
- tableHeaderHeight: tableHeaderEl.offsetHeight + 2, // 表头高度(含边框)
|
|
|
- });
|
|
|
+ if(tableBodyHeight !== this.state.tableBodyHeight) {
|
|
|
+ this.setState({
|
|
|
+ tableBodyHeight
|
|
|
+ }, () => {
|
|
|
+ typeof fetchFunction === 'function' && fetchFunction(1, Math.ceil(tableBodyHeight / 38));
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
const { title, modalClassName, fetchFunction, dataList, visibleBox, hideBox, dispatch } = this.props;
|
|
|
const { loading, columns, dataSource, pageSize, total } = dataList;
|
|
|
- const { screenWidth, screenHeight, boxW, boxH, columnWidth, tableHeaderHeight } = this.state;
|
|
|
- const tableBodyWidth = screenWidth * boxW - 10 - 10 - 18;
|
|
|
- const tableBodyHeight = screenHeight * boxH - 40 - 40 - tableHeaderHeight - 2;
|
|
|
+ const { boxW, boxH, columnWidth, tableBodyHeight } = this.state;
|
|
|
|
|
|
return <Modal
|
|
|
className={`datapreview ${modalClassName}`}
|
|
|
- style={{ top: `${(1 - boxH) * 0.5 * 100}%` }}
|
|
|
title={title}
|
|
|
width={`${100 * boxW}%`}
|
|
|
height={`${100 * boxH}%`}
|
|
|
@@ -110,7 +108,7 @@ class DataPreview extends React.Component {
|
|
|
typeof fetchFunction === 'function' && fetchFunction(page, pageSize);
|
|
|
}
|
|
|
}}
|
|
|
- scroll={{ x: columns ? columns.length * columnWidth : tableBodyWidth, y: tableBodyHeight }}
|
|
|
+ scroll={{ x: columns ? columns.length * columnWidth : false, y: tableBodyHeight }}
|
|
|
/>
|
|
|
</Modal>
|
|
|
}
|