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

 更新时间:2023年10月27日 10:08:24   作者:菜鸟书生  
这篇文章主要为大家介绍了vue使用smooth-signature实现移动端横竖屏电子签字示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

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

使用smooth-signature

npm install --save smooth-signature

页面引入插件

import SmoothSignature from "smooth-signature";

实现效果

完整代码

<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>

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

以上就是vue使用smooth-signature实现移动端横竖屏电子签字的详细内容,更多关于vue smooth-signature电子签字的资料请关注脚本之家其它相关文章!

相关文章

  • Vue3中使用ref与reactive创建响应式数据的示例代码

    Vue3中使用ref与reactive创建响应式数据的示例代码

    这篇文章主要介绍了Vue3中使用ref与reactive创建响应式数据的方法,文中通过代码示例讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下
    2024-08-08
  • vue之el-upload使用FormData多文件同时上传问题

    vue之el-upload使用FormData多文件同时上传问题

    这篇文章主要介绍了vue之el-upload使用FormData多文件同时上传问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • nuxt 实现在其它js文件中使用store的方式

    nuxt 实现在其它js文件中使用store的方式

    这篇文章主要介绍了nuxt 实现在其它js文件中使用store的方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11
  • Vue状态管理工具Pinia的安装与使用教程

    Vue状态管理工具Pinia的安装与使用教程

    这篇文章主要介绍了Vue状态管理工具Pinia的安装与使用,一步一步学习如何将pinia运用到项目实战中去,文中有详细的安装教程和使用方法,并通过代码示例讲解的非常详细,需要的朋友可以参考下
    2024-03-03
  • 搭建vue3项目以及按需引入element-ui框架组件全过程

    搭建vue3项目以及按需引入element-ui框架组件全过程

    element是基于vue.js框架开发的快速搭建前端的UI框架,下面这篇文章主要给大家介绍了关于搭建vue3项目以及按需引入element-ui框架组件的相关资料,文中通过图文以及代码介绍的非常详细,需要的朋友可以参考下
    2024-02-02
  • Vue中$attrs和$listeners详解以及使用方法

    Vue中$attrs和$listeners详解以及使用方法

    最近在研究Vue的组件库,之前也用过$attrs和$listeners,官方文档描述的不太详细,也没有太好的例子,下面这篇文章主要给大家介绍了关于Vue中$attrs和$listeners详解以及使用的相关资料,需要的朋友可以参考下
    2022-11-11
  • vue实现整屏滚动切换

    vue实现整屏滚动切换

    这篇文章主要为大家详细介绍了vue实现整屏滚动切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-06-06
  • 基于Vue实现支持按周切换的日历

    基于Vue实现支持按周切换的日历

    这篇文章主要为大家详细介绍了基于Vue实现支持按周切换的日历,根据实际开发情况按每年、每月、每周进行切换,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • Vue3中简单实现动态添加路由

    Vue3中简单实现动态添加路由

    本文主要介绍了Vue3中简单实现动态添加路由,,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-05-05
  • vue使用Split封装通用拖拽滑动分隔面板组件

    vue使用Split封装通用拖拽滑动分隔面板组件

    这篇文章主要介绍了vue使用Split封装通用拖拽滑动分隔面板组件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03

最新评论