main.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <el-button
  3. class="send-verification-code"
  4. :type="num < 60 ? 'info' : 'primary'"
  5. :plain="num < 60"
  6. :disabled="num < 60"
  7. @click="getCode"
  8. >{{ title }}</el-button
  9. >
  10. </template>
  11. <script>
  12. import { isMobile } from "@/utils/validate";
  13. import asyncRequest from "@/apis/service/user/index";
  14. import resToken from "@/mixins/resToken";
  15. export default {
  16. name:"sendVerificationCode",
  17. props: {
  18. mobile: {
  19. type: String,
  20. default: "",
  21. },
  22. },
  23. mixins: [resToken],
  24. data() {
  25. return {
  26. num: 60,
  27. title: "获取验证码",
  28. timer: null,
  29. };
  30. },
  31. computed: {},
  32. methods: {
  33. getCode() {
  34. if (this.mobile !== "" && isMobile(this.mobile)) {
  35. if (this.num === 60) {
  36. asyncRequest.verfiy({ mobile: this.mobile }).then(async (res) => {
  37. if (res && res.code === 0) {
  38. this.timer = setInterval(() => {
  39. if (this.num !== 0) {
  40. this.title = `${this.num}s后可重发`;
  41. this.num--;
  42. } else {
  43. clearInterval(this.timer);
  44. this.num = 60;
  45. this.title = "获取验证码";
  46. }
  47. }, 1000);
  48. } else if (res && res.code >= 100 && res.code <= 104) {
  49. await this.logout();
  50. } else {
  51. this.$message.warning(res.message);
  52. }
  53. });
  54. }
  55. } else {
  56. this.$emit("mobileErr", false);
  57. }
  58. },
  59. },
  60. };
  61. </script>
  62. <style lang="scss" scoped>
  63. .send-verification-code.el-button {
  64. border-top-left-radius: 0;
  65. border-bottom-left-radius: 0;
  66. width: 90px;
  67. height: 40px;
  68. line-height: 40px;
  69. padding: 0;
  70. font-size: 13px;
  71. text-align: center;
  72. }
  73. </style>