导出表格

62 阅读1分钟
    const resp = await axios({
        url: SafeprodApi.getExportDataUrl(),
        method: "POST",
        responseType: "blob",//必加,不然导出是乱码
        headers: { 'x-token': token, 'x-time': new Date().getTime() },
        data: params
    });


    if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(resp.data, fileName);
    } else {
        const link = document.createElement('a');
        const body = document.querySelector('body');

        const blob = new Blob([resp.data]);
        link.href = window.URL.createObjectURL(blob);
        link.download = (fileName || "数据导出") + ".xlsx";
        // fix Firefox
        link.style.display = 'none';
        body.appendChild(link);

        link.click();
        body.removeChild(link);
        // 释放URL 对象
        window.URL.revokeObjectURL(link.href);
    }