mine.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. const url = require('../../utils/url.js')
  2. var call = require("../../utils/net.js")
  3. var app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. avatarUrl: '',
  10. nickName: '',
  11. showContact: false
  12. },
  13. //登录/注册
  14. bindGetUserInfo(e) {
  15. console.log(e)
  16. // app.globalData.userInfo = e.detail.userInfo
  17. if (e.detail.errMsg == 'getUserInfo:ok') {
  18. this.setData({
  19. avatarUrl: e.detail.userInfo.avatarUrl,
  20. nickName: e.detail.userInfo.nickName
  21. })
  22. let reqData = {
  23. 'signature': e.detail.signature,
  24. 'rawData': e.detail.rawData
  25. }
  26. wx.login({
  27. success(res) {
  28. if (res.code) {
  29. let code = res.code
  30. reqData['code'] = code
  31. call.request(url.host + url.login,
  32. { code: res.code},
  33. res => {
  34. //console.log(res.data)
  35. wx.setStorageSync('userId', res.data.data); //将userIdEnc存入本地缓存
  36. if(res.data.code==200){
  37. call.request(url.host + url.getuserinfo,
  38. reqData,
  39. res => {
  40. console.log(res)
  41. },
  42. res => {
  43. console.log(res)
  44. })
  45. }else{
  46. wx.showToast({
  47. icon: 'none',
  48. title: res.data.msg,
  49. })
  50. }
  51. },
  52. res => {
  53. console.log(res)
  54. })
  55. } else {
  56. console.log('登录失败!' + res.errMsg)
  57. }
  58. }
  59. })
  60. } else if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
  61. wx.showToast({
  62. icon: 'none',
  63. title: '授权失败!',
  64. })
  65. }
  66. },
  67. //获取手机号
  68. getPhoneNumber(e) {
  69. //console.log(e)
  70. let iv = e.detail.iv
  71. let encryptedData = e.detail.encryptedData
  72. let reqData = {
  73. 'iv': iv,
  74. 'encryptedData': encryptedData
  75. }
  76. wx.login({
  77. success(res) {
  78. if (res.code) {
  79. let code = res.code
  80. reqData['code'] = code
  81. call.request(url.host + url.login,
  82. { code: res.code },
  83. res => {
  84. //console.log(res)
  85. if (res.data.code == 200) {
  86. call.request(url.host + url.getPhone,
  87. reqData,
  88. res => {
  89. console.log(res)
  90. },
  91. res => {
  92. console.log(res)
  93. })
  94. } else {
  95. wx.showToast({
  96. icon: 'none',
  97. title: res.data.msg,
  98. })
  99. }
  100. },
  101. res => {
  102. console.log(res)
  103. })
  104. } else {
  105. console.log('登录失败!' + res.errMsg)
  106. }
  107. }
  108. })
  109. },
  110. /**
  111. * 生命周期函数--监听页面加载
  112. */
  113. onLoad: function (options) {
  114. var that = this;
  115. },
  116. /**
  117. * 生命周期函数--监听页面初次渲染完成
  118. */
  119. onReady: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面显示
  123. */
  124. onShow: function () {
  125. var that = this;
  126. if (typeof this.getTabBar === 'function' &&
  127. this.getTabBar()) {
  128. this.getTabBar().setData({
  129. selected: 1
  130. })
  131. }
  132. //查看是否授权
  133. wx.getSetting({
  134. success(res) {
  135. if (res.authSetting['scope.userInfo']) {
  136. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  137. wx.getUserInfo({
  138. success: function (res) {
  139. //console.log(res.userInfo)
  140. that.setData({
  141. avatarUrl: res.userInfo.avatarUrl,
  142. nickName: res.userInfo.nickName
  143. })
  144. }
  145. })
  146. }
  147. }
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面隐藏
  152. */
  153. onHide: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面卸载
  157. */
  158. onUnload: function () {
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function () {
  164. },
  165. /**
  166. * 页面上拉触底事件的处理函数
  167. */
  168. onReachBottom: function () {
  169. },
  170. /**
  171. * 用户点击右上角分享
  172. */
  173. onShareAppMessage: function () {
  174. },
  175. //咨询客服
  176. call: function () {
  177. this.setData({
  178. showContact: true
  179. })
  180. },
  181. })