Skip to content

Signature 签名

介绍

基于 Canvas 的签名组件。默认竖屏模式使用,如使用横屏模式,请开发者自行设置旋转角度或者宽高。

基础用法

vue
<script>
export default {
  props: {},
  setup() {
    const demoSignUrl = ref('')
    const confirm = (canvas, data) => {
      if (data === '') {
        console.log(canvas)
        return false
      }
      demoSignUrl.value = data
      console.log('图片地址', canvas, data)
    }
    const clear = () => {
      demoSignUrl.value = ''
      console.log('清除事件')
    }
    return { confirm, clear, demoSignUrl }
  }
}
</script>

<template>
  <nut-signature
    @confirm="confirm"
    @clear="clear"
  />
  <image v-if="demoSignUrl" :src="demoSignUrl" class="demoSignUrl" />
</template>

修改颜色和签字粗细

vue
<script>
import { reactive } from 'vue'

export default {
  props: {},
  setup() {
    const state = reactive({
      lineWidth: 4,
      strokeStyle: 'green'
    })
    const demoSignUrl = ref('')
    const confirm = (canvas, data) => {
      if (data === '') {
        console.log(canvas)
        return false
      }
      demoSignUrl.value = data
      console.log('图片地址', canvas, data)
    }
    const clear = () => {
      demoSignUrl.value = ''
      console.log('清除事件')
    }
    return { ...state, demoSignUrl, confirm, clear }
  }
}
</script>

<template>
  <nut-signature
    :line-width="lineWidth"
    :stroke-style="strokeStyle"
    @confirm="confirm"
    @clear="clear"
  />
  <image v-if="demoSignUrl" :src="demoSignUrl" class="demoSignUrl" />
</template>

API

Props

参数说明类型默认值
custom-class自定义 classstring-
line-width线条的宽度number3
stroke-style绘图笔触颜色string#000
type图片格式stringpng
un-support-tpl不支持Canvas情况下的展示文案string对不起,当前浏览器不支持Canvas,无法使用本控件!

Events

事件名说明回调参数
start签名开始回调函数(指某次笔画的开始)-
signing正在签名的回调函数(指某次笔画进行中)event
end签名结束回调函数(指某次笔画的结束)-
confirm点击确认按钮触发事件回调函数canvas和签名图片展示的 data URI,<br>如未绘制,则返回提示信息和空 data URI
clear点击重签按钮触发事件回调函数-

MIT Licensed