account.js 2.3 KB

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