//index.js //获取应用实例 const app = getApp() Page({ data: { items:[ { top: 20, title: '我的订单', img:'../../images/order.png',page:'Order'}, { top: 1, title: '我的活动', img: '../../images/addr.png', page:'Activity'}, { top: 1, title: '联系客服', img: '../../images/service.png', page:'Transition'} ], sessionId: '' }, //事件处理函数 bindViewTap: function () { wx.navigateTo({ url: '../logs/logs' }) }, bindFocus: function () { wx.navigateTo({ title: "goback", url: '../jz/jz' }) }, goActivity: function (e) { wx.navigateTo({ url: '../activity_list/activity_list' }) }, goLogin: function (e) { wx.navigateTo({ url: '../login/login' }) }, goOrder: function (e) { wx.navigateTo({ url: '../order/order' }) }, goTransition: function (e) { wx.makePhoneCall({ phoneNumber: '400-6080100' }) }, onLoad: 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 != 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 }); }, complete: function (res) { }, }) 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 }) } })