瀏覽代碼

优化小程序代码

yanj 1 月之前
父節點
當前提交
04c51927fa
共有 4 個文件被更改,包括 57 次插入17 次删除
  1. 8 5
      pages/activity/detail.vue
  2. 16 4
      pages/checkIn/checkInRoute.vue
  3. 8 5
      pages/exhibitor/exhibit.vue
  4. 25 3
      pages/user/award.vue

+ 8 - 5
pages/activity/detail.vue

@@ -179,13 +179,16 @@ export default {
     this.getActiveInfo()
   },
   created() {
-    uni.$on('refreshData', (val) => {
-      if (val === 'pages/activity/detail') {
-        this.getActiveInfo()
-      }
-    })
+    uni.$on('refreshData', this.handleEvent)
+  },
+  onUnload() {
+    // 卸载时传递事件名和对应的处理函数
+    uni.$off('refreshData', this.handleEvent);
   },
   methods: {
+    handleEvent() {
+      this.getActiveInfo()
+    },
     onShareAppMessage: function () {
       return this.shareInfo
     },

+ 16 - 4
pages/checkIn/checkInRoute.vue

@@ -160,9 +160,15 @@ export default {
     };
   },
   mounted() {
-    this.getRouteListEvent()
+
+  },
+  onShow() {
+    this.handleEvent();
   },
   methods: {
+    handleEvent() {
+      this.getRouteListEvent()
+    },
     initSceneEvent() {
       //微信扫码进入
       if (this.scene) {
@@ -360,15 +366,21 @@ export default {
       }
     }
   },
-
+  onBackPress(options) {
+    if (options.from === 'backbutton' || options.from === 'navigateBack') {
+      // 这里处理手势返回事件
+      console.log('手势返回事件触发');
+      // 返回 true 阻止默认返回行为,返回 false 允许默认返回行为
+      return false;
+    }
+    return false;
+  },
   onLoad(option) {
     if (!store.getters.user) {
       this.navigateTo('/pages/user/login?redirect=' + encodeURIComponent('/pages/checkIn/checkInRoute?scene=' + option.scene))
       return false
     }
     this.scene = decodeURIComponent(option.scene || '');
-    console.log(this.scene, 'option_this.scene')
-
     this.initSceneEvent()
     if (option.rule === 'true')
       this.gotoRule()

+ 8 - 5
pages/exhibitor/exhibit.vue

@@ -150,13 +150,16 @@
 			this.getGlobalPollShow()
 			this.getAdData()
       this.getList()
-      uni.$on('refreshData', (val) => {
-        if (val === 'product') {
-          this.searchList()
-        }
-      })
+      uni.$on('refreshData', this.handleEvent)
 		},
+    /*onUnload() {
+      // 卸载时传递事件名和对应的处理函数
+      uni.$off('refreshData', this.handleEvent);
+    },*/
 		methods: {
+      handleEvent() {
+        this.searchList()
+      },
 			onChange(event) {
 				this.activeName = event
 			},

+ 25 - 3
pages/user/award.vue

@@ -142,6 +142,7 @@ export default {
   },
   data() {
     return {
+      loading: false,
       activeIndex: null,
       awardProgressValue: '0%',
       giftList: [],
@@ -164,10 +165,11 @@ export default {
       }
     };
   },
+  onShow() {
+    this.handleEvent();
+  },
   mounted() {
-    this.getGiftListEvent()
-    this.getActiveInfo()
-    this.getRouteListInfo()
+
   },
   onUnload() {
     clearTimeout(this.timer)
@@ -199,6 +201,11 @@ export default {
     },
   },
   methods: {
+    handleEvent() {
+      this.getGiftListEvent()
+      this.getActiveInfo()
+      this.getRouteListInfo()
+    },
     onShareTimeline() {
       return {
         title: '逛展会,领福利!',
@@ -265,6 +272,8 @@ export default {
         gift_id: this.current_gift.id,
       }).then(res => {
         if (res.code === 0) {
+          this.hideLoading()
+          this.loading = false
           this.qr_code = res.data.qrcode_url
           if (res.data.verify_note) {
             this.verify_note.company_name = res.data.verify_note.company_name
@@ -293,6 +302,11 @@ export default {
       if (item.is_receipts > 0 || this.activeIndex !== index) {
         return false
       }
+      if (this.loading) {
+        return  false
+      }
+      this.loading = true
+      this.showLoading()
       this.current_gift = item
       this.getRouteListInfo(() => {
         //获取当前是否生成过奖品二维码 is_receipts
@@ -308,10 +322,18 @@ export default {
               if (res.confirm) {
                 //获取二维码
                 this.claimDataEvent()
+              } else {
+                this.loading = false
+                this.hideLoading()
               }
+            },
+            fail: ()=>{
+              this.loading = false
+              this.hideLoading()
             }
           })
         }
+
       })
     },
     checkGiftState(callback) {