You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 rivejä
4.0 KiB

  1. const app = getApp()
  2. const config = require("../../config/config")
  3. const Http = require("../../utils/HttpBasics.js")
  4. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. imgHttps: app.globalData.imgHttps,
  9. userData: "",
  10. userPhone: "",
  11. showBindPhone: false,//绑定手机号边框
  12. Num: 60,
  13. NumFlag: false,
  14. code: ""//验证码
  15. },
  16. showBox() {
  17. this.setData({
  18. showBindPhone: true
  19. })
  20. },
  21. hideBox() {
  22. this.setData({
  23. showBindPhone: false
  24. })
  25. },
  26. setUserPhone(e) {
  27. let value = e.detail.value
  28. this.setData({
  29. userPhone: value
  30. })
  31. },
  32. setCodePhone(e) {
  33. let value = e.detail.value
  34. this.setData({
  35. code: value
  36. })
  37. },
  38. getCode() {//获取验证码
  39. console.log(this.data.userPhone);
  40. let myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
  41. if (!myreg.test(this.data.userPhone)) {
  42. tt.showToast({
  43. title: '请输入正确的手机号',
  44. icon: "none"
  45. });
  46. return
  47. }
  48. Http.get({
  49. url: config.api.getCodePhone,
  50. data: {
  51. phone: this.data.userPhone
  52. }
  53. }).then(res => {
  54. this.setData({
  55. NumFlag: true
  56. })
  57. let tiem = setInterval(() => {
  58. console.log(this.data.Num)
  59. this.setData({
  60. Num: this.data.Num - 1
  61. })
  62. if (this.data.Num <= 1) {
  63. clearInterval(tiem)
  64. this.setData({
  65. NumFlag: false
  66. })
  67. }
  68. }, 1000)
  69. tt.showToast({
  70. title: '发送成功',
  71. icon: "none"
  72. });
  73. }).catch(err => {
  74. tt.showToast({
  75. title: err.message ? err.message : err.data,
  76. icon: "none"
  77. });
  78. })
  79. },
  80. getUserData() {//获取用户信息
  81. Http.get({
  82. url:config.api.getUserInfo
  83. }).then(res=>{
  84. if(res.data.phone){
  85. this.setData({
  86. userPhone:res.data.phone
  87. })
  88. }
  89. }).catch(err=>{
  90. tt.showToast({
  91. title: err.message ? err.message : err.data,
  92. icon: "none"
  93. });
  94. })
  95. },
  96. onLoad: function () {
  97. console.log(123);
  98. this.getUserData()
  99. let _this = this
  100. tt.login({
  101. success(_res) {
  102. let { code } = _res
  103. Http.post({
  104. url: config.api.login,
  105. data: {
  106. code: code,
  107. appId: 'tt8183f73e1ebb053701'
  108. }
  109. }).then(res => {
  110. Http.setToken(res.data.token);
  111. app.globalData.token = res.data.token
  112. tt.getUserInfo({// 获取用户信息
  113. withCredentials: true,
  114. // withRealNameAuthenticationInfo: true,
  115. success(res) {
  116. console.log(res);
  117. _this.setData({
  118. userData: res.userInfo
  119. })
  120. Http.get({
  121. url: config.api.checkUserInfo
  122. }).then(res => {
  123. }).catch(err => {
  124. console.log("我没提交授权", err.code);
  125. if (err.code == 11004) {
  126. Http.post({
  127. url: config.api.userInfo,
  128. data: {
  129. iv: res.iv,
  130. encryptedData: res.encryptedData
  131. }
  132. }).then(res => {
  133. console.log(res);
  134. })
  135. }
  136. })
  137. },
  138. fail(res) {
  139. tt.navigateTo({
  140. url: 'pages/index/index' // 指定页面的url
  141. });
  142. },
  143. });
  144. }).catch(err => {
  145. console.log(err);
  146. tt.showModal({
  147. title: '提示',
  148. showCancel: false,
  149. content: '登录失败,请重新尝试',
  150. success: (res) => {
  151. if (res.cancel) {
  152. //点击取消,默认隐藏弹框
  153. } else {
  154. //点击确定
  155. wx.reLaunch({
  156. url: '/pages/index/index',
  157. })
  158. }
  159. }
  160. });
  161. })
  162. },
  163. });
  164. }
  165. })