//index.js //获取应用实例 const app = getApp() Page({ data: { loaddisplay: 'none', arr: [], indicatorDots: true, autoplay: true, interval: 5000, duration: 2000, userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo') }, hrefPm: function(e) { var index = e.currentTarget.dataset.index; wx.navigateTo({ url: '/pages/promotion/promotionhref?para=' + index }) console.log(index) console.log(e.currentTarget) if (index != null) { if (e.currentTarget.dataset.type == 1) { wx.navigateTo({ url: '/pages/promotion/promotionhref?para=' + index }) } if (e.currentTarget.dataset.type == 2) { wx.navigateTo({ url: index }) } } }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, finish: function() { this.setData({ loaddisplay: 'none' }) }, onLoad: function() { this.setData({ loaddisplay: true }) var that = this wx.request({ url: app.globalData.url + '/getPromotions', method: 'get', success: function(res) { console.log(res.data) that.setData({ arr: res.data }) }, fail() { app.timeOut() } }) if (app.globalData.userInfo) { this.setData({ userInfo: app.globalData.userInfo, hasUserInfo: true }) } else if (this.data.canIUse) { // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userInfoReadyCallback = res => { this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } } else { // 在没有 open-type=getUserInfo 版本的兼容处理 wx.getUserInfo({ success: res => { app.globalData.userInfo = res.userInfo this.setData({ userInfo: res.userInfo, hasUserInfo: true }) }, fail() { app.timeOut() } }) } let _this = this; _this.setData({ navH: app.globalData.navHeight }) }, getUserInfo: function(e) { app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }, onShareAppMessage: function() { return { title: '米粒-近期活动', path: '/pages/index/index?skip=1&path=/pages/promotion/promotion' } } })