phone.js 3.5 KB

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