account.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const loginMsg = require("./login"),
  2. md5 = require("../../../utils/md5"),
  3. _Http = getApp().globalData.http;
  4. Component({
  5. properties: {},
  6. options: {
  7. addGlobalClass: true
  8. },
  9. data: {
  10. accountno: "",
  11. password: "",
  12. inputType: "password", //密码输入框类型
  13. memory: true, //记忆
  14. focus: false,
  15. },
  16. lifetimes: {
  17. attached: function () {
  18. /* 恢复缓存中保存的账号密码 */
  19. this.setData({
  20. ...wx.getStorageSync('loginMsg')
  21. });
  22. this.allowOrNot();
  23. }
  24. },
  25. methods: {
  26. /* input输入 */
  27. inputChange(e) {
  28. this.setData({
  29. [e.target.dataset.name]: e.detail.value.trim()
  30. })
  31. this.allowOrNot()
  32. },
  33. /* 验证是否允许登录 */
  34. allowOrNot() {
  35. getCurrentPages()[0].setData({
  36. disabled: (this.data.accountno.length > 0 && this.data.password.length > 0) ? false : true
  37. })
  38. },
  39. /* 改变密码输入框类型 */
  40. changePasswordType() {
  41. this.setData({
  42. inputType: this.data.inputType == "text" ? 'password' : 'text'
  43. })
  44. },
  45. /* 是否记忆密码 */
  46. isMemory() {
  47. this.setData({
  48. memory: !this.data.memory
  49. })
  50. },
  51. /* 处理登录 */
  52. handleLogin() {
  53. _Http.login({
  54. "accountno": this.data.accountno,
  55. "password": md5.hexMD5(this.data.password),
  56. "systemclient": "wechatsaletool"
  57. }).then(res => {
  58. getCurrentPages()[0].setData({
  59. loading: false
  60. })
  61. if (res.msg != '成功') return wx.showToast({
  62. title: res.msg,
  63. icon: "none"
  64. })
  65. wx.setStorageSync('loginMsg', {
  66. accountno: this.data.accountno,
  67. password: (this.data.memory) ? this.data.password : ''
  68. })
  69. loginMsg.loginMsg(res);
  70. })
  71. }
  72. }
  73. })