0.1.0 • Published 10 months ago

esignature v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months 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

11 months ago

0.0.21

11 months ago

0.0.22

11 months ago

0.0.23

11 months ago

0.0.24

11 months ago

0.0.25

11 months ago

0.0.19

11 months ago

0.0.36

11 months ago

0.1.0

10 months ago

0.0.26

11 months ago

0.0.27

11 months ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago