文件下载

.then(response => {
  response.blob().then(blob => {
    if (afterDown) {
      afterDown();
    }
    if (response.status !== 200) {
      message.warn(
        formatMessage({ id: 'EXPORT_FILE_STATUS' })
          .replace('XXX', response.status)
          .replace('YYY', response.status)
      );
      return;
    }
    let fileName = response.headers.get('Content-Disposition');
    console.log(response.headers.get('Set-Cookie'))
    fileName = !isNvl(fileName) ? fileName : defaultFileName;
    fileName = fileName.replace('attachment;filename=', '');
    console.log(fileName)
    if (window.navigator.msSaveOrOpenBlob) {
      navigator.msSaveBlob(blob, fileName);
    } else {
      const blobUrl = window.URL.createObjectURL(blob);
      const aElement = document.createElement('a');
      document.body.appendChild(aElement);
      aElement.style.display = 'none';
      aElement.href = blobUrl;
      aElement.download = !isNvl(fileName) ? fileName : 'test.xlsx';
      aElement.click();
      document.body.removeChild(aElement);
    }
  });
})

你可能感兴趣的:(文件下载)