Browse Source

修改解析状态

yangg 9 months ago
parent
commit
45ed6dd802

File diff suppressed because it is too large
+ 0 - 0
dist/index.html


+ 0 - 0
dist/static/css/chunk-5b1b00c6.8d28e945.css → dist/static/css/chunk-79a693c7.8d28e945.css


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/app.f640a250.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-5b1b00c6.fe5a6f00.js


File diff suppressed because it is too large
+ 0 - 0
dist/static/js/chunk-79a693c7.e700d262.js


+ 1 - 1
src/store/modules/app.js

@@ -6,7 +6,7 @@ const state = {
     withoutAnimation: false
     withoutAnimation: false
   },
   },
   device: 'desktop',
   device: 'desktop',
-  size: Cookies.get('size') || 'medium'
+  size: Cookies.get('size') || 'small'
 }
 }
 
 
 const mutations = {
 const mutations = {

+ 40 - 20
src/views/knowledgeMenu/category/components/dataList.vue

@@ -319,11 +319,15 @@ export default {
       selectedRows: [],
       selectedRows: [],
       sortColumn: "",
       sortColumn: "",
       sortOrder: "",
       sortOrder: "",
+      analysisStatusCheckers: {}, // 新增:用于存储每个文档的状态检查器
     };
     };
   },
   },
   mounted() {
   mounted() {
     this.search();
     this.search();
   },
   },
+  beforeDestroy() {
+    Object.values(this.analysisStatusCheckers).forEach(clearTimeout);
+  },
   methods: {
   methods: {
     /* 排序 */
     /* 排序 */
     handleSortChange({ prop, order }) {
     handleSortChange({ prop, order }) {
@@ -395,7 +399,7 @@ export default {
       this.dataList.forEach((row) => {
       this.dataList.forEach((row) => {
         if (ids.includes(row.id)) {
         if (ids.includes(row.id)) {
           row.run = 1; // 设置状态为"解析中"
           row.run = 1; // 设置状态为"解析中"
-          this.checkAnalysisStatus(row);
+          this.startAnalysisStatusChecker(row);
         }
         }
       });
       });
     },
     },
@@ -419,9 +423,9 @@ export default {
     },
     },
     /* 解析 */
     /* 解析 */
     analysis(row) {
     analysis(row) {
-      if (row.run === 1 || row.run === 5) return; // 如果已经在解析中或待处理,直接返回
+      if (row.run === 1 || row.run === 5) return;
 
 
-      this.$set(row, "run", 1); // 使用 $set 确保视图更新
+      this.$set(row, "run", 1);
 
 
       analysis({
       analysis({
         document_id: row.id,
         document_id: row.id,
@@ -431,48 +435,63 @@ export default {
       })
       })
         .then((res) => {
         .then((res) => {
           if (res.status === 200) {
           if (res.status === 200) {
-            this.checkAnalysisStatus(row);
+            this.startAnalysisStatusChecker(row);
           } else {
           } else {
             this.$message.error("解析请求失败");
             this.$message.error("解析请求失败");
-            this.$set(row, "run", 0); // 如果请求失败,重置状态
+            this.$set(row, "run", 0);
           }
           }
         })
         })
         .catch((error) => {
         .catch((error) => {
           console.error("解析错误:", error);
           console.error("解析错误:", error);
           this.$message.error("解析过程中出现错误");
           this.$message.error("解析过程中出现错误");
-          this.$set(row, "run", 0); // 如果出现错误,重置状态
+          this.$set(row, "run", 0);
         });
         });
     },
     },
-    checkAnalysisStatus(row) {
+
+    startAnalysisStatusChecker(row) {
+      // 如果已经有一个检查器在运行,先停止它
+      if (this.analysisStatusCheckers[row.id]) {
+        clearTimeout(this.analysisStatusCheckers[row.id]);
+      }
+
       const checkStatus = () => {
       const checkStatus = () => {
         getRunStatus({ document_id: row.id })
         getRunStatus({ document_id: row.id })
           .then((res) => {
           .then((res) => {
             if (res.status === 200) {
             if (res.status === 200) {
-             /*   */
-              if (res.data.run === '3') {
-                this.$set(row, "run",Number(res.data.run));
-              } else if (res.data.run === '4') {
-                this.$set(row, "run", Number(res.data.run));
+              const newStatus = Number(res.data.run);
+              this.$set(row, "run", newStatus);
+
+              if (newStatus === 3) {
+                this.$message.success("解析成功");
+                delete this.analysisStatusCheckers[row.id];
+              } else if (newStatus === 4) {
                 this.$message.error("解析失败");
                 this.$message.error("解析失败");
-              } else if (res.data.run === '1') {
-                // 如果仍在解析中,5-10秒后再次检查
-                setTimeout(() => {
-                  this.checkAnalysisStatus(row);
-                }, 5000 + Math.random() * 5000);
+                delete this.analysisStatusCheckers[row.id];
+              } else if (newStatus === 1 || newStatus === 5) {
+                // 继续检查
+                this.analysisStatusCheckers[row.id] = setTimeout(
+                  checkStatus,
+                  5000 + Math.random() * 5000
+                );
               }
               }
             } else {
             } else {
               this.$message.error("获取解析状态失败");
               this.$message.error("获取解析状态失败");
-              this.$set(row, "run", 0); // 如果获取状态失败,重置状态
+              this.$set(row, "run", 0);
+              delete this.analysisStatusCheckers[row.id];
             }
             }
           })
           })
           .catch((error) => {
           .catch((error) => {
             console.error("获取解析状态错误:", error);
             console.error("获取解析状态错误:", error);
             this.$message.error("获取解析状态时出现错误");
             this.$message.error("获取解析状态时出现错误");
-            this.$set(row, "run", 0); // 如果出现错误,重置状态
+            this.$set(row, "run", 0);
+            delete this.analysisStatusCheckers[row.id];
           });
           });
       };
       };
+
+      // 立即开始第一次检查
       checkStatus();
       checkStatus();
     },
     },
+
     handleAnalClose() {
     handleAnalClose() {
       this.anaDialogVisible = false;
       this.anaDialogVisible = false;
     },
     },
@@ -625,6 +644,7 @@ export default {
           if (res.status !== 200) return;
           if (res.status !== 200) return;
           _this.dataList = res.data.documents.map((el) => ({
           _this.dataList = res.data.documents.map((el) => ({
             ...el,
             ...el,
+            token_num: 256,
             start_page: _this.analForm.start_page,
             start_page: _this.analForm.start_page,
             end_page: _this.analForm.end_page,
             end_page: _this.analForm.end_page,
           }));
           }));
@@ -635,7 +655,7 @@ export default {
           // Initialize the analysis status for each row
           // Initialize the analysis status for each row
           _this.dataList.forEach((row) => {
           _this.dataList.forEach((row) => {
             if (row.run === 1) {
             if (row.run === 1) {
-              _this.checkAnalysisStatus(row);
+              _this.startAnalysisStatusChecker(row);
             }
             }
           });
           });
         })
         })

Some files were not shown because too many files changed in this diff