Skip to content
# t-keyboard

Keyboard 键盘

t-keyboard 组件介绍 ​

自定义键盘组件,支持车牌键盘、数字键盘、身份证键盘,提供安全的输入方式。

t-keyboard 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-keyboard 基础用法 ​

vue
<template>
	<view class="p-15">
		<tui-theme-switch></tui-theme-switch>
		<t-card title="keyboard 键盘(5.0重构为Canvas绘制)"
				class="mb-15"
				sub-title="支持车牌键盘-数字键盘-身份证键盘"></t-card>
		<t-section title="弹窗模式"
				   class="mb-15"></t-section>
		<t-cell class="mb-15 r-10"
				@click="show('car')"
				title="车牌输入(点我弹出键盘)"></t-cell>
		<t-cell class="mb-15 r-10"
				@click="show('number')"
				title="数字键盘(点我弹出键盘)"></t-cell>
		<t-cell class="mb-15 r-10"
				@click="show('idcard')"
				title="身份证键盘(点我弹出键盘)"></t-cell>

		<t-section title="嵌入模式"
				   class="mb-15"></t-section>

		<t-keyboard ref="keyboardcar"
					mode="car"
					@input="input"></t-keyboard>
		<t-keyboard ref="keyboardnumber"
					mode="number"
					@input="input"></t-keyboard>
		<t-keyboard ref="keyboardidcard"
					mode="idcard"
					@input="input"></t-keyboard>

		<t-keyboard-car class="mb-15 r-10"
						type="primary"
						@back="back"
						@input="input"></t-keyboard-car>
		<t-keyboard-number class="mb-15 r-10"
						   type="success"
						   @back="back"
						   @input="input"
						   @confirm="confirm"></t-keyboard-number>
		<t-keyboard-idcard class="mb-15 r-10"
						   type="eror"
						   @back="back"
						   @input="input"
						   @confirm="confirm"></t-keyboard-idcard>
	</view>
</template>

<script setup>
	const keyboardcar = ref<ComponentPublicInstance | null>(null)
	const keyboardnumber = ref<ComponentPublicInstance | null>(null)
	const keyboardidcard = ref<ComponentPublicInstance | null>(null)
	const confirm = () => {
		uni.showToast({
			title: 'confirm'
		})
	}

	const back = () => {
		uni.showToast({
			title: 'back'
		})
	}

	const input = (val : string) => {
		uni.showToast({
			title: val
		})
	}
	const show = (type : string) => {
		if (type == 'car') {
			keyboardcar.value?.$callMethod('show')
		}
		if (type == 'number') {
			keyboardnumber.value?.$callMethod('show')
		}
		if (type == 'idcard') {
			keyboardidcard.value?.$callMethod('show')
		}
	}
</script>

t-keyboard Props ​

属性名类型默认值说明可选值
sizeString"medium"组件尺寸large, medium, small, mini
typeString"primary"组件类型info, primary, error, warning, success
disabledBooleanfalse组件是否禁用true, false
hoverBooleanfalse是否有点击效果true, false
pathString""点击组件后跳转的页面路径-
effectString""组件显示主题normal, dark, light, plain
modeString"car"键盘类型car, number, idcard
valueArray[]默认值-

t-keyboard Events ​

事件名说明回调参数
input输入时触发输入的值
back后退时触发-
confirm点击确认时触发确认的值
cancel点击取消时触发-
clear清除按钮时触发-
close关闭时触发-
click点击时触发-
transitionend动画结束时触发-
initFinished组件初始化完成触发组件的节点信息
touchstart触摸开始时触发触摸事件对象
touchend触摸结束时触发触摸事件对象
touchmove触摸移动时触发触摸事件对象
touchcancel触摸取消时触发触摸事件对象

Methods ​

方法名说明参数返回值
show显示键盘无无
hide隐藏键盘无无

Mode 说明 ​

模式说明
car车牌键盘,支持输入车牌号码
number数字键盘,支持输入数字
idcard身份证键盘,支持输入身份证号码