Appearance
ZSign
签字版,用于某些场景下的电子签名。 版本要求 >= 1.0.36
基础用法
<template>
<div class="box">
<z-sign width="858" fill="#f0f0f0"></z-sign>
</div>
</template>
<script setup lang="ts">
</script>
<style scoped>
</style>
背景
使用 src
和 fill
进行背景设置。
- src 通过传入一个本地或是在线的图片地址,进行背景图设置。
- fill 通过传入一个色值,进行单色背景设置。
- 您可以将两者结合使用,这并不冲突。
fill
src
fill + src

<template>
<div class="box">
<div class="item">
<h1>fill</h1>
<z-sign width="400" height="400" fill="#f0f0f0"></z-sign>
</div>
<div class="item">
<h1>src</h1>
<z-sign width="400" height="400" src="https://images.unsplash.com/photo-1733173523386-3006dec1a835?q=80&w=2705&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"></z-sign>
</div>
<div class="item">
<h1>fill + src</h1>
<z-sign
width="858"
fill="#f0f0f0"
src="/logo.png"
></z-sign>
</div>
</div>
</template>
<script setup lang="ts">
</script>
<style scoped>
.box {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
grid-gap: 24px 0;
}
</style>
画笔
<template>
<div class="box">
<z-sign fill="#f0f0f0" :config="config"></z-sign>
<div class="menu">
<z-slider v-model:value="config.size"></z-slider>
<div class="mb24">画笔大小</div>
<input type="color" v-model="config.color"/>
<div>画笔颜色</div>
</div>
</div>
</template>
<script setup lang="ts">
import { reactive } from "vue";
import type { ISignCanvasConfig } from "@d7ee/z-base-ui/dist/types/components/ZSign";
const config = reactive<ISignCanvasConfig>({
color: "#000",
size: 5
});
</script>
<style scoped>
.box {
display: flex;
align-items: flex-start;
justify-content: space-between;
}
.menu {
margin-top: 42px;
width: 300px;
}
.mb24{
margin-bottom: 24px;
}
</style>
功能一览
受支持的各项功能,包括但不限于下载,导出,撤销,橡皮擦。
<template>
<div class="box">
<z-sign ref="signRef" width="858" fill="#f0f0f0"></z-sign>
<div class="btn">
<z-button type="primary" @click="download">下载</z-button>
<z-button type="warning" @click="quash">撤销</z-button>
<z-button type="warning" @click="eraser">橡皮擦</z-button>
<z-button type="danger" @click="clearCanvas">清空画布</z-button>
</div>
</div>
</template>
<script setup lang="ts">
import {ref} from "vue";
const signRef = ref<HTMLDivElement | null>(null);
const download = () => {
if (!signRef.value) return;
signRef.value.exportImg().then(() => {
//
}).catch(() => {
//
})
}
const quash = () => {
if (!signRef.value) return;
signRef.value.quash();
}
const eraser = () => {
if (!signRef.value) return;
signRef.value.eraser();
}
const clearCanvas = () => {
if (!signRef.value) return;
signRef.value.clearCanvas();
}
</script>
<style scoped>
.btn {
margin-top: 24px;
}
</style>
API 属性
属性名 | 说明 | 类型 | 默认值 |
---|---|---|---|
width | 画布宽度 | number | string | 500 |
height | 画布高度 | number | string | 500 |
src | 背景图 | string | — |
fill | 背景色 | string | — |
transparently | 下载导出时背景为透明 | boolean | — |
color | 橡皮擦颜色 | string | — |
config | 画笔配置项 | ISignCanvasConfig | — |
config
属性名 | 说明 | 类型 | 默认值 |
---|---|---|---|
size | 画笔、橡皮擦大小 | number | 5 |
color | 画笔颜色 | string | #000 |
slot 插槽
slotName | 说明 | 参数 |
---|---|---|
eraser | 橡皮擦 |
event 事件
以下事件均通过refs.xxx的形式调佣
事件名称 | 说明 | 参数 | 返回值 |
---|---|---|---|
updateConfig | 手动更新config | ISignCanvasConfig | 无 |
exportImg | 导出或下载图片使用 | (state:? boolean, fileName?: string) | Promise |
quash | 撤销,恢复到上一个动作 | ||
eraser | 进入橡皮擦模式,再调用一次关闭 | ||
clearCanvas | 清除画布 |
exportImg
用于导出或下载签名,接收两个可选参数state和fileName。
- state: 类型为
boolean
,默认为true
,下载,false
时取消下载并返回一个base64 - fileName:自定义文件名,不传递时默认以当前时间戳为文件名,传递时无需携带后缀名
vue
<template>
<z-sign ref="signRef"></z-sign>
</template>
<script setup lang="ts">
import { ref } from "vue";
const signRef = ref<any>(null);
const donwload = () => {
signRef.value.exportImg(true, "自定义文件名").then(res => {
console.log(res);
}).catch(e => {
console.log(e);
});
}
</script>
类型声明
ISignCanvasConfig
typescript
interface ISignCanvasConfig {
// 画笔颜色
color?: number;
// 画笔、橡皮擦大小
size?: number;
}