account.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. let loginMsg = {
  70. accountno: this.data.accountno,
  71. baseUrl: getApp().globalData.http.baseUrl,
  72. password: (this.data.memory) ? this.data.password : ''
  73. }
  74. let list = wx.getStorageSync('logins') || [],
  75. index = list.findIndex(v => v.accountno == loginMsg.accountno && v.baseUrl == loginMsg.baseUrl);
  76. if (index != -1) {
  77. list[index] = loginMsg
  78. } else {
  79. list.push(loginMsg)
  80. }
  81. wx.setStorageSync('logins', list)
  82. wx.setStorageSync('loginMsg', loginMsg)
  83. require("./login").loginMsg(res);
  84. getApp().globalData.remindchangepassword = res.remindchangepassword == 1;
  85. })
  86. }
  87. }
  88. })