forget.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div class="forget">
  3. <div class="content">
  4. <div @click="goBack">X</div>
  5. <!-- 头部logo -->
  6. <div class="header">
  7. <img src="@/assets/logo-home.png" />
  8. </div>
  9. <!-- 主体 -->
  10. <div class="main">
  11. <wInput
  12. type="text"
  13. maxlength="11"
  14. placeholder="用户名/电话"
  15. v-model="phoneData"
  16. ></wInput>
  17. <wInput
  18. type="password"
  19. maxlength="11"
  20. placeholder="登录密码"
  21. v-model="passData"
  22. ></wInput>
  23. <wInput
  24. type="number"
  25. v-model="verCode"
  26. maxlength="4"
  27. placeholder="验证码1234"
  28. isShowCode
  29. ref="codeRef"
  30. @setCode="getVerCode()"
  31. ></wInput>
  32. </div>
  33. <wButton
  34. text="重置密码"
  35. :rotate="isRotate"
  36. @click.native="startForget"
  37. ></wButton>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import wInput from "@/components/watch-login/watch-input.vue"; //input
  43. import wButton from "@/components/watch-login/watch-button.vue"; //button
  44. import { forget } from "@/api/login.js";
  45. import { Toast } from "vant";
  46. export default {
  47. data() {
  48. return {
  49. phoneData: "", //电话
  50. passData: "", //密码
  51. verCode: "", //验证码
  52. isRotate: false //是否加载旋转
  53. };
  54. },
  55. methods: {
  56. goBack() {
  57. this.$router.go(-1);
  58. },
  59. getVerCode() {
  60. //获取验证码
  61. if (this.phoneData.length != 11) {
  62. Toast("手机号不正确");
  63. return false;
  64. }
  65. console.log("获取验证码");
  66. this.$refs.runCode.$emit("runCode"); //触发倒计时(一般用于请求成功验证码后调用)
  67. setTimeout(() => {
  68. this.$refs.runCode.$emit("runCode", 0); //假装模拟下需要 终止倒计时
  69. }, 60000);
  70. },
  71. async startForget() {
  72. //注册
  73. if (this.isRotate) {
  74. //判断是否加载中,避免重复点击请求
  75. return false;
  76. }
  77. if (this.phoneData.length != 11) {
  78. Toast("手机号不正确");
  79. return false;
  80. }
  81. if (this.passData.length < 6) {
  82. Toast("密码长度最少六位");
  83. return false;
  84. }
  85. if (this.verCode !== "1234") {
  86. Toast("验证码不正确");
  87. return false;
  88. }
  89. this.isRotate = true;
  90. try {
  91. await forget({ userName: this.phoneData, password: this.passData });
  92. Toast("重置密码成功");
  93. this.isRotate = false;
  94. this.goBack();
  95. } catch (error) {
  96. console.log(error);
  97. this.isRotate = false;
  98. }
  99. }
  100. },
  101. components: {
  102. wInput,
  103. wButton
  104. }
  105. };
  106. </script>
  107. <style>
  108. @import url("../components/watch-login/css/icon.css");
  109. @import url("../assets/css/main.css");
  110. </style>