微信小程序签名组件:
现在线上签名的需求越来越多,然后就封装了一下组件,方便以后使用,可以获取的图片格式有 base64和临时文件
组件展示:
可以扫码查看是否符合自己的需求
wxml:
<!--components/autograph/index.wxml-->
<view class="autograph-container" style="width: {
{
width }}; height: {
{
height }}; display: block;">
<canvas class="autograph-canvas" type="2d" disable-scroll style="width: 100%; height: 100%; display: block;" bindtouchstart="handleTouchStart" bindtouchmove="handleTouchMove" bindtouchend="handleTouchEnd" bindtouchcancel="handleTouchEnd" binderror="handleTouchEnd"></canvas>
</view>
js:
// components/autograph/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
width: {
type: String,
value: '100%'
},
height: {
type: String,
value: '400rpx'
},
lineWidth: {
type: Number,
value: 2
},
lineColor: {
type: String,
value: '#000000'
}
},
/**
* 组件的初始数据
*/
data: {
isDraw: false, // 是否能画画
canvasElement: null,
canvasContext