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) {
    },
相关推荐
胡萝卜术4 小时前
从API调用到手写LRU:力扣146「LRU缓存」的哈希表+双向链表终极进化之路
前端·javascript·面试
科技道人4 小时前
记录 默认置灰/禁用 app ‘Search Engine Selector‘ 的disable按钮
开发语言·前端·javascript
天疆说4 小时前
Zotero Connector 在 Edge 里找不到桌面 Zotero(Linux / Zotero 9.0.6 / Edge 150)
linux·前端·edge
李伟_Li慢慢5 小时前
02-从硬件说起WebGL
前端·three.js
IT曙光6 小时前
ubuntu apt-get离线源制作
linux·ubuntu
kyriewen6 小时前
看了微软几万人用AI编程的数据——效率涨24%的代价没人提
前端·ai编程·claude
2601_963771376 小时前
How to Scale Your WordPress Store Traffic in 2026
前端·php·plugin
亿元程序员6 小时前
老板说我的3D箭头游戏用来做试玩太普通了,没人想玩,让我变点花样...
前端
李伟_Li慢慢7 小时前
01-threejs架构原理-课程简介
前端·three.js
_瑞8 小时前
深入理解 iOS 渲染原理
前端·ios