Skip to content

NumberKeyboard 数字键盘

介绍

虚拟数字键盘,可以配合密码输入框组件或自定义的输入框组件使用。

引入

ts
import { IBestNumberKeyboard } from "@ibestservices/ibest-ui";

代码演示

基础用法

基础用法

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "默认键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        onInput: (value: string) => {
          console.log("输入:" + value)
        },
        onDelete: () => {
          console.log("删除")
        },
        onClose: () => {
          console.log("关闭")
        }
      })
    }
  }
}

带右侧栏的键盘

带右侧栏的键盘

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "带右侧栏的键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        styleType: "custom",
        extraKey: ".",
        closeBtnText: "完成"
      })
    }
  }
}

身份证号键盘

身份证号键盘

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "身份证号键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        extraKey: "X"
      })
    }
  }
}

带标题的键盘

带标题的键盘

TIP

通过 title 属性可以设置键盘标题, 为空时不显示标题栏。

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "带标题的键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        title: "键盘标题",
        extraKey: "."
      })
    }
  }
}

配置多个按键的键盘

配置多个按键的键盘

TIP

styleTypecustom 时,支持以数组的形式配置两个 extraKey。

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "配置多个按键的键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        styleType: "custom",
        extraKey: ["00", "."],
        closeBtnText: "完成"
      })
    }
  }
}

配置随机数字的键盘

配置随机数字的键盘

点我查看代码
ts
import { IBestCellGroup, IBestCell } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestCellGroup({ inset: true }) {
        IBestCell({
          title: "配置随机数字的键盘",
          value: this.value,
          clickable: true,
          onClickCell: () => {
            this.visible = true
          }
        })
      }
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        isRandomKeyOrder: true
      })
    }
  }
}

最大长度

最大长度

点我查看代码
ts
import { IBestCellGroup, IBestField } from "@ibestservices/ibest-ui"
@Entry
@Component
struct DemoPage {
  @State visible: boolean = false
  @State value: string = ''
  build() {
    Column(){
      IBestField({
        label: "最大长度",
        value: $value,
        readOnly: true,
        clickable: true,
        placeholder: "点此输入",
        hasBorder: false,
        onFieldClick: () => {
          this.visible = true
        }
      })
      IBestNumberKeyboard({
        visible: $visible,
        value: $value,
        maxLength: 6
      })
    }
  }
}

API

@Props

参数说明类型默认值
visible控制键盘显隐, 支持双向绑定booleanfalse
value当前输入的值, 支持双向绑定string''
title顶部标题文字string''
extraKey额外按键string | string[]''
closeBtnText关闭按钮文字string完成
deleteButtonText删除按钮文字, 为空时显示图标string''
styleType样式风格, 可选值为 default customstringdefault
isRandomKeyOrder是否随机排序booleanfalse
maxLength最大长度, 默认不限制number-1

Events

事件名说明回调参数
onInput按下按键后触发value: string
onDelete点击删除键时触发-
onClose点击关闭键时触发-