phone.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. focus: false,
  15. memory: true, //记忆
  16. disabled: true, //是否禁用
  17. loading: false, //登陆中
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. /* 恢复缓存中保存的账号密码 */
  24. this.setData({
  25. ...wx.getStorageSync('loginMsg')
  26. })
  27. /* 验证登录条件 */
  28. this.allowOrNot()
  29. },
  30. /* 微信登录 */
  31. wechatLogin() {
  32. if (!this.data.isAgree) return Toast({
  33. message: '请阅读并勾选用户协议',
  34. position: 'bottom'
  35. });
  36. wx.login({
  37. success(res) {
  38. if (res.code) {
  39. _Http.loginbywechat({
  40. wechat_code: res.code,
  41. "systemclient": "wechatsaletool"
  42. }).then(res => {
  43. if (res.code == 0) return wx.showToast({
  44. title: res.msg,
  45. icon: "none"
  46. })
  47. loginMsg.loginMsg(res);
  48. })
  49. } else {
  50. console.log('登录失败!' + res.errMsg)
  51. }
  52. }
  53. })
  54. },
  55. /* 用户登录 */
  56. userLogin() {
  57. if (this.data.loading || this.data.disabled) return;
  58. if (!this.data.isAgree) return Toast({
  59. message: '请阅读并勾选用户协议',
  60. position: 'bottom'
  61. });
  62. this.setData({
  63. loading: true
  64. })
  65. _Http.login({
  66. "accountno": this.data.accountno,
  67. "password": md5.hexMD5(this.data.password),
  68. "systemclient": "wechatsaletool"
  69. }).then(res => {
  70. this.setData({
  71. loading: false
  72. })
  73. if (res.msg != '成功') return wx.showToast({
  74. title: res.msg,
  75. icon: "none"
  76. })
  77. wx.setStorageSync('loginMsg', {
  78. accountno: this.data.accountno,
  79. password: (this.data.memory) ? this.data.password : ''
  80. })
  81. loginMsg.loginMsg(res);
  82. })
  83. },
  84. /* 改变密码输入框类型 */
  85. changePasswordType() {
  86. this.setData({
  87. inputType: this.data.inputType == "text" ? 'password' : 'text'
  88. })
  89. },
  90. /* 授权 */
  91. agreementChange({
  92. detail
  93. }) {
  94. this.setData({
  95. isAgree: detail
  96. })
  97. },
  98. /* 手机号 */
  99. inputPhone(e) {
  100. this.setData({
  101. accountno: e.detail.value.trim()
  102. })
  103. this.allowOrNot()
  104. },
  105. /* 密码 */
  106. inputPassword(e) {
  107. this.setData({
  108. password: e.detail.value.trim()
  109. })
  110. this.allowOrNot()
  111. },
  112. /* 验证是否允许登录 */
  113. allowOrNot() {
  114. this.setData({
  115. disabled: (this.data.accountno.length > 0 && this.data.password.length > 5) ? false : true
  116. })
  117. },
  118. /* 是否记忆密码 */
  119. isMemory() {
  120. this.setData({
  121. memory: !this.data.memory
  122. })
  123. },
  124. })