phone.js 3.3 KB

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