account.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }, 100)
  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. console.log('是否为初始密码', res.remindchangepassword == 1)
  73. getApp().globalData.remindchangepassword = res.remindchangepassword == 1;
  74. })
  75. }
  76. }
  77. })