import { fileLinkToStreamDownload , urlFile , throttle} from '@/utils/downFlie'
let filePath = this.appendPath(data.lcaPath)
console.log( filePath, 3333333 );
let fileName = urlFile(filePath, 1);
let fileExtension = urlFile(filePath, 2);
fileLinkToStreamDownload(filePath,fileName,fileExtension);
export function fileLinkToStreamDownload(url, fileName, type) {
let reg = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~\/])+$/;
if (!reg.test(url)) {
throw new Error("传入参数不合法,不是标准的文件链接");
} else {
let xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.setRequestHeader('Content-Type', `application/${type}`);
xhr.responseType = "blob";
xhr.onload = function () {
if (this.status == 200) {
console.log(this)
var blob = this.response;
const blobUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = blobUrl;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(blobUrl);
}
}
xhr.send();
}
}
export function urlFile(url, type) {
let filename = url.substring(url.lastIndexOf('/') + 1)
switch (type){
case 1: return filename; break;
case 2: return filename.substring(filename.lastIndexOf(".") + 1); break;
case 3: return filename.substring(0, filename.lastIndexOf(".")); break;
case 4: return url.substring(0, url.lastIndexOf('/') + 1)
}
}