Browse Source

Update index.ts

lex-xin 5 months ago
parent
commit
0b62620dfe
1 changed files with 27 additions and 5 deletions
  1. 27 5
      miniprogram/pages/index/index.ts

+ 27 - 5
miniprogram/pages/index/index.ts

@@ -33,13 +33,14 @@ Page({
     list: [] as any,
     isOverSaled: false, // 是否所有商品都没有库存
     selected: {} as any,
+    isFromPreviewImage: false,
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad() {
-    this.onInit()
+    // this.onInit()
   },
   /**
    * 获取基础信息
@@ -178,26 +179,47 @@ Page({
   onPreivewBannerImg(e: { currentTarget: { dataset: any } }) {
     wx.previewImage({
       current: e.currentTarget.dataset.src,
-      urls: this.data.imgList
+      urls: this.data.imgList,
+      success: () => {
+        this.setData({
+          isFromPreviewImage: true
+        })
+      }
     })
   },
   onPreivewGoodsImg(e: { currentTarget: { dataset: any } }) {
     wx.previewImage({
       current: e.currentTarget.dataset.src,
-      urls: this.data.goodsImgList
+      urls: this.data.goodsImgList,
+      success: () => {
+        this.setData({
+          isFromPreviewImage: true
+        })
+      }
     })
   },
   onPreivewGoods(e: { currentTarget: { dataset: any } }) {
     wx.previewImage({
       current: e.currentTarget.dataset.src,
-      urls: [e.currentTarget.dataset.src]
+      urls: [e.currentTarget.dataset.src],
+      success: () => {
+        this.setData({
+          isFromPreviewImage: true
+        })
+      }
     })
   },
   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    this.onInit()
+    if(!this.data.isFromPreviewImage) {
+      this.onInit()
+    } else {
+      this.setData({
+        isFromPreviewImage: false
+      })
+    }
   },
   openService() {
     wx.navigateTo({