Bläddra i källkod

修改下载报告代码

liujiejie 3 månader sedan
förälder
incheckning
b19dbf8ebe
1 ändrade filer med 202 tillägg och 201 borttagningar
  1. 202 201
      src/views/performance/assetssMag.vue

+ 202 - 201
src/views/performance/assetssMag.vue

@@ -67,13 +67,13 @@
           <!-- <el-button @click="handleDownLoadChart" size="small">下载</el-button> -->
         </el-form-item>
       </el-form>
-      <!-- <div class="progress" v-if="downloadDisabled">
+      <div class="progress" v-if="downloadDisabled">
         <div class="progressText">文档生成进度:</div>
         <el-progress
           :percentage="progressPercent"
           :color="colors"
         ></el-progress>
-      </div> -->
+      </div>
     </div>
     <div class="list-page">
       <el-table
@@ -309,7 +309,7 @@
           min-width="300"
         >
           <template slot-scope="scope">
-            <!-- <el-button
+            <el-button
               @click="handleDownLoadChart(scope.row)"
               type="text"
               size="small"
@@ -320,7 +320,7 @@
               "
             >
               下载报告
-            </el-button> -->
+            </el-button>
             <!-- <el-button
               @click="abnormalDialog(scope.row, '上传报告')"
               type="text"
@@ -481,7 +481,7 @@ import {
 import { downloadDocx } from "@/utils/common";
 import { getFieldInfo } from "@/api/overview";
 import axios from "axios";
-// import pLimit from "p-limit";
+import pLimit from "p-limit";
 import { allAnalysisType } from "./js/allAnalysisType";
 import { mapMutations, mapState } from "vuex";
 import {
@@ -685,204 +685,205 @@ export default {
         console.error("生成失败:", err);
       }
     },
-    // async handleDownLoadChart(row) {
-    //   this.progress.current = 0;
-    //   this.progress.total = 0;
-    //   this.fileDataList = {};
-    //   this.setDownloadDisabled(true);
-    //   this.$notify.warning("开始生成 Word 文档...");
-    //   try {
-    //     await this.getAllAnalysis(row.batchCode);
-    //     await this.getFieldDetail(row.batchCode);
-    //     this.$message.info("开始生成word文档");
-    //     const limit = pLimit(5); // 限制同时并发的请求数量为 5
-    //     const tasks = [];
-    //     for (const itemAnalysis of this.allAnalysis) {
-    //       const filterAnalysis = allAnalysisType.filter(
-    //         (itemType) => itemType.typeName === itemAnalysis.analysisTypeName,
-    //       )[0];
+    async handleDownLoadChart(row) {
+      this.progress.current = 0;
+      this.progress.total = 0;
+      this.fileDataList = {};
+      this.setDownloadDisabled(true);
+      this.$notify.warning("开始生成 Word 文档...");
+      try {
+        await this.getAllAnalysis(row.batchCode);
+        await this.getFieldDetail(row.batchCode);
+        this.$message.info("开始生成word文档");
+        const limit = pLimit(5); // 限制同时并发的请求数量为 5
+        const tasks = [];
+        for (const itemAnalysis of this.allAnalysis) {
+          const filterAnalysis = allAnalysisType.filter(
+            (itemType) => itemType.typeName === itemAnalysis.analysisTypeName,
+          )[0];
+
+          if (itemAnalysis.generalFiles) {
+            //这里过滤的是发电机温度的类型 在url 中是否能找到filterFileAddr
+            for (const itemField of filterAnalysis.filterFileAddr
+              ? itemAnalysis.generalFiles
+                  .filter((item) => item.fileAddr.endsWith(".json"))
+                  .filter((item) =>
+                    item.fileAddr.includes(filterAnalysis.filterFileAddr),
+                  ) || []
+              : itemAnalysis.generalFiles) {
+              //静态偏航误差 --通过allAnalysisType.js文件配置实现需求
+              if (Array.isArray(filterAnalysis.generalFiles.urlType)) {
+                filterAnalysis.generalFiles.urlType.map(
+                  (itemUrlType, indUrlType) => {
+                    tasks.push(
+                      limit(async () => {
+                        await this.postChartData(
+                          itemUrlType,
+                          row,
+                          itemAnalysis,
+                          itemField,
+                          filterAnalysis,
+                          "generalFiles",
+                        );
+                        this.progress.current++;
+                      }),
+                    );
+                  },
+                );
+              } else if (filterAnalysis.typeCode === "fault") {
+                if (itemField.fileAddr.includes("turbine_fault_result")) {
+                  if (itemField.engineTypeCode === "turbine_fault_result") {
+                    tasks.push(
+                      limit(async () => {
+                        await this.postChartData(
+                          "faultUnitChart",
+                          row,
+                          itemAnalysis,
+                          itemField,
+                          filterAnalysis,
+                          "generalFiles",
+                        );
+                        this.progress.current++;
+                      }),
+                    );
+                  }
+                } else {
+                  if (itemField.engineTypeCode === "total_fault_result") {
+                    tasks.push(
+                      limit(async () => {
+                        await this.postChartData(
+                          "faultAllChart",
+                          row,
+                          itemAnalysis,
+                          itemField,
+                          filterAnalysis,
+                          "generalFiles",
+                        );
+                        this.progress.current++;
+                      }),
+                    );
+                  }
+                }
+              } else if (filterAnalysis.typeCode === "production_indicator") {
+                //总图全场
+                if (
+                  itemField.fileAddr.includes(
+                    filterAnalysis.generalFiles.FileTypeFromUrl,
+                  )
+                ) {
+                  tasks.push(
+                    limit(async () => {
+                      await this.postChartData(
+                        filterAnalysis.generalFiles.urlType,
+                        row,
+                        itemAnalysis,
+                        itemField,
+                        filterAnalysis,
+                        "generalFiles",
+                      );
+                      this.progress.current++;
+                      // 每完成 10% 提示一次(可调)
+                    }),
+                  );
+                } else {
+                  tasks.push(
+                    limit(async () => {
+                      await this.postChartData(
+                        "radarChart",
+                        row,
+                        itemAnalysis,
+                        itemField,
+                        filterAnalysis,
+                        "generalFiles",
+                      );
+                      this.progress.current++;
+                    }),
+                  );
+                }
+              } else {
+                tasks.push(
+                  limit(async () => {
+                    await this.postChartData(
+                      filterAnalysis.generalFiles.urlType,
+                      row,
+                      itemAnalysis,
+                      itemField,
+                      filterAnalysis,
+                      "generalFiles",
+                    );
+                    this.progress.current++;
+                  }),
+                );
+              }
+            }
+          }
+          if (itemAnalysis.diagramRelations) {
+            for (const itemField of filterAnalysis.filterFileAddr
+              ? itemAnalysis.diagramRelations
+                  .filter((item) => item.fileAddr.endsWith(".json"))
+                  .filter((item) =>
+                    item.fileAddr.includes(filterAnalysis.filterFileAddr),
+                  ) || []
+              : itemAnalysis.diagramRelations) {
+              const urlType = Array.isArray(
+                filterAnalysis.diagramRelations.urlType,
+              )
+                ? this.getFileTypeFromUrl(
+                    itemField.fileAddr,
+                    filterAnalysis.diagramRelations.FileTypeFromUrl,
+                  ) === filterAnalysis.diagramRelations.FileTypeFromUrl
+                  ? filterAnalysis.diagramRelations.urlType[0]
+                  : filterAnalysis.diagramRelations.urlType[1]
+                : filterAnalysis.diagramRelations.urlType;
+              tasks.push(
+                limit(async () => {
+                  await this.postChartData(
+                    urlType,
+                    row,
+                    itemAnalysis,
+                    itemField,
+                    filterAnalysis,
+                    "diagramRelations",
+                  );
+                  this.progress.current++;
+                }),
+              );
+            }
+          }
+        }
+        this.progress.total = tasks.length;
+        await Promise.all(tasks);
 
-    //       if (itemAnalysis.generalFiles) {
-    //         //这里过滤的是发电机温度的类型 在url 中是否能找到filterFileAddr
-    //         for (const itemField of filterAnalysis.filterFileAddr
-    //           ? itemAnalysis.generalFiles
-    //               .filter((item) => item.fileAddr.endsWith(".json"))
-    //               .filter((item) =>
-    //                 item.fileAddr.includes(filterAnalysis.filterFileAddr),
-    //               ) || []
-    //           : itemAnalysis.generalFiles) {
-    //           //静态偏航误差 --通过allAnalysisType.js文件配置实现需求
-    //           if (Array.isArray(filterAnalysis.generalFiles.urlType)) {
-    //             filterAnalysis.generalFiles.urlType.map(
-    //               (itemUrlType, indUrlType) => {
-    //                 tasks.push(
-    //                   limit(async () => {
-    //                     await this.postChartData(
-    //                       itemUrlType,
-    //                       row,
-    //                       itemAnalysis,
-    //                       itemField,
-    //                       filterAnalysis,
-    //                       "generalFiles",
-    //                     );
-    //                     this.progress.current++;
-    //                   }),
-    //                 );
-    //               },
-    //             );
-    //           } else if (filterAnalysis.typeCode === "fault") {
-    //             if (itemField.fileAddr.includes("turbine_fault_result")) {
-    //               if (itemField.engineTypeCode === "turbine_fault_result") {
-    //                 tasks.push(
-    //                   limit(async () => {
-    //                     await this.postChartData(
-    //                       "faultUnitChart",
-    //                       row,
-    //                       itemAnalysis,
-    //                       itemField,
-    //                       filterAnalysis,
-    //                       "generalFiles",
-    //                     );
-    //                     this.progress.current++;
-    //                   }),
-    //                 );
-    //               }
-    //             } else {
-    //               if (itemField.engineTypeCode === "total_fault_result") {
-    //                 tasks.push(
-    //                   limit(async () => {
-    //                     await this.postChartData(
-    //                       "faultAllChart",
-    //                       row,
-    //                       itemAnalysis,
-    //                       itemField,
-    //                       filterAnalysis,
-    //                       "generalFiles",
-    //                     );
-    //                     this.progress.current++;
-    //                   }),
-    //                 );
-    //               }
-    //             }
-    //           } else if (filterAnalysis.typeCode === "production_indicator") {
-    //             //总图全场
-    //             if (
-    //               itemField.fileAddr.includes(
-    //                 filterAnalysis.generalFiles.FileTypeFromUrl,
-    //               )
-    //             ) {
-    //               tasks.push(
-    //                 limit(async () => {
-    //                   await this.postChartData(
-    //                     filterAnalysis.generalFiles.urlType,
-    //                     row,
-    //                     itemAnalysis,
-    //                     itemField,
-    //                     filterAnalysis,
-    //                     "generalFiles",
-    //                   );
-    //                   this.progress.current++;
-    //                   // 每完成 10% 提示一次(可调)
-    //                 }),
-    //               );
-    //             } else {
-    //               tasks.push(
-    //                 limit(async () => {
-    //                   await this.postChartData(
-    //                     "radarChart",
-    //                     row,
-    //                     itemAnalysis,
-    //                     itemField,
-    //                     filterAnalysis,
-    //                     "generalFiles",
-    //                   );
-    //                   this.progress.current++;
-    //                 }),
-    //               );
-    //             }
-    //           } else {
-    //             tasks.push(
-    //               limit(async () => {
-    //                 await this.postChartData(
-    //                   filterAnalysis.generalFiles.urlType,
-    //                   row,
-    //                   itemAnalysis,
-    //                   itemField,
-    //                   filterAnalysis,
-    //                   "generalFiles",
-    //                 );
-    //                 this.progress.current++;
-    //               }),
-    //             );
-    //           }
-    //         }
-    //       }
-    //       if (itemAnalysis.diagramRelations) {
-    //         for (const itemField of filterAnalysis.filterFileAddr
-    //           ? itemAnalysis.diagramRelations
-    //               .filter((item) => item.fileAddr.endsWith(".json"))
-    //               .filter((item) =>
-    //                 item.fileAddr.includes(filterAnalysis.filterFileAddr),
-    //               ) || []
-    //           : itemAnalysis.diagramRelations) {
-    //           const urlType = Array.isArray(
-    //             filterAnalysis.diagramRelations.urlType,
-    //           )
-    //             ? this.getFileTypeFromUrl(
-    //                 itemField.fileAddr,
-    //                 filterAnalysis.diagramRelations.FileTypeFromUrl,
-    //               ) === filterAnalysis.diagramRelations.FileTypeFromUrl
-    //               ? filterAnalysis.diagramRelations.urlType[0]
-    //               : filterAnalysis.diagramRelations.urlType[1]
-    //             : filterAnalysis.diagramRelations.urlType;
-    //           tasks.push(
-    //             limit(async () => {
-    //               await this.postChartData(
-    //                 urlType,
-    //                 row,
-    //                 itemAnalysis,
-    //                 itemField,
-    //                 filterAnalysis,
-    //                 "diagramRelations",
-    //               );
-    //               this.progress.current++;
-    //             }),
-    //           );
-    //         }
-    //       }
-    //     }
-    //     this.progress.total = tasks.length;
-    //     await Promise.all(tasks);
+        const engineTypeList = await this.getEngineTypeList(
+          this.fieldInfo.engineMillTypes,
+          row.batchCode,
+        );
+        this.$notify.success("✅ 图表全部生成完成,开始生成 Word 文档...");
+        const wordFilePath = await axios.post(
+          "/downLoadChart/chartServer/charts/CopyFileCsv",
+          {
+            fieldInfo: this.fieldInfo,
+            dataTime: `${this.analysisInfo.dataStartTime}-${this.analysisInfo.dataEndTime}`,
+            bucketName: "bucket-zhzn",
+            objectName: `charts/${row.fieldCode}/${row.batchCode}`,
+            engineTypeList: engineTypeList,
+            ...this.fileDataList,
+          },
+        );
+        // //下载minio 文件
+        downloadDocx(
+          wordFilePath.data.data.url,
+          wordFilePath.data.data.fileName,
+        );
+        this.$notify.success("🎉 Word 文档生成并已下载!");
+        this.setDownloadDisabled(false);
+      } catch (error) {
+        console.log(error, "error");
+        this.$notify.error("🎉 Word 文档生成并下载失败!");
+        this.setDownloadDisabled(false);
+      }
+    },
 
-    //     const engineTypeList = await this.getEngineTypeList(
-    //       this.fieldInfo.engineMillTypes,
-    //       row.batchCode,
-    //     );
-    //     this.$notify.success("✅ 图表全部生成完成,开始生成 Word 文档...");
-    //     const wordFilePath = await axios.post(
-    //       "/downLoadChart/chartServer/charts/CopyFileCsv",
-    //       {
-    //         fieldInfo: this.fieldInfo,
-    //         dataTime: `${this.analysisInfo.dataStartTime}-${this.analysisInfo.dataEndTime}`,
-    //         bucketName: "bucket-zhzn",
-    //         objectName: `charts/${row.fieldCode}/${row.batchCode}`,
-    //         engineTypeList: engineTypeList,
-    //         ...this.fileDataList,
-    //       },
-    //     );
-    //     // //下载minio 文件
-    //     downloadDocx(
-    //       wordFilePath.data.data.url,
-    //       wordFilePath.data.data.fileName,
-    //     );
-    //     this.$notify.success("🎉 Word 文档生成并已下载!");
-    //     this.setDownloadDisabled(false);
-    //   } catch (error) {
-    //     console.log(error, "error");
-    //     this.$notify.error("🎉 Word 文档生成并下载失败!");
-    //     this.setDownloadDisabled(false);
-    //   }
-    // },
     async getEngineTypeList(typeList, batchCode) {
       return await Promise.all(
         typeList.map((item) => this.getEngineMillList(item, batchCode)),