`

vue滑动验证组件

 
阅读更多
组件代码
<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项目拼图滑动验证组件

    vue项目拼图滑动验证组件,经过处理兼容IE及各个浏览器,图片需要自己上传,链接https://blog.csdn.net/Hei_lovely_cat/article/details/106214695

    使用Vue 实现滑动验证码功能

    本文章主要来介绍一下第一个阶段,也就是前端校验的验证码的实现,下面来介绍一下拖动验证码的具体实现。这篇文章主要介绍了利用 Vue 实现滑动验证码,需要的朋友可以参考下

    手机短信验证、滑动验证

    vue实现手机短信验证、滑动验证,vue,等真实可靠,,

    基于vue实现探探滑动组件功能

    嗨,说起探探想必各位程序汪都不陌生(毕竟妹子很多),能在上面丝滑的翻牌子,探探的的堆叠滑动组件起到了关键的作用,下面就来看看如何用vue写一个探探的堆叠组件 ? 一. 功能分析 简单使用下探探会发现,堆叠滑动的...

    vue行为验证压缩包.rar

    本文件适用于vue,中滑动滑块验证和依次点击字体验证,需要搭配本人文章结合了解,您可以将其视为一个组件放在项目中,请注意您的引入地址。

    滑动拼图验证,vue组件

    &lt;verifyImage :show="showVerifyImage" :imgs="imgs" @success="showVerifyImageSuccessHandle" @close="showVerifyImageCloseHandle"/&gt;

    Vue插件之滑动验证码

    主要为大家详细绍介绍了Vue插件之滑动验证码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    2018年最新vue2.5 硅谷外卖视频

    07_Vue项目_组件化编码.avi 08_Vue项目_引入vue-router.avi 09_Vue项目_FooterGuide组件.avi 10_Vue项目_各导航路由组件(静态).avi 11_Vue项目_HeaderTop组件.avi 12_Vue项目_使用swiper实现商品分类列表轮播....

    2018年最新vue2.5 硅谷外卖视频+源码

    Vue项目_解决惯性滑动不更新当前分类的bug.avi 59_Vue项目_点击分类项滑动右侧列表.avi 60_Vue项目_CartControl组件1.avi 61_Vue项目_CartControl组件2.avi 62_Vue项目_Food组件1.avi 63_Vue项目_Food组件2.avi 64_...

    vue-gn-components:这里有一些标准组件库可能没有的功能组件,已有组件:放大镜、签到、图片标签、滑动验证、倒计时、水印、拖拽、大家来找茬

    日常开发使用组件库一般都能满足大部分的需求,不过有些功能组件可能库里并没有,这里开源一些特定项目可能会使用到的组件,希望可以帮助到大家~ 示例查看 将本项目克隆到本地,安装完依赖,执行运行的命令即可查看...

    vue-demo:一些实用的vue+element组件功能

    主要的功能: 忘记密码发送验证码功能 账号密码错误弹出滑动验证框 顶部面包屑实现 侧边菜单栏实现,页面刷新高亮当前页面菜单 demo小组件 1. 组织架构图,树形图 2. 图片旋转 3. 放大镜功能 4. 级联面板应用 5. vue...

    vue如何在项目中调用腾讯云的滑动验证码

    在项目中使用滑动验证,可以调用腾讯云的组件和接口(付费项目) 导言 首先看看官方的步骤教学: https://cloud.tencent.com/document/product/1110/36839 其中,前端涉及到的是“步骤3:客户端接入”,里面介绍了...

    vue仿淘宝滑动验证码功能(样式模仿)

    我们知道验证码的目的 是为了验证到底是人还是机器。 淘宝滑动验证码会采集用户的操作数据,环境数据等等,通过算法加密成一个字符串,提交到... vue组件(下面是一个vue组件,可以引入直接使用) &lt;div clas

    vue2-verify:vue的验证码插件

    滑动验证码slide 通过简单的滑动即可完成验证,应用与移动端体验很好。 拼图验证码puzzle 拼图。 选字验证码pick 通过按顺序点选图中的汉字完成验证,ie浏览器要求9或以上。 请记住一件事! 纯前端是可以被别人绕过...

    EasySlideVerification:滑动验证,拼图验证

    滑动验证,拼图验证 简介: .net core平台下的滑动验证,拼图验证模块。可参考示例: 服务端生成校验图片,前端展示,验证用户操作结果。 校验数据存储支持本地内存和redis分布式缓存两种模式,开发调试或单机部署时...

    Vue实现滑动拼图验证码功能

    缘由:之前看哔哩哔哩官网登录的时候有一个拼图验证码,很好奇怎么去实现。然后就想着自己弄一个。先给大家看我的最终效果。后面再一点点拆解代码。...我个人也研究和编写了这块的组件功能(基于popp

    基于 Vue3 + Vite2+ Pinia + ts + windicss + Naive UI 的轻量级后台管理模板

    Naive-ui 尤大亲推的一款新 UI,完全 TypeScript 编写、组件多、主题配置方便、使用自由Pinia Pinia 是 Vue 的存储库,与 Vuex 功能相同,在使用方便比 Vuex 更舒服,代码提示让你爱不释手 axios 易用、简洁且高效的 ...

    关于滑动图片验证码、人机拖拽、 纯前端、前后端实现组件

    内容概要:通过带着读者手写基于vue3 所编写的人机拖拽基础组件,主要内容场景就是生成滑动验证码,人为手动拖拽到相应的位置,验证则成功,代码主要包含了2种情况,1。纯前端实现,后端不参与 2.前后端都参与 而...

    微信小程序电商实战课程SpringBoot2+Vue3(85到96讲)

    本套课程采用主流技术栈实现,Mysql数据库,SpringBoot2+Mybatis Plus后端,微信小程序原生实现,Vue3.2+Element Plus实现后台管理。...Form表单,rules验证框架,dialog以及第三方vue-quil富文本组件等。

Global site tag (gtag.js) - Google Analytics