我在获取一组数据 数据里面包含的是我即将要拷贝的数据
我遍历他们 返回进度的时候 很卡 但是 mobx数据已经修改了 但是页面就是不显示 除非重新进入的时候才会刷新
回调方法
const copyStatusChange = (index) => {
setCopyLoading(true);
message.loading({
content: "文件拷贝中...",
duration: 0,
key: currentTask.id,
});
console.log(index);
setSuccessCopyStatus(index);
if (index === 100) {
message.success({
content: "拷贝成功...",
key: currentTask.id,
});
setCopyLoading(false);
changeSetImageSelectType("sceneSort");
}
};
复制代码
执行方法
export const copyImagePromise = (infos, copyStatusChange) => {
return new Promise((resolve, reject) => {
let progress = 0;
for (let i = 0; i < infos.length; i++) {
progress = parseInt(((i / (infos.length - 1)) * 100).toString());
const fileInfraredName = infos[i].infrared_name;
const fileLightName = infos[i].light_name;
const outputInfraredImagePath = path.join(outputPath, fileInfraredName);
const outputLightImagePath = path.join(outputPath, fileLightName);
try {
fs.copyFileSync(infos[i].createLightPath, outputLightImagePath);
logPath && logPath(outputLightImagePath);
fs.copyFileSync(infos[i].createInfraredPath, outputInfraredImagePath);
logPath && logPath(outputInfraredImagePath);
} catch (err) {
console.log(fileInfraredName);
message.error(`${fileInfraredName}未找到,请重新选择文件`);
console.error(infos[i]);
}
copyStatusChange(progress); //将进度返回
}
progress === 100 && resolve(progress);
});
};
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END