微信小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
3 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // pages/index/index.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. import * as STORAGE from '../../../utils/storage'
  5. const APP = getApp();
  6. Page({
  7. data: {
  8. isIPhoneX:false,
  9. privacyCheck:true, //用户协议
  10. },
  11. onLoad: function (options) {
  12. this.setData({
  13. isIPhoneX:UTIL.isIPhoneX()
  14. })
  15. this.automaticLogin()
  16. //this.getUserInfo()
  17. //this.getPhoneNumber()
  18. },
  19. //自动登录
  20. automaticLogin(){
  21. let automatic = STORAGE.getToken();
  22. let getOpenId = STORAGE.getOpenId();
  23. if(automatic == '' && getOpenId ==''){
  24. console.log(1);
  25. UTIL.getCOdeFromWX({
  26. complate: (code) => {
  27. let sendData = {
  28. code: code
  29. }
  30. UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
  31. success: (res) => {
  32. console.log(res);
  33. if (res.code == API.SUCCESS_CODE) {
  34. wx.navigateTo({
  35. url: '/pages/index/index',
  36. })
  37. } else{
  38. this.getPhoneNumber()
  39. }
  40. }
  41. })
  42. }
  43. });
  44. }else{
  45. // wx.navigateTo({
  46. // url: '/pages/index/index',
  47. // })
  48. }
  49. },
  50. //用户隐私协议选项
  51. checkboxChange: function(res) {
  52. let checkStatus = false;
  53. if(res.detail.value.length!=0){
  54. checkStatus = true;
  55. }else{
  56. checkStatus = false;
  57. }
  58. this.setData({
  59. privacyCheck:checkStatus
  60. })
  61. },
  62. /* 获取用户信息*/
  63. getUserInfo(){
  64. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  65. success: (res) => {
  66. if (res.code == API.SUCCESS_CODE) {
  67. this.setData({userInfoObj:res.user})
  68. }
  69. }
  70. })
  71. },
  72. //微信一键登录授权
  73. getPhoneNumber: function(res) {
  74. let that = this;
  75. let {
  76. detail
  77. } = res;
  78. if (!detail.encryptedData) {
  79. //允许授权
  80. APP.showToast("未获取到手机号码,注册失败!");
  81. return;
  82. }else if(this.data.privacyCheck == false){
  83. APP.showToast("请阅读并同意用户协议和隐私政策!");
  84. return;
  85. }
  86. let sendData = {
  87. sessionKey:STORAGE.getSessionKey(),
  88. iv:detail.iv,
  89. encryptedData:detail.encryptedData
  90. }
  91. UTIL.httpRequestNoneDetal(API.URL_POST_DECRYPTEDWXDATA, sendData, "POST", {
  92. success: (res) => {
  93. console.log(res)
  94. if (res.code == API.SUCCESS_CODE) {
  95. let phoneNumber = res.data.phoneNumber;
  96. //微信手机号码绑定
  97. that.wxUserBand(phoneNumber)
  98. // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  99. } else {
  100. //待删
  101. UTIL.showToastNoneIcon(res.msg)
  102. }
  103. },
  104. fail: (res) => {
  105. console.log("fail");
  106. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  107. }
  108. })
  109. // UTIL.httpRequest(API.URL_POST_DECRYPTEDWXDATA, sendData,{
  110. // success: (res) => {
  111. // console.log(res);
  112. // // if (res.code == API.SUCCESS_CODE) {
  113. // // let phoneNumber = res.data.phoneNumber;
  114. // // //微信手机号码绑定
  115. // // that.wxUserBand(phoneNumber)
  116. // // // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  117. // // } else {
  118. // // //待删
  119. // // UTIL.showToastNoneIcon(res.msg)
  120. // // }
  121. // },
  122. // fail: (res) => {
  123. // console.log("fail");
  124. // UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  125. // }
  126. // });
  127. },
  128. wxUserBand(phone){
  129. let sendData = {
  130. openId:STORAGE.getOpenId(),
  131. phonenumber:phone
  132. }
  133. console.log(STORAGE.getOpenId());
  134. UTIL.httpRequestNoneDetal(API.URL_POST_USERBAND, sendData,"POST",{
  135. success: (res) => {
  136. if (res.code == API.SUCCESS_CODE) {
  137. wx.navigateTo({
  138. url: '/pages/index/index',
  139. })
  140. }else{
  141. UTIL.showToastNoneIcon(res.msg)
  142. }
  143. },
  144. fail: (res) => {
  145. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  146. }
  147. });
  148. //
  149. }
  150. })