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

优化代码

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