对于小程序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 ...
随机推荐
- 【风控算法】二、SQL->Python->PySpark计算KS,AUC及PSI
KS,AUC 和 PSI 是风控算法中最常计算的几个指标,本文记录了多种工具计算这些指标的方法. 生成本文的测试数据: import pandas as pd import numpy as np i ...
- vscode 翻译插件推荐 Easy Translator,只因为有音标,和位置好
vscode 翻译插件推荐 Easy Translator,只因为有音标,和位置好
- 将谷歌chrome浏览器主题变黑的方法
两个步骤: 第一: 桌面找到google chrome图标右键->属性,在后面加上: --force-dark-mode (注意有空格) 第二: 1.浏览器地址输入chrome://flags/ ...
- 基于六轴传感器MPU6050的加速度和角度值读取
一 系统简介 1.简介 MPU-60x0 是全球首例 9 轴运动处理传感器.它集成了 3 轴MEMS陀螺仪,3 轴MEMS加速度计,以及一个可扩展的数字运动处理器 DMP(Digital Motion ...
- 超低功耗mcu芯片AMA3B 开发备忘之初串口打印
一 前言 对于软件工程师来说,没什么比看到一个hello world的打印更让人感觉兴奋了.调试芯片,很多人都知道,hello world这个打印意味着什么. 二 软硬件准备 1 一个AM ...
- c语言中静态链接库的创建和使用
静态链接库的创建 静态链接库其实就相当于压缩包,其内部可以包含多个源文件.但需要注意的是,并非任何一个源文件都可以被加工成静态链接库,其至少需要满足以下 2 个条件: 源文件中只提供可以重复使用的代码 ...
- buu第一页复盘
这里就对之前第一遍没写出来的题目再写一次wp 写在之前 贴一下我的模块文件 from pwn import * from LibcSearcher import * from struct impor ...
- 简洁版docker跑mongo
参考,欢迎点击原文:https://www.runoob.com/docker/docker-install-mongodb.html(菜鸟) 以下是拉取docker镜像并运行起来 docker pu ...
- Feign调用远程服务时传递Cookie信息
@Configuration public class TtpfFeignConfig { @Bean public RequestInterceptor requestInterceptor(){/ ...
- 你是怎么理解ES6中 Decorator 的?使用场景?
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 一.介绍 Decorator,即装饰器,从名字上很容易让我们联想到装饰者模式 简单来讲,装饰者模式就是一种在不改变原类和使用继承的情况下, ...
