vue仿京东画线验证码,前端手指位置数据获取
需求是这样的,京东H5移动端登录,有个安照箭头方向,画线登录的验证,看看是怎么实现的:
直接上代码了:
<template>
<div v-if="visible">
<div class="modal">
<p style="font-size:0.15rem;color: #333333;line-height: 0.22rem;padding:0.08rem 0">{{title}}</p>
<div class="captchaArea">
<img @touchstart="touchStartCaptcha($event)" @touchmove="touchMoveCaptcha($event)"
@touchend="touchEndCaptcha($event)" :src="imgUrl" alt="" @error="onError($event)"
style="width:100%;height:100%;">
</div>
<div class="tips">请按照箭头路线滑动手指</div>
</div>
<div class="shade">
</div>
<div id="canvas-wrapper" v-show="showCanvas">
<canvas id="captcha_canvas">您的浏览器不支持!请换用高版本浏览器!</canvas>
</div>
</div>
</template> <script>
export default {
name: '',
data () {
return {
showCanvas: false,
imgUrl: "",
da: [],
pa: [],
initTime: '',
defaultPic: ''
}
},
props: {
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: "安全验证"
}
},
methods: {
onError (e) {
this.showCanvas = false
e.target.src = this.defaultPic;
},
show () {
this.visible = true;
},
hide () {
this.visible = false;
},
loadImg (imgUrl) {
if (imgUrl) {
this.imgUrl = imgUrl
}
},
drawCanvas (e) { // 绘制手指划过的路线
let c = e.touches[0].clientX
let t = e.touches[0].clientY
let sx = e.touches[0].screenX
let sy = e.touches[0].screenY
this.pa.push({
x: c,
y: t
})
this.da.push([sx, sy, c, t, (new Date).getTime() - this.initTime]) // 持续添加坐标
let oa = document.getElementById("captcha_canvas").getContext("2d")
oa.clearRect(0, 0, window.screen.width, window.screen.height)
oa.strokeStyle = "#ff9046"
oa.lineWidth = 6
oa.beginPath()
oa.moveTo(this.pa[0].x, this.pa[0].y)
for (let i = 1; i < this.pa.length - 2; i++) {
let drawX = (this.pa[i].x + this.pa[i + 1].x) / 2
let drawY = (this.pa[i].y + this.pa[i + 1].y) / 2
oa.quadraticCurveTo(this.pa[i].x, this.pa[i].y, drawX, drawY) // 多次绘制
}
oa.stroke()
this.initTime = new Date().getTime()
},
touchStartCaptcha (e) {
this.initTime = new Date().getTime()
this.showCanvas = true
let canvas = document.getElementById("captcha_canvas")
canvas.width = window.screen.width
canvas.height = window.screen.height
this.drawCanvas(e) // 开始绘制手指划过路线
},
touchMoveCaptcha (e) {
if (this.da.length > 400) {
this.da = []
this.pa = []
this.showCanvas = false
return false
}
this.drawCanvas(e) // 持续绘制手指划过路线
},
touchEndCaptcha () {
let c = { 'x':10, 'y':55, 'ht':179.313, 'wt':290.078, 'list': this.da }
this.da = []
this.pa = []
this.showCanvas = false
let str = JSON.stringify(c)
this.$emit('touchEndCaptcha', str)
}
}
}
</script>
<style scoped>
i {
background-image: url("../assets/img/cancel.png");
width: 45px;
height: 45px;
display: inline-block;
position: absolute;
transform: scale(0.3, 0.3);
right: 0px;
top: 0px;
} .shade {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: black;
opacity: 0.5;
z-index: 1;
} #canvas-wrapper {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: transparent;
z-index: 3;
} #captcha_canvas {
/*width: 100%;*/
/*height: 100%;*/
pointer-events: none;
} .modal {
position: absolute;
width: 90%;
height: 3rem;
background-color: #ffffff;
opacity: 1;
z-index: 2;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
border-radius: 5px;
padding: 0.08rem 0.2rem;
text-align: center;
box-sizing: border-box;
}
.captchaArea {
height: 1.8rem;
margin-bottom: 0.3rem;
background-color: #D8D8D8;
} .tips {
font-size: 0.16rem;
} .bottom {
height: 0.4rem;
margin-top: 0.1rem;
line-height: 0.4rem;
text-align: left;
} .bottom span {
display: inline-block;
vertical-align: top;
} .bottom img {
display: inline-block;
width: 50%;
}
</style>
最终的输出:(无需关注)
{'x':10,'y':55,'ht':179.313,'wt':290.078,'list':[[1058,440,90.66666412353516,276,1],[1058,440,90.66666412353516,276,0],[1066,444,101.33333587646484,281.3333435058594,150],[1068,444,104,281.3333435058594,9],[1071,446,108,284,7],[1074,447,112,285.3333435058594,8],[1075,447,113.33333587646484,285.3333435058594,8],[1077,449,116,288,8],[1078,450,117.33333587646484,289.3333435058594,8],[1079,450,118.66666412353516,289.3333435058594,8],[1080,450,120,289.3333435058594,10],[1081,450,121.33333587646484,289.3333435058594,17],[1082,450,122.66666412353516,289.3333435058594,5],[1083,451,124,290.6666564941406,11],[1084,451,125.33333587646484,290.6666564941406,5],[1085,451,126.66666412353516,290.6666564941406,11],[1086,452,128,292,5],[1088,453,130.6666717529297,293.3333435058594,11],[1089,453,132,293.3333435058594,5],[1090,453,133.3333282470703,293.3333435058594,17],[1091,454,134.6666717529297,294.6666564941406,8],[1092,454,136,294.6666564941406,7],[1094,454,138.6666717529297,294.6666564941406,9],[1095,454,140,294.6666564941406,8],[1096,454,141.3333282470703,294.6666564941406,8],[1098,454,144,294.6666564941406,7],[1099,454,145.3333282470703,294.6666564941406,8],[1100,454,146.6666717529297,294.6666564941406,8],[1101,455,148,296,8],[1102,455,149.3333282470703,296,8],[1103,455,150.6666717529297,296,129],[1104,456,152,297.3333435058594,15],[1105,456,153.3333282470703,297.3333435058594,8],[1107,457,156,298.6666564941406,9],[1108,457,157.3333282470703,298.6666564941406,16],[1109,457,158.6666717529297,298.6666564941406,7],[1111,457,161.3333282470703,298.6666564941406,9],[1113,457,164,298.6666564941406,8],[1115,458,166.6666717529297,300,7],[1117,458,169.3333282470703,300,9],[1119,458,172,300,7],[1122,458,176,300,9],[1125,458,180,300,7],[1127,458,182.6666717529297,300,11],[1130,458,186.6666717529297,300,5],[1132,457,189.3333282470703,298.6666564941406,10],[1134,457,192,298.6666564941406,6],[1137,457,196,298.6666564941406,11],[1141,456,201.3333282470703,297.3333435058594,16],[1142,456,202.6666717529297,297.3333435058594,5],[1143,456,204,297.3333435058594,16],[1144,456,205.3333282470703,297.3333435058594,9],[1145,456,206.6666717529297,297.3333435058594,23],[1146,456,208,297.3333435058594,25],[1148,456,210.6666717529297,297.3333435058594,7],[1149,455,212,296,8],[1150,455,213.3333282470703,296,16],[1151,455,214.6666717529297,296,11],[1152,455,216,296,5],[1153,455,217.3333282470703,296,13],[1155,455,220,296,3],[1156,455,221.3333282470703,296,12],[1162,455,229.3333282470703,296,14],[1164,455,232,296,7],[1166,455,234.6666717529297,296,10],[1168,455,237.3333282470703,296,5],[1170,455,240,296,8],[1171,455,241.3333282470703,296,9],[1172,455,242.6666717529297,296,8],[1173,455,244,296,7],[1175,455,246.6666717529297,296,152],[1176,455,248,296,32],[1177,456,249.3333282470703,297.3333435058594,8],[1178,457,250.6666717529297,298.6666564941406,8],[1179,457,252,298.6666564941406,24],[1181,458,254.6666717529297,300,72],[1181,459,254.6666717529297,301.3333435058594,8],[1183,459,257.3333435058594,301.3333435058594,8],[1183,460,257.3333435058594,302.6666564941406,8],[1184,460,258.6666564941406,302.6666564941406,11],[1185,461,260,304,21],[1185,462,260,305.3333435058594,17],[1186,464,261.3333435058594,308,23],[1187,466,262.6666564941406,310.6666564941406,32],[1187,467,262.6666564941406,312,8],[1188,469,264,314.6666564941406,25],[1188,470,264,316,23],[1188,471,264,317.3333435058594,8],[1188,473,264,320,8],[1188,474,264,321.3333435058594,18],[1188,475,264,322.6666564941406,6],[1188,476,264,324,10],[1188,477,264,325.3333435058594,16],[1188,478,264,326.6666564941406,6],[1188,479,264,328,9],[1188,480,264,329.3333435058594,15],[1188,481,264,330.6666564941406,9],[1188,482,264,332,10],[1188,483,264,333.3333435058594,14],[1188,484,264,334.6666564941406,7],[1188,485,264,336,8],[1189,488,265.3333435058594,340,17],[1189,489,265.3333435058594,341.3333435058594,15],[1190,492,266.6666564941406,345.3333435058594,16],[1190,494,266.6666564941406,348,32],[1191,496,268,350.6666564941406,8],[1192,498,269.3333435058594,353.3333435058594,17],[1192,499,269.3333435058594,354.6666564941406,16],[1193,501,270.6666564941406,357.3333435058594,7],[1193,502,270.6666564941406,358.6666564941406,16],[1194,503,272,360,9],[1194,504,272,361.3333435058594,16],[1194,505,272,362.6666564941406,23],[1195,506,273.3333435058594,364,9],[1196,507,274.6666564941406,365.3333435058594,7],[1197,509,276,368,25],[1198,511,277.3333435058594,370.6666564941406,23],[1198,512,277.3333435058594,372,24],[1198,513,277.3333435058594,373.3333435058594,16],[1199,515,278.6666564941406,376,8],[1199,516,278.6666564941406,377.3333435058594,33],[1199,517,278.6666564941406,378.6666564941406,15],[1200,518,280,380,32],[1200,519,280,381.3333435058594,8],[1200,520,280,382.6666564941406,72],[1200,521,280,384,16],[1200,523,280,386.6666564941406,40],[1200,524,280,388,8],[1200,525,280,389.3333435058594,40],[1200,526,280,390.6666564941406,8],[1200,527,280,392,8],[1199,527,278.6666564941406,392,49],[1198,528,277.3333435058594,393.3333435058594,7],[1197,529,276,394.6666564941406,24],[1196,530,274.6666564941406,396,32],[1195,530,273.3333435058594,396,8],[1194,531,272,397.3333435058594,8],[1192,531,269.3333435058594,397.3333435058594,41],[1191,531,268,397.3333435058594,23],[1189,531,265.3333435058594,397.3333435058594,16],[1188,531,264,397.3333435058594,8],[1184,531,258.6666564941406,397.3333435058594,8],[1182,531,256,397.3333435058594,9],[1179,531,252,397.3333435058594,7],[1176,531,248,397.3333435058594,8],[1172,530,242.6666717529297,396,16],[1170,530,240,396,8],[1167,528,236,393.3333435058594,8],[1164,528,232,393.3333435058594,8],[1162,528,229.3333282470703,393.3333435058594,8],[1160,527,226.6666717529297,392,8],[1158,526,224,390.6666564941406,8],[1156,525,221.3333282470703,389.3333435058594,8],[1154,525,218.6666717529297,389.3333435058594,8],[1153,525,217.3333282470703,389.3333435058594,9],[1151,524,214.6666717529297,388,7],[1150,523,213.3333282470703,386.6666564941406,16],[1149,523,212,386.6666564941406,9],[1149,522,212,385.3333435058594,8],[1148,522,210.6666717529297,385.3333435058594,15],[1146,522,208,385.3333435058594,8],[1145,522,206.6666717529297,385.3333435058594,9],[1144,521,205.3333282470703,384,7],[1142,521,202.6666717529297,384,9],[1140,520,200,382.6666564941406,8],[1138,519,197.3333282470703,381.3333435058594,8],[1136,519,194.6666717529297,381.3333435058594,7],[1134,519,192,381.3333435058594,8],[1133,519,190.6666717529297,381.3333435058594,16],[1130,518,186.6666717529297,380,8],[1129,518,185.3333282470703,380,8],[1127,517,182.6666717529297,378.6666564941406,8],[1125,517,180,378.6666564941406,8],[1124,516,178.6666717529297,377.3333435058594,8],[1123,516,177.3333282470703,377.3333435058594,8],[1121,515,174.6666717529297,376,24],[1120,515,173.3333282470703,376,25],[1118,515,170.6666717529297,376,15],[1117,515,169.3333282470703,376,16],[1115,515,166.6666717529297,376,16],[1111,514,161.3333282470703,374.6666564941406,8],[1110,514,160,374.6666564941406,9],[1109,514,158.6666717529297,374.6666564941406,17],[1108,514,157.3333282470703,374.6666564941406,6],[1107,514,156,374.6666564941406,16],[1106,514,154.6666717529297,374.6666564941406,8],[1104,514,152,374.6666564941406,9],[1103,514,150.6666717529297,374.6666564941406,23],[1102,514,149.3333282470703,374.6666564941406,8],[1101,514,148,374.6666564941406,8],[1100,514,146.6666717529297,374.6666564941406,25],[1098,513,144,373.3333435058594,7],[1097,512,142.6666717529297,372,10],[1096,512,141.3333282470703,372,118],[1094,512,138.6666717529297,372,8],[1092,511,136,370.6666564941406,24],[1091,511,134.6666717529297,370.6666564941406,16],[1090,511,133.3333282470703,370.6666564941406,8],[1088,510,130.6666717529297,369.3333435058594,8],[1087,510,129.3333282470703,369.3333435058594,66],[1085,510,126.66666412353516,369.3333435058594,222]]}
这样就能获取到整个手指划过的路线数据了。
vue仿京东画线验证码,前端手指位置数据获取的更多相关文章
- vue仿京东省市区三级联动选择组件
工作中需要一个盒京东购物车地址选择相似的一个省市区三级联动选择组件,google查了下都是下拉框形式的,于是自己写了一个,希望对使用vue开发项目的朋友有帮助,显示效果如下:使用vue2.0开发 ht ...
- vue 专题 vue2.0各大前端移动端ui框架组件展示
Vue 专题 一个数据驱动的组件,为现代化的 Web 界面而生.具有可扩展的数据绑定机制,原生对象即模型,简洁明了的 API 组件化 UI 构建 多个轻量库搭配使用 请访问链接: https://ww ...
- Android中Path类的lineTo方法和quadTo方法画线的区别
转载:http://blog.csdn.net/stevenhu_223/article/details/9229337 当我们需要在屏幕上形成画线时,Path类的应用是必不可少的,而Path类的li ...
- jQuery仿京东无限级菜单HoverTree
官方网址:http://keleyi.com/jq/hovertree/ 效果图: 看了上面效果图,你或许已经明白为什么是仿京东菜单.如果还不明白,请访问http://list.jd.com/list ...
- React-Native牛刀小试仿京东砍啊砍砍到你手软
React-Native牛刀小试仿京东砍啊砍砍到你手软 React-Native基础教程 *React-Native基础篇作者git *React-Native官方文档 *Demo 几个月前faceb ...
- 仿京东树形菜单插件hovertree
hovertree是一个仿京东的树形菜单jquery插件,暂时有银色和绿色两种. 官方网址:http://keleyi.com/jq/hovertree/欢迎下载使用 查看绿色效果:http://ke ...
- android中实现在ImageView上随意画线涂鸦
我实现的思路: 1.继承ImageView类 2.重写onTouchEvent方法,在ACTION_MOVE(即移动时),记录下所经过的点坐标,在ACTION_UP时(即手指离开时,这时一条线已经画完 ...
- 浅谈android中只使用一个TextView实现高仿京东,淘宝各种倒计时
今天给大家带来的是只使用一个TextView实现一个高仿京东.淘宝.唯品会等各种电商APP的活动倒计时.近期公司一直加班也没来得及时间去整理,今天难得歇息想把这个分享给大家.只求共同学习,以及自己兴许 ...
- 解题:在下面画线的地方填任何代码,使得最终输出 'hello world',至少写五个不同思路的方案
今天(已经好些天前了...),群里面(JS前端开发跳板6群[81501322])有个群友问了这样一个问题. 如题:在下面画线的地方填任何代码,使得最终输出 'hello world',至少写五个不同思 ...
随机推荐
- corethink功能模块探索开发(十六)后台搜索功能
效果图: 代码很简单,就是添加搜索框,搜索字段,在初始化页面查询的时候添加查询条件. 1.添加搜索框 添加到删除按钮后边. ->setSearch('请输入设备名称/MAC/宿舍号', U('i ...
- PHP引用符&的用法详细解析
本文转自:http://blog.csdn.net/vip_linux/article/details/10206091PHP中引用符&的用法.关于php的引用(就是在变量或者函数.对象等前面 ...
- beego——模型(model)
beego ORM是一个强大的Go语言ORM框架.她的灵感主要来自Django ORM和SQLAlchemy. 已经支持的数据库驱动: MySQL:https://github.com/go-sql- ...
- LeetCode:前K个高频单词【692】
LeetCode:前K个高频单词[692] 题目描述 给一非空的单词列表,返回前 k 个出现次数最多的单词. 返回的答案应该按单词出现频率由高到低排序.如果不同的单词有相同出现频率,按字母顺序排序. ...
- CodeForces - 986A Fair (BFS+贪心)
题意:有N个点M条边的无向图,每个点有给定的ai(1<=ai<=K,K<=200)表示该点拥有的物品编号,保证1-K在N个点全部出现.求每个点收集S个不同的物品所要走过的最短路程(边 ...
- 给IT男推荐一款车
标题是为了吸引人,其实这里要推荐的不是汽车而是自行车,确切的说是电动自行车(也有叫锂电自行车),见下图! (备注:淘宝截图,有便宜的2K就能搞定,好点的像这一款3K吧!) 码农这个词真不是瞎叫的,做这 ...
- gitlab + jenkins + docker + k8s
总体流程: 在开发机开发代码后提交到gitlab 之后通过webhook插件触发jenkins进行构建,jenkins将代码打成docker镜像,push到docker-registry 之后将在k8 ...
- 【Head First Servlets and JSP】笔记1
1.把Java放到HTML中,JSP应运而生. 2.Servlet本身并没有main()方法,所以必须要有其他Java程序去调用它,这个Java程序就是Web容器(Container).Tomcat就 ...
- Windows:FTP命令大全
Windows:FTP命令大全 简介 1, open:与服务器相连接: 2, send(put):上传文件: 3,get:下载文件: 4,mget:下载多个文件: 用法: mget *:下载当前路径下 ...
- 苹果Dock样式的菜单
在线演示 本地下载