Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit bbd8a53d
authored
Jul 03, 2025
by
chenweiran
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 增加基于图片拼图切片平移的验证码
1 parent
8554924c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
3 deletions
packages/effects/common-ui/src/components/captcha/index.ts
packages/effects/common-ui/src/components/captcha/slider-translate-captcha/index.vue
packages/effects/common-ui/src/components/captcha/types.ts
playground/src/locales/langs/en-US/examples.json
playground/src/locales/langs/zh-CN/examples.json
playground/src/router/routes/modules/examples.ts
packages/effects/common-ui/src/components/captcha/index.ts
View file @
bbd8a53
...
@@ -3,4 +3,5 @@ export { default as PointSelectionCaptchaCard } from './point-selection-captcha/
...
@@ -3,4 +3,5 @@ export { default as PointSelectionCaptchaCard } from './point-selection-captcha/
export
{
default
as
SliderCaptcha
}
from
'./slider-captcha/index.vue'
;
export
{
default
as
SliderCaptcha
}
from
'./slider-captcha/index.vue'
;
export
{
default
as
SliderRotateCaptcha
}
from
'./slider-rotate-captcha/index.vue'
;
export
{
default
as
SliderRotateCaptcha
}
from
'./slider-rotate-captcha/index.vue'
;
export
{
default
as
SliderTranslateCaptcha
}
from
'./slider-translate-captcha/index.vue'
;
export
type
*
from
'./types'
;
export
type
*
from
'./types'
;
packages/effects/common-ui/src/components/captcha/slider-translate-captcha/index.vue
View file @
bbd8a53
...
@@ -127,7 +127,12 @@ function resetCanvas() {
...
@@ -127,7 +127,12 @@ function resetCanvas() {
if
(
!
puzzleCanvas
||
!
pieceCanvas
)
return
;
if
(
!
puzzleCanvas
||
!
pieceCanvas
)
return
;
pieceCanvas
.
width
=
canvasWidth
;
pieceCanvas
.
width
=
canvasWidth
;
const
puzzleCanvasCtx
=
puzzleCanvas
.
getContext
(
'2d'
);
const
puzzleCanvasCtx
=
puzzleCanvas
.
getContext
(
'2d'
);
const
pieceCanvasCtx
=
pieceCanvas
.
getContext
(
'2d'
);
// Canvas2D: Multiple readback operations using getImageData
// are faster with the willReadFrequently attribute set to true.
// See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently (anonymous)
const
pieceCanvasCtx
=
pieceCanvas
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
,
});
if
(
!
puzzleCanvasCtx
||
!
pieceCanvasCtx
)
return
;
if
(
!
puzzleCanvasCtx
||
!
pieceCanvasCtx
)
return
;
puzzleCanvasCtx
.
clearRect
(
0
,
0
,
canvasWidth
,
canvasHeight
);
puzzleCanvasCtx
.
clearRect
(
0
,
0
,
canvasWidth
,
canvasHeight
);
pieceCanvasCtx
.
clearRect
(
0
,
0
,
canvasWidth
,
canvasHeight
);
pieceCanvasCtx
.
clearRect
(
0
,
0
,
canvasWidth
,
canvasHeight
);
...
@@ -139,9 +144,16 @@ function initCanvas() {
...
@@ -139,9 +144,16 @@ function initCanvas() {
const
pieceCanvas
=
unref
(
pieceCanvasRef
);
const
pieceCanvas
=
unref
(
pieceCanvasRef
);
if
(
!
puzzleCanvas
||
!
pieceCanvas
)
return
;
if
(
!
puzzleCanvas
||
!
pieceCanvas
)
return
;
const
puzzleCanvasCtx
=
puzzleCanvas
.
getContext
(
'2d'
);
const
puzzleCanvasCtx
=
puzzleCanvas
.
getContext
(
'2d'
);
const
pieceCanvasCtx
=
pieceCanvas
.
getContext
(
'2d'
);
// Canvas2D: Multiple readback operations using getImageData
// are faster with the willReadFrequently attribute set to true.
// See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently (anonymous)
const
pieceCanvasCtx
=
pieceCanvas
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
,
});
if
(
!
puzzleCanvasCtx
||
!
pieceCanvasCtx
)
return
;
if
(
!
puzzleCanvasCtx
||
!
pieceCanvasCtx
)
return
;
const
img
=
new
Image
();
const
img
=
new
Image
();
// 解决跨域
img
.
crossOrigin
=
'Anonymous'
;
img
.
src
=
src
;
img
.
src
=
src
;
img
.
addEventListener
(
'load'
,
()
=>
{
img
.
addEventListener
(
'load'
,
()
=>
{
draw
(
puzzleCanvasCtx
,
pieceCanvasCtx
);
draw
(
puzzleCanvasCtx
,
pieceCanvasCtx
);
...
@@ -158,6 +170,7 @@ function initCanvas() {
...
@@ -158,6 +170,7 @@ function initCanvas() {
);
);
pieceCanvas
.
width
=
pieceLength
;
pieceCanvas
.
width
=
pieceLength
;
pieceCanvasCtx
.
putImageData
(
imageData
,
0
,
sy
);
pieceCanvasCtx
.
putImageData
(
imageData
,
0
,
sy
);
setLeft
(
'0'
);
});
});
}
}
...
@@ -265,7 +278,7 @@ onMounted(() => {
...
@@ -265,7 +278,7 @@ onMounted(() => {
@
click=
"resume"
@
click=
"resume"
></canvas>
></canvas>
<div
<div
class=
"
absolute bottom-3 left-0 z-10 block h-7
w-full text-center text-xs leading-[30px] text-white"
class=
"
h-15 absolute bottom-3 left-0 z-10 block
w-full text-center text-xs leading-[30px] text-white"
>
>
<div
<div
v-if=
"state.showTip"
v-if=
"state.showTip"
...
...
packages/effects/common-ui/src/components/captcha/types.ts
View file @
bbd8a53
...
@@ -159,6 +159,42 @@ export interface SliderRotateCaptchaProps {
...
@@ -159,6 +159,42 @@ export interface SliderRotateCaptchaProps {
defaultTip
?:
string
;
defaultTip
?:
string
;
}
}
export
interface
SliderTranslateCaptchaProps
{
/**
* @description 拼图的宽度
* @default 420
*/
canvasWidth
?:
number
;
/**
* @description 拼图的高度
* @default 280
*/
canvasHeight
?:
number
;
/**
* @description 切块上正方形的长度
* @default 42
*/
squareLength
?:
number
;
/**
* @description 切块上圆形的半径
* @default 10
*/
circleRadius
?:
number
;
/**
* @description 图片的地址
*/
src
?:
string
;
/**
* @description 允许的最大差距
* @default 3
*/
diffDistance
?:
number
;
/**
* @description 默认提示文本
*/
defaultTip
?:
string
;
}
export
interface
CaptchaVerifyPassingData
{
export
interface
CaptchaVerifyPassingData
{
isPassing
:
boolean
;
isPassing
:
boolean
;
time
:
number
|
string
;
time
:
number
|
string
;
...
...
playground/src/locales/langs/en-US/examples.json
View file @
bbd8a53
...
@@ -41,6 +41,7 @@
...
@@ -41,6 +41,7 @@
"pointSelection"
:
"Point Selection Captcha"
,
"pointSelection"
:
"Point Selection Captcha"
,
"sliderCaptcha"
:
"Slider Captcha"
,
"sliderCaptcha"
:
"Slider Captcha"
,
"sliderRotateCaptcha"
:
"Rotate Captcha"
,
"sliderRotateCaptcha"
:
"Rotate Captcha"
,
"sliderTranslateCaptcha"
:
"Translate Captcha"
,
"captchaCardTitle"
:
"Please complete the security verification"
,
"captchaCardTitle"
:
"Please complete the security verification"
,
"pageDescription"
:
"Verify user identity by clicking on specific locations in the image."
,
"pageDescription"
:
"Verify user identity by clicking on specific locations in the image."
,
"pageTitle"
:
"Captcha Component Example"
,
"pageTitle"
:
"Captcha Component Example"
,
...
...
playground/src/locales/langs/zh-CN/examples.json
View file @
bbd8a53
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
"pointSelection"
:
"点选验证"
,
"pointSelection"
:
"点选验证"
,
"sliderCaptcha"
:
"滑块验证"
,
"sliderCaptcha"
:
"滑块验证"
,
"sliderRotateCaptcha"
:
"旋转验证"
,
"sliderRotateCaptcha"
:
"旋转验证"
,
"sliderTranslateCaptcha"
:
"拼图滑块验证"
,
"captchaCardTitle"
:
"请完成安全验证"
,
"captchaCardTitle"
:
"请完成安全验证"
,
"pageDescription"
:
"通过点击图片中的特定位置来验证用户身份。"
,
"pageDescription"
:
"通过点击图片中的特定位置来验证用户身份。"
,
"pageTitle"
:
"验证码组件示例"
,
"pageTitle"
:
"验证码组件示例"
,
...
...
playground/src/router/routes/modules/examples.ts
View file @
bbd8a53
...
@@ -197,6 +197,15 @@ const routes: RouteRecordRaw[] = [
...
@@ -197,6 +197,15 @@ const routes: RouteRecordRaw[] = [
},
},
},
},
{
{
name
:
'TranslateVerifyExample'
,
path
:
'/examples/captcha/slider-translate'
,
component
:
()
=>
import
(
'#/views/examples/captcha/slider-translate-captcha.vue'
),
meta
:
{
title
:
$t
(
'examples.captcha.sliderTranslateCaptcha'
),
},
},
{
name
:
'CaptchaPointSelectionExample'
,
name
:
'CaptchaPointSelectionExample'
,
path
:
'/examples/captcha/point-selection'
,
path
:
'/examples/captcha/point-selection'
,
component
:
()
=>
component
:
()
=>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment