//index.js //获取应用实例 const app = getApp() Page({ data: { items: [ // { top: 20, title: '我的订单', img: '../../images/ico_order.png', page: 'Order' }, { top: 20, title: '我的活动', img: '../../images/ico_actions.png', page: 'Activity' }, { top: 1, title: '联系客服', img: '../../images/service.png', page: 'Transition' } ], sessionId: '' }, goActivity: function (e) { if (this.data.sessionId == undefined || this.data.sessionId.length == 0) { this.goLogin(e); } else { wx.navigateTo({ url: '../activity_list/activity_list' }) } }, goLogin: function (e) { wx.navigateTo({ url: '../login/login' }) }, goOrder: function (e) { if (this.data.sessionId == undefined || this.data.sessionId.length == 0) { this.goLogin(e); } else { wx.navigateTo({ url: '../order/order' }) } }, goTransition: function (e) { wx.makePhoneCall({ phoneNumber: '400-6080100' }) }, onLoad: function () { }, onShow: function(){ this.setData({ sessionId: wx.getStorageSync('sessionId') }) let that = this; wx.request({ url: app.gw.hostUrl + '/mall/wxa/user/baseinfo', data: {}, header: { "Content-Type": "application/json", 'sessionId': wx.getStorageSync('sessionId') }, method: 'GET', dataType: 'json', responseType: 'text', success: function (res) { var data = res.data; var status = data.code; if (status == 666){ wx.removeStorageSync('sessionId') that.setData({ sessionId: null }) return } else if (status != 0) { wx.showToast({ title: data.msg, icon: 'none', duration: 3000 }); return; } that.setData({ items2: res.data.response }) }, fail: function (res) { wx.showToast({ title: '网络异常!err:authlogin', icon: 'none', duration: 2000 }); }, }) 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 }) } }) } }, getUserInfo: function (e) { app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })