// pages/my/my.js import itt from '../../utils/util' import { ittLogin } from '../../api/app' const app = getApp() Page({ /** * 页面的初始数据 */ data: { pageLogin: false, name: '点击授权登录', avatarUrl: '', count: 0, gridList: [ { id: 0, title: '我的地址', url: '/pages/address/address?form=my&back=0', imgUrl: '../../imaes/dizhi@2x.png' }, { id: 1, title: '我的档案', url: '/pages/myFile/myFile?form=my', imgUrl: '../../imaes/dangan@2x.png' }, { id: 2, title: '我的预约', url: '/pages/myAppointment/myAppointment?form=my', imgUrl: '../../imaes/yuyue@2x.png' }, { id: 3, title: '我的记录', url: '/pages/myRecord/myRecord?form=my', imgUrl: '../../imaes/jilu@2x.png' }, { id: 4, title: '我的报告', url: '/pages/report/report?form=my', imgUrl: '../../imaes/baogao2@2x.png' }, { id: 5, title: '开通区域', url: '/pages/openArea/openArea?form=my', imgUrl: '../../imaes/quyu@2x.png' }, { id: 6, title: '设置', url: '/pages/set/set?form=my', imgUrl: '../../imaes/shezhi@2x.png' } ] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 获取用户信息 */ getUserProfile() { if (this.data.avatarUrl == '') { var that = this; wx.getUserProfile({ desc:"授权信息", success:function(res){ if(res.userInfo){ that.loginFn(res.userInfo) } }, }) } }, loginFn (userInfo) { var that = this wx.login({ success (res) { if (res.code) { console.log(res.code, 'code'); let data = { code: res.code } ittLogin(data).then(res => { console.log(res,'then login'); app.globalData.userInfo.login = true that.setData({ name: userInfo.nickName, avatarUrl: userInfo.avatarUrl, pageLogin: true }) }) } } }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ pageLogin: app.globalData.userInfo.login }) }, // 路由跳转 handleNavTo (e) { var url = e.currentTarget.dataset.url wx.navigateTo({ url: url, }) // this.authNavTo(url) }, /** * 路由拦截 * **/ authNavTo (url) { if (itt.loginAuth()) { wx.navigateTo({ url: url, }) } else { itt.errorToast('请先授权登录') } } })