join.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. //这里分了cp(企微号)或sms短信配置
  82. util.request(api.CPQrCode, {
  83. mobile: options.mobile,
  84. cp: options.cp ? options.cp : '',
  85. sms: options.sms ? options.sms : ''
  86. }).then(function (res) {
  87. if (res.errno == 0) {
  88. that.setData({
  89. img: res.data
  90. })
  91. } else {
  92. util.showErrorToast(res.errmsg);
  93. }
  94. }).catch(res => {
  95. console.info(res)
  96. util.showErrorToast(res.errMsg);
  97. })
  98. } else if (options.cp) { //根据传的参数 加载二维码
  99. that.setData({
  100. img: 'https://7a68-zhaijieshi-3guecm78383ca692-1307626841.tcb.qcloud.la/wx/qw/' + options.cp + '.png'
  101. })
  102. }
  103. },
  104. showMyQr() {
  105. //如果携带了手机号 不弹出授权框
  106. if (!this.data.mobile) return;
  107. this.setData({
  108. myqr_blur: 8,
  109. myqr_show: true
  110. });
  111. let that = this;
  112. user.login().then(res => {
  113. console.info(res)
  114. that.setData({
  115. code: res.code
  116. })
  117. })
  118. },
  119. goCloseMyqr: function () { //关闭分享图片的弹层
  120. this.setData({
  121. myqr_blur: 0,
  122. myqr_show: false
  123. });
  124. },
  125. qrtouchstart: function () {
  126. this.setData({
  127. myqr_blur: 0,
  128. myqr_show: false
  129. });
  130. },
  131. /**
  132. * 生命周期函数--监听页面初次渲染完成
  133. */
  134. onReady: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面显示
  138. */
  139. onShow: function () {
  140. wx.hideHomeButton();
  141. console.info(app.globalData.hasLogin);
  142. if (!app.globalData.hasLogin) {
  143. this.showMyQr();
  144. } else {
  145. this.goCloseMyqr();
  146. }
  147. },
  148. /**
  149. * 生命周期函数--监听页面隐藏
  150. */
  151. onHide: function () {
  152. },
  153. /**
  154. * 生命周期函数--监听页面卸载
  155. */
  156. onUnload: function () {
  157. },
  158. /**
  159. * 页面相关事件处理函数--监听用户下拉动作
  160. */
  161. onPullDownRefresh: function () {
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom: function () {
  167. },
  168. /**
  169. * 用户点击右上角分享
  170. */
  171. onShareAppMessage: function () {
  172. }
  173. })