getPercent(url){
let xhr = new XMLHttpRequest();
// xhr.abort()取消请求
xhr.open('GET', url, true);
xhr.onprogress = function (e) {
let percent = Math.floor( e.loaded / e.total * 100); // 下载进度
if(percent==100){
window.location.href = `ngie://${that.directSeedingId}`;
}
console.log(percent, '进度');
};
xhr.send();
xhr.responseType = "arraybuffer";
xhr.onreadystatechange = event => {
if(xhr.readyState == 4){
if (xhr.status == 200){
const fileName = 'metaWorks.exe';
let blob = new Blob([xhr.response], { type: "exe", application: "application/octet-stream" }); // 文件类型
const downLoadLink = document.createElement('a');
downLoadLink.download = fileName;
downLoadLink.href = URL.createObjectURL(blob);
downLoadLink.click();
}
}
}
}
},
网友评论