123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //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'
- }
- }
- })
|