Ucarkeyboard.vue 6.3 KB

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