咨询热线:15811653920

2009-2017

我们一直走在国际设计的前沿,追求与研究从未停止

我的位置:首页 > 学院 > 小程序

微信小程序实现手写签名(签字版)

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>


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 }



js


Page({

  data: {

    context1: null,

    hasDraw:false, //默认没有画

    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

          })

          

        }

      }))

    }

  },

});


想了解更多,请访问齐创互联,需要网站建设,浏览快速建站模板快速建站
点击在线客服联系客服,联系电话:15811653920 联系人: 丁生.


感谢您关注我们,如果您有建站需求,请与我们取得联系。
扫一扫上面的二维码图案,加我微信
扫一扫上面的二维码图案,加我微信
咨询直线:15811653920 丁生

建站模板

Web Templates

建站龙头,低价保证,贴心服务

权威认证建站龙头企业,合理定价,实现与客户的长期合作,30万家企业级用户优选!