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) {
    },
相关推荐
竹林8184 分钟前
用Viem替代ethers.js:从一次签名失败到完整迁移的实战记录
前端·javascript
之歆9 分钟前
DAY08_CSS浮动与行内块布局实战指南(上)
前端·css
light blue bird30 分钟前
主子端台二分法任务汇总组件
前端·数据库·.net·桌面端winform
jeffwang1 小时前
我做了个让 AI 看屏幕跑测试的工具,因为 Playwright 测不了我的 Flutter Web
前端
HSunR2 小时前
dify 搭建ai作业批改流
开发语言·前端·javascript
代码不加糖2 小时前
2026 跨境电商独立站实战:从 0 到 1 搭建高转化 SaaS 商城(附源码)
开发语言·前端·javascript
亲亲小宝宝鸭2 小时前
拖一拖控件,拖出个问卷(低代码平台)
前端·低代码
江南十四行2 小时前
ReAct Agent 基本理论与项目实战(一)
前端·react.js·前端框架
We་ct3 小时前
LeetCode 72. 编辑距离:动态规划经典题解
前端·算法·leetcode·typescript·动态规划
小呆呆6663 小时前
Codex 穷鬼大救星
前端·人工智能·后端