소스 검색

处理异步生成,确保图片按照顺序返回保存

htc 3 일 전
부모
커밋
64f6a7efcc
1개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 9 9
      pagesHome/pdf.vue

+ 9 - 9
pagesHome/pdf.vue

@@ -263,9 +263,14 @@
 				title:'正在生成PDF所需的图片...'
 			})
 			await this.downloadZtzdfxImg();
-			this.reportData.dimensionAnalysis.forEach(async d=>{
-				await this.generateScoreImage(d)
-			})
+			for(const d of this.reportData.dimensionAnalysis){
+				const fileurl = await this.generateScoreImage(d);
+				this.pdfImages.push(fileurl)
+			}
+			
+			this.$showToast(`生成成功,共计${this.pdfImages.length}张`);
+			uni.hideLoading();
+			console.log(this.pdfImages);
 		},
 		// 绘制主函数
 		async generateScoreImage(dimensionData) {
@@ -333,12 +338,7 @@
 				                console.log('图片生成成功!', result.tempFilePath);
 				                const fileurl = await this.uploadFilePromise(result.tempFilePath);
 				                console.log(fileurl, 'fileurl');
-								this.pdfImages.push(fileurl);
-								if(this.pdfImages.length===7){
-									uni.hideLoading();
-									console.log(this.pdfImages,'pdfImages');
-								}
-								resolve()
+								resolve(fileurl)
 				            },
 				            fail: (err) => {
 				                console.error('图片生成失败', err);