微信小程序?qū)崿F(xiàn)電子簽名并導(dǎo)出圖片
更新時間:2020年05月27日 17:10:40 作者:朝花�
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)電子簽名,并導(dǎo)出圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序做電子簽名,并導(dǎo)出圖片的具體代碼,供大家參考,具體內(nèi)容如下
wxml:
<canvas class="canvas" id="canvas" canvas-id="canvas" disable-scroll="true" bindtouchstart="canvasStart" bindtouchmove="canvasMove" bindtouchend="canvasEnd" touchcancel="canvasEnd" binderror="canvasIdErrorCallback"></canvas> <button type="default" bindtap="cleardraw">清除畫布</button> <button type="default" bindtap="getimg">導(dǎo)出圖片</button>
wxss:
.canvas { width: 100%; min-height: 400rpx; border: 1rpx solid #000; /*//突出canvas畫布范圍 */ box-sizing: border-box; }
js:
var context = null;// 使用 wx.createContext 獲取繪圖上下文 var isButtonDown = false; var arrx = []; var arry = []; var arrz = []; var canvasw = 0; var canvash = 0; //獲取系統(tǒng)信息 wx.getSystemInfo({ success: function (res) { canvasw = res.windowWidth;//設(shè)備寬度 canvash = res.windowHeight; //設(shè)備高度 } }); Page({ canvasIdErrorCallback: function (e) { console.error(e.detail.errMsg) }, //繪制開始 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); }, //導(dǎo)出圖片 getimg: function () { if (arrx.length == 0) { wx.showModal({ title: '提示', content: '簽名內(nèi)容不能為空!', showCancel: false }); return false; }; //生成圖片 wx.canvasToTempFilePath({ canvasId: 'canvas', success: function (res) { wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success(res) { // console.log(res) wx.showToast({ title: '保存成功', }); }, fail(err) { console.log(err) } }) //將照片存入服務(wù)器 // wx.uploadFile({ // url: '', //接口地址 // filePath: res.tempFilePath, // name: 'file', // formData: { // 'user': 'test' // }, // success function (res) { // console.log(res); // }, // fail: function (res) { // console.log(res); // }, // complete: function (res) { // } // }); } }) }, /** * 頁面的初始數(shù)據(jù) */ data: { }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { // 使用 wx.createContext 獲取繪圖上下文 context context = wx.createCanvasContext('canvas'); context.beginPath() context.setStrokeStyle('#000000'); context.setLineWidth(4); context.setLineCap('round'); context.setLineJoin('round'); } })
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript將list轉(zhuǎn)換成樹狀結(jié)構(gòu)的實例
下面小編就為大家?guī)硪黄猨avascript將list轉(zhuǎn)換成樹狀結(jié)構(gòu)的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09Vue項目vscode 安裝eslint插件的方法(代碼自動修復(fù))
這篇文章主要介紹了Vue項目vscode 安裝eslint插件的方法 代碼自動修復(fù),需要的朋友可以參考下2020-04-04編寫高性能的JavaScript 腳本的加載與執(zhí)行
把腳本放在body中,當(dāng)瀏覽器遇見<script>標(biāo)簽時, 瀏覽器不知道腳本會插入文本還是html標(biāo)簽,因此瀏覽器會停止分析html頁面而去執(zhí)行腳本。2010-04-04JavaScript遞歸函數(shù)解“漢諾塔”算法代碼解析
這篇文章主要介紹了JavaScript遞歸函數(shù)解“漢諾塔”算法代碼解析,需要的朋友可以參考下2018-07-07JavaScript解析json格式數(shù)據(jù)簡單示例
這篇文章主要介紹了JavaScript解析json格式數(shù)據(jù)簡單示例,本文通過for循環(huán)來獲取json結(jié)點數(shù)據(jù),需要的朋友可以參考下2014-12-12推薦三款日期選擇插件(My97DatePicker、jquery.datepicker、Mobiscroll)
這篇文章主要介紹了推薦三款日期選擇插件,My97DatePicker、用于PC端的jquery.datepicker,以及專注于移動端的Mobiscroll,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04