溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

微信小程序如何實(shí)現(xiàn)手寫簽名

發(fā)布時(shí)間:2022-07-08 10:10:44 來源:億速云 閱讀:1870 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹了微信小程序如何實(shí)現(xiàn)手寫簽名的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇微信小程序如何實(shí)現(xiàn)手寫簽名文章都會(huì)有所收獲,下面我們一起來看看吧。

效果

微信小程序如何實(shí)現(xiàn)手寫簽名

wxml

<view class="sign">
  <view class="paper">
    <canvas class="handWriting" disable-scroll="true" bindtouchstart="touchstart1" bindtouchmove="touchmove1"  canvas-id="handWriting1">
    </canvas>
  </view>
  <view class="signBtn">
    <button size="" type="primary" bindtap="sign1ok">完成簽字</button> 
    <button size="" type="warn" bindtap="reSign1">重新簽字</button>
  </view>
</view>
<view class="image" hidden="{{src?false:true}}">
<image src="{{src}}" ></image>
</view>

js

Page({
  data: {
    context1: null,
    hasDraw:false, //默認(rèn)沒有畫
    src:null
  },
  onLoad: function() {
    var context1 = wx.createCanvasContext('handWriting1');
    context1.setStrokeStyle("#000000")
    context1.setLineWidth(3);
    this.setData({
      context1: context1,
    })
  },
  touchstart1: function(e) {
    var context1 = this.data.context1;
    context1.moveTo(e.touches[0].x, e.touches[0].y);
    this.setData({
      context1: context1,
      hasDraw : true, //要簽字了
    });
  },
  touchmove1: function(e) {
    var x = e.touches[0].x;
    var y = e.touches[0].y;
    var context1 = this.data.context1;
    context1.setLineWidth(3);
    context1.lineTo(x, y);
    context1.stroke();
    context1.setLineCap('round');
    context1.draw(true);
    context1.moveTo(x, y);
  },
  reSign1: function() { //重新畫
    var that = this;
    var context1 = that.data.context1;
    context1.draw(); //清空畫布
    that.setData({
      hasDraw: false, //沒有畫
      src: null
    });
  },
  sign1ok: function () {
    var that = this;
    if(!that.data.hasDraw){
      console.log("簽字是空白的 沒有簽字")
    }else{
      var context1 = that.data.context1;
      context1.draw(true, wx.canvasToTempFilePath({
        canvasId: 'handWriting1',
        success(res) {
          console.log(res.tempFilePath) //得到了圖片下面自己寫上傳吧
          that.setData({
            src: res.tempFilePath
          })
          
        }
      }))
    }
  },
});

wxss

.paper{border:1px solid #dedede; margin: 10px; height:160px }
.image{border:1px solid #dedede; margin: 10px; height:160px }
.signBtn{display: flex; margin-top:20px;}
.signTitle{ text-align: center; font-size:1.2em;margin:10px auto;}
.handWriting{width:100%}
.image image{width:100%; height:160px }

關(guān)于“微信小程序如何實(shí)現(xiàn)手寫簽名”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“微信小程序如何實(shí)現(xiàn)手寫簽名”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI