翻譯進行中
本頁尚未翻譯為繁體中文,以下顯示簡體中文原文。範例的預設元件文字仍使用繁體中文。
NumberKeyboard 数字键盘
数字输入面板,值由业务管理;支持受控拼接、删除、随机排序和确认守卫。
引入
uni-app 配置 easycom 后使用 <hui-number-keyboard>。公开类型和函数从 @nscode/handy-uni 导入;普通 Vue 3 安装 @nscode/handy-uni/web 预览插件。
示例
示例可独立运行;交互结果直接显示在页面。
vue
<template>
<view>
<hui-space direction="vertical" fill>
<hui-input
custom-class="hui-space__item"
:model-value="value"
readonly
placeholder="点下方按钮 / Open below"
/>
<hui-button custom-class="hui-space__item" @click="visible = true"
>打开数字键盘 / Open keyboard</hui-button
>
<hui-number-keyboard
v-model:visible="visible"
v-model="value"
custom-class="hui-space__item"
theme="custom"
:maxlength="6"
:extra-key="['.', '00']"
confirm-text="完成 / Done"
@input="(key) => (lastEvent = key)"
@delete="lastEvent = 'delete'"
@confirm="(value) => (lastEvent = 'confirm:' + String(value))"
@close="(reason) => (lastEvent = 'close:' + reason)"
/>
<text class="hui-space__item">{{ value }} / {{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const visible = ref(false)
const value = ref('')
</script>
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
visible | boolean | undefined | v-model:visible(同 相关组件) |
defaultVisible | boolean | false | v-model:visible(同 相关组件) |
modelValue | string | — | v-model;不传时键盘不管值 |
maxlength | number | Infinity | 只在有 modelValue 时生效 |
theme | NumberKeyboardTheme | 'default' | custom 右侧多一列:删除键和“完成”大按钮 |
extraKey | string | string[] | '' | 左下角的附加键(.、X);custom 时最多两个,放在 0 两边 |
title | string | — | 键盘上方标题(“安全键盘”) |
closeText | string | — | 标题栏右侧的关闭文字,传了才显示;default 主题用它收起键盘 |
confirmText | string | — | custom 主题大按钮文字,不传用 t('numberKeyboard.done') |
showDeleteKey | boolean | true | 显示删除键。 |
randomKeyOrder | boolean | false | 每次打开时打乱 0~9 的位置(支付密码);打开期间顺序不变 |
closeOnClickOutside | boolean | true | 键盘上方放透明遮罩,点了收起(结论第 9 条,用户已定);false 时不放遮罩,页面可以照常操作 |
beforeConfirm | (value: string | undefined) => boolean | void | Promise<boolean | void> | — | 点“完成”前的钩子,exclusive 模式;等待时大按钮显示加载 |
safeAreaInsetBottom | boolean | true | safeAreaInsetBottom 属性。 |
vibrate | boolean | false | 按键轻震 |
zIndex | number | — | zIndex 属性。 |
rootPortal | boolean | false | 微信小程序使用根门户提升弹层。 |
根节点类名和样式使用 customClass、customStyle。尺寸数字按 px,时长除明确说明外按 ms。
Events
| 事件 | 参数 |
|---|---|
update:modelValue | (value: string) |
input | (key: string) |
delete | () |
confirm | (value: string | undefined) |
update:visible | (visible: boolean) |
close | (reason: NumberKeyboardCloseReason) |
受控状态由父级回写更新事件后改变。多词事件使用短横线。禁用操作、取消及过期异步结果不提交成功变更。
Slots
| 插槽 | 作用域 |
|---|---|
title | — |
delete | — |
extra-key | { keyValue } |
方法
无。
类型
NumberKeyboardTheme、NumberKeyboardCloseReason、NumberKeyboardProps、NumberKeyboardEmits.
平台说明
三端统一使用键盘上方透明遮罩;打开时点另一个输入框通常需先收起再点一次。长按删除按 80ms 连续触发,松手后的补发点击被跳过。不传 modelValue 时只发 input/delete;金额和小数位规则由业务处理。
设备冒烟清单.