vue中实现签名画板


特意封装成了一个组件,签名之后会生成一张图片
signBoard.vue

typescript 复制代码
<template>
  <el-drawer title="签名" :visible.sync="isShowBoard" append-to-body :show-close="false" :before-close="closeBoard" size="50%" @close="closeBoard">
    <div class="drawer-body">
      <el-row v-loading="loading">
        <vue-sign ref="esign" :width="800" :height="300" :is-crop="isCrop" :line-width="lineWidth" :line-color="lineColor" />
        <button class="mt20" @click="handleReset">清空画板</button>
      </el-row>
    </div>
    <div class="drawer-footer">
      <el-button @click="closeBoard">关 闭</el-button>
      <el-button type="primary" :loading="loading" @click="handleSign">签 名</el-button>
    </div>
  </el-drawer>

</template>

<script>
import vueSign from 'vue-esign'
import oss from '@/utils/oss'
const baseUrl = process.env.VUE_APP_OSS_URL
export default {
  components: { vueSign },
  props: {
    folder: {
      type: String,
      default: ''
    },
    isShowBoard: {
      type: Boolean,
      default: false
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      lineWidth: 6,
      lineColor: '#000000',
      bgColor: '#eee',
      fileList: [],
      signSrc: '',
      isCrop: false
    }
  },
  methods: {
    handleReset() {
      this.$refs.esign.reset()
      this.$refs.esign.$el.style.background = '#eee'
    },
    async handleGenerate() {
      try {
        const res = await this.$refs.esign.generate()
        //服务器上传
        const result = await oss.dataURLtoFile(res, this.folder)
        this.signSrc = baseUrl + '' + result.fileUrl
        this.$emit('sign', this.signSrc)
      } catch (e) {
        this.$message.error('请先进行手签')
      }
    },
    handleSign() {
      this.handleConfirm(() => this.handleGenerate())
    },
    closeBoard() {
      this.handleReset()
      this.$emit('update:isShowBoard', false)
    }
  }
}
</script>

使用

typescript 复制代码
  <sign-board
    :folder="CONSTANT.EMPLOYEE_CHECK"
    :is-show-board.sync="isShowBoard"
    :loading="loading"
    @sign="getSignSrc"
  />
    getSignSrc(src) {
    },
相关推荐
护国神蛙27 分钟前
给你一个页面如何定时刷新
前端·javascript·浏览器
一直游到海水变蓝丿35 分钟前
el-select下拉框 添加 el-checkbox 多选框
前端·javascript·vue.js
罗政1 小时前
基于 SpringBoot + Vue 在线点餐系统(前后端分离)
vue.js·spring boot·后端
懒羊羊大王呀1 小时前
Ubuntu20.04中MySQL的安装和配置
linux·mysql·ubuntu
浅安的邂逅1 小时前
Ubuntu apt-get安装-报错:尝试“apt --fix-broken install”有未能满足的依赖关系,几种解决办法
linux·ubuntu·apt install
Viooocc1 小时前
ubuntu网络连接失败 + mobaxterm拖拽文件出错等问题解决方法
ubuntu
阿奇__1 小时前
element 跨页选中,回显el-table选中数据
前端·vue.js·elementui
努力往上爬de蜗牛1 小时前
vue3 daterange正则踩坑
javascript·vue.js·elementui
谢尔登1 小时前
【React】SWR 和 React Query(TanStack Query)
前端·react.js·前端框架
断竿散人1 小时前
专题一、HTML5基础教程-Viewport属性深入理解:移动端网页的魔法钥匙
前端