Ucarkeyboard.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view
  3. style=" bottom: 0;
  4. left: 0;
  5. right: 0;
  6. background-color: #ffffff;
  7. display: block;
  8. position: absolute;"
  9. >
  10. <slot />
  11. <view class="u-tooltip" v-if="tooltip">
  12. <view class="u-tooltip-item u-tooltip-cancel" hover-class="u-tooltip-cancel-hover" @tap="onCancel">
  13. {{cancelBtn ? cancelText : ''}}
  14. </view>
  15. <view v-if="showTips" class="u-tooltip-item u-tooltip-tips">
  16. {{tips ? tips : mode == 'number' ? '数字键盘' : mode == 'card' ? '身份证键盘' : '车牌号键盘'}}
  17. </view>
  18. <view v-if="confirmBtn" @tap="onConfirm" class="u-tooltip-item u-tooltips-submit" hover-class="u-tooltips-submit-hover">
  19. {{confirmBtn ? confirmText : ''}}
  20. </view>
  21. </view>
  22. <block v-if="mode == 'number' || mode == 'card'">
  23. <u-number-keyboard :random="random" @backspace="backspace" @change="change" :mode="mode" :dotEnabled="dotEnabled"></u-number-keyboard>
  24. </block>
  25. <block v-else>
  26. <u-car-keyboard :random="random" @backspace="backspace" ref="thiscar" @change="change"></u-car-keyboard>
  27. </block>
  28. </view>
  29. </template>
  30. <script>
  31. /**
  32. * keyboard 键盘
  33. * @description 此为uViw自定义的键盘面板,内含了数字键盘,车牌号键,身份证号键盘3中模式,都有可以打乱按键顺序的选项。
  34. * @tutorial https://www.uviewui.com/components/keyboard.html
  35. * @property {String} mode 键盘类型,见官网基本使用的说明(默认number)
  36. * @property {Boolean} dot-enabled 是否显示"."按键,只在mode=number时有效(默认true)
  37. * @property {Boolean} tooltip 是否显示键盘顶部工具条(默认true)
  38. * @property {String} tips 工具条中间的提示文字,见上方基本使用的说明,如不需要,请传""空字符
  39. * @property {Boolean} cancel-btn 是否显示工具条左边的"取消"按钮(默认true)
  40. * @property {Boolean} confirm-btn 是否显示工具条右边的"完成"按钮(默认true)
  41. * @property {Boolean} mask 是否显示遮罩(默认true)
  42. * @property {String} confirm-text 确认按钮的文字
  43. * @property {String} cancel-text 取消按钮的文字
  44. * @property {Number String} z-index 弹出键盘的z-index值(默认1075)
  45. * @property {Boolean} random 是否打乱键盘按键的顺序(默认false)
  46. * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
  47. * @property {Boolean} mask-close-able 是否允许点击遮罩收起键盘(默认true)
  48. * @event {Function} change 按键被点击(不包含退格键被点击)
  49. * @event {Function} cancel 键盘顶部工具条左边的"取消"按钮被点击
  50. * @event {Function} confirm 键盘顶部工具条右边的"完成"按钮被点击
  51. * @event {Function} backspace 键盘退格键被点击
  52. * @example <u-keyboard mode="number" v-model="show"></u-keyboard>
  53. */
  54. export default {
  55. name: "u-keyboard",
  56. props: {
  57. // 键盘的类型,number-数字键盘,card-身份证键盘,car-车牌号键盘
  58. mode: {
  59. type: String,
  60. default: 'number'
  61. },
  62. // 是否显示键盘的"."符号
  63. dotEnabled: {
  64. type: Boolean,
  65. default: true
  66. },
  67. // 是否显示顶部工具条
  68. tooltip: {
  69. type: Boolean,
  70. default: true
  71. },
  72. // 是否显示工具条中间的提示
  73. showTips: {
  74. type: Boolean,
  75. default: true
  76. },
  77. // 工具条中间的提示文字
  78. tips: {
  79. type: String,
  80. default: ''
  81. },
  82. // 是否显示工具条左边的"取消"按钮
  83. cancelBtn: {
  84. type: Boolean,
  85. default: true
  86. },
  87. // 是否显示工具条右边的"完成"按钮
  88. confirmBtn: {
  89. type: Boolean,
  90. default: true
  91. },
  92. // 是否打乱键盘按键的顺序
  93. random: {
  94. type: Boolean,
  95. default: false
  96. },
  97. // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距
  98. safeAreaInsetBottom: {
  99. type: Boolean,
  100. default: false
  101. },
  102. // 是否允许通过点击遮罩关闭键盘
  103. maskCloseAble: {
  104. type: Boolean,
  105. default: false
  106. },
  107. // 通过双向绑定控制键盘的弹出与收起
  108. value: {
  109. type: Boolean,
  110. default: false
  111. },
  112. // 是否显示遮罩,某些时候数字键盘时,用户希望看到自己的数值,所以可能不想要遮罩
  113. mask: {
  114. type: Boolean,
  115. default: false
  116. },
  117. // z-index值
  118. zIndex: {
  119. type: [Number, String],
  120. default: ''
  121. },
  122. // 取消按钮的文字
  123. cancelText: {
  124. type: String,
  125. default: '取消'
  126. },
  127. // 确认按钮的文字
  128. confirmText: {
  129. type: String,
  130. default: '确认'
  131. }
  132. },
  133. data() {
  134. return {
  135. //show: false
  136. }
  137. },
  138. computed: {
  139. uZIndex() {
  140. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  141. }
  142. },
  143. methods: {
  144. changeCarInputValue(){
  145. return this.$refs.thiscar.abc
  146. },
  147. changeCarInputMode(){
  148. this.$refs.thiscar.changeCarInputMode()
  149. return this.$refs.thiscar.abc
  150. },
  151. change(e) {
  152. this.$emit('change', e);
  153. },
  154. // 键盘关闭
  155. popupClose() {
  156. // 通过发送input这个特殊的事件名,可以修改父组件传给props的value的变量,也即双向绑定
  157. this.$emit('input', false);
  158. },
  159. // 输入完成
  160. onConfirm() {
  161. this.popupClose();
  162. this.$emit('confirm');
  163. },
  164. // 取消输入
  165. onCancel() {
  166. this.popupClose();
  167. this.$emit('cancel');
  168. },
  169. // 退格键
  170. backspace() {
  171. this.$emit('backspace');
  172. },
  173. // 关闭键盘
  174. // close() {
  175. // this.show = false;
  176. // },
  177. // // 打开键盘
  178. // open() {
  179. // this.show = true;
  180. // }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. // @import "../../libs/css/style.components.scss";
  186. .u-keyboard {
  187. position: relative;
  188. z-index: 1003;
  189. }
  190. .u-tooltip {
  191. // @include vue-flex;
  192. display:flex;
  193. justify-content: space-between;
  194. }
  195. .u-tooltip-item {
  196. color: #333333;
  197. flex: 0 0 33.333333%;
  198. text-align: center;
  199. padding: 20rpx 10rpx;
  200. font-size: 28rpx;
  201. }
  202. .u-tooltips-submit {
  203. text-align: right;
  204. flex-grow: 1;
  205. flex-wrap: 0;
  206. padding-right: 40rpx;
  207. color: $u-type-primary;
  208. }
  209. .u-tooltip-cancel {
  210. text-align: left;
  211. flex-grow: 1;
  212. flex-wrap: 0;
  213. padding-left: 40rpx;
  214. color: #888888;
  215. }
  216. .u-tooltips-submit-hover {
  217. color: $u-type-success;
  218. }
  219. .u-tooltip-cancel-hover {
  220. color: #333333;
  221. }
  222. </style>