
import { ElLoading } from 'element-plus'

let downloadLoadingInstance;
export function download(res, name) {
    const blob = new Blob([res]);
    const fileName = name;
    downloadLoadingInstance = ElLoading.service({ text: "正在下载数据，请稍候", background: "rgba(0, 0, 0, 0.7)", })
    if ("download" in document.createElement("a")) {
        const elink = document.createElement("a");
        elink.download = fileName;
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); //释放URL
        document.body.removeChild(elink);
        downloadLoadingInstance.close();
    } else {
        navigator.msSaveBlob(blob, fileName);
        downloadLoadingInstance.close();
    }
};
