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
114
115
116
117
118
| <!--
| * @Author: 小明丶
| * @Date: 2019-08-30 10:21:30
| * @LastEditors: 小明丶
| * @LastEditTime: 2019-09-06 16:06:30
| * @Description:
| -->
| <template>
| <div class="f-vercode" :style="{margin:margin?'10px 0':'0'}">
| <group>
| <x-input placeholder='请输入短信验证码' @on-change='changeVal' v-model="verCode" :max="4">
| <div slot="right" class="getVerCode" :style="{color:abledClick?'#bfa073':'#a3a3a3'}" @click="getStatus">{{ verText }}</div>
| </x-input>
| </group>
| </div>
| </template>
| <script>
| export default {
| name: 'f-vercode',
| data() {
| return {
| verCode: '',
| abledClick: true,
| verText: '发送验证码',
| timer: null
| };
| },
| props: {
| clear: {
| type: Boolean,
| default: false
| },
| value: {
| type: String,
| default: ''
| },
| passStatus: {
| type: Boolean,
| required: true,
| default: false
| },
| api: {
| type: String,
| required: true,
| default: ''
| },
| params: {
| type: Object,
| default: () => {
| return {};
| }
| },
| margin: {
| type: Boolean,
| default: false
| }
| },
| watch: {
| passStatus(val) {
| if (val) {
| this.sendCode();
| }
| },
| clear(val) {
| if (val) {
| this.abledClick = true;
| clearInterval(this.timer);
| this.verText = '发送验证码';
| this.$emit('update:passStatus', false);
| }
| }
| },
| methods: {
| changeVal(val) {
| this.$emit('input', val);
| },
| getStatus() {
| this.$emit('sendCode');
| },
| sendCode() {
| if (!this.abledClick) {
| return;
| }
| this.abledClick = false;
| // 设置倒计时
| let countDown = 60;
| this.verText = countDown + 's后重发';
| this.timer = setInterval(() => {
| countDown--;
| this.verText = countDown + 's后重发';
| if (countDown === 0) {
| clearInterval(this.timer);
| this.verText = '重新发送';
| this.$emit('update:passStatus', false);
| this.abledClick = true;
| }
| }, 1000);
| //开始拉取接口
| this.$api[this.api](this.params).then(res => {
| this.$emit('end', res);
| });
| }
| }
| };
| </script>
| <style lang="less" scoped>
| .f-vercode {
| .getVerCode {
| width: 105px;
| text-align: center;
| box-sizing: border-box;
| padding-left: 18px;
| border-left: 1px solid #dddddd;
| color: @color-text-three;
| font-size: @font-size-medium;
| }
| }
| </style>
|
|