wang-hao-jie
2022-08-25 2b506494d7c73a3978004bd0b32a5d0783b25efa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
  <div>
    <Button
      :countTime="countTime"
      :loading="loading"
      :type="type"
      :size="size"
      :ghost="ghost"
      :disabled="disabled || clicked"
      :icon="icon"
      :shape="shape"
      :long="long"
      @click="handleClick"
      >{{ buttonText }}</Button
    >
  </div>
</template>
 
<script>
export default {
  name: "iconChoose",
  props: {
    text: {
      type: String,
      default: "提交",
    },
    autoCountDown: {
      type: Boolean,
      default: true,
    },
    countTime: {
      type: [Number, String],
      default: 60,
    },
    suffixText: {
      type: String,
      default: "秒后重试",
    },
    type: String,
    size: String,
    loading: {
      type: Boolean,
      default: false,
    },
    ghost: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    icon: String,
    shape: String,
    long: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      buttonText: this.text,
      count: Number(this.countTime),
      clicked: false,
    };
  },
  methods: {
    init() {},
    handleClick() {
      if (this.autoCountDown) {
        this.clicked = true;
        this.countDown();
      }
      this.$emit("on-click", true);
    },
    startCountDown() {
      this.clicked = true;
      this.countDown();
    },
    countDown() {
      if (this.count == 0) {
        this.clicked = false;
        this.count = this.countTime;
        this.buttonText = this.text;
        return;
      } else {
        this.buttonText = this.count + " " + this.suffixText;
        this.count--;
      }
      setTimeout(() => {
        this.countDown();
      }, 1000);
    },
    setText(value) {
      if (value === this.buttonText) {
        return;
      }
      this.buttonText = value;
    },
  },
  watch: {
    text(val) {
      this.setText(val);
    },
  },
  mounted() {
    this.init();
  },
};
</script>
 
<style lang="less">
</style>