phone.js 3.2 KB

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