Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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