NumberKeyboard 数字键盘

Scan me!

一般用于密码,验证码或支付金额输入等金融场景

引入

  1. import { NumberKeyboard } from 'mand-mobile'
  2. Vue.component(NumberKeyboard.name, NumberKeyboard)

代码演示

基本

有确认键和小数点,一般用于价格或金额输入

NumberKeyboard 数字键盘 - 图2

  1. <template>
  2. <div class="md-example-child md-example-child-number-keyboard md-example-child-number-keyboard-0">
  3. <md-button @click="toggleKeyboard(0)">{{ isKeyBoardShow[0] ? '收起键盘' : '唤起键盘,有小数点' }}</md-button>
  4. <md-number-keyboard
  5. v-model="isKeyBoardShow[0]"
  6. @enter="onNumberEnter"
  7. @delete="onNumberDelete"
  8. ></md-number-keyboard>
  9. <md-button @click="toggleKeyboard(1)">{{ isKeyBoardShow[1] ? '收起键盘' : '唤起键盘,无小数点' }}</md-button>
  10. <md-number-keyboard
  11. v-model="isKeyBoardShow[1]"
  12. hide-dot
  13. @enter="onNumberEnter"
  14. @delete="onNumberDelete"
  15. ></md-number-keyboard>
  16. <md-button @click="toggleKeyboard(2)">{{ isKeyBoardShow[2] ? '收起键盘' : '唤起键盘,替换键值' }}</md-button>
  17. <md-number-keyboard
  18. v-model="isKeyBoardShow[2]"
  19. :text-render="keyFormatter"
  20. @enter="onNumberEnter"
  21. @delete="onNumberDelete"
  22. ></md-number-keyboard>
  23. <div class="md-example-display" v-show="isKeyBoardShow" v-text="number"></div>
  24. </div>
  25. </template>
  26. <script>
  27. import {NumberKeyboard, Button} from 'mand-mobile'
  28. export default {
  29. name: 'number-keyboard-demo',
  30. components: {
  31. [Button.name]: Button,
  32. [NumberKeyboard.name]: NumberKeyboard,
  33. },
  34. data() {
  35. return {
  36. isKeyBoardShow: [],
  37. number: '',
  38. }
  39. },
  40. methods: {
  41. toggleKeyboard(index) {
  42. this.$set(this.isKeyBoardShow, index, !this.isKeyBoardShow[index])
  43. },
  44. keyFormatter(val) {
  45. if (val === '.') {
  46. return 'x'
  47. }
  48. },
  49. onNumberEnter(val) {
  50. this.number += val
  51. },
  52. onNumberDelete() {
  53. if (this.number === '') {
  54. return
  55. }
  56. this.number = this.number.substr(0, this.number.length - 1)
  57. },
  58. },
  59. }
  60. </script>
  61. <style lang="stylus">
  62. .md-example-child-number-keyboard-0
  63. .md-button
  64. margin-bottom 10px
  65. .md-example-display
  66. position fixed
  67. top 30%
  68. left 50%
  69. z-index 9999
  70. transform translate(-50%, -50%)
  71. font-size 120px
  72. text-shadow 0 4px 20px #666
  73. </style>
  74.  

数字键乱序

NumberKeyboard 数字键盘 - 图3

        <template>
  <div class="md-example-child md-example-child-number-keyboard md-example-child-number-keyboard-2">
    <md-button @click="isKeyBoardShow = !isKeyBoardShow">{{ isKeyBoardShow ? '收起键盘' : '唤起键盘' }}</md-button>
    <md-number-keyboard
      v-model="isKeyBoardShow"
      ok-text="支付"
      disorder
      @enter="onNumberEnter"
      @delete="onNumberDelete"
    ></md-number-keyboard>
    <div class="md-example-display" v-show="isKeyBoardShow" v-text="number"></div>
  </div>
</template>

<script>
import {NumberKeyboard, Button} from 'mand-mobile'

export default {
  name: 'number-keyboard-demo',
  components: {
    [Button.name]: Button,
    [NumberKeyboard.name]: NumberKeyboard,
  },
  data() {
    return {
      isKeyBoardShow: false,
      number: '',
    }
  },
  methods: {
    onNumberEnter(val) {
      this.number += val
    },
    onNumberDelete() {
      if (this.number === '') {
        return
      }
      this.number = this.number.substr(0, this.number.length - 1)
    },
  },
}

</script>

<style lang="stylus" scoped>
.md-example-display
  position fixed
  top 30%
  left 50%
  z-index 9999
  transform translate(-50%, -50%)
  font-size 120px
  text-shadow 0 4px 20px #666
</style>

      

简单类型

无确认键和小数点,一般用于密码或验证码输入

NumberKeyboard 数字键盘 - 图4

        <template>
  <div class="md-example-child md-example-child-number-keyboard md-example-child-number-keyboard-1">
    <md-button @click="isKeyBoardShow = !isKeyBoardShow">{{ isKeyBoardShow ? '收起键盘' : '唤起键盘' }}</md-button>
    <md-number-keyboard
      v-model="isKeyBoardShow"
      type="simple"
      @enter="onNumberEnter"
      @delete="onNumberDelete"
    ></md-number-keyboard>
    <div class="md-example-display" v-show="isKeyBoardShow" v-text="number"></div>
  </div>
</template>

<script>
import {NumberKeyboard, Button} from 'mand-mobile'

export default {
  name: 'number-keyboard-demo',
  components: {
    [Button.name]: Button,
    [NumberKeyboard.name]: NumberKeyboard,
  },
  data() {
    return {
      isKeyBoardShow: false,
      number: '',
    }
  },
  methods: {
    onNumberEnter(val) {
      this.number += val
    },
    onNumberDelete() {
      if (this.number === '') {
        return
      }
      this.number = this.number.substr(0, this.number.length - 1)
    },
  },
}

</script>

<style lang="stylus" scoped>
.md-example-display
  position fixed
  top 30%
  left 50%
  z-index 9999
  transform translate(-50%, -50%)
  font-size 120px
  text-shadow 0 4px 20px #666
</style>

      

插槽

NumberKeyboard 数字键盘 - 图5

        <template>
  <div class="md-example-child md-example-child-number-keyboard md-example-child-number-keyboard-3">
    <md-button @click="isKeyBoardShow = !isKeyBoardShow">{{ isKeyBoardShow ? '收起键盘' : '唤起键盘' }}</md-button>
    <md-number-keyboard
      v-model="isKeyBoardShow"
      ok-text="支付"
      disorder
    >
      <p class="number-keyboard-header">
        <md-icon name="security"></md-icon>&nbsp;安全支付
      </p>
    </md-number-keyboard>
  </div>
</template>

<script>
import {NumberKeyboard, Button, Icon} from 'mand-mobile'

export default {
  name: 'number-keyboard-demo',
  components: {
    [Button.name]: Button,
    [Icon.name]: Icon,
    [NumberKeyboard.name]: NumberKeyboard,
  },
  data() {
    return {
      isKeyBoardShow: false,
    }
  },
}

</script>

<style lang="stylus" scoped>
.number-keyboard-header
  display flex
  align-items center
  justify-content center
  padding 10px 0
  font-size 14px
  color #999
</style>

      

API

NumberKeyboard Props

属性说明类型默认值备注
v-model键盘是否展示Booleanfalse-
is-view是否内嵌在页面内展示,否则以弹层形式Booleanfalse-
type键盘类型Stringprofessionalprofessional有确认键和小数点常用于价格或金额输入,simple一般用于密码或验证码输入
disorder键盘数字键是否乱序Booleanfalse-
is-hide-confirm确认时自动隐藏键盘Booleantrue-
text-render自定义指定按键的值Function(value: string): string-可替换键0,1,…9,.
ok-text键盘确认键文案String确认-

NumberKeyboard Slots

default

<md-number-keyboard>
  <md-icon name="security"></md-icon>&nbsp;安全支付
</md-number-keyboard>

NumberKeyboard Methods

show()

展示键盘

hide()

隐藏键盘

NumberKeyboard Events

@enter(val)

数字键点击事件

属性说明类型
val数字Number
@delete()

回退键点击事件

@confirm()

确认键点击事件