uniapp开发小程序手写板、签名、签字

本文介绍如何在uni-app中实现小程序的手写板和签名功能。虽然DCloud插件市场提供了lime-signature插件,但未提供VUE3 Composition API的写法。文章建议使用Composition API进行实现,因为它更简洁且灵活。文中步骤包括创建小程序项目、替换index.vue代码,并展示了在微信开发工具和手机真机上的运行效果。此外,还提及了压感设置对笔画粗细的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

可以使用这个插件进行操作 

手写板-签名签字-lime-signature - DCloud 插件市场

但是目前这个插件没有VUE3 setup Composition API的写法。所以对于此文档提供的可以直接使用,需要使用Composition API方式实现的,可以继续看。

因为Composition API方式,更加的简单、灵活,在今后的编程之中要多用、多学,这样才能写出更加健壮的代码。

1.首先建立一个可以运行的小程序


2.把index.vue的代码直接替换一下

<template>
	<view style="width: 750rpx; height: 750rpx;">
		<l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize"
			:openSmooth="openSmooth"></l-signature>
	</view>
	<view>
		<button @click="onClick('clear')">清空</button>
		<button @click="onClick('undo')">撤消</button>
		<button @click="onClick('save')">保存</button>
		<!-- uvue 不支持 openSmooth -->
		<button @click="onClick('openSmooth')">压感{{openSmooth ? '开' : '关'}}</button>
	</view>
</template>
 
<script setup>
	import {
		ref
	} from 'vue';
 
	const penColor = ref('red')
	const penSize = ref(5)
	const url = ref('')
	const openSmooth = ref(true)
	const signatureRef = ref(null);
 
	function onClick(type) {
		if (type === 'openSmooth') {
			openSmooth.value = !openSmooth.value;
			return;
		}
		if (type === 'save' && signatureRef.value) {
			signatureRef.value.canvasToTempFilePath({
				success: (res) => {
					console.log(res.isEmpty) // 是否为空画板 无签名
					url.value = res.tempFilePath // 生成图片的临时路径
				}
			});
			return;
		}
		if (signatureRef.value) {
			signatureRef.value[type]();
		}
	}
</script>
 
<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100%;
	}
 
	canvas {
		width: 375px;
		height: 200px;
		border: 1px solid #ccc;
	}
 
	.clear-btn,
	.save-btn {
		margin-top: 10px;
	}
</style>

3.微信开发工具运行效果

4.手机真机调试效果

5.其中压感关和开,是增加笔画粗细的设置

加粗就是压感关

变细就是压感开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值