Skip to content

PlateKeyBoard 车牌号输入键盘

介绍

PlateKeyBoard 是一个专为中国车牌号输入设计的键盘组件,支持普通车牌和新能源车牌的输入,提供直观的输入体验。

导入

js
import PlateKeyBoard from '@/components/keyboard/PlateKeyBoard.vue'

使用方法

基础用法

PlateKeyBoard 组件通过 v-model:show 控制显示与隐藏,并通过 input 和 delete 事件处理输入内容。

vue
<template>
  <view>
    <CellGroup round inset>
      <Field v-model="text" placeholder="请输入车牌号" />
    </CellGroup>

    <Height :size="20" />

    <CellGroup round inset>
      <Cell title="弹出车牌号键盘" showArrow touchable @click="check1 = true" />
    </CellGroup>

    <PlateKeyBoard
      v-model:show="check1"
      @input="onInput"
      @delete="onDelete"
      @blur="check1 = false"
    />
  </view>
</template>

<script setup lang="ts">
import Cell from '@/components/basic/Cell.vue';
import CellGroup from '@/components/basic/CellGroup.vue';
import DemoPage from '@/components/demo/DemoPage.vue';
import Field from '@/components/form/Field.vue';
import PlateKeyBoard from '@/components/keyboard/PlateKeyBoard.vue';
import Height from '@/components/layout/space/Height.vue';
import { ref } from 'vue';

const check1 = ref(false);
const text = ref('');

function onInput(value: string) {
  text.value += value;
};
function onDelete() {
  text.value = text.value.substring(0, text.value.length - 1)
};
</script>

API 参考

PlateKeyBoard

车牌号输入键盘组件。

Props

名称说明类型必填默认值
v-model:show是否显示键盘booleanfalse
mask是否显示键盘遮罩,显示遮罩时无法操作下方组件booleanfalse
title键盘标题string-
showFinishButton是否显示完成按钮booleantrue
showDeleteButton是否显示删除按钮booleantrue
finishButtonText完成按钮文字string'完成'
deleteButtonText删除按钮文字string'删除'
keyHeight按键高度number100
keyboardHeight键盘高度(容纳多少行)number8
keyColumCount每行按键数number7
keyStyle自定义按键的样式ViewStyle-
keyTextStyle自定义按键文字的样式TextStyle-
keyColor按键的背景颜色string'white'
keyTextColor完成按键的文字颜色string'black'
keyPressedColor自定义按键按下时的颜色string'pressed.white'
keyPressedImpactFeedback按键按下时是否有触感反馈booleantrue
keysProvinceText自定义车牌省选项string[]KeysProvinceText
keysNumberText自定义车牌数字选项string[]KeysNumberText
keysWordText自定义车牌字母选项string[]KeysWordText
keysLastWordText自定义车牌尾字选项string[]KeysLastWordText

默认按键

默认按键数组定义,可以从 PlateKeyBoardDefine 中导入。

ts
import { 
  KeysProvinceText, // 默认车牌省选项
  KeysNumberText, // 默认车牌数字选项
  KeysWordText, // 默认车牌字母选项
  KeysLastWordText // 默认车牌尾字选项
} from '@/components/keyboard/PlateKeyBoardDefine'

Events

名称说明参数
input输入字符时触发string 输入的字符
delete删除字符时触发-
finish完成输入时触发-
cancel取消输入时触发-
blur键盘失焦时触发-

主题变量

名称类型默认值说明
PlateKeyBoardShowFinishButtonbooleantrue是否显示完成按钮
PlateKeyBoardShowDeleteButtonbooleantrue是否显示删除按钮
PlateKeyBoardFinishButtonTextstring'完成'完成按钮文字
PlateKeyBoardDeleteButtonTextstring'删除'删除按钮文字
PlateKeyBoardKeyHeightnumber100按键高度
PlateKeyBoardKeyColorstring'white'按键的背景颜色
PlateKeyBoardKeyTextColorstring'black'按键文字颜色
PlateKeyBoardKeyPressedColorstring'pressed.white'按键按下时的颜色
PlateKeyBoardKeyPressedImpactFeedbackbooleantrue按键按下时是否有触感反馈
PlateKeyBoardKeyPadBackgroundColorstring'light'键盘区域背景颜色
PlateKeyBoardKeyMarginnumber7按键间距
PlateKeyBoardTitleColorstring'black'标题文字颜色
PlateKeyBoardTitleFontSizenumber32标题文字大小
PlateKeyBoardKeyFontSizenumber34按键文字大小
PlateKeyBoardDotMarginnumber10分隔点边距
PlateKeyBoardDotWidthnumber10分隔点宽度
PlateKeyBoardDotHeightnumber10分隔点高度
PlateKeyBoardDotBackgroundColorstring'text.second'分隔点背景颜色
PlateKeyBoardDotBorderRadiusnumber10分隔点圆角半径