Kaynağa Gözat

fix: handle router back type

wangyuan 2 yıl önce
ebeveyn
işleme
fbcd5a57ae
3 değiştirilmiş dosya ile 17 ekleme ve 15 silme
  1. 1 1
      pages/appointment/appointment.js
  2. 12 10
      pages/buy/buy.js
  3. 4 4
      pages/index/index.js

+ 1 - 1
pages/appointment/appointment.js

@@ -253,7 +253,7 @@ Page({
         success (res) {
           if (res.confirm) {
             wx.navigateTo({
-              url: '/pages/buy/buy?form=appointment',
+              url: '/pages/buy/buy?from=appointment',
             })
           } else if (res.cancel) {
             wx.navigateTo({

+ 12 - 10
pages/buy/buy.js

@@ -17,16 +17,19 @@ Page({
     orderAmount: '',
     num: '',
     appusername: '',
-    appuserheadimg: ''
+    appuserheadimg: '',
+    from: '' // 从哪个页面进入的页面
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onLoad() {
+  onLoad(options) {
+    console.log(options, 'options');
     this.getGoodsList()
     this.getAccountNmberFn()
     this.setData({
+      from: options.from,
       appusername: app.globalData.userInfo.userName.length > 4 ? app.globalData.userInfo.userName.substring(0,4) : app.globalData.userInfo.userName,
       appuserheadimg: app.globalData.userInfo.headImg
     })
@@ -127,9 +130,13 @@ Page({
             cancelColor: '#666',
             success (modalRes) {
               if (modalRes.confirm) {
-                wx.navigateTo({
-                  url: '/pages/appointment/appointment'
-                })
+                if (that.data.from == 'appointment') {
+                  wx.navigateBack()
+                } else {
+                  wx.navigateTo({
+                    url: '/pages/appointment/appointment?from=buy'
+                  })
+                }
               }
             }
           })
@@ -149,10 +156,5 @@ Page({
         showCancel: false
       })
     })
-  },
-  handleAppointment () {
-    wx.navigateTo({
-      url: '/pages/appointment/appointment',
-    })
   }
 })

+ 4 - 4
pages/index/index.js

@@ -83,12 +83,12 @@ Page({
     switch (type) {
       case 0:
         wx.navigateTo({
-          url: '/pages/buy/buy',
+          url: '/pages/buy/buy?from=index',
         })
       break;
       case 1:
         wx.navigateTo({
-          url: '/pages/appointment/appointment',
+          url: '/pages/appointment/appointment?from=index',
         })
       break;
     }
@@ -117,7 +117,7 @@ Page({
         success (res) {
           if (res.confirm) {
             wx.navigateTo({
-              url: '/pages/buy/buy?form=index',
+              url: '/pages/buy/buy?from=index',
             })
           } else if (res.cancel) {
             wx.navigateTo({
@@ -128,7 +128,7 @@ Page({
       })
     } else {
       wx.navigateTo({
-        url: '/pages/appointment/appointment'
+        url: '/pages/appointment/appointment?from=index'
       })
     }
   },