学员端小程序
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.

164 lines
4.8 KiB

1 year 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.js';
  71. /**
  72. * keyboard 键盘
  73. * @description 此为uViw自定义的键盘面板内含了数字键盘车牌号键身份证号键盘3中模式都有可以打乱按键顺序的选项
  74. * @tutorial https://www.uviewui.com/components/keyboard.html
  75. * @property {String} mode 键盘类型见官网基本使用的说明 默认 'number'
  76. * @property {Boolean} dotDisabled 是否显示"."按键只在mode=number时有效 默认 false
  77. * @property {Boolean} tooltip 是否显示键盘顶部工具条 默认 true
  78. * @property {Boolean} showTips 是否显示工具条中间的提示 默认 true
  79. * @property {String} tips 工具条中间的提示文字见上方基本使用的说明如不需要请传""空字符
  80. * @property {Boolean} showCancel 是否显示工具条左边的"取消"按钮 默认 true
  81. * @property {Boolean} showConfirm 是否显示工具条右边的"完成"按钮 默认 true
  82. * @property {Boolean} random 是否打乱键盘按键的顺序 默认 false
  83. * @property {Boolean} safeAreaInsetBottom 是否开启底部安全区适配 默认 true
  84. * @property {Boolean} closeOnClickOverlay 是否允许点击遮罩收起键盘 默认 true
  85. * @property {Boolean} show 控制键盘的弹出与收起默认 false
  86. * @property {Boolean} overlay 是否显示遮罩 默认 true
  87. * @property {String | Number} zIndex 弹出键盘的z-index值 默认 1075
  88. * @property {String} cancelText 取消按钮的文字 默认 '取消'
  89. * @property {String} confirmText 确认按钮的文字 默认 '确认'
  90. * @property {Object} customStyle 自定义样式对象形式
  91. * @event {Function} change 按键被点击(不包含退格键被点击)
  92. * @event {Function} cancel 键盘顶部工具条左边的"取消"按钮被点击
  93. * @event {Function} confirm 键盘顶部工具条右边的"完成"按钮被点击
  94. * @event {Function} backspace 键盘退格键被点击
  95. * @example <u-keyboard mode="number" v-model="show"></u-keyboard>
  96. */
  97. export default {
  98. name: "u-keyboard",
  99. data() {
  100. return {
  101. }
  102. },
  103. mixins: [uni.$u.mpMixin, uni.$u.mixin,props],
  104. methods: {
  105. change(e) {
  106. this.$emit('change', e);
  107. },
  108. // 键盘关闭
  109. popupClose() {
  110. this.$emit('close');
  111. },
  112. // 输入完成
  113. onConfirm() {
  114. this.$emit('confirm');
  115. },
  116. // 取消输入
  117. onCancel() {
  118. this.$emit('cancel');
  119. },
  120. // 退格键
  121. backspace() {
  122. this.$emit('backspace');
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. @import "../../libs/css/components.scss";
  129. .u-keyboard {
  130. &__tooltip {
  131. @include flex;
  132. justify-content: space-between;
  133. background-color: #FFFFFF;
  134. padding: 14px 12px;
  135. &__item {
  136. color: #333333;
  137. flex: 1;
  138. text-align: center;
  139. font-size: 15px;
  140. }
  141. &__submit {
  142. text-align: right;
  143. color: $u-primary;
  144. }
  145. &__cancel {
  146. text-align: left;
  147. color: #888888;
  148. }
  149. &__tips {
  150. color: $u-tips-color;
  151. }
  152. }
  153. }
  154. </style>