join.js 5.5 KB

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