提交 30c14344 authored 作者: 钟是志's avatar 钟是志

优化代码

上级 128051c9
...@@ -115,6 +115,7 @@ export default class ImportUtil extends React.PureComponent { ...@@ -115,6 +115,7 @@ export default class ImportUtil extends React.PureComponent {
current: 3, current: 3,
isShow: true, isShow: true,
visible: false, visible: false,
openProgress: false,
}); });
} }
}; };
......
import React, { useEffect, useState, useRef } from 'react'; import React, { useEffect, useState, useRef, useMemo } from 'react';
import { Progress, message } from 'antd'; import { Progress, message } from 'antd';
import styles from './ImportUtil.less'; import styles from './ImportUtil.less';
import { connect } from 'dva'; import { connect } from 'dva';
function ProgressDiy(props) { function ProgressDiy(props) {
const { fileCacheKey, dispatch, changeOpenProgress = () => {} } = props; const {
fileCacheKey,
dispatch,
changeOpenProgress = () => {
},
} = props;
const interv = useRef(); const interv = useRef();
const [speedData, setData] = useState({ ...props }); const [speedData, setData] = useState({ ...props });
useEffect(() => { useEffect(() => {
...@@ -15,17 +20,34 @@ function ProgressDiy(props) { ...@@ -15,17 +20,34 @@ function ProgressDiy(props) {
cacheKey: fileCacheKey, cacheKey: fileCacheKey,
}, },
callback: res => { callback: res => {
console.log(res);
setData(res); setData(res);
if (res.finished) { if (res.finished) {
debugger;
clearInterval(interv.current); clearInterval(interv.current);
message.success('导入完成'); // message.success('导入完成');
// changeOpenProgress(false); // 导入成功 changeOpenProgress(false); // 导入成功
} }
}, },
}); });
}, 1000); }, 1000);
}, []); }, []);
const percent = useMemo(() => {
const {
success,
total,
fail,
} = speedData;
const r = success + fail;
if (total === 0) {
return 0;
} else if (r > total) {
return 100;
}
return Math.floor(r / total * 100);
}, [speedData.success]);
console.log(percent);
return ( return (
<div className={styles.juzhongSpin}> <div className={styles.juzhongSpin}>
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
...@@ -35,20 +57,21 @@ function ProgressDiy(props) { ...@@ -35,20 +57,21 @@ function ProgressDiy(props) {
'0%': '#108ee9', '0%': '#108ee9',
'100%': '#87d068', '100%': '#87d068',
}} }}
percent={ percent={percent}
speedData.finished ? 100 : (speedData.success + speedData.fail) / speedData.total
}
status={speedData.finished ? 'success ' : 'active'} status={speedData.finished ? 'success ' : 'active'}
format={percent => `${speedData.success + speedData.fail}/${speedData.total}`} // format={percent => `${speedData.success + speedData.fail}/${speedData.total}`}
/> />
<div className={styles.textCenter}> <div className={styles.textCenter}>
正在处理导入数据: 共计 {speedData.total} 已处理{speedData.success + speedData.fail}. 正在处理导入数据: 共计 {speedData.total} 已处理{speedData.success + speedData.fail}.
</div> </div>
</div> </div>
</div> </div>
); );
} }
export default connect(({ DataObj, loading }) => ({ export default connect(({
DataObj,
loading
}) => ({
DataObj, DataObj,
}))(ProgressDiy); }))(ProgressDiy);
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论