Skip to content

引入组件 ​

局部引入

ts
// parent.vue
const FPlateKeyboard = defineAsyncComponent(() => import('@/components/formaui/f-plate-keyboard/f-plate-keyboard.vue'))

基础用法 ​

v-model控制显隐;首字为省份简称盘,后续为字母数字盘(不含 I、O)。

html
<f-plate-keyboard v-model="showKeyboard" @item-click="onItemClick" @cancel="onCancel">
  <view class="kb-header">
    <view class="kb-title">请输入车牌号</view>
    <f-plate-input v-model="plateValue" plate-color="blue" />
  </view>
</f-plate-keyboard>
<f-button width="320rpx" margin="200rpx auto" @click="open">打开车牌键盘</f-button>
ts
import { ref } from 'vue'

const showKeyboard = ref(false)
const plateValue = ref('')

const open = () => {
  plateValue.value = ''
  showKeyboard.value = true
}

const onItemClick = (value: string) => {
  plateValue.value = value
  if (value.length >= 8) {
    uni.showToast({ title: value, icon: 'none' })
    showKeyboard.value = false
  }
}

const onCancel = () => {}

键盘布局 ​

阶段说明
省份盘输入长度为 0,或点击「省份」强制改首字时展示 31 个省份简称
字母数字盘已有首字后展示 0-9 + 字母(无 I、O)

功能键:

  • 取消:关闭键盘并触发 cancel
  • 删除:删除末位字符
  • 省份:切回省份盘以修改首字

最大长度 ​

maxLength属性:车牌最大长度(默认8)

达到上限后不再追加字符。

html
<f-plate-keyboard v-model="showKeyboard" :max-length="8" @item-click="onItemClick" />

遮罩与动画 ​

isMask / closeOnClickMask / isAnimate

html
<f-plate-keyboard
  v-model="showKeyboard"
  :is-mask="true"
  :close-on-click-mask="true"
  :is-animate="true"
  @item-click="onItemClick" />

文案与样式 ​

按钮文案:cancelText、delText、provinceText

html
<f-plate-keyboard
  v-model="showKeyboard"
  cancel-text="关闭"
  del-text="回退"
  province-text="改省份"
  @item-click="onItemClick" />

颜色与圆角:borderRadius、fontSize、textColor、bgColor、cancelColor、cancelBgColor、delColor、delBgColor

html
<f-plate-keyboard
  v-model="showKeyboard"
  border-radius="24rpx"
  font-size="30rpx"
  text-color="#0B1D4A"
  bg-color="#FFFFFF"
  @item-click="onItemClick" />

键盘样式默认读取全局 uni.$fui.fKeyboard(与数字键盘共用配置块)。

与格子组件组合 ​

f-plate-input 仅负责展示;输入逻辑由本组件完成。完整示例见演示页 /extends/plate。

html
<f-plate-input v-model="plateValue" :plate-color="plateColor" @click="showKeyboard = true" />
<f-plate-keyboard v-model="showKeyboard" @item-click="(v) => (plateValue = v)" />

注意:键盘打开时会清空内部临时字符串,请通过 itemClick 同步到外部。

插槽 ​

名称说明
default键盘上方内容(常放车牌格子)

属性 ​

名称类型说明默认值
v-modelboolean是否显示键盘false
isMaskboolean是否显示遮罩层true
closeOnClickMaskboolean是否点击遮罩层关闭键盘true
isAnimateboolean是否显示动画true
borderRadiusstring自定义圆角大小16rpx
fontSizestring自定义字体大小32rpx
textColorstring自定义字体颜色主题色
cancelTextstring自定义取消按钮文字取消
cancelColorstring自定义取消按钮字体颜色主题色
cancelBgColorstring自定义取消按钮背景颜色#E7E6EB
delTextstring自定义删除按钮文字删除
delColorstring自定义删除按钮字体颜色主题色
delBgColorstring自定义删除按钮背景颜色#E7E6EB
provinceTextstring切换省份键盘按钮文字省份
bgColorstring自定义键盘背景颜色#FFFFFF
maxLengthnumber车牌最大长度8
zIndexnumber自定义键盘 z-index12000

事件 ​

事件名说明回调参数
itemClick按键后触发,参数为当前临时车牌字符串string(当前值)
cancel取消或点击遮罩关闭时触发-

方法 ​

方法名说明传入参数
---