zoukankan      html  css  js  c++  java
  • 微信小程序实现电子签名

    <style lang="less">
    .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{100%}
    .image image{100%; height:160px }
    </style>
    
    <template>
        <view class="sign">
            <view class="signTitle">被检查单位签字</view>
            <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>
    </template>
    
    <script>
    import wepy from 'wepy'
    import api from '../api/api';
        export default class Login extends wepy.page {
            config = {
                navigationBarTitleText: '电子签名',
                backgroundColor: "#f5f5f5",
                navigationBarBackgroundColor: "#2EBAFF",
                navigationBarTextStyle: "white",
                "usingComponents": {
                    "i-icon": "../iview/icon/index",
                    'i-modal': '../iview/modal/index'
                }
            };
            data = {
                context1: null,
                hasDraw:false, //默认没有画
                src:null
            };
            computed = {
            }
            methods = {
                touchstart1(e) {
                    let context1 = this.context1;
                    context1.moveTo(e.touches[0].x, e.touches[0].y);
                    this.context1 = context1;
                    this.hasDraw = true; //要签字了
                    this.$apply();
                },
                touchmove1(e) {
                    let x = e.touches[0].x;
                    let y = e.touches[0].y;
                    let context1 = this.context1;
                    context1.setLineWidth(3);
                    context1.lineTo(x, y);
                    context1.stroke();
                    context1.setLineCap('round');
                    context1.draw(true);
                    context1.moveTo(x, y);
                },
                reSign1() { //重新画
                    let that = this;
                    let context1 = that.context1;
                    context1.draw(); //清空画布
                    that.hasDraw = false;
                    that.src= null;
                    that.$apply()
                },
                sign1ok() {
                    let that = this;
                    if(!that.hasDraw){
                        console.log("签字是空白的 没有签字")
                    }else{
                        let context1 = that.context1;
                        context1.draw(true, wx.canvasToTempFilePath({
                            canvasId: 'handWriting1',
                            success(res) {
                                console.log(res.tempFilePath) //得到了图片下面自己写上传吧
                                that.src = res.tempFilePath;
                                that.$apply();
    
                                // wx.uploadFile({
                                //   url: "http://**************",
                                //   filePath: res.tempFilePath,
                                //   name: "file",
                                //   formData: {
                                //     filetype: "image",
                                //   },
                                //   success: function (result) {
                                //     console.log(result)
                                //   }
                                // })
                                /*api.uploadImg({data:res.tempFilePath})
                                    .then(res => {
    
                                        that.$apply()
                                    })*/
                            }
                        }))
                    }
                },
            }
            onUnload() {
    
            }
            onLoad(){
                let context1 = wx.createCanvasContext('handWriting1');
                context1.setStrokeStyle("#000000")
                context1.setLineWidth(3);
                this.context1= context1;
                console.log(context1)
                this.$apply()
            }
        }
    </script>

    参考:https://www.dznx.cn/front/16.html

  • 相关阅读:
    TestFlight使用方法
    jmeter 单接口测试方案(接口无业务关联)
    jenkins+ANT+jmeter 接口测试环境搭建
    Pytorch实战(3)----分类
    莫烦大大keras的Mnist手写识别(5)----自编码
    莫烦大大keras学习Mnist识别(4)-----RNN
    莫烦大大keras学习Mnist识别(3)-----CNN
    算法68------数组和矩阵问题
    Keras学习基础(2)
    TensorFlow实战笔记(17)---TFlearn
  • 原文地址:https://www.cnblogs.com/dongxiaolei/p/14985451.html
Copyright © 2011-2022 走看看