account.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. this.allowOrNot();
  23. }
  24. },
  25. methods: {
  26. /* input输入 */
  27. inputChange(e) {
  28. this.setData({
  29. [e.target.dataset.name]: e.detail.value.trim()
  30. })
  31. this.allowOrNot()
  32. },
  33. /* 验证是否允许登录 */
  34. allowOrNot() {
  35. getCurrentPages()[0].setData({
  36. disabled: (this.data.accountno.length > 0 && this.data.password.length > 0) ? false : true
  37. })
  38. },
  39. /* 改变密码输入框类型 */
  40. changePasswordType() {
  41. this.setData({
  42. inputType: this.data.inputType == "text" ? 'password' : 'text'
  43. })
  44. },
  45. /* 是否记忆密码 */
  46. isMemory() {
  47. this.setData({
  48. memory: !this.data.memory
  49. })
  50. },
  51. /* 处理登录 */
  52. handleLogin() {
  53. _Http.login({
  54. "accountno": this.data.accountno,
  55. "password": md5.hexMD5(this.data.password),
  56. "systemclient": "wechatsaletool"
  57. }).then(res => {
  58. console.log("登录", res)
  59. getCurrentPages()[0].setData({
  60. loading: false
  61. })
  62. if (res.msg != '成功') return wx.showToast({
  63. title: res.msg,
  64. icon: "none"
  65. })
  66. if (res.account_list.length == 1 && res.account_list[0].status == 'INACTIVE') return wx.showToast({
  67. title: '该账号已停用',
  68. icon: "none",
  69. mask: true
  70. })
  71. wx.setStorageSync('loginMsg', {
  72. accountno: this.data.accountno,
  73. password: (this.data.memory) ? this.data.password : ''
  74. })
  75. loginMsg.loginMsg(res);
  76. })
  77. }
  78. }
  79. })