account.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. imagecaptcha: "",
  13. inputType: "password", //密码输入框类型
  14. memory: true, //记忆
  15. focus: false,
  16. timestamp: ""
  17. },
  18. lifetimes: {
  19. attached: function () {
  20. /* 恢复缓存中保存的账号密码 */
  21. this.setData({
  22. ...wx.getStorageSync('loginMsg')
  23. });
  24. setTimeout(() => {
  25. this.allowOrNot();
  26. }, 300)
  27. this.setData({
  28. timestamp: new Date().getTime()
  29. })
  30. }
  31. },
  32. methods: {
  33. changeTimestamp() {
  34. this.setData({
  35. timestamp: new Date().getTime()
  36. })
  37. },
  38. /* input输入 */
  39. inputChange(e) {
  40. this.setData({
  41. [e.target.dataset.name]: e.detail.value.trim()
  42. })
  43. this.allowOrNot()
  44. },
  45. /* 验证是否允许登录 */
  46. allowOrNot() {
  47. getCurrentPages()[0].setData({
  48. disabled: (this.data.accountno.length > 0 && this.data.password.length > 0) ? false : true
  49. })
  50. },
  51. /* 改变密码输入框类型 */
  52. changePasswordType() {
  53. this.setData({
  54. inputType: this.data.inputType == "text" ? 'password' : 'text'
  55. })
  56. },
  57. /* 是否记忆密码 */
  58. isMemory() {
  59. this.setData({
  60. memory: !this.data.memory
  61. })
  62. },
  63. /* 处理登录 */
  64. handleLogin() {
  65. _Http.login({
  66. "accountno": this.data.accountno,
  67. "password": md5.hexMD5(this.data.password),
  68. "imagecaptcha": this.data.imagecaptcha || '',
  69. "systemclient": "wechatsaletool"
  70. }).then(res => {
  71. getCurrentPages()[0].setData({
  72. loading: false
  73. })
  74. if (res.msg != '成功') return wx.showToast({
  75. title: res.msg,
  76. icon: "none"
  77. })
  78. wx.setStorageSync('loginMsg', {
  79. accountno: this.data.accountno,
  80. password: (this.data.memory) ? this.data.password : ''
  81. })
  82. loginMsg.loginMsg(res);
  83. getApp().globalData.remindchangepassword_str = res.remindchangepassword_str;
  84. })
  85. }
  86. }
  87. })