Ucarkeyboard.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. <ucarkeyboardmod :random="random" @backspace="backspace" ref="thiscar" @change="change"></ucarkeyboardmod>
  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. import ucarkeyboardmod from '@/components/Ucarkeyboard-mod.vue'
  55. export default {
  56. components: {
  57. ucarkeyboardmod
  58. },
  59. name: "u-keyboard",
  60. props: {
  61. // 键盘的类型,number-数字键盘,card-身份证键盘,car-车牌号键盘
  62. mode: {
  63. type: String,
  64. default: 'number'
  65. },
  66. // 是否显示键盘的"."符号
  67. dotEnabled: {
  68. type: Boolean,
  69. default: true
  70. },
  71. // 是否显示顶部工具条
  72. tooltip: {
  73. type: Boolean,
  74. default: true
  75. },
  76. // 是否显示工具条中间的提示
  77. showTips: {
  78. type: Boolean,
  79. default: true
  80. },
  81. // 工具条中间的提示文字
  82. tips: {
  83. type: String,
  84. default: ''
  85. },
  86. // 是否显示工具条左边的"取消"按钮
  87. cancelBtn: {
  88. type: Boolean,
  89. default: true
  90. },
  91. // 是否显示工具条右边的"完成"按钮
  92. confirmBtn: {
  93. type: Boolean,
  94. default: true
  95. },
  96. // 是否打乱键盘按键的顺序
  97. random: {
  98. type: Boolean,
  99. default: false
  100. },
  101. // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距
  102. safeAreaInsetBottom: {
  103. type: Boolean,
  104. default: false
  105. },
  106. // 是否允许通过点击遮罩关闭键盘
  107. maskCloseAble: {
  108. type: Boolean,
  109. default: false
  110. },
  111. // 通过双向绑定控制键盘的弹出与收起
  112. value: {
  113. type: Boolean,
  114. default: false
  115. },
  116. // 是否显示遮罩,某些时候数字键盘时,用户希望看到自己的数值,所以可能不想要遮罩
  117. mask: {
  118. type: Boolean,
  119. default: false
  120. },
  121. // z-index值
  122. zIndex: {
  123. type: [Number, String],
  124. default: ''
  125. },
  126. // 取消按钮的文字
  127. cancelText: {
  128. type: String,
  129. default: '取消'
  130. },
  131. // 确认按钮的文字
  132. confirmText: {
  133. type: String,
  134. default: '确认'
  135. }
  136. },
  137. data() {
  138. return {
  139. //show: false
  140. }
  141. },
  142. computed: {
  143. uZIndex() {
  144. return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
  145. }
  146. },
  147. methods: {
  148. changeCarInputValue(){
  149. return this.$refs.thiscar.abc
  150. },
  151. changeCarInputMode(){
  152. this.$refs.thiscar.changeCarInputMode()
  153. return this.$refs.thiscar.abc
  154. },
  155. change(e) {
  156. this.$emit('change', e);
  157. },
  158. // 键盘关闭
  159. popupClose() {
  160. // 通过发送input这个特殊的事件名,可以修改父组件传给props的value的变量,也即双向绑定
  161. this.$emit('input', false);
  162. },
  163. // 输入完成
  164. onConfirm() {
  165. this.popupClose();
  166. this.$emit('confirm');
  167. },
  168. // 取消输入
  169. onCancel() {
  170. this.popupClose();
  171. this.$emit('cancel');
  172. },
  173. // 退格键
  174. backspace() {
  175. this.$emit('backspace');
  176. },
  177. // 关闭键盘
  178. // close() {
  179. // this.show = false;
  180. // },
  181. // // 打开键盘
  182. // open() {
  183. // this.show = true;
  184. // }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. // @import "../../libs/css/style.components.scss";
  190. .u-keyboard {
  191. position: relative;
  192. z-index: 1003;
  193. }
  194. .u-tooltip {
  195. // @include vue-flex;
  196. display:flex;
  197. justify-content: space-between;
  198. }
  199. .u-tooltip-item {
  200. color: #333333;
  201. flex: 0 0 33.333333%;
  202. text-align: center;
  203. padding: 20rpx 10rpx;
  204. font-size: 28rpx;
  205. }
  206. .u-tooltips-submit {
  207. text-align: right;
  208. flex-grow: 1;
  209. flex-wrap: 0;
  210. padding-right: 40rpx;
  211. color: $u-type-primary;
  212. }
  213. .u-tooltip-cancel {
  214. text-align: left;
  215. flex-grow: 1;
  216. flex-wrap: 0;
  217. padding-left: 40rpx;
  218. color: #888888;
  219. }
  220. .u-tooltips-submit-hover {
  221. color: $u-type-success;
  222. }
  223. .u-tooltip-cancel-hover {
  224. color: #333333;
  225. }
  226. </style>