// 图片资源预加载器
const imgPreloader = url => {
    return new Promise((resolve, reject) => {
        let image = new Image();
        image.src = url;
        image.onload = () => {
            resolve();
        };
        image.onerror = () => {
            reject();
        };
    });
};
const Preloader = ({ name, imgs, callback }) => {
    let promiseArr = [];
    let num = 0
    imgs.forEach(element => {
        promiseArr.push(imgPreloader(element).then((res => {
            num++
            let progress = parseInt((num / imgs.length) * 100)
            callback(progress)
        })));
    });

    console.log(name, promiseArr.length, '张');
    return Promise.all(promiseArr);
};



export default Preloader