Explorar o código

fix 舌象检测修改更友好的错误提示

1cd9cd35a657b1124d1636fe171dea7f1f045f63
cc12458 hai 1 ano
pai
achega
2fb288ad70

+ 26 - 25
miniprogram/module/chats/components/questionnaire/questionnaire.ts

@@ -30,6 +30,7 @@ Component({
     messages: {} as Record<number, Message>,
     lastId: '',
     _next: {
+      classify: "",
       dialogId: "",
       questions: []
     } as AnyObject,
@@ -64,6 +65,7 @@ Component({
         });
         if (count > 0) {
           this.setData({
+            [`_next.classify`]: '',
             [`_next.dialogId`]: '',
             [`_next.questions`]: [],
             _timestamp: Date.now(),
@@ -82,16 +84,21 @@ Component({
     },
     _end() {
       this.setData({
+        [`_next.classify`]: '',
         [`_next.dialogId`]: '',
         [`_next.questions`]: [],
       })
       this.triggerEvent('next', { component: 'guide', scroll: true });
     },
-    _pre() { },
-    _error(): string | void { },
     async _next() {
+      if (this.data._next.classify === 'tongue') {
+        this._createMessage({
+          id: `tongue-loading.${Date.now()}`, type: 'text',
+          payload: { title: '分析中', loading: true }
+        });
+        this.triggerEvent('to');
+      }
       try {
-        this._pre();
         const { data } = await Post(`/dialogueManage/dialog`, this.data._next);
         data.nextQuestions?.forEach((question: any, index: number) => {
           if (question.classify === 'tongue_result') {
@@ -100,22 +107,6 @@ Component({
               payload: { title: question.content }
             })
           } else {
-            if (question.classify === 'tongue') {
-              this._pre = () => {
-                this._createMessage({
-                  id: `${question.classify}.${question.id}.loading`, type: 'text',
-                  payload: { title: '分析中', loading: true }
-                });
-                this.triggerEvent('to');
-              }
-              this._error = () => {
-                setTimeout(() => this._start(), 20);
-                return `图像检测失败,请重新拍摄上传`
-              }
-            } else {
-              this._pre = () => { }
-              this._error = () => { };
-            }
             if (question.css === 'tongue') {
               this._createMessage({
                 id: `${question.classify}.${question.id}.${index}`, type: 'analysis',
@@ -161,17 +152,27 @@ Component({
         if (data.over) return this._end();
 
         this.setData({
+          [`_next.classify`]: data.classify,
           [`_next.dialogId`]: data.dialogId,
           [`_next.questions`]: data.nextQuestions,
         })
         this.triggerEvent('to');
       } catch (error) {
-        const date = Date.now();
-        this._createMessage({
-          id: `system-${date}`, type: 'system',
-          payload: { date, title: this._error() ?? error.errMsg ?? `分析错误,请重试!`, }
-        });
-        this._end();
+        if (this.data._next.classify === 'tongue') {
+          this._updateMessage({
+            id: `tongue-error-${Date.now()}`, type: 'text',
+            payload: { title: error.errMsg ?? `图像检测失败,请重新拍摄上传`, }
+          });
+          this.triggerEvent('to');
+          setTimeout(() => this._start(), 20);
+        } else {
+          const date = Date.now();
+          this._createMessage({
+            id: `system-${date}`, type: 'system',
+            payload: { date, title: error.errMsg ?? `分析错误,请重试!`, }
+          });
+          this._end();
+        }
       }
     },