1
1
<template >
2
2
<!-- 本体部分 -->
3
- <div
4
- :id =" id"
5
- :class =" ['vue-puzzle-vcode', { show_: show }]"
6
- @mousedown =" onCloseMouseDown"
7
- @mouseup =" onCloseMouseUp"
8
- @touchstart =" onCloseMouseDown"
9
- @touchend =" onCloseMouseUp"
10
- >
11
- <div class =" vue-auth-box_" @mousedown.stop @touchstart.stop >
12
- <div class =" auth-body_" :style =" `height: ${canvasHeight}px`" >
3
+ <div :id =" id"
4
+ :class =" ['vue-puzzle-vcode', { show_: show }]"
5
+ @mousedown =" onCloseMouseDown"
6
+ @mouseup =" onCloseMouseUp"
7
+ @touchstart =" onCloseMouseDown"
8
+ @touchend =" onCloseMouseUp" >
9
+ <div class =" vue-auth-box_"
10
+ @mousedown.stop
11
+ @touchstart.stop >
12
+ <div class =" auth-body_"
13
+ :style =" `height: ${canvasHeight}px`" >
13
14
<!-- 主图,有缺口 -->
14
- <canvas
15
- ref =" canvas1"
16
- :width =" canvasWidth"
17
- :height =" canvasHeight"
18
- :style =" `width:${canvasWidth}px;height:${canvasHeight}px`"
19
- />
15
+ <canvas ref =" canvas1"
16
+ :width =" canvasWidth"
17
+ :height =" canvasHeight"
18
+ :style =" `width:${canvasWidth}px;height:${canvasHeight}px`" />
20
19
<!-- 成功后显示的完整图 -->
21
- <canvas
22
- ref =" canvas3"
23
- :class =" ['auth-canvas3_', { show: isSuccess }]"
24
- :width =" canvasWidth"
25
- :height =" canvasHeight"
26
- :style =" `width:${canvasWidth}px;height:${canvasHeight}px`"
27
- />
20
+ <canvas ref =" canvas3"
21
+ :class =" ['auth-canvas3_', { show: isSuccess }]"
22
+ :width =" canvasWidth"
23
+ :height =" canvasHeight"
24
+ :style =" `width:${canvasWidth}px;height:${canvasHeight}px`" />
28
25
<!-- 小图 -->
29
- <canvas
30
- :width =" puzzleBaseSize"
31
- class =" auth-canvas2_"
32
- :height =" canvasHeight"
33
- ref =" canvas2"
34
- :style ="
26
+ <canvas :width =" puzzleBaseSize"
27
+ class =" auth-canvas2_"
28
+ :height =" canvasHeight"
29
+ ref =" canvas2"
30
+ :style ="
35
31
`width:${puzzleBaseSize}px;height:${canvasHeight}px;transform:translateX(${styleWidth -
36
32
sliderBaseSize -
37
33
(puzzleBaseSize - sliderBaseSize) *
38
34
((styleWidth - sliderBaseSize) /
39
35
(canvasWidth - sliderBaseSize))}px)`
40
- "
41
- />
36
+ " />
42
37
<div :class =" ['loading-box_', { hide_: !loading }]" >
43
38
<div class =" loading-gif_" >
44
39
<span ></span >
48
43
<span ></span >
49
44
</div >
50
45
</div >
51
- <div
52
- :class =" ['info-box_', { show: infoBoxShow }, { fail: infoBoxFail }]"
53
- >
46
+ <div :class =" ['info-box_', { show: infoBoxShow }, { fail: infoBoxFail }]" >
54
47
{{ infoText }}
55
48
</div >
56
- <div
57
- :class =" ['flash_', { show: isSuccess }]"
58
- :style ="
49
+ <div :class =" ['flash_', { show: isSuccess }]"
50
+ :style ="
59
51
`transform: translateX(${
60
52
isSuccess
61
53
? `${canvasWidth + canvasHeight * 0.578}px`
62
54
: `-${canvasHeight * 0.578}px`
63
55
}) skew(-30deg, 0);`
64
- "
65
- ></div >
66
- <img class =" reset_" @click =" reset" :src =" resetSvg" />
56
+ " ></div >
57
+ <img class =" reset_"
58
+ @click =" reset"
59
+ :src =" resetSvg" />
67
60
</div >
68
61
<div class =" auth-control_" >
69
- <div class =" range-box" :style =" `height:${sliderBaseSize}px`" >
62
+ <div class =" range-box"
63
+ :style =" `height:${sliderBaseSize}px`" >
70
64
<div class =" range-text" >{{ sliderText }}</div >
71
- <div
72
- class =" range-slider"
73
- ref =" range-slider"
74
- :style =" `width:${styleWidth}px`"
75
- >
76
- <div
77
- :class =" ['range-btn', { isDown: mouseDown }]"
78
- :style =" `width:${sliderBaseSize}px`"
79
- @mousedown =" onRangeMouseDown($event)"
80
- @touchstart =" onRangeMouseDown($event)"
81
- >
65
+ <div class =" range-slider"
66
+ ref =" range-slider"
67
+ :style =" `width:${styleWidth}px`" >
68
+ <div :class =" ['range-btn', { isDown: mouseDown }]"
69
+ :style =" `width:${sliderBaseSize}px`"
70
+ @mousedown =" onRangeMouseDown($event)"
71
+ @touchstart =" onRangeMouseDown($event)" >
82
72
<div ></div >
83
73
<div ></div >
84
74
<div ></div >
@@ -111,7 +101,7 @@ export default {
111
101
closeDown: false , // 为了解决Mac上的click BUG
112
102
isSuccess: false , // 验证成功
113
103
resetSvg,
114
- imgIndex: - 1 , // 用于自定义图片时不会随机到重复的图片
104
+ imgIndex: - 1 // 用于自定义图片时不会随机到重复的图片
115
105
};
116
106
},
117
107
/** 父级参数 **/
@@ -126,20 +116,20 @@ export default {
126
116
range: { type: Number , default: 10 }, // 允许的偏差值
127
117
// 所有的背景图片
128
118
imgs: {
129
- type: Array ,
119
+ type: Array
130
120
},
131
121
successText: {
132
122
type: String ,
133
- default: " 验证通过!" ,
123
+ default: " 验证通过!"
134
124
},
135
125
failText: {
136
126
type: String ,
137
- default: " 验证失败,请重试" ,
127
+ default: " 验证失败,请重试"
138
128
},
139
129
sliderText: {
140
130
type: String ,
141
- default: " 拖动滑块完成拼图" ,
142
- },
131
+ default: " 拖动滑块完成拼图"
132
+ }
143
133
},
144
134
145
135
/** 生命周期 **/
@@ -149,7 +139,7 @@ export default {
149
139
document .addEventListener (" mouseup" , this .onRangeMouseUp , false );
150
140
151
141
document .addEventListener (" touchmove" , this .onRangeMouseMove , {
152
- passive: false ,
142
+ passive: false
153
143
});
154
144
document .addEventListener (" touchend" , this .onRangeMouseUp , false );
155
145
if (this .show ) {
@@ -164,7 +154,7 @@ export default {
164
154
document .removeEventListener (" mouseup" , this .onRangeMouseUp , false );
165
155
166
156
document .removeEventListener (" touchmove" , this .onRangeMouseMove , {
167
- passive: false ,
157
+ passive: false
168
158
});
169
159
document .removeEventListener (" touchend" , this .onRangeMouseUp , false );
170
160
},
@@ -179,7 +169,7 @@ export default {
179
169
} else {
180
170
document .body .classList .remove (" vue-puzzle-overflow" );
181
171
}
182
- },
172
+ }
183
173
},
184
174
185
175
/** 计算属性 **/
@@ -208,7 +198,7 @@ export default {
208
198
),
209
199
10
210
200
);
211
- },
201
+ }
212
202
},
213
203
214
204
/** 方法 **/
@@ -277,7 +267,7 @@ export default {
277
267
this .pinY = this .getRandom (
278
268
20 ,
279
269
this .canvasHeight - this .puzzleBaseSize - 20
280
- ); // -60(slider自身高度) - 20(留20边距)
270
+ ); // 主图高度 - 拼图块自身高度 - 20边距
281
271
img .crossOrigin = " anonymous" ; // 匿名,想要获取跨域的图片
282
272
img .onload = () => {
283
273
const [x , y , w , h ] = this .makeImgSize (img);
@@ -586,8 +576,8 @@ export default {
586
576
this .startX = 0 ; // 鼠标按下时的X
587
577
this .newX = 0 ; // 鼠标当前的偏移X
588
578
this .init ();
589
- },
590
- },
579
+ }
580
+ }
591
581
};
592
582
</script >
593
583
<style lang="less">
0 commit comments