Page({
data: {
context1: null,
hasDraw:false, //默认没有画
src:null,
test:"",
},
onLoad: function() {
var context1 = wx.createCanvasContext('handWriting1');
context1.setStrokeStyle("#000000")
context1.setLineWidth(3);
this.setData({
context1: context1,
})
},
touchstart1: function(e) {
var context1 = this.data.context1;
context1.moveTo(e.touches[0].x, e.touches[0].y);
this.setData({
context1: context1,
hasDraw : true, //要签字了
});
},
touchmove1: function(e) {
var x = e.touches[0].x;
var y = e.touches[0].y;
var context1 = this.data.context1;
context1.setLineWidth(3);
context1.lineTo(x, y);
context1.stroke();
context1.setLineCap('round');
context1.draw(true);
context1.moveTo(x, y);
},
reSign1: function() { //重新画
var that = this;
var context1 = that.data.context1;
context1.draw(); //清空画布
that.setData({
hasDraw: false, //没有画
src: null
});
},
sign1ok: function () {
var that = this;
if(!that.data.hasDraw){
console.log("签字是空白的 没有签字")
}else{
var context1 = that.data.context1;
context1.draw(true, wx.canvasToTempFilePath({
canvasId: 'handWriting1',
success(res) {
console.log(res.tempFilePath) //得到了图片下面自己写上传吧
that.setData({
src: res.tempFilePath
})
that.getBase64Image(that.data.src);
}
}))
}
},
//转换图片为base64函数
getBase64Image(img) {
let that=this;
wx.getFileSystemManager().readFile({
filePath: img, //选择图片返回的相对路径
encoding: "base64", //这个是很重要的
success: res => { //成功的回调
//返回base64格式
var base64Str = 'data:image/' + 'jpeg' + ';base64,' + res.data
console.log(base64Str);
that.setData({test:base64Str});
},
fail: err => {
console.log(err)
reject(err)
}
})
},
});
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序在线签名(可上传,可转base64,两种方法都有)
共16个文件
json:6个
js:5个
wxss:3个
需积分: 5 2 下载量 134 浏览量
2023-10-23
11:09:23
上传
评论
收藏 5KB RAR 举报
温馨提示
微信小程序在线签名(可上传,可转base64,两种方法都有)
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序在线签名.rar (16个子文件)
sitemap.json 191B
project.private.config.json 347B
pages
index
index.wxml 516B
index.js 2KB
index.json 27B
index.wxss 302B
logs
logs.json 77B
logs.js 305B
logs.wxml 197B
logs.wxss 106B
.eslintrc.js 587B
app.json 295B
project.config.json 1KB
app.js 364B
utils
util.js 460B
app.wxss 194B
共 16 条
- 1
资源评论
qaakd
- 粉丝: 27
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功