btnUpdate(name, i, item) {
i.videoUrl = process.env.VUE_APP_BASE_API + "/common/download/resource?resource=/profile" + i.videoUrl; // 拼接地址,后台给全路径无需拼接
this.getBlob(i.videoUrl).then(blob => {
var suffix = i.videoUrl.substring(i.videoUrl.lastIndexOf("."), i.videoUrl.length); // 切除后台给的文件名前缀
const filename = item ? `${name}-${item.position}-${item.code}孔-${i.startTime}${suffix}` : name + suffix; // 自定义文件名称
this.DownloadItem(blob, filename); // 传入方法
});
}
getBlob(url) {
return new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
},
DownloadItem(blob,fileName){
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
},