组件代码
<template>
<el-form-item label="验证">
<div class="form-inline-input">
<div class="code-box" id="code-box">
<input type="text" name="code" class="code-input" />
<p></p>
<span>>>></span>
</div>
</div>
</el-form-item>
</template>
<script>
export default {
name: 'Checker',
data() {
return {
verification: false,
}
},
mounted(){
let _this = this;
let code = "jsaidaisd656";
let codeFn = new _this.moveCode(code,_this);
},
methods: {
isVerify(){
console.log("isVerify");
return this.verification;
},
//获取元素距离页面边缘的距离
getOffset(box,direction){
var setDirection = (direction == 'top') ? 'offsetTop' : 'offsetLeft' ;
var offset = box[setDirection];
var parentBox = box.offsetParent;
while(parentBox){
offset+=parentBox[setDirection];
parentBox = parentBox.offsetParent;
}
parentBox = null;
return parseInt(offset);
},
moveCode(code,_this){
var fn = {codeVluae : code};
var box = document.querySelector("#code-box"),
progress = box.querySelector("p"),
codeInput = box.querySelector('.code-input'),
evenBox = box.querySelector("span");
//默认事件
var boxEven = ['mousedown','mousemove','mouseup'];
//改变手机端与pc事件类型
if(typeof document.ontouchstart == 'object'){
boxEven = ['touchstart','touchmove','touchend'];
}
var goX,offsetLeft,deviation,evenWidth,endX;
function moveFn(e){
e.preventDefault();
e = (boxEven['0'] == 'touchstart') ? e.touches[0] : e || window.event;
endX = e.clientX - goX;
endX = (endX > 0) ? (endX > evenWidth) ? evenWidth : endX : 0;
if(endX > evenWidth * 0.7){
progress.innerText = '松开验证';
progress.style.backgroundColor = "#66CC66";
}else{
progress.innerText = '';
progress.style.backgroundColor = "#FFFF99";
}
progress.style.width = endX+deviation+'px';
evenBox.style.left = endX+'px';
}
function removeFn() {
document.removeEventListener(boxEven['2'],removeFn,false);
document.removeEventListener(boxEven['1'],moveFn,false);
if(endX > evenWidth * 0.7){
console.log("......ok");
progress.innerText = '验证成功';
progress.style.width = evenWidth+deviation+'px';
evenBox.style.left = evenWidth+'px'
codeInput.value = fn.codeVluae;
evenBox.onmousedown = null;
_this.verification = true;
console.log(_this.verification);
}else{
progress.style.width = '0px';
evenBox.style.left = '0px';
}
};
function getOffset(box,direction){
var setDirection = (direction == 'top') ? 'offsetTop' : 'offsetLeft' ;
var offset = box[setDirection];
var parentBox = box.offsetParent;
while(parentBox){
offset+=parentBox[setDirection];
parentBox = parentBox.offsetParent;
}
parentBox = null;
return parseInt(offset);
};
evenBox.addEventListener(boxEven['0'], function(e) {
e = (boxEven['0'] == 'touchstart') ? e.touches[0] : e || window.event;
goX = e.clientX,
offsetLeft = getOffset(box,'left'),
deviation = this.clientWidth,
evenWidth = box.clientWidth - deviation,
endX;
document.addEventListener(boxEven['1'],moveFn,false);
document.addEventListener(boxEven['2'],removeFn,false);
},false);
fn.setCode = function(code){
if(code)
fn.codeVluae = code;
}
fn.getCode = function(){
return fn.codeVluae;
}
fn.resetCode = function(){
evenBox.removeAttribute('style');
progress.removeAttribute('style');
codeInput.value = '';
};
return fn;
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container {
position: fixed;
height: 100%;
width: 100%;
background-color: $bg;
.login-form {
position: absolute;
left: 0;
right: 0;
width: 520px;
max-width: 100%;
padding: 35px 35px 15px 35px;
margin: 120px auto;
}
.tips {
font-size: 14px;
color: #fff;
margin-bottom: 10px;
span {
&:first-of-type {
margin-right: 16px;
}
}
}
.svg-container {
padding: 6px 5px 6px 15px;
color: $dark_gray;
vertical-align: middle;
width: 30px;
display: inline-block;
}
.title-container {
position: relative;
.title {
font-size: 26px;
color: $light_gray;
margin: 0px auto 40px auto;
text-align: center;
font-weight: bold;
}
.set-language {
color: #fff;
position: absolute;
top: 5px;
right: 0px;
}
}
.show-pwd {
position: absolute;
right: 10px;
top: 7px;
font-size: 16px;
color: $dark_gray;
cursor: pointer;
user-select: none;
}
.thirdparty-button {
position: absolute;
right: 35px;
bottom: 28px;
}
}
.form-inline-input{
border:1px solid #dadada;
border-radius:5px;
}
.form-inline-input input,
.code-box{
padding: 0 3px;
width: 298px;
height: 40px;
color: #fff;
text-shadow: 1px 1px 1px black;
background: #efefef;
border: 0;
border-radius: 5px;
outline: none;
}
.code-box{
position: relative;
}
.code-box p,
.code-box span{
display:block;
position: absolute;
left: 0;
height: 40px;
text-align: center;
line-height: 40px;
border-radius: 5px;
padding:0;
margin:0;
}
.code-box span{
width: 40px;
background-color:#fff;
font-size: 16px;
cursor: pointer;
margin-right:1px;
}
.code-box p{
width: 0;
background-color: #FFFF99;
overflow: hidden;
text-indent: -20px;
transition: background 1s ease-in;
}
.code-box .code-input{
display: none;
}
.code-box .code-input{
display: none;
}
.form-inline-input{
border:1px solid #dadada;
border-radius:5px;
}
.form-inline-input input,
.code-box{
padding: 0 3px;
width: 100%;
height: 40px;
color: #fff;
text-shadow: 1px 1px 1px black;
background: #efefef;
border: 0;
border-radius: 5px;
outline: none;
}
.code-box{
position: relative;
}
.code-box p,
.code-box span{
display:block;
position: absolute;
left: 0;
height: 40px;
text-align: center;
line-height: 40px;
border-radius: 5px;
padding:0;
margin:0;
}
.code-box span{
width: 40px;
background-color:#fff;
font-size: 16px;
cursor: pointer;
margin-right:1px;
}
.code-box p{
width: 0;
background-color: #FFFF99;
overflow: hidden;
text-indent: -20px;
transition: background 1s ease-in;
}
.code-box .code-input{
display: none;
}
.code-box .code-input{
display: none;
}
</style>
引用方式
<template>
……
<Checker ref="checker"/>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登录
</el-button>
……
</template>
……
<script>
……
methods:{
handleLogin() {
if(!this.$refs.checker.isVerify()){
this.$message({
message: '请先完成拖动验证',
type: 'warning'
});
return;
}
}
}
……
</script>
分享到:
相关推荐
vue项目拼图滑动验证组件,经过处理兼容IE及各个浏览器,图片需要自己上传,链接https://blog.csdn.net/Hei_lovely_cat/article/details/106214695
vue2 滑块滑动验证
其中,“vue滑块验证,图片验证,图片旋转验证,滑动验证”是常见且有效的防止恶意机器人或自动化程序进行短信盗刷的手段。这些验证方式旨在增加额外的人工交互环节,降低自动化工具的成功率。 **Vue.js** 是一个...
综上所述,Vue在实现滑动验证码中发挥着关键作用,通过组件化的开发方式,简化了开发流程并保证了前端用户的良好体验。在实际应用中,开发者可以根据具体需求进一步增强滑动验证码的安全性和交互性,比如调整滑块的...
在这个背景下,我们关注的是一个基于Vue2.x版本开发的日历组件,它被设计为轻量级且具有滑动功能,非常适合在各种Web应用中实现日期选择或日程安排的功能。 首先,我们来深入理解Vue2.x的核心概念。Vue2.x引入了...
本资源“uni 滑动验证码 css和验证组件.zip”提供了一个针对uni-app框架的滑动验证码实现,包含了CSS样式和验证组件的源代码。uni-app是一个多端开发框架,支持编写一次代码,运行于iOS、Android、H5等多个平台。...
vue实现手机短信验证、滑动验证,vue,等真实可靠,,
对于滑动验证,你可能希望提供一个重置按钮让用户重新尝试;对于点击验证,你可以设置一个计时器限制用户完成验证的时间,增加安全性。此外,这些组件应当具有良好的可配置性,以便适应不同的应用场景和需求。 总之...
基于 Vue.js 实现的滑动验证码组件源码+使用说明.zip基于 Vue.js 实现的滑动验证码组件源码+使用说明.zip基于 Vue.js 实现的滑动验证码组件源码+使用说明.zip基于 Vue.js 实现的滑动验证码组件源码+使用说明.zip基于...
Vue插件之滑动验证码是用于增强Web应用安全性的前端组件,通过添加一个滑动验证的过程来区分人类用户和自动化程序。在当下互联网环境中,各类恶意爬虫和自动化脚本泛滥,验证码成为了防护措施中常见的一环。滑动...
在名为"vue-jigsaw-captcha-master"的压缩包中,你将找到这个Vue滑动拼图验证码的源代码,包括Vue组件、样式表以及可能的服务器接口示例。通过阅读和理解这些代码,你可以学习如何在自己的项目中实现类似的验证码...
使用Vue.js的生命周期钩子和事件监听器来实现滑动验证的核心逻辑。 - **数据绑定**:初始化数据,包括滑动条的初始位置、最大宽度、验证状态等。 ```javascript data() { return { beginClientX: 0, ...
7. **框架与库的使用**:现代Web开发中,常常使用前端框架如React、Vue或Angular,以及库如jQuery,它们提供丰富的功能和组件,可以帮助快速实现滑动验证这样的复杂交互功能。 以上就是关于"登陆页面带滑动验证"所...
通过上述的描述,可以看到Vue登录滑动验证实现涉及到HTML、CSS以及JavaScript的基础知识,同时还需要对Vue框架的响应式数据绑定和组件生命周期有所了解。实现这一功能可以帮助开发者增强Web应用的用户体验和安全性。
<verifyImage :show="showVerifyImage" :imgs="imgs" @success="showVerifyImageSuccessHandle" @close="showVerifyImageCloseHandle"/>
前端执行滑动验证并打印返回结果,然后在调试工具中填写必填参数,包括Ticket、CaptchaAppId、Randstr等,模拟调用后端接口验证。 在实际开发中,还需要考虑错误处理、用户体验优化、无障碍访问支持等细节。确保在...
首先,`week.vue`、`month.vue`和`day.vue`这三个文件分别代表一周、一月和一天的筛选组件。Vue组件是Vue.js的核心特性之一,它允许我们将UI拆分成可重用的独立部分,每个部分都有自己的数据和逻辑。这些文件很可能...
vue-drag-verify这是一个vue组件,可以滑动以解锁以进行登录或注册。 这用于保护您的Web应用程序免受机器人攻击。 演示I vue-drag-verify这是一个vue组件,可以滑动以解锁以进行登录或注册。 这用于保护您的Web应用...
在这个"vue 拼图人机验证 右滑拼图验证.zip"压缩包中,包含的是一个Vue.js实现的拼图验证码(又称滑动拼图验证)的示例项目。这种验证方式是防止自动化机器人操作的一种常见手段,常用于提高网站的安全性。 拼图...