account.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. setTimeout(() => {
  23. this.allowOrNot();
  24. }, 300)
  25. setTimeout(() => {
  26. this.allowOrNot();
  27. }, 500)
  28. }
  29. },
  30. methods: {
  31. /* input输入 */
  32. inputChange(e) {
  33. this.setData({
  34. [e.target.dataset.name]: e.detail.value.trim()
  35. })
  36. this.allowOrNot()
  37. },
  38. /* 验证是否允许登录 */
  39. allowOrNot() {
  40. getCurrentPages()[0].setData({
  41. disabled: (this.data.accountno.length > 0 && this.data.password.length > 0) ? false : true
  42. })
  43. },
  44. /* 改变密码输入框类型 */
  45. changePasswordType() {
  46. this.setData({
  47. inputType: this.data.inputType == "text" ? 'password' : 'text'
  48. })
  49. },
  50. /* 是否记忆密码 */
  51. isMemory() {
  52. this.setData({
  53. memory: !this.data.memory
  54. })
  55. },
  56. /* 处理登录 */
  57. handleLogin() {
  58. _Http.login({
  59. "accountno": this.data.accountno,
  60. "password": md5.hexMD5(this.data.password),
  61. "systemclient": "wechatsaletool"
  62. }).then(res => {
  63. getCurrentPages()[0].setData({
  64. loading: false
  65. })
  66. if (res.msg != '成功') return wx.showToast({
  67. title: res.msg,
  68. icon: "none"
  69. })
  70. wx.setStorageSync('loginMsg', {
  71. accountno: this.data.accountno,
  72. password: (this.data.memory) ? this.data.password : ''
  73. })
  74. loginMsg.loginMsg(res);
  75. getApp().globalData.remindchangepassword_str = res.remindchangepassword_str;
  76. })
  77. }
  78. }
  79. })