phone.js 3.6 KB

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