index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import {
  2. ApiModel
  3. } from "../../utils/api"
  4. const _Http = new ApiModel;
  5. var utilMd5 = require('../../utils/md5');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. pageType: 0, //页面类型,0登录,1新账号注册,2多账号
  12. userTelephone: 13732579910, //电话号
  13. securityCode: 123456, //验证码
  14. userList: [], //多账户用户列表
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. },
  21. /* 赋值号码 */
  22. inputTelephone(e) {
  23. /* 验证号码 */
  24. this.setData({
  25. userTelephone: e.detail.value
  26. })
  27. },
  28. /* 验证手机号 */
  29. verifyTelephone(value) {
  30. const regMobile = /^(0|86\17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
  31. if (!regMobile.test(value)) {
  32. wx.showToast({
  33. title: '请输入正确手机号码',
  34. icon: 'none',
  35. duration: 2000 //持续的时间
  36. })
  37. }
  38. return regMobile.test(value);
  39. },
  40. /* 获取验证码 */
  41. getSecurityCode(e) {
  42. /* 验证号码 */
  43. if (!this.verifyTelephone(this.data.userTelephone)) return;
  44. /* 发送请求 */
  45. _Http.getPassword({
  46. "phonenumber": this.data.userTelephone
  47. }).then(s => {
  48. console.log(s)
  49. })
  50. },
  51. /* 验证码赋值 */
  52. inputVerify(e) {
  53. if (e.detail.value == "") return console.log("验证码错误")
  54. this.data.securityCode = e.detail.value
  55. },
  56. /* 登录 */
  57. login() {
  58. /* 验证号码 */
  59. if (!this.verifyTelephone(this.data.userTelephone)) return;
  60. _Http.login({
  61. "phonenumber": this.data.userTelephone,
  62. "password": utilMd5.hexMD5(this.data.securityCode)
  63. }).then(s => {
  64. console.log(s)
  65. if (s.msg != "成功") return wx.showToast({
  66. title: s.msg,
  67. icon: 'none',
  68. duration: 2000 //持续的时间
  69. })
  70. getApp().globalData.accountList = s.account_list;
  71. if (s.account_list.length >= 2) {
  72. console.log("多账号")
  73. this.setData({
  74. pageType: 2,
  75. userList: s.account_list
  76. })
  77. } else if (s.account_list[0].isnewregister == 1) {
  78. console.log("新账号")
  79. wx.setStorageSync('token', s.account_list[0].token);
  80. this.setData({
  81. pageType: 1
  82. })
  83. } else {
  84. console.log("单账号")
  85. wx.setStorageSync('token', s.account_list[0].token);
  86. wx.reLaunch({
  87. url: "/pages/tabbarPage/Home/index"
  88. })
  89. }
  90. })
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload: function () {
  111. },
  112. /**
  113. * 页面相关事件处理函数--监听用户下拉动作
  114. */
  115. onPullDownRefresh: function () {
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. onReachBottom: function () {
  121. },
  122. /**
  123. * 用户点击右上角分享
  124. */
  125. onShareAppMessage: function () {
  126. }
  127. })