Переглянути джерело

优化首页通知点击多次才触发的问题

张田田 3 місяців тому
батько
коміт
f30e23c62f

+ 8 - 0
miniprogram/pages/home/home.scss

@@ -420,6 +420,11 @@ $scale: 0.5;
   align-items: center;
   padding: 15px 0;
   border-bottom: 1px solid #f0f0f0;
+  min-height: 44px; // 确保有足够的点击区域
+  cursor: pointer;
+  -webkit-tap-highlight-color: transparent; // 移除点击高亮
+  position: relative; // 确保点击区域正确
+  z-index: 1; // 确保在 scroll-view 中可点击
 
   &:last-child {
     border-bottom: none;
@@ -429,11 +434,14 @@ $scale: 0.5;
 .popup-text {
   font-size: 16px;
   color: #333;
+  flex: 1;
+  // 移除 pointer-events,让事件冒泡到父元素
 }
 
 .popup-action {
   font-size: 14px;
   color: #37b473;
+  // 移除 pointer-events,让事件冒泡到父元素
 }
 
 .t-popup__close {

+ 53 - 38
miniprogram/pages/home/home.ts

@@ -51,6 +51,7 @@ Page({
     pageHeight: "100vh", // 默认值
     popupList: [] as AnyArray,
     isShowPopup: false,
+    isCompleting: false, // 防止重复点击标志
     patients: [] as (App.Patient.Model & { isDefault: "Y" | "N" })[],
     patient: null as App.Patient.Model | null,
     patientDescription: "",
@@ -313,22 +314,22 @@ Page({
   },
   getNotDealList() {
     getNotDealLists().then((res) => {
+      console.log(res, "res===获取通知列表");
       if (res.length > 0) {
         this.setData({
           popupList: res,
+          isShowPopup: true,
         });
+      }else{
         this.setData({
-          isShowPopup: true,
+          popupList: [],
+          isShowPopup: false,
         });
       }
     });
   },
   showFollowPopup() {
-    if (this.data.popupList.length > 0) {
-      this.setData({
-        isShowPopup: true,
-      });
-    }
+    this.getNotDealList();
   },
   onVisibleChange(e: { detail: { visible: any } }) {
     this.setData({
@@ -339,40 +340,54 @@ Page({
   async goComplete(e: {
     currentTarget: { dataset: { page: string; id: number; title: string } };
   }) {
-    const { title } = e.currentTarget.dataset;
-    let page = e.currentTarget.dataset.page;
-    let id = e.currentTarget.dataset.id;
-    if (page === "/module/chats/pages/index/index") {
-      if (title === "健康评估") {
-        wx.setStorageSync("isAnalysis", 4);
-        toChats("questionnaire", 2);
+    // 防止重复点击
+    if (this.data.isCompleting) {
+      return;
+    }
+    
+    this.setData({ isCompleting: true });
+    
+    try {
+      const { title } = e.currentTarget.dataset;
+      let page = e.currentTarget.dataset.page;
+      let id = e.currentTarget.dataset.id;
+      if (page === "/module/chats/pages/index/index") {
+        if (title === "健康评估") {
+          wx.setStorageSync("isAnalysis", 4);
+          toChats("questionnaire", 2);
+        } else {
+          wx.setStorageSync("isAnalysis", 2);
+          wx.setStorageSync("workId", id);
+          wx.navigateTo({
+            url: `${page}?component=questionnaire&messageType=1&id=${id}`,
+          });
+        }
+      } else if (page === "/module/article/pages/science-info/science-info") {
+        try {
+          const res = await Get(`/psarticle/clickPsaNotice`, {
+            params: { noticeSendRecordId: id },
+          });
+          const url = res?.data;
+          const item = {
+            url,
+          };
+          wx.navigateTo({
+            url: `${page}`,
+          }).then((res) => {
+            res.eventChannel.emit("load", item);
+          });
+        } catch (error) {
+          console.log(error);
+        }
       } else {
-        wx.setStorageSync("isAnalysis", 2);
-        wx.setStorageSync("workId", id);
-        wx.navigateTo({
-          url: `${page}?component=questionnaire&messageType=1&id=${id}`,
-        });
+        // 随访
+        wx.redirectTo({ url: `${page}?id=${id}` });
       }
-    } else if (page === "/module/article/pages/science-info/science-info") {
-      try {
-        const res = await Get(`/psarticle/clickPsaNotice`, {
-          params: { noticeSendRecordId: id },
-        });
-        const url = res?.data;
-        const item = {
-          url,
-        };
-        wx.navigateTo({
-          url: `${page}`,
-        }).then((res) => {
-          res.eventChannel.emit("load", item);
-        });
-      } catch (error) {
-        console.log(error);
-      }
-    } else {
-      // 随访
-      wx.redirectTo({ url: `${page}?id=${id}` });
+    } finally {
+      // 延迟重置标志,防止快速连续点击
+      setTimeout(() => {
+        this.setData({ isCompleting: false });
+      }, 500);
     }
   },
   // 随访评估报告已出

+ 7 - 4
miniprogram/pages/home/home.wxml

@@ -17,7 +17,7 @@
       <view class="follow-box" bind:tap="showFollowPopup">
         <image src="../../assets/bg/icon_notice@3x.png" mode="heightFix" class="notice-icon" />
         <view class="pieces">{{popupList.length}}</view>
-        <view class="follow-text" wx:if="{{popupList.length>0}}">{{popupList[0].title}}</view>
+        <view class="follow-text" wx:if="{{isShowPopup}}">{{popupList[0].title}}</view>
       </view>
       <view class="tool-bar-wrapper">
         <view class="tool" wx:if="{{location.description}}">
@@ -246,9 +246,12 @@
     <view class="popup-container">
       <view class="popup-block">
         <scroll-view class="scroll_live" scroll-y="{{true}}" show-scrollbar="{{false}}" enhanced="{{true}}" animation="{{animationData}}">
-          <view class="popup-item" wx:for="{{popupList}}" wx:key="{{id}}" catch:tap="goComplete" data-page="{{item.page}}" data-id="{{item.pendingWorkId}}" data-title="{{item.title}}">
-            <text class="popup-text">{{index+1}}.{{item.title}}</text>
-            <text class="popup-action">{{item.button}}</text>
+          <view class="popup-item" wx:for="{{popupList}}" wx:key="{{id}}" 
+          catch:tap="goComplete" 
+          data-page="{{item.page}}" 
+          data-id="{{item.pendingWorkId}}" data-title="{{item.title}}">
+            <view class="popup-text">{{index+1}}.{{item.title}}</view>
+            <view class="popup-action">{{item.button}}</view>
           </view>
         </scroll-view>
       </view>