join.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. var api = require('../../../config/api.js');
  2. var util = require('../../../utils/util.js');
  3. var user = require('../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. img: '',
  11. myqr_blur: 0, //背景模糊值
  12. myqr_show: true,
  13. authImg: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/sq.png',
  14. authBtn: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/sq-btn.png',
  15. code: ""
  16. },
  17. getPhoneNumber: function (e) {
  18. var ivObj = e.detail.iv
  19. var telObj = e.detail.encryptedData
  20. var that = this;
  21. let r_userid = r_userid = 0;
  22. console.log("请求授权登录:code:" + that.data.code + "encryptedData," + telObj + "iv," + ivObj + 'r_userid,' + r_userid);
  23. //------执行Login---------
  24. util.request(api.AuthRegister, {
  25. code: that.data.code,
  26. encryptedData: telObj,
  27. iv: ivObj,
  28. r_userid: r_userid
  29. }).then(function (res) {
  30. if (res.errno === 0) {
  31. //存储用户信息
  32. app.globalData.hasLogin = true;
  33. app.globalData.userInfo = res.data.userInfo;
  34. wx.setStorageSync('userInfo', res.data.userInfo);
  35. wx.setStorageSync('token', res.data.token);
  36. wx.showToast({
  37. title: '授权注册成功',
  38. icon: 'success',
  39. duration: 2000,
  40. complete: function () {
  41. setTimeout(function () {
  42. that.goCloseMyqr();
  43. }, 2000);
  44. }
  45. })
  46. } else {
  47. console.info(res);
  48. wx.showToast({
  49. title: '授权失败请重试',
  50. icon: 'error',
  51. duration: 3000
  52. });
  53. }
  54. });
  55. //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面
  56. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝
  57. wx.showModal({
  58. title: '警告',
  59. content: '您点击了拒绝授权,部分功能无法使用!!!',
  60. showCancel: false,
  61. confirmText: '确定',
  62. success: function (res) {
  63. that.goCloseMyqr();
  64. }
  65. })
  66. }
  67. },
  68. /**
  69. * 生命周期函数--监听页面加载
  70. */
  71. onLoad: function (options) {
  72. let that = this;
  73. //这里写个兼容
  74. //老的只有cp参数 新接口 加入客户手机mobile
  75. console.info(options.mobile)
  76. if (options.mobile&&options.mobile.length==11) {
  77. util.request(api.CPQrCode, {
  78. mobile: options.mobile,
  79. cp: options.cp
  80. }).then(function (res) {
  81. if (res.errno == 0) {
  82. that.setData({
  83. img: res.data
  84. })
  85. } else {
  86. util.showErrorToast(res.errmsg);
  87. }
  88. }).catch(res => {
  89. console.info(res)
  90. util.showErrorToast(res.errMsg);
  91. })
  92. } else if (options.cp) { //根据传的参数 加载二维码
  93. that.setData({
  94. img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/' + options.cp + '.png'
  95. })
  96. }
  97. },
  98. showMyQr() {
  99. this.setData({
  100. myqr_blur: 8,
  101. myqr_show: true
  102. });
  103. },
  104. goCloseMyqr: function () { //关闭分享图片的弹层
  105. this.setData({
  106. myqr_blur: 0,
  107. myqr_show: false
  108. });
  109. },
  110. qrtouchstart: function () {
  111. this.setData({
  112. myqr_blur: 0,
  113. myqr_show: false
  114. });
  115. },
  116. /**
  117. * 生命周期函数--监听页面初次渲染完成
  118. */
  119. onReady: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面显示
  123. */
  124. onShow: function () {
  125. wx.hideHomeButton();
  126. console.info(app.globalData.hasLogin);
  127. if (!app.globalData.hasLogin) {
  128. this.showMyQr();
  129. let that = this;
  130. user.login().then(res => {
  131. console.info(res)
  132. that.setData({
  133. code: res.code
  134. })
  135. })
  136. }else{
  137. this.goCloseMyqr();
  138. }
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })