对于小程序canvas在某些情况下touchmove 不能触发导致的签名不连续替代方案(企微)
1.问题
尝试过新版canvas,在
企业微信中签名依然是依然断触,有问题的手机是iphoe15,系统版本以及企微版本微信版本均与签名正常的手机一致,但是那个手机就是无法正常签字,在微信中无论新旧canvas均能正常签字
2.解决方案
既然canvas的touchmove触发有问题,那么就可以通过
替代canvas的touchmove来实现,通过在canvas上覆盖一层dom,通过这层dom的touchmove来获取手指划过的轨迹即可,此文章中并没有小程序实际代码只是使用了h5验证可行性的代码
2.1 注意点
- 要区别手指是否连续滑动,由于点击事件触发存在如下情况
区别手指是否连续滑动采用时间间隔判断
触发事件间隔小于80ms 主要用于判断是否松开手指再次滑动,正常手速来说80ms,人很难在画完一个线段后,松手再次画一个线段,如果无这个处理会出现滑动一个线段之后,再次点击另一个点会把线段和新点位连接起来
没有采取通过touchstart与touchend做一个判断是因为touchmove并不是固定一直在start与end事件中间触发

2.2 移动端浏览器体验地址
2.2 vue2代码
<template>
<div class="DomCanvasSignature">
<div :style="{ height: height + 'px', width: width + 'px' }" class="signatureWrapper" id="signatureWrapper"
draggable="false" @mousedown="touchstart" @mouseup="touchend" @touchstart="touchstart" @touchend="touchend"
@touchmove="touchmove" @mousemove="touchmove">
<canvas canvas-id="999" :height="height" :width="width - 3" class="canvas" />
</div>
</div>
</template>
<script>
export default {
name: 'DomCanvasSignature',
data () {
return {
height: 302,
width: 302,
mycanvas: null,
previousPoint: {
x: 0,
y: 0
},
isPcStart: false,
removeLisner: () => { }
}
},
methods: {
initSize () {
this.width = window.innerWidth
this.height = window.innerHeight - 300
},
lisner () {
this.initSize()
window.addEventListener('resize', this.initSize)
return () => {
window.removeEventListener('resize', this.initSize)
}
},
touchstart () {
this.isPcStart = true
console.log('====start') // zdz-log
},
touchend () {
this.isPcStart = false
console.log('====end') // zdz-log
},
touchmove (e) {
console.log('move', e) // zdz-log
// 阻止滚动
e.preventDefault()
if (e.type === 'mousemove' && !this.isPcStart) {
return
}
// 合并处理 pc 与移动端
const changeObj = e.changedTouches && e.changedTouches[0] || e
const current = { x: changeObj.clientX, y: changeObj.clientY, timeStamp: e.timeStamp }
// 1.获取元素
// 2.获取上下文,绘制工具箱
let ctx = this.mycanvas.getContext('2d')
// 3.移动画笔
const currentY = (current.y) - signatureWrapper.offsetTop
// todo 改为touchstart 与end判断 无法实现 因为move 执行存在在 start end事件之后
let diffLarge = false
console.log(current.timeStamp - this.previousPoint.timeStamp) // zdz-log
// 判断是否松手重新绘制
if (this.previousPoint.timeStamp) {
const timeDiff = current.timeStamp - this.previousPoint.timeStamp > 80
if (timeDiff) {
diffLarge = true
}
}
const preY = diffLarge ? current.y - signatureWrapper.offsetTop : (this.previousPoint.y || current.y) - signatureWrapper.offsetTop
const moveX = diffLarge ? current.x : this.previousPoint.x || current.x
ctx.moveTo(moveX, preY < 0 ? 0 : preY)
// 4.绘制直线(轨迹,绘制路径)
ctx.lineTo(current.x, currentY < 0 ? 0 : currentY)
// 5.描边
ctx.stroke()
this.previousPoint = current
},
},
created () {
this.removeLisner = this.lisner()
},
destroyed () {
this.removeLisner()
},
mounted () {
this.mycanvas = document.querySelector('canvas')
this.signatureWrapper = document.getElementById('signatureWrapper')
},
}
</script>
<style scoped>
.canvas {
border: 1px solid red;
}
.signatureWrapper {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid black;
background-color: transparent;
}
</style>
对于小程序canvas在某些情况下touchmove 不能触发导致的签名不连续替代方案(企微)的更多相关文章
- 小程序Canvas性能优化实战
以下内容转载自totoro的文章<小程序Canvas性能优化实战!> 作者:totoro 链接:https://blog.totoroxiao.com/canvas-perf-mini/ ...
- 技术博客--微信小程序canvas实现图片编辑
技术博客--微信小程序canvas实现图片编辑 我们的这个小程序不仅仅是想给用户提供一个保存和查找的平台,还希望能给用户一个展示自己创意的舞台,因此我们实现了图片的编辑部分.我们对对图片的编辑集成了很 ...
- 微信小程序-canvas绘制文字实现自动换行
在使用微信小程序canvas绘制文字时,时常会遇到这样的问题:因为canvasContext.fillText参数为 我们只能设置文本的最大宽度,这就产生一定的了问题.如果我们绘制的文本长度不确定或者 ...
- 优化版小程序canvas,增加失败逻辑,及完善文字
wxml <view class="shareBox" style="backgound:{{isShow ? '#000' : '#fff'}}" wx ...
- [技术博客]海报图片生成——小程序canvas画布
目录 背景介绍 canvas简介 代码实现 难点讲解 圆角矩形裁剪失败之PS的妙用 编码不要过硬 对过长的文字进行截取 真机首次生成时字体不对 drawImage只能使用本地图片 背景介绍 目标:利用 ...
- 微信小程序 - canvas实现多行文本 ,实现文本断行
1.canvas绘制文本坑点 绘制的文本不管多长,永远只有一行,不会断行. 2.解决思路 根据每行文本字数来断行,超出的就向下排列. 由于 canvas绘制文本的语法如下: context.fillT ...
- 原创:WeZRender:微信小程序Canvas增强组件
WeZRender是一个微信小程序Canvas增强组件,基于HTML5 Canvas类库ZRender. 使用 WXML: <canvas style="width: 375px; h ...
- 微信小程序怎么用?线下商家最适合玩小程序
随着微信小程序不断地释放新功能,许多行业越来越关注小程序,目前已经有不少餐饮和线下传统零售企业开始谋划利用好小程序.但是,线下商业有着复杂的场景,如何针对自己行业的特点和需求开发出属于自己的小程序,是 ...
- 记录一下小程序canvas
小程序canvas学习 效果图: .wxml <canvas style="width: 100vw; height: 100vh;" canvas-id="fir ...
- 微信小程序 canvas 字体自动换行(支持换行符)
微信小程序 canvas 自动适配 自动换行,保存图片分享到朋友圈 https://github.com/richard1015/News 微信IDE演示代码https://developers.w ...
随机推荐
- 【数据结构】哈夫曼树与哈夫曼编码(Huffman Encoding)
一.背景 编码是信息处理的基础(重新表示信息). 普通的编码是等长编码,例如7位的ASCIL编码,对出现频率不同的字符都使用相同的编码长度.但其在传输和存储等情况下编码效率不高. 可使用不等长编码,来 ...
- IDEA无限试用插件
原文地址 之前一直在找激活方法,忽然想到IDEA不是可以试用吗?一直试用不就可以变相地达到了激活的效果? 本篇作废,本篇作废,本篇作废,由于IDEA插件的问题,导致并不能成功的进行重置试用 新整了个J ...
- 【Atcoder F - Cumulative Cumulative Cumulative Sum】线段树
要特别注意下精度,long,int范围.WA了几次 import java.util.Scanner; class Main { // static long[] A2 ;//i^2*AI // st ...
- 记录-JS 基础知识大全
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 1.通过javascript向文档中输出文本 document是javascript的内置对象,代表浏览器的文档部分 document.w ...
- FFmpeg开发笔记(六)如何访问Github下载FFmpeg源码
学习FFmpeg的时候,经常要到GitHub下载各种开源代码,比如FFmpeg的源码页面位于https://github.com/FFmpeg/FFmpeg.然而国内访问GitHub很不稳定,经常打 ...
- vue核心基础-过渡动画
第一种方法:引入类名 .v-enter{ opacity: 0; } .v-enter-to{ opacity: 1; } .v-leave{ opacity: 1; } .v-leave-to{ o ...
- Java 多级文件夹创建
File类中的mkdir()和mkdirs(): mkdir():只能创建一层目录. mkdirs():可以创建多层目录 String path = "E:\\lxwtest\\test& ...
- ssh连接相关工具下载地址
1.Finalshell 下载地址: http://www.hostbuf.com/t/988.html 2.xShell https://www.xshell.com/zh/xshell/ 3.pu ...
- KingbaseES 数据插入更新操作
数据库使用过程中,经常会遇到一种场景:业务系统对数据进行dml操作,当数据库中数据不存在时,将数据做为新记录插入到表中,当数据库中数据存在时,对现有数据进行更新操作. 下面介绍KingbaseES中对 ...
- 【Java】快速排序
代码: 1 public static void quickSort(int[] arr) { 2 if (arr == null || arr.length < 2) { 3 return; ...
