Coder Social home page Coder Social logo

vue-esign's Introduction

vue-esign

Canvas 手写签字 电子签名

npm GitHub package.json version

时隔三年的更新!!支持vue3

  • 支持vue3!!!!更新依赖后,仅bgColor原来的.sync修饰符需改为vue3写法v-model:bgColor;
  • 新增属性 isClearBgColor,默认值true, 清空画布时(reset)是否同时清空设置的背景色(bgColor) ;
  • 直接npm install vue-esign@latest --save即可,对vue2版本无任何影响;

功能

  1. 兼容 PC 和 Mobile;
  2. 画布自适应屏幕大小变化(窗口缩放、屏幕旋转时画布无需重置,自动校正坐标);
  3. 自定义画布尺寸(导出图尺寸),画笔粗细、颜色,画布背景色;
  4. 支持裁剪 (针对需求:有的签字需要裁剪掉四周空白)。
  5. 导出图片格式为 base64
  6. 示例demo

安装

npm install vue-esign --save

使用

  1. 全局使用 、局部
// 全局 vue2 main.js
import vueEsign from 'vue-esign'
Vue.use(vueEsign)
// 全局vue3 main.js
import { createApp } from 'vue'
import App from './App.vue'
import vueEsign from 'vue-esign'
const app = createApp(App)
app.use(vueEsign)
// 局部
import vueEsign from 'vue-esign'
components: { vueEsign }
  1. 页面中使用 必须设置 ref ,用来调用组件的两个内置方法 reset()generate()

无需给组件设置 style 的宽高,如果画布的 width属性值没超出父元素的样式宽度,则该组件的样式宽度就是画布宽度,超出的话,组件样式宽度则是父元素的100%; 所以只需设置好父元素的宽度即可;

<!-- vue2 -->
<vue-esign ref="esign" :width="800" :height="300" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" />
<!-- vue3 -->
<vue-esign ref="esign" :width="800" :height="300" :isCrop="isCrop" :lineWidth="lineWidth" :lineColor="lineColor" v-model:bgColor="bgColor" />

<!-- isClearBgColor为false时,不必再给bgColor加sync修饰符或v-model -->

<button @click="handleReset">清空画板</button>
<button @click="handleGenerate">生成图片</button>
data () {
  return {
    lineWidth: 6,
    lineColor: '#000000',
    bgColor: '',
    resultImg: '',
    isCrop: false
  }
},
methods: {
  handleReset () {
    this.$refs.esign.reset()
  },
  handleGenerate () {
    this.$refs.esign.generate().then(res => {
      this.resultImg = res
    }).catch(err => {
      alert(err) // 画布没有签字时会执行这里 'Not Signned'
    })
  }
}
  1. 说明
属性 类型 默认值 说明
width Number 800 画布宽度,即导出图片的宽度
height Number 300 画布高度,即导出图片的高度
lineWidth 4 Number 画笔粗细
lineColor String #000000 画笔颜色
bgColor String 画布背景色,为空时画布背景透明,
支持多种格式 '#ccc','#E5A1A1','rgb(229, 161, 161)','rgba(0,0,0,.6)','red'
isCrop Boolean false 是否裁剪,在画布设定尺寸基础上裁掉四周空白部分
isClearBgColor Boolean true 清空画布时(reset)是否同时清空设置的背景色(bgColor)
format String image/png 生成图片格式 image/jpeg(jpg格式下生成的图片透明背景会变黑色请慎用或指定背景色)、 image/webp
quality Number 1 生成图片质量;在指定图片格式为 image/jpeg 或 image/webp的情况下,可以从 0 到 1 的区间内选择图片的质量。如果超出取值范围,将会使用默认值 0.92。其他参数会被忽略。

两个内置方法,通过给组件设置 ref 调用:

清空画布

this.$refs.esign.reset()

生成图片

// 可选配置参数 ,在未设置format或quality属性时可在生成图片时配置 例如: {format:'image/jpeg', quality: 0.5}
// this.$refs.esign.generate({format:'image/jpeg', quality: 0.5})

this.$refs.esign.generate().then(res => {
  console.log(res) // base64图片
}).catch(err => {
  alert(err) // 画布没有签字时会执行这里 'Not Signned'
})

vue-esign's People

Contributors

jaimecheng avatar lanjiannull avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vue-esign's Issues

手写签名偏移过大

使用vue-esign 时,手机侧向,第一个字便宜正常,第二个就偏移过大, 使用得是demo实例

typescript版本

你好,我这边有需求使用到你提供的技术,但我没找到有对应的typescript版。因此我参照你们的重写了一份typesrcirpt版本的,如果你们需要,可以从地址拉去

组件销毁后resize事件未删除

vue3中组件销毁前的回调是bedoreUnMount,但是源码中使用的仍然是bedoreDestroy,导致removeEvents方法没有生效,resize方法没有删除,改变视口大小时,后台会一直报错。

Vue3.2 + Vite 打包报错 openBlock' is not exported by

首先感谢作者提供的签名插件,很好用,不过发生了很尴尬的事情

当前环境:Vue 3.2.25,Vite 2.8.0

Vite 打包报错

'openBlock' is not exported by node_modules/vue-esign/node_modules/vue/dist/vue.runtime.esm.js, imported by node_modules/vue-esign/src/index.vue import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue" ^ 269: 270: function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { error during build: Error: 'openBlock' is not exported by node_modules/vue-esign/node_modules/vue/dist/vue.runtime.esm.js, imported by node_modules/vue-esign/src/index.vue

是因为插件包用的Vue是2.x版本吗

Add placeholder

Hope to add default text,
期望增加默认文字,

Or, return to hasdrew to determine whether it is displayed
或者,返回hasDrew,自己判断是否显示placeholder
hasDrew(newVal){ this.$emit('hasDrew',newVal) }
image

nuxt+vue-esign打包问题请教?

RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript) nitro 15:51:31

1:
^
2: <canvas ref="canvas" @mousedown="mouseDown" @mousemove="mouseMove" @mouseup="mouseUp"
3: @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">

ERROR Unexpected token (Note that you need plugins to import files that are not JavaScript)

这个问题是问题nuxt使用的vue3的语法,vue-esign使用vue2导致的吗?有木有解决方案呢。

vit3.0 vue 打包报错

项目能够正常运行,但是在打包的时候报错
'openBlock' is not exported by node_modules/vue-esign/node_modules/vue/dist/vue.runtime.esm.js, imported by node_modules/vue-esign/src/index.vue
file: D:/work/test/datagovern-ui/node_modules/vue-esign/src/index.vue:278:9
276: }
277:
278: import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
^
279:
280: function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
error during build:
Error: 'openBlock' is not exported by node_modules/vue-esign/node_modules/vue/dist/vue.runtime.esm.js, imported by node_modules/vue-esign/src/index.vue
at error (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
at Module.error (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:12412:16)
at Module.traceVariable (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:12771:29)
at ModuleScope.findVariable (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:11423:39)
at FunctionScope.findVariable (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:6355:38)
at ChildScope.findVariable (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:6355:38) at Identifier.bind (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:7422:40)
at CallExpression.bind (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:5252:23)
at CallExpression.bind (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:8918:15)
at SequenceExpression.bind (file:///D:/work/test/datagovern-ui/node_modules/rollup/dist/es/shared/rollup.js:5248:73)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.