小程序?qū)崿F(xiàn)手寫板簽名
本文實例為大家分享了小程序?qū)崿F(xiàn)手寫板簽名的具體代碼,供大家參考,具體內(nèi)容如下
1.wxss代碼
page { ? ? background: #F8F8F8; } /* 簽名 */ .qianming { ? ? background: #fff; ? ? padding: 20rpx 30rpx; ? ? font-size: 32rpx; ? ? color: #333; ? ? padding-bottom: 0; ? ? position: fixed; ? ? bottom: 0; ? ? left: 0; ? ? width: 92%; ? ? height: 47%; } .qianming .clear { ? ? font-size: 26rpx; ? ? color: #669AF2; } .flex-def { ? ? display: flex; } .flex-one { ? ? flex: 1; } .flex-cCenter { ? ? align-items: center; } /* 底部按鈕 */ .bottom_btn { ? ? font-size: 32rpx; ? ? color: #fff; ? ? padding: 30rpx 0; ? ? background: #fff; ? ? width: 100%; } .bottom_btn view { ? ? width: 100%; ? ? background: #FF083C; ? ? border-radius: 40rpx; ? ? height: 80rpx; ? ? line-height: 80rpx; ? ? text-align: center; } /*隱藏滾動條*/ ::-webkit-scrollbar { ? ? width: 0; ? ? height: 0; ? ? color: transparent; ? ? display: none; }
2.wxml代碼
<view class="qianming"> ? ? <view class="qianming_top flex-def flex-cCenter" wx:if="{{is_sign==1}}"> ? ? ? ? <view class="flex-one">簽名</view> ? ? ? ? <view class="clear" bindtap="clear">清空</view> ? ? </view> ? ? <view class="canvas"> ? ? ? ? <canvas style="width: 100%;height: 360rpx;border: 1px #eee solid;background-color: #fff;border-radius: 16rpx;margin-top: 20rpx;" canvas-id="firstCanvas" id='firstCanvas' bindtouchstart="bindtouchstart" bindtouchmove="bindtouchmove"></canvas> ? ? </view> ? ? <view class="bottom_btn"> ? ? ? ? <view class="skin-bg-{{theme}}" bindtap='export'>我已知悉并同意</view> ? ? </view> </view>
3.js代碼
data: { ? ? ? ? context: null, ? ? ? ? imgUrl: "", ? ? ? ? index:0,//用來判斷是否簽名 ? ? }, ? ? /**記錄開始點 */ ? ? bindtouchstart: function (e) { ? ? ? ? this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y) ? ? ? ? // 記錄已經(jīng)開始簽名 ? ? ? ? this.setData({ ? ? ? ? ? ? index:1 ? ? ? ? }) ? ? }, ? ? /**記錄移動點,刷新繪制 */ ? ? bindtouchmove: function (e) { ? ? ? ? this.data.context.lineTo(e.changedTouches[0].x, e.changedTouches[0].y); ? ? ? ? this.data.context.stroke(); ? ? ? ? this.data.context.draw(true); ? ? ? ? this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y); ? ? ? ? // 記錄已經(jīng)開始簽名 ? ? ? ? this.setData({ ? ? ? ? ? ? index:1 ? ? ? ? }) ? ? }, ? ? /**清空畫布 */ ? ? clear: function () { ? ? ? ? this.data.context.draw(); ? ? ? ? this.setData({ ? ? ? ? ? ? index:0 ? ? ? ? }) ? ? }, ? ? /**導(dǎo)出圖片 點擊確定按鈕*/ ? ? export: function () { ? ? ? ? const that = this; ? ? ? ?? ? ? ? ? ? ? if (that.data.index==0) { ? ? ? ? ? ? ? ? wx.showToast({ ? ? ? ? ? ? ? ? ? ? title: '請閱讀并簽名', ? ? ? ? ? ? ? ? ? ? icon: 'none', ? ? ? ? ? ? ? ? ? ? duration: 2000 ? ? ? ? ? ? ? ? }) ? ? ? ? ? ? ? ? return ? ? ? ? ? ? ? ? } ? ? ? ? ? ? that.data.context.draw(true, ? ? ? ? ? ? ? ? wx.canvasToTempFilePath({ ? ? ? ? ? ? ? ? ? ? x: 0, ? ? ? ? ? ? ? ? ? ? y: 0, ? ? ? ? ? ? ? ? ? ? fileType: 'png', ? ? ? ? ? ? ? ? ? ? canvasId: 'firstCanvas', ? ? ? ? ? ? ? ? ? ? success(res) { ? ? ? ? ? ? ? ? ? ? ? ? that.upload_image(res.tempFilePath) ? ? ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? ? ? fail() { ? ? ? ? ? ? ? ? ? ? ? ? wx.showToast({ ? ? ? ? ? ? ? ? ? ? ? ? ? ? title: '簽名失敗', ? ? ? ? ? ? ? ? ? ? ? ? ? ? icon: 'none', ? ? ? ? ? ? ? ? ? ? ? ? ? ? duration: 2000 ? ? ? ? ? ? ? ? ? ? ? ? }) ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? }) ? ? ? ? ? ? ) ? ? ? ? } ? ? ? ?? ? ? }, ? ? // 將圖片保存到服務(wù)器 ? ? upload_image(imgurl) { ? ? ? ? var that = this; ? ? },
4.注意json文件必須加這個參數(shù)為true,否則簽名時晃動
{ "disableScroll": true }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS使用for循環(huán)遍歷Table的所有單元格內(nèi)容
JS遍歷Table的所有單元格內(nèi)容思路是遍歷Table的所有Row,遍歷Row中的每一列,獲取Table中單元格的內(nèi)容2014-08-08element-ui?對話框dialog使用echarts報錯'dom沒有獲取到'的問題
這篇文章主要介紹了element-ui?對話框dialog里使用echarts,報錯'dom沒有獲取到'的問題,在這個事件里邊進行echarts的初始化,執(zhí)行數(shù)據(jù),本文結(jié)合實例代碼給大家詳細講解,需要的朋友可以參考下2022-11-11Vue之vue-tree-color組件實現(xiàn)組織架構(gòu)圖案例詳解
這篇文章主要介紹了Vue之vue-tree-color組件實現(xiàn)組織架構(gòu)圖案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-09-09js實現(xiàn)json數(shù)據(jù)行到列的轉(zhuǎn)換的實例代碼
為了實現(xiàn)這樣的數(shù)據(jù)顯示出來三個序列,分別為鄭州、新鄉(xiāng)、安陽的電量,就需要自己實現(xiàn)對這樣數(shù)據(jù)的轉(zhuǎn)換,轉(zhuǎn)換成如下的形式:2013-08-08easyui tree帶checkbox實現(xiàn)單選的簡單實例
下面小編就為大家?guī)硪黄猠asyui tree帶checkbox實現(xiàn)單選的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11