account.js 1.7 KB

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