Skip to content

Signature 签名

用于签名场景,基于 Canvas 实现的签名组件。它提供了多种自定义选项,包括签名笔的颜色、宽度以及自定义操作按钮。

提醒

如果遇到导出图片不清晰,可以将exportScale设置为2以上。

基础用法

html
<wui-signature @submit="confirm" @clear="clear" />
<wui-img :height="img.height" :width="img.width" :src="img.src" v-if="img.src" />
typescript
const img = ref({
  width: 0,
  height: 0,
  src: ''
})
function confirm(result: SignatureResult) {
  img.value.src = result.tempFilePath
  img.value.height = result.height
  img.value.width = result.width
}

自定义画笔颜色

pen-color设置签名笔的颜色,默认为黑色

html
<wui-signature pen-color="red" />

自定义画笔宽度

line-width设置签名笔的宽度,默认为2

html
<wui-signature :line-width="6" />

自定义背景色

background-color设置画板的背景色,无默认值。

html
<wui-signature background-color="lightgray" />

禁用滚动

disable-scroll设置是否禁用画布滚动,默认为true

html
<wui-signature :disable-scroll="false" />

自定义按钮

通过footer插槽可以自定义按钮。

html
<wui-signature :disabled="disabled">
  <template #footer="{ clear, confirm }">
    <wui-button block @click="changeDisabled" v-if="disabled">开始签名</wui-button>
    <wui-button v-if="!disabled" size="small" plain @click="clear">清除</wui-button>
    <wui-button v-if="!disabled" size="small" custom-style="margin-left: 4px" @click="confirm">确认</wui-button>
  </template>
</wui-signature>
typescript
const disabled = ref(true)

function changeDisabled() {
  disabled.value = false
}

Attributes

参数说明类型可选值默认值最低版本
penColor签名笔颜色String--#000000-
lineWidth签名笔宽度Number--2-
height画布的高度Number--200-
width画布的宽度Number--300-
clearText清空按钮的文本String--清空-
confirmText确认按钮的文本String--确认-
fileType目标文件的类型,uni.canvasToTempFilePath 属性介绍String--png-
quality图片的质量,取值范围为 (0, 1],不在范围内时当作 1.0 处理,uni.canvasToTempFilePath 属性介绍Number--1-
exportScale导出图片的缩放比例Number--1-
disabled是否禁用签名板Boolean--false-
backgroundColor画板的背景色String-----
disableScroll是否禁用画布滚动Boolean--true-
showFooter是否显示 FooterBoolean--true-
isRotate生成签名图片是否旋转Boolean--false-
promptText没有笔记时提交提示文案String--''-

Slot

name说明参数最低版本
footer自定义 footer{ clear, confirm }-

Events

事件名称说明参数最低版本
start开始签名时触发--
end结束签名时触发--
signing签名过程中触发event-
confirm点击确定按钮时触发{tempFilePath, width, height, success} 分别为生成文件的临时路径 (本地路径)、生成图片宽、生成图片高、是否成功-
clear点击清空按钮时触发--

Methods

对外暴露函数

事件名称说明参数最低版本
confirm点击确认按钮时触发{tempFilePath, width, height, success} 分别为生成文件的临时路径 (本地路径)、生成图片宽、生成图片高、是否成功-
clear点击清空按钮时触发--

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.