微信小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

login.js 3.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. },
  17. //自动登录
  18. automaticLogin(){
  19. let automatic = STORAGE.getToken();
  20. let getOpenId = STORAGE.getOpenId();
  21. if(automatic == '' && getOpenId ==''){
  22. console.log();
  23. UTIL.getCOdeFromWX({
  24. complate: (code) => {
  25. let sendData = {
  26. code: code
  27. }
  28. UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
  29. success: (res) => {
  30. if (res.code == API.SUCCESS_CODE) {
  31. wx.navigateTo({
  32. url: '/pages/index/index',
  33. })
  34. }
  35. }
  36. })
  37. }
  38. });
  39. }else{
  40. // wx.navigateTo({
  41. // url: '/pages/index/index',
  42. // })
  43. }
  44. },
  45. //用户隐私协议选项
  46. checkboxChange: function(res) {
  47. let checkStatus = false;
  48. if(res.detail.value.length!=0){
  49. checkStatus = true;
  50. }else{
  51. checkStatus = false;
  52. }
  53. this.setData({
  54. privacyCheck:checkStatus
  55. })
  56. },
  57. //微信一键登录授权
  58. getPhoneNumber: function(res) {
  59. let that = this;
  60. let {
  61. detail
  62. } = res;
  63. if (!detail.encryptedData) {
  64. //允许授权
  65. APP.showToast("未获取到手机号码,注册失败!");
  66. return;
  67. }else if(this.data.privacyCheck == false){
  68. APP.showToast("请阅读并同意用户协议和隐私政策!");
  69. return;
  70. }
  71. let sendData = {
  72. sessionKey:STORAGE.getSessionKey(),
  73. iv:detail.iv,
  74. encryptedData:detail.encryptedData
  75. }
  76. UTIL.httpRequest(API.URL_POST_DECRYPTEDWXDATA, sendData,{
  77. success: (res) => {
  78. if (res.code == API.SUCCESS_CODE) {
  79. let phoneNumber = res.data.phoneNumber;
  80. //微信手机号码绑定
  81. that.wxUserBand(phoneNumber)
  82. // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  83. } else {
  84. //待删
  85. UTIL.showToastNoneIcon(res.msg)
  86. }
  87. },
  88. fail: (res) => {
  89. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  90. }
  91. });
  92. },
  93. wxUserBand(phone){
  94. let sendData = {
  95. openId:STORAGE.getOpenId(),
  96. phonenumber:phone
  97. }
  98. UTIL.httpRequest(API.URL_POST_USERBAND, sendData,{
  99. success: (res) => {
  100. if (res.code == API.SUCCESS_CODE) {
  101. wx.navigateTo({
  102. url: '/pages/index/index',
  103. })
  104. }else{
  105. UTIL.showToastNoneIcon(res.msg)
  106. }
  107. },
  108. fail: (res) => {
  109. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  110. }
  111. });
  112. console.log(sendData)
  113. //
  114. }
  115. })