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
| /**
| * CInputPhoneCode
| * @author Tevin
| */
|
| <template>
| <view class="c-input-phone-code">
| <AtInput
| :name="itemRes.name"
| :title="itemRes.label"
| type="text"
| :placeholder="placeholder"
| :required="itemRes.required"
| :error="itemRes.error"
| :value="itemRes.formData[itemRes.name]"
| :onChange="evt=>itemRes.onChange(evt)"
| >
| <AtButton
| class="c-input-phone-btn"
| type="primary"
| size="small"
| :disabled="holding"
| :onClick="evt=>handleClick()"
| >{{btnText}}</AtButton>
| </AtInput>
| </view>
| </template>
|
| <script>
| import { AtInput, AtButton } from 'taro-ui-vue';
| import './cInputPhoneCode.scss';
|
| export default {
| name: 'CInputPhoneCode',
| components: {
| AtInput,
| AtButton,
| },
| props: {
| placeholder: String,
| itemRes: Object,
| autoStart: { type: Boolean, default: true },
| onCallPhoneCode: Function,
| },
| data() {
| return {
| cd: 60,
| holding: false,
| };
| },
| computed: {
| btnText() {
| if (this.holding) {
| return this.cd + '秒后重新获取';
| } else {
| return '重新获取验证码';
| }
| },
| },
| methods: {
| handleClick() {
| if (this.holding) {
| return;
| }
| const startCD = () => {
| this.holding = true;
| this.cd = 60;
| setInterval(() => {
| this.cd -= 1;
| if (this.cd === 0) {
| this.holding = false;
| this.cd = 60;
| }
| }, 1000);
| };
| if (this.autoStart) {
| startCD();
| this.onCallPhoneCode(() => null);
| } else {
| this.onCallPhoneCode(() => {
| startCD();
| });
| }
| },
| },
| };
| </script>
|
|