You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.9 KiB

4 months ago
  1. <template>
  2. <u-popup
  3. :overlay="overlay"
  4. :closeOnClickOverlay="closeOnClickOverlay"
  5. mode="bottom"
  6. :popup="false"
  7. :show="show"
  8. :safeAreaInsetBottom="safeAreaInsetBottom"
  9. @close="popupClose"
  10. :zIndex="zIndex"
  11. :customStyle="{
  12. backgroundColor: 'rgb(214, 218, 220)'
  13. }"
  14. >
  15. <view class="u-keyboard">
  16. <slot />
  17. <view
  18. class="u-keyboard__tooltip"
  19. v-if="tooltip"
  20. >
  21. <view
  22. hover-class="u-hover-class"
  23. :hover-stay-time="100"
  24. >
  25. <text
  26. class="u-keyboard__tooltip__item u-keyboard__tooltip__cancel"
  27. v-if="showCancel"
  28. @tap="onCancel"
  29. >{{showCancel && cancelText}}</text>
  30. </view>
  31. <view>
  32. <text
  33. v-if="showTips"
  34. class="u-keyboard__tooltip__item u-keyboard__tooltip__tips"
  35. >{{tips ? tips : mode == 'number' ? '数字键盘' : mode == 'card' ? '身份证键盘' : '车牌号键盘'}}</text>
  36. </view>
  37. <view
  38. hover-class="u-hover-class"
  39. :hover-stay-time="100"
  40. >
  41. <text
  42. v-if="showConfirm"
  43. @tap="onConfirm"
  44. class="u-keyboard__tooltip__item u-keyboard__tooltip__submit"
  45. hover-class="u-hover-class"
  46. >{{showConfirm && confirmText}}</text>
  47. </view>
  48. </view>
  49. <template v-if="mode == 'number' || mode == 'card'">
  50. <u-number-keyboard
  51. :random="random"
  52. @backspace="backspace"
  53. @change="change"
  54. :mode="mode"
  55. :dotDisabled="dotDisabled"
  56. ></u-number-keyboard>
  57. </template>
  58. <template v-else>
  59. <u-car-keyboard
  60. :random="random"
  61. :autoChange="autoChange"
  62. @backspace="backspace"
  63. @change="change"
  64. ></u-car-keyboard>
  65. </template>
  66. </view>
  67. </u-popup>
  68. </template>
  69. <script>
  70. import { props } from './props';
  71. import { mpMixin } from '../../libs/mixin/mpMixin';
  72. import { mixin } from '../../libs/mixin/mixin';
  73. /**
  74. * keyboard 键盘
  75. * @description 此为uViw自定义的键盘面板内含了数字键盘车牌号键身份证号键盘3中模式都有可以打乱按键顺序的选项
  76. * @tutorial https://ijry.github.io/uview-plus/components/keyboard.html
  77. * @property {String} mode 键盘类型见官网基本使用的说明 默认 'number'
  78. * @property {Boolean} dotDisabled 是否显示"."按键只在mode=number时有效 默认 false
  79. * @property {Boolean} tooltip 是否显示键盘顶部工具条 默认 true
  80. * @property {Boolean} showTips 是否显示工具条中间的提示 默认 true
  81. * @property {String} tips 工具条中间的提示文字见上方基本使用的说明如不需要请传""空字符
  82. * @property {Boolean} showCancel 是否显示工具条左边的"取消"按钮 默认 true
  83. * @property {Boolean} showConfirm 是否显示工具条右边的"完成"按钮 默认 true
  84. * @property {Boolean} random 是否打乱键盘按键的顺序 默认 false
  85. * @property {Boolean} safeAreaInsetBottom 是否开启底部安全区适配 默认 true
  86. * @property {Boolean} closeOnClickOverlay 是否允许点击遮罩收起键盘 默认 true
  87. * @property {Boolean} show 控制键盘的弹出与收起默认 false
  88. * @property {Boolean} overlay 是否显示遮罩 默认 true
  89. * @property {String | Number} zIndex 弹出键盘的z-index值 默认 1075
  90. * @property {String} cancelText 取消按钮的文字 默认 '取消'
  91. * @property {String} confirmText 确认按钮的文字 默认 '确认'
  92. * @property {Object} customStyle 自定义样式对象形式
  93. * @event {Function} change 按键被点击(不包含退格键被点击)
  94. * @event {Function} cancel 键盘顶部工具条左边的"取消"按钮被点击
  95. * @event {Function} confirm 键盘顶部工具条右边的"完成"按钮被点击
  96. * @event {Function} backspace 键盘退格键被点击
  97. * @example <u-keyboard mode="number" v-model="show"></u-keyboard>
  98. */
  99. export default {
  100. name: "u-keyboard",
  101. data() {
  102. return {
  103. }
  104. },
  105. mixins: [mpMixin, mixin, props],
  106. emits: ["change", "close", "confirm", "cancel", "backspace"],
  107. methods: {
  108. change(e) {
  109. this.$emit('change', e);
  110. },
  111. // 键盘关闭
  112. popupClose() {
  113. this.$emit('close');
  114. },
  115. // 输入完成
  116. onConfirm() {
  117. this.$emit('confirm');
  118. },
  119. // 取消输入
  120. onCancel() {
  121. this.$emit('cancel');
  122. },
  123. // 退格键
  124. backspace() {
  125. this.$emit('backspace');
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. @import "../../libs/css/components.scss";
  132. .u-keyboard {
  133. &__tooltip {
  134. @include flex;
  135. justify-content: space-between;
  136. background-color: #FFFFFF;
  137. padding: 14px 12px;
  138. &__item {
  139. color: #333333;
  140. flex: 1;
  141. text-align: center;
  142. font-size: 15px;
  143. }
  144. &__submit {
  145. text-align: right;
  146. color: $u-primary;
  147. }
  148. &__cancel {
  149. text-align: left;
  150. color: #888888;
  151. }
  152. &__tips {
  153. color: $u-tips-color;
  154. }
  155. }
  156. }
  157. </style>