captcha.vue
2.16 KB
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
<template>
<div class="captcha-box">
<div class="captcha-box-header">
<span>请将下列图片点击翻转至正确方向</span>
<a href="javascript:;" class="img-check-refresh" @click="captchaRefresh">换一批</a>
</div>
<div class="captcha-box-content">
<div class="item"
v-for="block in blocks"
:key="block.posX"
:style="{
'background-image': `url(${imgSrc})`,
'background-position': `${block.posX}px ${block.posY}px`
}"
@click="captchaClick(block)"></div>
</div>
</div>
</template>
<script>
import _ from 'lodash';
export default {
name: 'captcha-box',
data() {
return {
captchaSrc: '/Api/captcha.jpg',
random: Math.random(),
blocks: []
};
},
created() {
this.blocks = [{
val: 0,
posX: 0,
posY: 0
}, {
val: 0,
posX: -60,
posY: 0
}, {
val: 0,
posX: -120,
posY: 0
}, {
val: 0,
posX: -180,
posY: 0
}];
},
computed: {
imgSrc() {
return `${this.captchaSrc}?r=${this.random}`;
}
},
methods: {
captchaClick(block) {
block.val = (block.val + 1) % 4;
block.posY = (block.posY - 60) % 240;
let vals = _.map(this.blocks, b => {
return b.val;
});
this.$emit('change', vals);
},
captchaRefresh() {
this.random = Math.random();
}
}
};
</script>
<style lang="scss">
.captcha-box {
margin: 0 auto;
width: 270px;
}
.captcha-box-header {
color: #b0b0b0;
a {
color: #ff1901;
float: right;
}
}
.captcha-box-content {
display: flex;
.item {
flex: 1;
cursor: pointer;
margin-right: 10px;
width: 60px;
height: 60px;
overflow: hidden;
border: solid 1px #ccc;
background-size: 240px;
&:last-child {
margin-right: 0;
}
}
}
</style>