刘洋 7 meses atrás
pai
commit
9940508a56
1 arquivos alterados com 37 adições e 7 exclusões
  1. 37 7
      src/modules/admin/ocr/OcrTest.vue

+ 37 - 7
src/modules/admin/ocr/OcrTest.vue

@@ -82,6 +82,9 @@ export default {
       type: "GENERAL",
       resultText: "",
       loading: false,
+      key: "",
+      timer: null,
+      index: 0,
     };
   },
   computed: {
@@ -94,6 +97,9 @@ export default {
       this.file = null;
       this.imageUrl = "";
       this.type = "GENERAL";
+      this.resultText = "";
+      this.clear();
+      this.key = "";
     },
     cancel() {
       this.modalIsShow = false;
@@ -116,6 +122,7 @@ export default {
     },
     customSubmit(option) {
       this.resultText = "";
+      this.key = Math.random() + "";
       this.loading = true;
       orgTestApi({
         id: this.curRow.id,
@@ -125,7 +132,7 @@ export default {
         .then((res) => {
           if (res && res.text) {
             let initText = (res.text || "").replaceAll(/\n/g, "<br />");
-            this.writing(0, initText);
+            this.writing(initText, this.key);
           }
         })
         .finally(() => {
@@ -140,14 +147,35 @@ export default {
         this.imageUrl = URL.createObjectURL(file.raw);
       });
     },
-    writing(index, data) {
-      if (index < data.length) {
-        this.resultText = this.resultText + data[index];
-        setTimeout(() => {
-          this.writing(++index, data);
-        }, 8);
+    clear() {
+      if (this.timer) {
+        clearInterval(this.timer);
+        this.timer = null;
       }
     },
+    writing(data, key) {
+      // if (index < data.length && !this.reset) {
+      //   this.resultText = this.resultText + data.slice(index, index + 10);
+      //   setTimeout(() => {
+      //     this.writing(index + 10, data);
+      //   }, 20);
+      // }
+      this.clear();
+      this.index = 0;
+      this.timer = setInterval(() => {
+        if (key !== this.key) {
+          this.clear();
+          return;
+        }
+        this.resultText =
+          this.resultText + data.slice(this.index, this.index + 20);
+        this.index = this.index + 20;
+      }, 50);
+    },
+  },
+  beforeDestroy() {
+    this.clear();
+    this.key = "";
   },
 };
 </script>
@@ -173,6 +201,8 @@ export default {
         .result-text {
           height: calc(100% - 44px);
           overflow: auto;
+          font-size: 16px;
+          line-height: 1.5;
         }
       }
       .left {