0.1.0 • Published 2 years ago

esignature v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Vue 3 的电子手写签名hooks

适配移动和pc端, 从vue2组件的方式变更为vue最新的hooks方式, 旨在更好的兼容 VUE 组合式API, 更好的对调用者暴露可选操作;

调用 hook 时的可选项说明

参数说明类型默认值
type类型, 可选值为 png jpg jpeg svgstringpng
quality质量, 可选值为 0~1number0.8
minDistance最小距离, 以像素为单位number5
velocityFilterWeight速度过滤器权重, 可选值为 0~1number0.7
backgroundColor签名画布的背景色stringrgba(0,0,0,0)
throttle节流阀速度, 以毫秒为单位number16
dotSize画笔的大小, 大于0, 则minWidthmaxWidth失效number0
minWidth画笔的最小宽度number0.5
maxWidth画笔的最大宽度number2.5
penColor画笔颜色stringblack

用例

iimport { defineComponent, ref } from "vue";
import './index.scss';
import { useSign } from "../hook";

export default defineComponent({
  setup() {
    const src = ref<string>();
    const canvas = ref<HTMLCanvasElement>();
    // 调用电子签名的hooks
    const sign = useSign(canvas);;

    const preview = () => {
      src.value = sign.getData();
    }
    return () => (
      <>
        <div class="e-sign">
          <canvas style='width:100%' ref={canvas} />
        </div>
        <div class="option">
          <button type="button" onClick={sign.undo}>撤销</button>
          <button type="button" onClick={sign.changePenColor}>颜色</button >
          <button type="button" onClick={sign.clear}> 重置</button >
          <button type="button" onClick={sign.save}> 保存</button >
          <button type="button" onClick={preview}> 预览</button>
        </div>
        <div class="e-sign">
          <img src={src.value} alt="preview" />
        </div>
      </>
    );
  }
});
/* index.scss */
.e-sign {
  display: flex;
  height: 9rem;
  border: 1px solid #d7d7d7;
  border-radius: 4px;

  img {
    width: 100%;
    object-fit: contain;
  }
}

.option {
  margin: 5px 0;
  display: flex;
  justify-content: space-around;
}
0.0.20

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.19

2 years ago

0.0.36

2 years ago

0.1.0

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago