当前位置: 首页 > news >正文

vue前端 多次同步请求一个等一个下载

sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));
},
/** 导出按钮操作 */handleExport() {if (this.ids.length === 0) {this.$message.warning("请至少选择一条记录进行导出");return;}this.$confirm('是否确认导出所选交接记录?', "警告", {confirmButtonText: "确定",cancelButtonText: "取消",type: "warning"}).then(async () => {try {this.$message.info("正在导出...")for (const id of this.ids) {await this.sleep(1000)await exportTxJjjlExcel(id).then(response => {this.download(response,id);});}this.$message.success('导出完成');} catch (error) {this.$message.error(`导出失败: ${error.message}`);} finally {}});
},// 下载文件
download(res,id) {// 检查响应是否为JSON格式的错误信息let find = this.jjjlList.find((e)=>e.ID==id);console.log("res",res)if (res.type === 'application/json') {// 读取JSON错误信息const reader = new FileReader();reader.onload = e => {try {const errorInfo = JSON.parse(e.target.result);this.$message.error(`导出失败: ${errorInfo.msg || '未知错误'}`);} catch (error) {this.$message.error('导出失败,请联系管理员');}};reader.readAsText(res);return;}// 正常处理Excel文件下载const blob = new Blob([res], { type: 'application/vnd.ms-excel' });const link = document.createElement('a');link.href = URL.createObjectURL(blob);link.download = `${this.parseTime(find.JBRQ,'{y}-{m}-{d}')}_${find.JBBYB}_${new Date().getTime()}.xlsx`;link.click();URL.revokeObjectURL(link.href);
}
http://www.dtcms.com/a/233429.html

相关文章:

  • 10.vue.js中封装axioa(3)
  • spring的webclient与vertx的webclient的比较
  • 机器学习——XGBoost
  • Python Einops库:深度学习中的张量操作革命
  • 深度强化学习驱动的智能爬取策略优化:基于网页结构特征的状态表示方法
  • Multi Agents Collaboration OS:Web DeepSearch System
  • delphi7 链表 使用方法
  • 数数科技正式加入上海市人工智能协会,共筑DATA×AI新基建
  • 实数域上的二分
  • UE Learning Record
  • k8S 命令
  • React Navive初识
  • 优化Docker容器化安装与配置的最佳实践
  • Golang面试精解:实现并发安全带过期清理的缓存结构
  • 极限复习c++
  • Spring Plugin框架应用实践:医院多租户客户端动态路由方案解析
  • 【地址区间划分】
  • 【科研绘图系列】R语言绘制和弦图(Chord diagram plot)
  • 如何通过requests和time模块限制爬虫请求速率?
  • MATLAB读取文件内容:Excel、CSV和TXT文件解析
  • 极昆仑HybridRAG方案:突破原生 RAG 瓶颈,开启大模型应用新境界
  • Linux磁盘管理与文件系统
  • 七彩喜智慧养老平台:科技赋能下的市场蓝海,满足多样化养老服务需求
  • 利率的计量
  • ml307 二次开发
  • SpringBoot项目移动之后无法运行
  • 电路设计基础-3
  • 新建网站部署流程
  • 2025年阿里最新软件测试面试题:Web 测试+接口测试+App 测试
  • GitHub 开源 AI 图像超分辨率工具 upscayl 介绍