小程序?qū)崿F(xiàn)手寫板簽名
本文實(shí)例為大家分享了小程序?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;
}
/*隱藏滾動(dòng)條*/
::-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,//用來判斷是否簽名
? ? },
? ? /**記錄開始點(diǎn) */
? ? bindtouchstart: function (e) {
? ? ? ? this.data.context.moveTo(e.changedTouches[0].x, e.changedTouches[0].y)
? ? ? ? // 記錄已經(jīng)開始簽名
? ? ? ? this.setData({
? ? ? ? ? ? index:1
? ? ? ? })
? ? },
? ? /**記錄移動(dòng)點(diǎn),刷新繪制 */
? ? 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)出圖片 點(diǎn)擊確定按鈕*/
? ? export: function () {
? ? ? ? const that = this;
? ? ? ??
? ? ? ? ? ? if (that.data.index==0) {
? ? ? ? ? ? ? ? wx.showToast({
? ? ? ? ? ? ? ? ? ? title: '請(qǐng)閱讀并簽名',
? ? ? ? ? ? ? ? ? ? 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文件必須加這個(gè)參數(shù)為true,否則簽名時(shí)晃動(dòng)
{
"disableScroll": true
}以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS使用for循環(huán)遍歷Table的所有單元格內(nèi)容
JS遍歷Table的所有單元格內(nèi)容思路是遍歷Table的所有Row,遍歷Row中的每一列,獲取Table中單元格的內(nèi)容2014-08-08
element-ui?對(duì)話框dialog使用echarts報(bào)錯(cuò)'dom沒有獲取到'的問題
這篇文章主要介紹了element-ui?對(duì)話框dialog里使用echarts,報(bào)錯(cuò)'dom沒有獲取到'的問題,在這個(gè)事件里邊進(jìn)行echarts的初始化,執(zhí)行數(shù)據(jù),本文結(jié)合實(shí)例代碼給大家詳細(xì)講解,需要的朋友可以參考下2022-11-11
Bootstrap的基本應(yīng)用要點(diǎn)淺析
BootStrap是基于HTML、CSS和JavaScript的框架,使你只需要寫簡單的代碼就可以很快的搭建一個(gè)還不錯(cuò)的前端框架,他是后端程序員的福音,使他們只需要專注業(yè)務(wù)邏輯,而無須浪費(fèi)太多的精力在界面設(shè)計(jì)上2016-12-12
javaScript實(shí)現(xiàn)支付10秒倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了javaScript實(shí)現(xiàn)支付10秒倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
JS實(shí)現(xiàn)仿騰訊微博無刷新刪除微博效果代碼
這篇文章主要介紹了JS實(shí)現(xiàn)仿騰訊微博無刷新刪除微博效果代碼,涉及JavaScript實(shí)現(xiàn)Ajax無刷新刪除的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Vue之vue-tree-color組件實(shí)現(xiàn)組織架構(gòu)圖案例詳解
這篇文章主要介紹了Vue之vue-tree-color組件實(shí)現(xiàn)組織架構(gòu)圖案例詳解,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09
js實(shí)現(xiàn)json數(shù)據(jù)行到列的轉(zhuǎn)換的實(shí)例代碼
為了實(shí)現(xiàn)這樣的數(shù)據(jù)顯示出來三個(gè)序列,分別為鄭州、新鄉(xiāng)、安陽的電量,就需要自己實(shí)現(xiàn)對(duì)這樣數(shù)據(jù)的轉(zhuǎn)換,轉(zhuǎn)換成如下的形式:2013-08-08
easyui tree帶checkbox實(shí)現(xiàn)單選的簡單實(shí)例
下面小編就為大家?guī)硪黄猠asyui tree帶checkbox實(shí)現(xiàn)單選的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11

