my.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.setData({
  75. name:res.userInfo.nickName,
  76. avatarUrl:res.userInfo.avatarUrl,
  77. pageLogin: true
  78. })
  79. app.globalData.userInfo.login = true
  80. }
  81. },
  82. })
  83. }
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow() {
  89. wx.login({
  90. success (res) {
  91. if (res.code) {
  92. let data = {
  93. code: res.code
  94. }
  95. ittLogin(data).then(res => {
  96. console.log(res,'then login');
  97. })
  98. }
  99. }
  100. })
  101. return
  102. wx.login({
  103. success (res) {
  104. if (res.code) {
  105. //发起网络请求
  106. let data = {
  107. code: res.code
  108. }
  109. itt.postLogin('http://itt.chl6zk.store/api/user/login/v1', data, function (res) {
  110. console.log(res, 'itt my');
  111. })
  112. } else {
  113. console.log('登录失败!' + res.errMsg)
  114. }
  115. }
  116. })
  117. this.setData({
  118. pageLogin: app.globalData.userInfo.login
  119. })
  120. },
  121. // 路由跳转
  122. handleNavTo (e) {
  123. var url = e.currentTarget.dataset.url
  124. this.authNavTo(url)
  125. },
  126. /**
  127. * 路由拦截
  128. * **/
  129. authNavTo (url) {
  130. if (itt.loginAuth()) {
  131. wx.navigateTo({
  132. url: url,
  133. })
  134. } else {
  135. itt.errorToast('请先授权登录')
  136. }
  137. }
  138. })