uni-app 指纹验证

次demo 在插件市场找的

链接地址:  https://ext.dcloud.net.cn/plugin?id=358

<template>
	<view>
		<button  class="button_fin" @tap="fingerprint()" :disabled="disabled">按下开始识别指纹</button>
		 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				 
				disabled: true
			}
		},
		onLoad() {
			
			// #ifdef APP-PLUS
			if (!plus.fingerprint.isSupport()) {
				uni.showToast({
					title: '此设备不支持指纹识别',
					icon: 'none',
					duration: 2000
				});
		 
				// alert("此设备不支持指纹识别")
				this.disabled = true;
			} else if (!plus.fingerprint.isKeyguardSecure()) {
				uni.showToast({
					title: '此设备未设置密码锁屏,无法使用指纹识别',
					icon: 'none',
					duration: 2000
				});
			 
				this.disabled = true;
			} else if (!plus.fingerprint.isEnrolledFingerprints()) {
				uni.showToast({
					title: '此设备未录入指纹,请到设置中开启',
					icon: 'none',
					duration: 2000
				});
				 
				this.disabled = true;
			} else {
			 
				// this.disabled=true
				this.disabled = false;
			}
			// #endif
			
			// #ifdef MP-WEIXIN
			this.disabled = false;
			 
			uni.showToast({
				title: '请在微信真机中使用,模拟器不支持',
				icon: 'none',
				duration: 2000
			});
			// #endif
			// #ifndef APP-PLUS || MP-WEIXIN
			 
 
			uni.showToast({
				title: '此平台不支持指纹识别',
				icon: 'none',
				duration: 2000
			});

			// #endif
			// 初次调用指纹
			// this.fingerprint()
		},
		methods: {			
			fingerprint: function() {
				// #ifdef APP-PLUS
				plus.fingerprint.authenticate(function() {
					plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
					// plus.nativeUI.alert('指纹识别成功');
					// plus.nativeUI.alert("指纹识别成功", function(){
					// 		console.log("1111");
					// 	}, "指纹验证", "确定");
					  
					uni.showToast({
						title: '指纹识别成功',
						// icon: 'none',
						mask:true,
						image:"/static/FingerprintBlue.png",
						duration: 2000
					});
					// uni.showModal({
					// 	title: '友情提示',
					// 	content: '指纹识别成功',
					// 	success: function(res) {
					// 		if (res.confirm) {
					// 			console.log('用户点击确定');
					// 		} else if (res.cancel) {
					// 			console.log('用户点击取消');
					// 		}
					// 	}
					// });
				}, function(e) {
					switch (e.code) {
						case e.AUTHENTICATE_MISMATCH:
							plus.nativeUI.toast('指纹匹配失败,请重新输入');
							break;
						case e.AUTHENTICATE_OVERLIMIT:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败次数超出限制,请使用其它方式进行认证');
							break;
						case e.CANCEL:
							plus.nativeUI.toast('已取消识别');
							break;
						default:
							plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败,请重试');
							break;
					}
				});
				// Android平台手动弹出等待提示框 
				if ('Android' == plus.os.name) {
					// var opt = '{"width":"150px","height":"150px","style": "white",  "color": "#1d8079"}';
					// plus.nativeUI.showWaiting('指纹识别中...', JSON.parse(opt)).onclose = function() {
					// 	plus.fingerprint.cancel();
					// }
					var wt=plus.nativeUI.showWaiting("请验证指纹",{
						width:"200px",
						height:"200px",
						color: "#1d8079",
						mask:true,
						background:"#ffffff",
						loading:{
							icon:"/static/Fingerprint.png"
						}
					});
					wt.onclose=function(){
						plus.fingerprint.cancel();
					}
					 
				 
				}
				// #endif

				// #ifdef MP-WEIXIN
				wx.startSoterAuthentication({
					requestAuthModes: ['fingerPrint'],
					challenge: '123456',
					authContent: '请用指纹解锁',
					success(res) {
						uni.showToast({
							title: '识别成功',
							mask: false,
							duration: 1500
						});
					}
				})
				// #endif
			}
		}
	}
</script>

<style>
.button_fin{
	background-color: #00BBB1;
	border-radius: 5px ;
	width: 80%;
	color: #D1E9E9;
}
</style>

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值