join.js 4.4 KB

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