phone.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. let loginMsg = require("./login"),
  2. md5 = require("../../../utils/md5"),
  3. _Http = getApp().globalData.http,
  4. deleteMark = require("../../../utils/deleteMark"),
  5. downCount = null;
  6. Component({
  7. options: {
  8. addGlobalClass: true
  9. },
  10. data: {
  11. phonenumber: '',
  12. password: '',
  13. showText: "获取验证码",
  14. memory: true
  15. },
  16. lifetimes: {
  17. attached: function () {
  18. /* 恢复缓存中保存的账号密码 */
  19. if (wx.getStorageSync('loginMsg')) {
  20. this.setData({
  21. ...wx.getStorageSync('loginMsg')
  22. });
  23. this.allowOrNot();
  24. }
  25. }
  26. },
  27. methods: {
  28. /* 获取验证码 */
  29. getPassword() {
  30. if (this.data.showText != "获取验证码") return;
  31. if (!deleteMark.CheckPhoneNumber(this.data.phonenumber)) return;
  32. _Http.getpassword({
  33. "phonenumber": this.data.phonenumber,
  34. "systemclient": "wechatsaletool"
  35. }).then(res => {
  36. wx.showToast({
  37. title: res.msg,
  38. icon: "none",
  39. duration: 3000
  40. })
  41. if (res.code != 1) return;
  42. this.setData({
  43. showText: 30
  44. })
  45. downCount = setInterval(() => {
  46. let showText = this.data.showText;
  47. if (showText == 0) {
  48. clearInterval(downCount)
  49. showText = '获取验证码'
  50. } else {
  51. showText--
  52. }
  53. this.setData({
  54. showText
  55. })
  56. }, 1000)
  57. })
  58. },
  59. /* input输入 */
  60. inputChange(e) {
  61. this.setData({
  62. [e.target.dataset.name]: e.detail.value.trim()
  63. })
  64. this.allowOrNot();
  65. },
  66. /* 验证是否允许登录 */
  67. allowOrNot() {
  68. getCurrentPages().forEach(v => {
  69. if (['pages/login/phone'].includes(v.__route__)) v.setData({
  70. disabled: this.data.phonenumber.length == 0 || this.data.password.length == 0
  71. })
  72. })
  73. },
  74. /* 处理登录 */
  75. handleLogin() {
  76. _Http.plogin({
  77. "phonenumber": this.data.phonenumber,
  78. "password": md5.hexMD5(this.data.password),
  79. "systemclient": "wechatsaletool"
  80. }).then(res => {
  81. getCurrentPages()[0].setData({
  82. loading: false
  83. })
  84. if (res.msg != '成功') return wx.showToast({
  85. title: res.msg,
  86. icon: "none"
  87. })
  88. wx.setStorageSync('loginMsg', {
  89. phonenumber: (this.data.memory) ? this.data.phonenumber : ''
  90. })
  91. loginMsg.loginMsg(res);
  92. })
  93. },
  94. /* 是否记忆密码 */
  95. isMemory() {
  96. this.setData({
  97. memory: !this.data.memory
  98. })
  99. },
  100. }
  101. })