Parcourir la source

在线咨询bug优化

张田田 il y a 5 mois
Parent
commit
6d1e9892df

+ 43 - 38
miniprogram/module/chats/components/guide/guide.ts

@@ -3,7 +3,7 @@ import { getPatients } from "../../../../pages/home/request";
 import { toCertificationPage } from "../../../../pages/home/router";
 import { Post } from "../../../../lib/request/method";
 
-let next: 'handleA' | 'handleB' | 'handleC';
+let next: "handleA" | "handleB" | "handleC";
 
 Component({
   lifetimes: {
@@ -23,9 +23,9 @@ Component({
       // 获取评估剩余次数
       this.setAnalysisCount().then(() => {
         if (next) {
-          const patientId = wx.getStorageSync('patientId');
+          const patientId = wx.getStorageSync("patientId");
           if (patientId) this[next]();
-          else wx.showToast({ title: '请先完善信息!', icon: 'none' });
+          else wx.showToast({ title: "请先完善信息!", icon: "none" });
           next = undefined;
         }
       });
@@ -51,7 +51,8 @@ Component({
           {},
           {
             transform({ data }: any) {
-              if (data?.usedCou === 0 && data.residuedCou === 0) data.residuedCou = 3;
+              if (data?.usedCou === 0 && data.residuedCou === 0)
+                data.residuedCou = 3;
               return data?.residuedCou;
             },
           }
@@ -65,35 +66,19 @@ Component({
       const { patient } = await getPatients(/*this.data.patientId*/);
       if (!patient) {
         await toCertificationPage();
-        next = 'handleA';
-      }
-      else {
+        next = "handleA";
+      } else {
         if (this.data.active) {
-          this.triggerEvent("next", {
-            component: "questionnaire",
-            scroll: true,
-          });
+          // 设置 isAnalysis 为 3(健康分析/对话管家)
+          wx.setStorageSync("isAnalysis", 3);
+          // 先触发 nextType 更新 messageType,然后触发 next 切换组件
           this.triggerEvent("nextType", { MessageType: 2 });
-        }
-      }
-    },
-    // 在线咨询
-    async handleE() {
-      const { patient } = await getPatients(/*this.data.patientId*/);
-      if (!patient) await toCertificationPage();
-      else {
-        if (this.data.active) {
-          // 清除之前的咨询结束状态,开始新咨询
-          wx.setStorageSync("consultEnded", false);
-          wx.setStorageSync("lastConsultTime", Date.now());
-          
-          wx.setStorageSync("isAnalysis", 5);
-          this.triggerEvent("next", {
-            component: "questionnaire",
-            scroll: true,
-          });
-          this.triggerEvent("nextType", { MessageType: 3 });
-          
+          setTimeout(() => {
+            this.triggerEvent("next", {
+              component: "questionnaire",
+              scroll: true,
+            });
+          }, 100);
         }
       }
     },
@@ -101,9 +86,8 @@ Component({
       const { patient } = await getPatients(/*this.data.patientId*/);
       if (!patient) {
         await toCertificationPage();
-        next = 'handleB';
-      }
-      else {
+        next = "handleB";
+      } else {
         if (this.data.active)
           wx.navigateTo({
             url: "/module/health/pages/status/status",
@@ -113,11 +97,10 @@ Component({
     },
     async handleC() {
       const { patient } = await getPatients(/*this.data.patientId*/);
-      if (!patient){
+      if (!patient) {
         await toCertificationPage();
-        next = 'handleC';
-      }
-      else {
+        next = "handleC";
+      } else {
         if (this.data.active)
           wx.navigateTo({
             url: "/module/user/pages/user-edit/user-edit",
@@ -136,7 +119,29 @@ Component({
         wx.redirectTo({ url: "/pages/home/home" });
       }
     },
+    // 在线咨询
+    async handleE() {
+      const { patient } = await getPatients(/*this.data.patientId*/);
+      if (!patient) await toCertificationPage();
+      else {
+        if (this.data.active) {
+          // 清除之前的咨询结束状态,开始新咨询
+          wx.setStorageSync("consultEnded", false);
+          wx.setStorageSync("lastConsultTime", Date.now());
 
+          wx.setStorageSync("isAnalysis", 5);
+          // 先触发 nextType 更新 messageType,然后立即触发 next 切换组件
+          // 由于 nextType 事件处理是同步的,所以可以立即触发 next
+          this.triggerEvent("nextType", { MessageType: 3 });
+          setTimeout(() => {
+            this.triggerEvent("next", {
+              component: "questionnaire",
+              scroll: true,
+            });
+          }, 100);
+        }
+      }
+    },
     _update(result: string[]) {
       if (result.length) {
         this.setData({ result });

+ 41 - 13
miniprogram/module/chats/components/message-consult/message-consult.ts

@@ -82,6 +82,7 @@ Component({
       const safeBottomRpx = calculateSafeBottomRpx();
       const tabBarHeight = 100; // rpx
       const baseBottom = safeBottomRpx + tabBarHeight;
+      console.log("baseBottom==输入框的位置", baseBottom);
       // 获取咨询中的id
       const consultId = wx.getStorageSync("consultId");
       let messages: ConsultMessage[] = [];
@@ -109,19 +110,34 @@ Component({
       );
 
       const consultEnded = hasEndMessage || wx.getStorageSync("consultEnded");
-
+      console.log(
+        "安全区的距离",
+        safeBottomRpx,
+        "consultEnded==是否已结束咨询",
+        consultEnded
+      );
       this.setData({
         baseInputBottom: baseBottom,
         inputBoxBottom: baseBottom,
         messages,
         consultEnded: !!consultEnded,
       });
+      console.log("baseBottom==输入框的位置", baseBottom);
       this.triggerEvent("boxBottom", { inputBoxBottom: baseBottom });
-      // 键盘高度监听作为位置同步的补充
+      // 监听键盘高度变化事件
+      let lastHeight = 0;
+
       const kbHandler = (res: any) => {
         const height = res?.height ?? 0;
-        // 如果键盘高度没有实际变化,不更新位置(避免输入时的高度变化触发位置更新)
-        if (Math.abs(height - this.data._keyboardHeight) < 5) {
+        if (!this.data.inputFocus) {
+          lastHeight = 0;
+        } else {
+          lastHeight = Math.max(lastHeight, height); // 记录键盘最大高度
+        }
+        console.log("height==键盘高度", height, "lastHeight=====", lastHeight);
+
+        // 如果键盘高度没有实际变化,不更新位置
+        if (this.data._keyboardHeight && lastHeight) {
           return;
         }
 
@@ -132,12 +148,11 @@ Component({
 
         // 键盘展开时立即更新位置,确保没有空隙
         // 键盘收起时稍微延迟,避免与输入框高度变化冲突
-        const delay = height > 0 ? 0 : 100; // 键盘展开时立即更新,不延迟
-        const timer = setTimeout(() => {
-          this._updateInputPosition(height);
-        }, delay) as unknown as number;
-
-        this.setData({ _kbTimer: timer });
+        let _kbTimer = setTimeout(() => {
+          console.log("lastHeight==键盘高度 zx", lastHeight);
+          this._updateInputPosition(lastHeight);
+        }, 300);
+        this.setData({ _kbTimer: _kbTimer });
       };
 
       wx.onKeyboardHeightChange?.(kbHandler);
@@ -372,14 +387,19 @@ Component({
       this._updateInputPosition(keyboardHeight);
     },
     onInputBlur() {
+      console.log("onInputBlur==输入框失焦");
+
       // 设置 focus 状态
       this.setData({
         inputFocus: false,
       });
-
-      // 立即恢复位置(键盘高度为 0)
-      this._updateInputPosition(0);
+      clearTimeout(this.data._kbTimer);
+      // 延迟恢复位置,确保键盘完全收起
+      setTimeout(() => {
+        this._updateInputPosition(0);
+      }, 100);
     },
+
     // 启动轮询最新消息
     _startPolling() {
       // 如果咨询已结束,不启动轮询
@@ -470,7 +490,15 @@ Component({
           messageContent,
         }).then(() => {
           // 发送成功后获取最新消息
+          // 重置轮询定时器,避免短时间内重复调用
+          this._stopPolling();
           this._getLatestMessages();
+          // 重新启动轮询,避免重复调用
+          setTimeout(() => {
+            if (!this.data.consultEnded) {
+              this._startPolling();
+            }
+          }, 5000);
         });
       } catch (error: any) {
         wx.showToast({

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

@@ -88,7 +88,9 @@ Component({
       this.triggerEvent("to", option.detail.id);
     },
     boxBottom(event: boxBottom) {
+      console.log("event==boxBottom", event);
       this.setData({ inputBoxBottom: event.detail.inputBoxBottom });
+      console.log("this.data.inputBoxBottom", this.data.inputBoxBottom);
       this.triggerEvent("boxBottom", {
         inputBoxBottom: this.data.inputBoxBottom + 100,
       });
@@ -115,7 +117,8 @@ Component({
     },
     async _start() {
       const isAnalysis = wx.getStorageSync("isAnalysis");
-      if (isAnalysis === 5) {
+      // 在线咨询:isAnalysis === 5 且 messageType === 3
+      if (isAnalysis === 5 && this.data.messageType === 3) {
         this.setData({
           [`_next.classify`]: "",
           [`_next.dialogId`]: "",

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

@@ -77,7 +77,6 @@ Component({
   },
   methods: {
     boxBottom(event: boxBottom) {
-      // 移除之前为上传图片按钮预留的 60rpx 补偿,现在按钮位置已改变
       // 直接使用子组件传递的 inputBoxBottom 值
       this.setData({
         inputBoxBottom: event.detail.inputBoxBottom,

+ 5 - 3
miniprogram/pages/home/home.scss

@@ -5,7 +5,6 @@
 
 .body-img {
   position: relative;
-  pointer-events: none;
   .body-bg-image {
     position: absolute;
     top: 0;
@@ -20,7 +19,7 @@
     -ms-image-rendering: crisp-edges;
   }
 
-  > view,
+  > view:not(.chat-status),
   > text,
   > image {
     position: relative;
@@ -144,6 +143,9 @@
   display: flex;
   align-items: center;
   justify-content: center;
+  position: relative;
+  z-index: 10;
+  pointer-events: auto;
 
   .report-box {
     display: flex;
@@ -660,7 +662,7 @@ $scale: 0.5;
   color: #1d6ff6;
   font-weight: 500;
   font-size: 24rpx;
-  z-index: 999999;
+  z-index: 999999 !important;
   &__dot {
     width: 20rpx;
     height: 20rpx;

+ 6 - 5
miniprogram/pages/home/home.ts

@@ -640,10 +640,12 @@ Page({
     wx.navigateTo({ url: `/module/article/pages/science-list/science-list` });
   },
   async toReportPage() {
+    console.log("toReportPage==跳转到报告页面");
     // const { patient } = await getPatients(/*this.data.patientId*/);
     if (!this.data.patient) await toCertificationPage();
     else {
       const id = this.data.healthId;
+      console.log("id==报告id", id);
       if (id)
         wx.navigateTo({ url: `/module/health/pages/report/report?id=${id}` });
       else wx.showToast({ title: "暂无分析报告", icon: "none" });
@@ -715,17 +717,16 @@ Page({
   async checkConsultationStatus() {
     //获取正在咨询中的咨询id
     const res = await Post("/consultManage/getConsultIng");
-    const isConsulting = !!res.data;
+    const isConsulting = !!res.data.id;
+    const hasNewMessage = res.data?.patientUnreadCount > 0;
+    // 是否有新消息
+    this.setData({ hasNewMessage });
     if (isConsulting) {
       // 保存咨询id,标记咨询未结束
       wx.setStorageSync("consultId", res.data);
       wx.setStorageSync("consultEnded", false);
-      // 判断是否有新消息(只有在有咨询时才判断) 调获取新消息
-      const isNew = await Post(`/consultManage/getLatestMsgs/${res?.data}`);
-      const hasNewMessage = isNew?.data?.length > 0;
       this.setData({
         isConsulting: true,
-        hasNewMessage: hasNewMessage,
       });
     } else {
       // 没有咨询,清理相关数据

+ 1 - 1
miniprogram/pages/home/home.wxml

@@ -57,7 +57,7 @@
         </view>
       </view>
 
-      <view class="report-container" bind:tap="toReportPage" wx:if="{{healthReport.data.reportTime}}">
+      <view class="report-container" bindtap="toReportPage" wx:if="{{healthReport.data.reportTime}}">
         <view class="report-box">
           <view>
             <image src="../../assets/bg/icon_file@3x.png" class="report-img" />