微信小程序 手写签名_小程序手写签名(wepy)

清除

保存图片

import wepy from 'wepy';

var content = null;

var touchs = [];

var canvasw = 0;

var canvash = 0;

export default class Index extends wepy.page {

config = {};

components = {};

data = {

signImage: '',

};

events = {};

methods = {

start: function(event) {

// console.log("触摸开始" + event.changedTouches[0].x)

// console.log("触摸开始" + event.changedTouches[0].y)

//获取触摸开始的 x,y

let point = {

x: event.changedTouches[0].x,

y: event.changedTouches[0].y

}

touchs.push(point)

},

// 画布的触摸移动手势响应

move: function(e) {

let point = {

x: e.touches[0].x,

y: e.touches[0].y

}

touchs.push(point)

if (touchs.length >= 2) {

this.draw(touchs)

}

},

// 画布的触摸取消响应

cancel: function(e) {

console.log("触摸取消" + e)

},

// 画布的长按手势响应

tap: function(e) {

console.log("长按手势" + e)

},

error: function(e) {

console.log("画布触摸错误" + e)

},

// 画布的触摸移动结束手势响应

end: function(e) {

console.log("触摸结束" + e)

//清空轨迹数组

for (let i = 0; i < touchs.length; i++) {

touchs.pop()

}

},

};

async onShow() {}

async onLoad(options) {

//获得Canvas的上下文

content = wx.createCanvasContext('firstCanvas')

//设置线的颜色

content.setStrokeStyle("#00ff00")

//设置线的宽度

content.setLineWidth(5)

//设置线两端端点样式更加圆润

content.setLineCap('round')

//设置两条线连接处更加圆润

content.setLineJoin('round')

}

draw(touchs) {

let point1 = touchs[0]

let point2 = touchs[1]

touchs.shift()

content.moveTo(point1.x, point1.y)

content.lineTo(point2.x, point2.y)

content.stroke()

content.draw(true)

}

clearClick() {

//清除画布

content.clearRect(0, 0, canvasw, canvash)

content.draw(true)

}

saveClick() {

var that = this

wx.canvasToTempFilePath({

canvasId: 'firstCanvas',

success: function(res) {

//打印图片路径

console.log(res.tempFilePath)

//设置保存的图片

that.setData({

signImage: res.tempFilePath

})

}

})

}

}

.content {

width: 100%;

height: 500px;

background-color: red;

}

.firstCanvas {

background-color: blue;

width: 100%;

height: 200px;

}

image {

width: 100%;

height: 200px;

background-color: orange;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值