phone.js 3.4 KB

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