微信小程序?qū)崿F(xiàn)電子簽名功能
更新時間:2020年07月29日 14:52:53 作者:youqiting
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)電子簽名功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序?qū)崿F(xiàn)電子簽名的具體代碼,供大家參考,具體內(nèi)容如下
// XXXX.wxml <view class="signName"> <canvas class="canvas" id="canvas" canvas-id="canvas" disable-scroll="true" bindtouchstart="canvasStart" bindtouchmove="canvasMove" bindtouchend="canvasEnd" touchcancel="canvasEnd" binderror="canvasIdErrorCallback"></canvas> </view> <view class="CList flex"> <view class="flex_item marginR20" > <view class="saveBtn" bindtap="uploadImg">上傳簽名</view> </view> <view class="flex_item"> <view class="clearBtn" bindtap="cleardraw">清除簽名</view> </view>
js:
var context = null;// 使用 wx.createContext 獲取繪圖上下文 context var isButtonDown = false;//是否在繪制中 var arrx = [];//動作橫坐標 var arry = [];//動作縱坐標 var arrz = [];//總做狀態(tài),標識按下到抬起的一個組合 var canvasw = 0;//畫布寬度 var canvash = 0;//畫布高度 Page({ data: { }, onLoad: function () { this.startCanvas(); }, /** * 以下 - 手寫簽名 / 上傳簽名 */ startCanvas: function () {//畫布初始化執(zhí)行 var that = this; //獲取系統(tǒng)信息 wx.getSystemInfo({ success: function (res) { canvasw = res.windowWidth; canvash = res.windowHeight; that.setData({ canvasw: canvasw }); that.setData({ canvash: canvash }); } }); this.initCanvas(); this.cleardraw(); }, //初始化函數(shù) initCanvas: function () { context = wx.createCanvasContext('canvas'); context.beginPath() context.fillStyle = 'rgba(255, 255, 255, 0)'; context.setStrokeStyle('#000000'); context.setLineWidth(4); context.setLineCap('round'); context.setLineJoin('round'); }, canvasStart: function (event) { isButtonDown = true; arrz.push(0); arrx.push(event.changedTouches[0].x); arry.push(event.changedTouches[0].y); }, canvasMove: function (event) { if (isButtonDown) { arrz.push(1); arrx.push(event.changedTouches[0].x); arry.push(event.changedTouches[0].y); } for (var i = 0; i < arrx.length; i++) { if (arrz[i] == 0) { context.moveTo(arrx[i], arry[i]) } else { context.lineTo(arrx[i], arry[i]) } } context.clearRect(0, 0, canvasw, canvash); context.setStrokeStyle('#000000'); context.setLineWidth(4); context.setLineCap('round'); context.setLineJoin('round'); context.stroke(); context.draw(false); }, canvasEnd: function (event) { isButtonDown = false; }, //清除畫布 cleardraw: function () { arrx = []; arry = []; arrz = []; context.clearRect(0, 0, canvasw, canvash); context.draw(true); }, uploadImg(){ var that = this //生成圖片 wx.canvasToTempFilePath({ canvasId: 'canvas', //設置輸出圖片的寬高 // destWidth:150, // destHeight:150, // fileType:'jpg', quality:1.0, success: function (res) { console.log(res) // canvas圖片地址 res.tempFilePath }, fail: function () { wx.showModal({ title: '提示', content: 'canvas生成圖片失敗。微信當前版本不支持,請更新到最新版本!', showCancel: false }); }, complete: function () {} }) }, })
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
ZeroClipboard.js使用一個flash復制多個文本框
這篇文章主要為大家詳細介紹了ZeroClipboard.js使用一個flash復制多個文本框,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06javascript中的replace函數(shù)(帶注釋demo)
在js中有兩個replace函數(shù) 一個是location.replace(url) 跳轉(zhuǎn)到一個新的url.一個string.replace("xx","yy") 替換字符串 返回一個新的字符串,該方法并不改變字符串本身。下面通過本文給大家介紹javascript中的replace函數(shù)2018-01-01js遍歷json對象所有key及根據(jù)動態(tài)key獲取值的方法(必看)
下面小編就為大家?guī)硪黄猨s遍歷json對象所有key及根據(jù)動態(tài)key獲取值的方法(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03鼠標拖動改變DIV等網(wǎng)頁元素的大小的實現(xiàn)方法
下面小編就為大家?guī)硪黄髽送蟿痈淖僁IV等網(wǎng)頁元素的大小的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07