keyboard.nvue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="u-page">
  3. <u-navbar
  4. title="键盘"
  5. @leftClick="navigateBack"
  6. safeAreaInsetTop
  7. fixed
  8. placeholder
  9. ></u-navbar>
  10. <u-gap height="20" bgColor="#fff"></u-gap>
  11. <u-cell-group>
  12. <u-cell
  13. :titleStyle="{fontWeight: 500}"
  14. @click="openKeyboard(index)"
  15. :title="item.title"
  16. v-for="(item, index) in list"
  17. :key="index"
  18. isLink
  19. >
  20. <image
  21. slot="icon"
  22. class="u-cell-icon"
  23. :src="item.iconUrl"
  24. mode="widthFix"
  25. ></image>
  26. </u-cell>
  27. </u-cell-group>
  28. <u-keyboard
  29. :mode="keyData.mode"
  30. :dotDisabled="keyData.dotDisabled"
  31. :random='keyData.random'
  32. :show="show"
  33. @close="close"
  34. @cancel="cancel"
  35. @confirm="confirm"
  36. @change="change"
  37. @backspace="backspace"
  38. ></u-keyboard>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. input: '',
  46. keyData: {
  47. mode: '',
  48. dotDisabled: false,
  49. random: false,
  50. },
  51. list: [{
  52. title: '车牌号键盘',
  53. iconUrl: 'https://cdn.uviewui.com/uview/demo/keyboard/car.png'
  54. },
  55. {
  56. title: '数字键盘',
  57. iconUrl: 'https://cdn.uviewui.com/uview/demo/keyboard/number.png'
  58. },
  59. {
  60. title: '身份证键盘',
  61. iconUrl: 'https://cdn.uviewui.com/uview/demo/keyboard/IdCard.png'
  62. },
  63. {
  64. title: '隐藏键盘"."符号',
  65. iconUrl: 'https://cdn.uviewui.com/uview/demo/keyboard/dot.png'
  66. },
  67. {
  68. title: '打乱键盘按键的顺序',
  69. iconUrl: 'https://cdn.uviewui.com/uview/demo/keyboard/order.png'
  70. },
  71. ],
  72. show: false
  73. }
  74. },
  75. methods: {
  76. navigateBack() {
  77. uni.navigateBack();
  78. },
  79. // 点击展示不同的键盘
  80. openKeyboard(indexNum) {
  81. this.keyData = {
  82. mode: '',
  83. dotDisabled: false,
  84. random: false,
  85. }
  86. if (indexNum == 0) {
  87. this.keyData.mode = ''
  88. } else if (indexNum == 1) {
  89. this.keyData.mode = 'number'
  90. } else if (indexNum == 2) {
  91. this.keyData.mode = 'card'
  92. } else if (indexNum == 3) {
  93. this.keyData.mode = 'number'
  94. this.keyData.dotDisabled = true
  95. } else if (indexNum == 4) {
  96. this.keyData.mode = 'number'
  97. this.keyData.random = true
  98. }
  99. this.input = ''
  100. this.show = true
  101. },
  102. change(e) {
  103. // console.log('change');
  104. this.input += e
  105. },
  106. close() {
  107. // console.log('close');
  108. this.show = false
  109. },
  110. cancel() {
  111. // console.log('cancel');
  112. this.show = false
  113. },
  114. confirm() {
  115. // console.log('confirm');
  116. this.show = false
  117. },
  118. backspace() {
  119. this.input = this.input.slice(0, -1)
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss">
  125. .u-page {
  126. padding: 0;
  127. }
  128. </style>