All Projects → javaLuo → Vue Puzzle Vcode

javaLuo / Vue Puzzle Vcode

Licence: apache-2.0
vue 拼图人机验证 右滑拼图验证

Labels

Projects that are alternatives of or similar to Vue Puzzle Vcode

slidey
Slide the tiles to fix the picture!
Stars: ✭ 15 (-86.11%)
Mutual labels:  puzzle
Puzzleview
Android Jigsaw puzzle support,inspired by Instagram's layout.
Stars: ✭ 727 (+573.15%)
Mutual labels:  puzzle
Regex
A Regular Expression game for Android
Stars: ✭ 80 (-25.93%)
Mutual labels:  puzzle
Twenty48
A modified clone of the puzzle game 2048, built in react/typescript!
Stars: ✭ 31 (-71.3%)
Mutual labels:  puzzle
Great Puzzles
A curated list of great puzzles
Stars: ✭ 448 (+314.81%)
Mutual labels:  puzzle
Advent Of Code 2020
My JavaScript solutions for Advent of Code 2020
Stars: ✭ 22 (-79.63%)
Mutual labels:  puzzle
CoTerminalApps
Retro ASCII Puzzles plus SpaceInvaders, Pacman & Frogger arcade games that run WITH SOUND in a terminal on any platform !!
Stars: ✭ 21 (-80.56%)
Mutual labels:  puzzle
Puzzlemaker
Swift framework responsible for generating puzzles from the image
Stars: ✭ 99 (-8.33%)
Mutual labels:  puzzle
Robotopia
🤖 Introducing kids to coding with tiny virtual robots!
Stars: ✭ 478 (+342.59%)
Mutual labels:  puzzle
Parachuting Robots
An interactive version of a classic puzzle
Stars: ✭ 67 (-37.96%)
Mutual labels:  puzzle
Quantum Game
Quantum Game (old version) - a puzzle game with real quantum mechanics in a browser
Stars: ✭ 294 (+172.22%)
Mutual labels:  puzzle
Ordinary Puzzles App
Mobile and web puzzle game built with React-Native
Stars: ✭ 376 (+248.15%)
Mutual labels:  puzzle
Sudoku Generator
A Sudoku puzzle generator written in C++ using modified and efficient backtracking algorithm.
Stars: ✭ 33 (-69.44%)
Mutual labels:  puzzle
bottomless-block-barrage
Panel de Pon (Tetris Attack) clone for the 3ds.
Stars: ✭ 15 (-86.11%)
Mutual labels:  puzzle
Codedojos
Code dojos
Stars: ✭ 84 (-22.22%)
Mutual labels:  puzzle
react-crossword
A flexible, responsive, and easy-to-use crossword component for React apps.
Stars: ✭ 80 (-25.93%)
Mutual labels:  puzzle
Sudoku
Can Neural Networks Crack Sudoku?
Stars: ✭ 742 (+587.04%)
Mutual labels:  puzzle
Matchimals.fun
🦁 🃏 📱 An animal matching puzzle card game– built with turn-based game engine boardgame.io and React-Native + React-Native-Web
Stars: ✭ 101 (-6.48%)
Mutual labels:  puzzle
Opencx
An open-source cryptocurrency exchange toolkit for implementing experimental exchange features
Stars: ✭ 86 (-20.37%)
Mutual labels:  puzzle
Match3
✨🐠The most original game on Earth: Match3 - now in Unity!✨🐟
Stars: ✭ 50 (-53.7%)
Mutual labels:  puzzle

vue-puzzle-vcode npm npm downloads

Vue 纯前端的拼图人机验证、右滑拼图验证
我知道有第 3 方的很好用,比如 GEETEST 的拼图验证,但要引入 SDK 跟后台配合,还有接口交互。
太麻烦了,有时候突然改需求来不及弄,为了应付老板,就弄了个纯前端的随便验一下得了。

DEMO: https://isluo.com/work/vue-puzzle-vcode/

img

重要更新

2020/03/16 v1.1.0 事件名改变

@onSuccess -> @success
@onClose -> @close
@onFail -> @fail

安装

  npm install vue-puzzle-vcode --save

使用

import Vcode from "vue-puzzle-vcode";

<Vcode :show="isShow" @success="success" @close="close" />

IE

我没加babel-polyfill,所以在 IE 里会报错:SCRIPT1002: 语法错误(IE 不支持箭头 函数)
需要兼容 IE 的朋友,请直接复制src/app.vuesrc/assets这两个东西 到自己的项目里,给app.vue随便改个名字,就是个普通 vue 组件,直接用即可。
src/assets里是一张小图片,app.vue中有引用,注意自己匹配一下引用路径

最简单例子

<template>
  <div>
    <Vcode :show="isShow" @success="success" @close="close" />
    <button @click="submit">登录</button>
  </div>
</template>

<script>
import Vcode from "vue-puzzle-vcode";
export default {
  data() {
    return {
      isShow: false, // 验证码模态框是否出现
    };
  },
  components: {
    Vcode,
  },
  methods: {
    submit() {
      this.isShow = true;
    },
    // 用户通过了验证
    success(msg) {
      this.isShow = false; // 通过验证后,需要手动隐藏模态框
    },
    // 用户点击遮罩层,应该关闭模态框
    close() {
      this.isShow = false;
    },
  },
};
</script>

参数

字段 类型 默认值 说明
show Boolean false 是否显示验证码弹框
canvasWidth Number 310 主图区域的宽度,单位 px
canvasHeight Number 160 主图区域的高度,单位 px
puzzleScale Number 1 拼图块(小的拼图)的大小比例,0.2 ~ 2 ,数字越大,拼图越大
sliderSize Number 50 左下角用户拖动的那个滑块的尺寸,单位 px
range Number 10 判断成功的误差范围,单位 px, 滑动的距离和拼图的距离小于等于此值时,会判定重合
imgs Array null 自定义图片,见下方例子
successText String "验证通过!" 验证成功时的提示文字
failText String "验证失败,请重试" 验证失败时的提示文字
sliderText String "拖动滑块完成拼图" 下方滑动条里的文字

事件

事件名 返回值 说明
success 偏差值 验证通过时会触发,返回值是用户移动的距离跟目标距离的偏差值 px
fail 偏差值 验证失败时会触发,返回值同上
close null 用户点击遮罩层的回调

自定义图片

<template>
  <Vcode :imgs="[Img1, Img2]" />
</template>

<script>
import Img1 from "~/assets/img1.png";
import Img2 from "~/assets/img2.png";

export default {
  data() {
    return {
      Img1,
      Img2,
    };
  },
};
</script>
  • 也可以是网络图片完整 URL 路径,但注意图片跨域问题,因为 canvas api 无法调用跨 域的图片

说明

  • 当不传递 imgs 字段或图片加载出错时,会自动生成随机图片
  • 模态框的显示和隐藏完全由父级控制,所以用户通过验证后,需要手动隐藏模态框

更新日志

1.1.5 2021/02/09 把所有package包更新到最新,减小代码体积。 (目前不支持vue3.0, 会报错, 等vue3.0正式发布时再改)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].