导出流文件同时可以提示错误
const exportParams = { ...queryParams }; delete exportParams.pageIndex; delete exportParams.pageSize; const blobAxiosResponse = await aaaa(exportParams); if (blobAxiosResponse.type === 'application/json') { const reader = new FileReader(); reader.onload = () => { try { const json = JSON.parse(reader.result); // 转换为 JSON 对象 proxy?.$modal.msgError(json.msg || '导出失败,请检查参数'); // 提示用户 } catch (e) { proxy?.$modal.msgError('收到非 JSON 格式的错误响应'); } }; reader.readAsText(blobAxiosResponse); // 以文本形式读取 Blob return; // 停止后续执行 } const link = document.createElement('a'); const blobUrl = URL.createObjectURL(blobAxiosResponse); link.href = blobUrl; link.download = '团购列表.xlsx'; // 设置文件名 document.body.appendChild(link); link.click(); URL.revokeObjectURL(blobUrl); document.body.removeChild(link);
您还未登录, 登录 后可进行评论
发表
还没有评论哦,来抢个沙发吧!