account.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. getApp().globalData.Language.getLanguagePackage(this)
  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 && this.data.password.length) ? 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. getApp().globalData.http.login({
  59. "accountno": this.data.accountno,
  60. "password": require("../../../utils/md5").hexMD5(this.data.password),
  61. "systemclient": "wechatsaletool"
  62. }).then(res => {
  63. getCurrentPages()[0].setData({
  64. loading: false
  65. })
  66. if (res.code != '1') return wx.showToast({
  67. title: res.msg,
  68. icon: "none"
  69. })
  70. let loginMsg = {
  71. accountno: this.data.accountno,
  72. baseUrl: getApp().globalData.http.baseUrl,
  73. password: (this.data.memory) ? this.data.password : ''
  74. }
  75. let list = wx.getStorageSync('logins') || [],
  76. index = list.findIndex(v => v.accountno == loginMsg.accountno && v.baseUrl == loginMsg.baseUrl);
  77. if (index != -1) {
  78. list[index] = loginMsg
  79. } else {
  80. list.push(loginMsg)
  81. }
  82. wx.setStorageSync('logins', list)
  83. wx.setStorageSync('loginMsg', loginMsg)
  84. require("./login").loginMsg(res);
  85. getApp().globalData.remindchangepassword = res.remindchangepassword == 1;
  86. })
  87. }
  88. }
  89. })