小程序?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)文章
JavaScript實(shí)現(xiàn)大文件上傳的示例代碼
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)大文件上傳功能的示例代碼,文中的代碼講解詳細(xì),對(duì)我們學(xué)習(xí)JavaScript有一定幫助,感興趣可以跟隨小編一起學(xué)習(xí)一下2022-11-11
利用Three.js如何實(shí)現(xiàn)陰影效果實(shí)例代碼
使用three.js可以方便的讓我們?cè)诰W(wǎng)頁中做出各種不同的3D效果,下面這篇文章主要給大家介紹了關(guān)于利用Three.js如何實(shí)現(xiàn)陰影效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-09-09
javascript返回頂部的按鈕實(shí)現(xiàn)方法
這篇文章主要介紹了javascript返回頂部的按鈕實(shí)現(xiàn)方法,需要的朋友可以參考下2016-01-01
ES6中async函數(shù)與await表達(dá)式的基本用法舉例
async和await是我們進(jìn)行Promise時(shí)的一個(gè)語法糖,async/await為了讓我們書寫代碼時(shí)更加流暢,增強(qiáng)了代碼的可讀性,下面這篇文章主要給大家介紹了關(guān)于ES6中async函數(shù)與await表達(dá)式的基本用法,需要的朋友可以參考下2022-07-07
用javascript實(shí)現(xiàn)倒計(jì)時(shí)效果
這篇文章主要為大家詳細(xì)介紹了用javascript實(shí)現(xiàn)倒計(jì)時(shí)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-02-02
在IE8上JS實(shí)現(xiàn)combobox支持拼音檢索功能
這篇文章主要介紹了在IE8上JS實(shí)現(xiàn)combobox支持拼音檢索功能的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-05-05
微信小程序?qū)崿F(xiàn)列表項(xiàng)左滑刪除效果
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)列表項(xiàng)左滑刪除效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08

