Skip to content

Signature 签名

TSignature 是一个用于创建签名区域的组件,支持多种配置,包括线条颜色、大小、平滑模式等。

支持平台

安卓iosweb微信小程序支付宝小程序QQ小程序
xxx

示例

html
<template>
	<view class="sign-content">
		<view class="sign-bg">
			<text class="txt">签名区</text>
		</view>
		<t-signature class="ff" ref="signatures" type="p" :lineSize="3"></t-signature>
	</view>
	<view class="sign-toos-box">
		<t-status-bar />
		<t-button class="sign-toos sign-toos-mar" type="error" @click="quit">退出</t-button>
		<view style="flex: 1;"></view>
		<view style="padding-bottom: 40rpx;">
			<view class="buttonbox">
				<t-button class="sign-toos sign-toos-mar" type="error" @click="clear">清空</t-button>
			</view>
			<view class="buttonbox">
				<t-button class="sign-toos sign-toos-mar" type="warning" @click="undo">撤消</t-button>
			</view>
			<view class="buttonbox">
				<t-button class="sign-toos sign-toos-mar" type="success" @click="redo">恢复</t-button>
			</view>
			<view class="buttonbox">
				<t-button class="sign-toos sign-toos-mar sign-toos-bottom" type="primary" @click="save">确定</t-button>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				signEl: null as TSignatureComponentPublicInstance | null
			}
		},
		methods: {
			quit() {
				uni.navigateBack()
			},
			clear() {
				const sign = this.signEl as TSignatureComponentPublicInstance
				sign.clear()
			},
			undo() {
				const sign = this.signEl as TSignatureComponentPublicInstance
				sign.undo()
			},
			redo() {
				const sign = this.signEl as TSignatureComponentPublicInstance
				sign.redo()
			},
			save() {
				const sign = this.signEl as TSignatureComponentPublicInstance
				sign.save().then((res : string) => {
					uni.previewImage({ urls: [res] })
				})
			}
		},
		mounted() {
			this.signEl = this.$refs['signatures'] as TSignatureComponentPublicInstance
		}
	}
</script>
<style lang="scss" scoped>
	.sign-content {
		background-color: #FEFAE7;
		flex: 1;
		position: relative;

		.sign-bg {
			position: absolute;
			left: 0;
			right: 0;
			bottom: 0;
			top: 0;
			display: flex;
			align-items: center;
			justify-content: center;

			.txt {
				color: #eeead9;
				font-size: 150rpx;
				transform: rotate(90deg);
				letter-spacing: 15rpx;
			}
		}
	}

	.buttonbox {
		height: 120rpx;
		padding-top: 20rpx;
		overflow: visible;
	}

	.sign-toos-box {
		position: fixed;
		bottom: 0;
		left: 0;
		top: 0;
		display: flex;
		justify-content: space-between;
		background-color: #F6F0DE;
		padding: 0 12rpx;
	}

	.sign-toos {
		// transform-origin: top center;
		transform: rotate(90deg);
	}

	.sign-toos-mar {
		margin-top: 40rpx;
	}

	.sign-toos-bottom {
		margin-bottom: 40rpx;
	}
</style>

Props

名称描述类型默认值
color线条颜色String''
lineSize线条大小Number2
openSmooth是否开启平滑模式Booleanfalse
minWidth线条最小宽度Number2
maxWidth线条最大宽度Number6
minSpeed最小速度Number1.5
maxWidthDiffRate最大宽度变化率Number20
maxHistory最大历史记录点数Number20
disableScroll是否禁用滚动Booleantrue
disabled是否禁用组件Booleanfalse
landscape是否横屏模式Booleantrue

Methods

名称描述
clear清除画布上的签名
undo撤销上一次绘制
redo重做上一次撤销的操作
save保存签名图像为数据URL