0.1.0 • Published 2 years 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
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