phone.js 3.2 KB

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