phone.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import Toast from '@vant/weapp/toast/toast';
  2. const _Http = getApp().globalData.http;
  3. const md5 = require("../../utils/md5");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isAgree: true,
  10. phoneNumber: "",
  11. password: "",
  12. inputType: "password", //密码输入框类型
  13. memory: true, //记忆
  14. disabled: true, //是否禁用
  15. loading: false, //登陆中
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. this.setData({
  22. ...wx.getStorageSync('loginMsg')
  23. })
  24. this.allowOrNot()
  25. },
  26. /* 用户登录 */
  27. userLogin() {
  28. if (this.data.loading || this.data.disabled) return;
  29. if (!this.data.isAgree) return Toast({
  30. message: '请阅读并勾选用户协议',
  31. position: 'bottom'
  32. });
  33. this.setData({
  34. loading: true
  35. })
  36. /* "accountno": this.data.phoneNumber,
  37. "password": md5.hexMD5(this.data.password), */
  38. _Http.login({
  39. "accountno": "test",
  40. "password": "e10adc3949ba59abbe56e057f20f883e",
  41. "systemclient": "wechatapp"
  42. }).then(res => {
  43. console.log("登录", res)
  44. this.setData({
  45. loading: false
  46. })
  47. if (res.msg != '成功') return wx.showToast({
  48. title: res.msg,
  49. icon: "none"
  50. })
  51. wx.setStorageSync('account_list', res.account_list)
  52. wx.setStorageSync('loginMsg', {
  53. phoneNumber: this.data.phoneNumber,
  54. password: (this.data.memory) ? this.data.password : ''
  55. })
  56. wx.switchTab({
  57. url: '/pages/tabbar/home/index'
  58. })
  59. })
  60. },
  61. /* 改变密码输入框类型 */
  62. changePasswordType() {
  63. this.setData({
  64. inputType: this.data.inputType == "text" ? 'password' : 'text'
  65. })
  66. },
  67. /* 授权 */
  68. agreementChange({
  69. detail
  70. }) {
  71. this.setData({
  72. isAgree: detail
  73. })
  74. },
  75. /* 手机号 */
  76. inputPhone(e) {
  77. this.setData({
  78. phoneNumber: e.detail.value.trim()
  79. })
  80. this.allowOrNot()
  81. },
  82. /* 密码 */
  83. inputPassword(e) {
  84. this.setData({
  85. password: e.detail.value.trim()
  86. })
  87. this.allowOrNot()
  88. },
  89. /* 验证是否允许登录 */
  90. allowOrNot() {
  91. this.setData({
  92. disabled: (this.data.phoneNumber.length == 11 && this.data.password.length >= 6) ? false : true
  93. })
  94. },
  95. /* 是否记忆密码 */
  96. isMemory() {
  97. this.setData({
  98. memory: !this.data.memory
  99. })
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady() {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload() {
  120. },
  121. /**
  122. * 页面相关事件处理函数--监听用户下拉动作
  123. */
  124. onPullDownRefresh() {
  125. },
  126. /**
  127. * 页面上拉触底事件的处理函数
  128. */
  129. onReachBottom() {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage() {
  135. }
  136. })