فهرست منبع

优化健康分析回答显示重复问题

张田田 8 ماه پیش
والد
کامیت
59d7f9ef96

+ 11 - 4
miniprogram/module/chats/components/questionnaire/questionnaire.ts

@@ -31,6 +31,7 @@ interface MessageType {
 Component({
   lifetimes: {
     attached: function () {
+
       let isAnalysis: number;
       isAnalysis = wx.getStorageSync("isAnalysis");
       if (isAnalysis === 3 || isAnalysis === 4) {
@@ -67,6 +68,8 @@ Component({
     } as AnyObject,
 
     _timestamp: Date.now(),
+    // 防止 _next 被并发/重复触发(例如 classify === 'tongue' 时)
+    _requesting: false,
   },
   observers: {
     "messages.**"(messages) {
@@ -180,9 +183,13 @@ Component({
       }
     },
     async _next() {
+      // 并发与重复触发保护
+      if (this.data._requesting) {
+        return;
+      }
+      this.setData({ _requesting: true });
       let isAnalysis: number;
       isAnalysis = wx.getStorageSync("isAnalysis");
-      console.log("isAnalysis", isAnalysis, this.data._next);
       if (isAnalysis === 3 || isAnalysis === 4) {
         // 对话管家
         if (this.data._next.classify === "tongue") {
@@ -291,7 +298,6 @@ Component({
               }
             }
           });
-          console.log("最后一个问题", data,isAnalysis);
           // 对话管家
           if (
             (isAnalysis === 3 && data.classify === "report") ||
@@ -313,7 +319,6 @@ Component({
               this.triggerEvent("to");
             }
             if (data.over) {
-              console.log("结束触发", data, isAnalysis);
               // 延迟触发滚动,确保报告消息已经渲染完成
               setTimeout(() => {
                 this.triggerEvent("to");
@@ -327,7 +332,6 @@ Component({
             [`_next.questions`]: data.nextQuestions,
           });
 
-          console.log("页面向上移动", data,isAnalysis);
           this.triggerEvent("to");
         }
       } catch (error) {
@@ -348,6 +352,9 @@ Component({
           });
           this._end();
         }
+      } finally {
+        // 恢复请求锁
+        this.setData({ _requesting: false });
       }
     },
 

+ 7 - 1
miniprogram/module/chats/pages/analysis/analysis.ts

@@ -73,6 +73,7 @@ Component({
     activeObj: {},
     followObj: {},
     workId: 0,
+    _submitting: false,
   },
   attached() {
     // 从存储中拿到之前的对话信息
@@ -146,6 +147,8 @@ Component({
     },
     async onSubmit() {
       const submitBtn = this.selectComponent('#submitBtn');
+      if (this.data._submitting) return;
+      this.setData({ _submitting: true });
       const data = {
         thumbnail: [] as any,
         source: [] as any,
@@ -156,11 +159,13 @@ Component({
           console.log('[Analysis] Upload in progress, resetting button');
           wx.showToast({ title: `请等待图片上传完毕`, icon: "none" });
           submitBtn?.resetState();
+          this.setData({ _submitting: false });
           return;
         } else if (item.required && !this.data.original[index]) {
           console.log('[Analysis] Missing required image, resetting button');
           wx.showToast({ title: `请上传${item.label}`, icon: "none" });
           submitBtn?.resetState();
+          this.setData({ _submitting: false });
           return;
         }
         if (this.data.original[index])
@@ -213,9 +218,10 @@ Component({
           console.log('[Analysis] Submit failed, resetting button');
           wx.showToast({ title: error?.errMsg ?? "提交失败", icon: "none" });
           submitBtn?.resetState();
+          this.setData({ _submitting: false });
         }
       } else {
-        console.log("对话管家",data)
+        // console.log("对话管家",data)
         // 对话管家
         this.getOpenerEventChannel().emit("update", data);
         wx.navigateBack();

+ 8 - 0
miniprogram/module/chats/pages/index/index.ts

@@ -30,6 +30,10 @@ Component({
         date: dayjs().format("MM-DD HH:mm:ss"),
       });
       const component = this.data.component as "guide" | "questionnaire";
+      // 若路由指定进入 guide,确保展示 guide
+      if (component === "guide") {
+        this.setData({ isShowGuide: true });
+      }
       this.handle({ detail: { component, scroll: true } });
       console.log("id-index",this.data.messages);
       // 计算底部bottom
@@ -102,6 +106,10 @@ Component({
           component: event.detail?.component,
         },
       });
+      // 当切换到 guide 时,强制显示 guide
+      if (event.detail?.component === "guide") {
+        this.setData({ isShowGuide: true });
+      }
       if (event.detail?.scroll) this.scrollIntoView();
     },
     scrollIntoView(event?: ScrollIntoViewEvent) {