Skip to content

NumberKeyboard 数字键盘

介绍

虚拟数字键盘,用于输入支付密码的场景。

默认键盘

在线调试请将浏览器变为手机模式

html
<template>
  <nut-number-keyboard
    v-model="value"
    v-model:visible="visible"
  ></nut-number-keyboard>
</template>
ts
const value = ref("");
const visible = ref(false);

带右侧栏键盘

html
<template>
  <nut-number-keyboard
    v-model="value"
    v-model:visible="visible"
    type="rightColumn"
    :custom-key="customKey"
    confirm-text="支付"
    @confirm="onConfirm"
  ></nut-number-keyboard>
</template>
ts
const value = ref("");
const visible = ref(false);
const customKey = reactive(["."]);

function onConfirm() {
  console.log("confirm");
}

随机键位键盘

html
<template>
  <nut-number-keyboard
    v-model="value"
    v-model:visible="visible"
    random-keys
  ></nut-number-keyboard>
</template>

带标题栏键盘

html
<template>
  <nut-number-keyboard
    v-model="value"
    v-model:visible="visible"
    title="默认键盘"
  ></nut-number-keyboard>
</template>

身份证键盘

html
<template>
  <nut-number-keyboard
    v-model="value"
    v-model:visible="visible"
    :custom-key="customKey"
  ></nut-number-keyboard>
</template>
ts
const customKey = reactive(["X"]);

API

Props

参数说明类型可选值默认值
v-model当前输入值string--
v-model:visible是否显示键盘boolean-false
title键盘标题string--
type键盘模式(default:默认样式,rightColumn:带右侧栏)stringdefault / rightColumndefault
random-keys随机键位boolean-false
custom-key自定义键盘额外的键(数组形式,最多支持添加 2 个)Array-[]
overlay是否显示遮罩boolean-false
maxlength输入值最大长度number / string-6
confirm-text自定义完成按钮文字(如"支付"、"下一步"、"提交"等)string--
pop-class自定义弹框类名string--

Events

事件名说明类型
input点击按键时触发(value: string) => void
delete点击删除键时触发() => void
close点击关闭按钮或非键盘区域时触发() => void
confirm 1.7.9点击确认按钮() => void

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-numberkeyboard-width100%
--nut-numberkeyboard-padding0
--nut-numberkeyboard-background-color#f2f3f5
--nut-numberkeyboard-header-height34px
--nut-numberkeyboard-header-padding6px 0 0 0
--nut-numberkeyboard-header-color#646566
--nut-numberkeyboard-header-font-size16px
--nut-numberkeyboard-header-close-padding0 16px
--nut-numberkeyboard-header-close-color#576b95
--nut-numberkeyboard-header-close-font-size14px
--nut-numberkeyboard-header-close-background-colortransparent
--nut-numberkeyboard-key-background-color#fff
--nut-numberkeyboard-key-active-background-color#ebedf0
--nut-numberkeyboard-key-height48px
--nut-numberkeyboard-key-line-height1.5
--nut-numberkeyboard-key-border-radius8px
--nut-numberkeyboard-key-font-size28px
--nut-numberkeyboard-key-font-size-color#333
--nut-numberkeyboard-key-finish-font-size16px
--nut-numberkeyboard-key-finish-font-size-color#fff
--nut-numberkeyboard-key-finish-background-color#1989fa
--nut-numberkeyboard-key-activeFinsh-background-color#0570db

MIT Licensed