phone.js 3.2 KB

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