0.1.0 • Published 10 months ago
esignature v0.1.0
Vue 3 的电子手写签名hooks
适配移动和pc端, 从vue2组件的方式变更为vue最新的hooks方式, 旨在更好的兼容 VUE
组合式API
, 更好的对调用者暴露可选操作;
调用 hook 时的可选项说明
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
type | 类型, 可选值为 png jpg jpeg svg | string | png |
quality | 质量, 可选值为 0~1 | number | 0.8 |
minDistance | 最小距离, 以像素为单位 | number | 5 |
velocityFilterWeight | 速度过滤器权重, 可选值为 0~1 | number | 0.7 |
backgroundColor | 签名画布的背景色 | string | rgba(0,0,0,0) |
throttle | 节流阀速度, 以毫秒为单位 | number | 16 |
dotSize | 画笔的大小, 大于0, 则minWidth 和maxWidth 失效 | number | 0 |
minWidth | 画笔的最小宽度 | number | 0.5 |
maxWidth | 画笔的最大宽度 | number | 2.5 |
penColor | 画笔颜色 | string | black |
用例
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