import request from "@/utils/request";
import { Loading } from 'element-ui';
export function GetFile(path,fileName){
    const loading = Loading.service({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
    });
    request({
        method:"get",
        url:path,
        responseType: "blob"
    }).then(res=>{
        download(res,fileName);
        loading.close();
    }).catch((error)=>{console.log(error)})
}

function download(data,fileName){
    if(!data) return;
    console.log(fileName);
    let url=window.URL.createObjectURL(new Blob([data]));
    let link = document.createElement("a");
    link.style.display = "none";
    link.href=url;
    link.setAttribute('download',fileName);
    document.body.appendChild(link);
    link.click();
    link.remove();
}
