• vue使用smooth-signature实现移动端电子签字,包括横竖屏


    vue使用smooth-signature实现移动端电子签字,包括横竖屏

    1.使用smooth-signature

    npm install --save smooth-signature
    
    • 1

    二.页面引入插件

    import SmoothSignature from "smooth-signature";
    
    • 1

    三.实现效果

    企业微信截图_16983060016752.png

    企业微信截图_16983060187445.png

    四.完整代码

    <template>
      <div class="sign-finish">
        <div class="wrap1" v-show="showFull">
          <span class="sign-title">请在区域内签字</span>
          <canvas class="canvas1" ref="canvas1" />
          <div class="actions">
              <button class="danger" @click="handleClear1" >清除</button>
              <button class="warning" @click="handleUndo1" >撤销</button>
              <button class="primary" @click="handleFull" >横屏</button>
              <button class="success" @click="handlePreview1" >保存</button>
          </div>
        </div>
        <div class="wrap2" v-show="!showFull">
          <div class="actionsWrap">
            <div class="actions">
              <button class="danger" @click="handleClear1" >清除</button>
              <button class="warning" @click="handleUndo1" >撤销</button>
              <button class="primary" @click="handleFull" >竖屏</button>
              <button class="success" @click="handlePreview1" >保存</button>
            </div>
          </div>
          <canvas class="canvas" ref="canvas2" />
        </div>
      </div>
    </template>
    
    <script>
    import SmoothSignature from "smooth-signature";
    export default {
      name: "mbDemo",
      data() {
        return {
          showFull: true,
        };
      },
      mounted() {
        this.initSignature1();
        this.initSignture2();
      },
      methods: {
        initSignature1() {
          const canvas = this.$refs["canvas1"];
          const options = {
            width: window.innerWidth - 30,
            height: 200,
            minWidth: 2,
            maxWidth: 6,
            openSmooth:true,
            // color: "#1890ff",
            bgColor: '#f6f6f6',
          };
          this.signature1 = new SmoothSignature(canvas, options);
        },
        initSignture2() {
          const canvas = this.$refs["canvas2"];
          const options = {
            width: window.innerWidth - 120,
            height: window.innerHeight - 80,
            minWidth: 3,
            maxWidth: 10,
            openSmooth:true,
            // color: "#1890ff",
            bgColor: '#f6f6f6',
          };
          this.signature2 = new SmoothSignature(canvas, options);
        },
        handleClear1() {
          this.signature1.clear();
        },
        handleClear2() {
          this.signature2.clear();
        },
        handleUndo1() {
          this.signature1.undo();
        },
        handleUndo2() {
          this.signature2.undo();
        },
        handleFull() {
          this.showFull = !this.showFull;
        },
        handlePreview1() {
          const isEmpty = this.signature1.isEmpty();
          if (isEmpty) {
            alert("isEmpty");
            return;
          }
          const pngUrl = this.signature1.getPNG();
          console.log(pngUrl);
          // window.previewImage(pngUrl);
        },
        handlePreview2() {
          const isEmpty = this.signature2.isEmpty();
          if (isEmpty) {
            alert("isEmpty");
            return;
          }
          const canvas = this.signature2.getRotateCanvas(-90);
          const pngUrl = canvas.toDataURL();
          console.log('pngUrl',pngUrl);
          // window.previewImage(pngUrl, 90);
        },
      },
    };
    </script>
    
    <style lang="less">
    .sign-finish {
      height: 100vh;
      width: 100vw;
      button {
        height: 32px;
        padding: 0 8px;
        font-size: 12px;
        border-radius: 2px;
      }
      .danger {
        color: #fff;
        background: #ee0a24;
        border: 1px solid #ee0a24;
      }
      .warning {
        color: #fff;
        background: #ff976a;
        border: 1px solid #ff976a;
      }
      .primary {
        color: #fff;
        background: #1989fa;
        border: 1px solid #1989fa;
      }
      .success {
        color: #fff;
        background: #07c160;
        border: 1px solid #07c160;
      }
      canvas {
        border-radius: 10px;
        border: 2px dashed #ccc;
        
      }
      .wrap1 {
        height: 100%;
        width: 96%;
        margin: auto;
        margin-top: 100px;
        .actions {
          display: flex;
          justify-content: space-around;
        }
      }
      .wrap2 {
        padding: 15px;
        height: 100%;
        display: flex;
        justify-content: center;
        .actionsWrap {
          width: 50px;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .canvas {
          flex: 1;
        }
        .actions {
          margin-right: 10px;
          white-space: nowrap;
          transform: rotate(90deg);
          button{
              margin-right: 20px;
          }
        }
      }
    }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176

    五.参考

    https://github.com/linjc/smooth-signature

  • 相关阅读:
    linux离线安装glibc.i686
    机器学习 | MATLAB实现支持向量机回归参数设定
    pycharm新建html时,图标问题
    rh358 005 dhcp dhcp6 打印机 ansible配置dhcp和打印机
    Torch学习(一)
    PHP模拟上传文件使用CURLFile函数 加精!!!
    100+Python挑战性编程练习系列 -- day 22
    Nvidia GPU 入门教程之 04 如何在 Ubunt 上安装 Anaconda Python 发行版
    Flutter 应用启动从闪屏页短暂黑屏再到第一个页面
    HTML三叉戟,标签、元素、属性各个的意义是什么?
  • 原文地址:https://blog.csdn.net/weixin_41360517/article/details/134060596