Explorar el Código

始宁农业小程序:轮播跳转

panyong hace 2 años
padre
commit
6e8b5c5c65

+ 11 - 3
htmldev/shiningWxMini/pages/home/home.js

@@ -1,6 +1,7 @@
 const pages = require('../../mixin/pages')
 const { getProductCategoryList } = require('../../api/common')
 const { getLunboList } = require('./api/index')
+const app = getApp()
 let leftHeight = 0
 let rightHeight = 0
 let query = null
@@ -206,6 +207,7 @@ Page({
     })
   },
   handleSwiperClick(e) {
+    const isTab = app.globalData.tabBarList.map(item => item.pagePath)
     const { item } = e.currentTarget.dataset
     if (Object.prototype.toString.call(item) === '[object Object]') {
       const { lunbo_link_url } = item
@@ -214,9 +216,15 @@ Page({
           url: '/pages/h5/h5?url=' + lunbo_link_url
         })
       } else if (/^\/pages/.test(lunbo_link_url)) {
-        wx.navigateTo({
-          url: lunbo_link_url
-        })
+        if (isTab.findIndex(item => lunbo_link_url.indexOf(item) > -1) > -1) {
+          wx.switchTab({
+            url: lunbo_link_url
+          })
+        } else {
+          wx.navigateTo({
+            url: lunbo_link_url
+          })
+        }
       }
     }
   },

+ 2 - 2
htmldev/shiningWxMini/pages/home/home.wxml

@@ -26,7 +26,7 @@
       indicator-color="rgba(151, 209, 79, 1)"
       indicator-active-color="#FFF"
       autoplay="{{false}}">
-      <block wx:for="{{lunbos}}" wx:key="*this">
+      <block wx:for="{{lunbos}}" wx:key="lunbo_img_url">
         <swiper-item
           data-item="{{item}}"
           bind:tap="handleSwiperClick">
@@ -47,7 +47,7 @@
       interval="{{2000}}"
       circular="{{true}}"
       autoplay="{{true}}">
-      <block wx:for="{{txtlist}}" wx:key="*this">
+      <block wx:for="{{txtlist}}" wx:key="index">
         <swiper-item>
           <view class="swiper-item {{item}}">{{item}}</view>
         </swiper-item>

+ 1 - 1
htmldev/shiningWxMini/pages/login/login.js

@@ -45,7 +45,7 @@ Page({
   onUnload() {
   },
   async getPhoneNumber(e) {
-    const isTab = ['pages/home/home', 'pages/partner/partner', 'pages/news/news', 'pages/mine/mine']
+    const isTab = app.globalData.tabBarList.map(item => item.pagePath)
     const { errMsg, encryptedData, iv } = e.detail
     if (errMsg === 'getPhoneNumber:ok') {
       this.setData({