phone.js 3.4 KB

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