my.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // pages/my/my.js
  2. import itt from '../../utils/util'
  3. import { ittLogin } from '../../api/app'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. pageLogin: false,
  11. name: '点击授权登录',
  12. avatarUrl: '',
  13. count: 0,
  14. gridList: [
  15. {
  16. id: 0,
  17. title: '我的地址',
  18. url: '/pages/address/address?form=my&back=0',
  19. imgUrl: '../../imaes/dizhi@2x.png'
  20. },
  21. {
  22. id: 1,
  23. title: '我的档案',
  24. url: '/pages/myFile/myFile?form=my',
  25. imgUrl: '../../imaes/dangan@2x.png'
  26. },
  27. {
  28. id: 2,
  29. title: '我的预约',
  30. url: '/pages/myAppointment/myAppointment?form=my',
  31. imgUrl: '../../imaes/yuyue@2x.png'
  32. },
  33. {
  34. id: 3,
  35. title: '我的记录',
  36. url: '/pages/myRecord/myRecord?form=my',
  37. imgUrl: '../../imaes/jilu@2x.png'
  38. },
  39. {
  40. id: 4,
  41. title: '我的报告',
  42. url: '/pages/report/report?form=my',
  43. imgUrl: '../../imaes/baogao2@2x.png'
  44. },
  45. {
  46. id: 5,
  47. title: '开通区域',
  48. url: '/pages/openArea/openArea?form=my',
  49. imgUrl: '../../imaes/quyu@2x.png'
  50. },
  51. {
  52. id: 6,
  53. title: '设置',
  54. url: '/pages/set/set?form=my',
  55. imgUrl: '../../imaes/shezhi@2x.png'
  56. }
  57. ]
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad(options) {
  63. },
  64. /**
  65. * 获取用户信息
  66. */
  67. getUserProfile() {
  68. if (this.data.avatarUrl == '') {
  69. var that = this;
  70. wx.getUserProfile({
  71. desc:"授权信息",
  72. success:function(res){
  73. if(res.userInfo){
  74. that.loginFn(res.userInfo)
  75. }
  76. },
  77. })
  78. }
  79. },
  80. loginFn (userInfo) {
  81. var that = this
  82. wx.login({
  83. success (res) {
  84. if (res.code) {
  85. let data = {
  86. code: res.code
  87. }
  88. ittLogin(data).then(res => {
  89. console.log(res,'then login');
  90. app.globalData.userInfo.login = true
  91. that.setData({
  92. name: userInfo.nickName,
  93. avatarUrl: userInfo.avatarUrl,
  94. pageLogin: true
  95. })
  96. })
  97. }
  98. }
  99. })
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow() {
  105. this.setData({
  106. pageLogin: app.globalData.userInfo.login
  107. })
  108. },
  109. // 路由跳转
  110. handleNavTo (e) {
  111. var url = e.currentTarget.dataset.url
  112. this.authNavTo(url)
  113. },
  114. /**
  115. * 路由拦截
  116. * **/
  117. authNavTo (url) {
  118. if (itt.loginAuth()) {
  119. wx.navigateTo({
  120. url: url,
  121. })
  122. } else {
  123. itt.errorToast('请先授权登录')
  124. }
  125. }
  126. })