u-car-keyboard.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="u-keyboard" @touchmove.stop.prevent="() => {}">
  3. <view class="u-keyboard-grids">
  4. <block>
  5. <view v-for="(group, i) in abc ? EngKeyBoardList : areaList" :key="i" class="u-keyboard-grids-item">
  6. <view v-for="(item, j) in group" :key="j" :hover-stay-time="100"
  7. class="u-keyboard-grids-btn"
  8. hover-class="u-carinput-hover" @tap="carInputClick(i, j)">
  9. {{ item }}
  10. </view>
  11. </view>
  12. <view :hover-stay-time="100" class="u-keyboard-back" hover-class="u-hover-class" @touchend="clearTimer"
  13. @touchstart="backspaceClick">
  14. <u-icon :bold="true" :size="38" name="backspace"></u-icon>
  15. </view>
  16. <view :hover-stay-time="100" class="u-keyboard-change" hover-class="u-carinput-hover" @tap="changeCarInputMode">
  17. <text :class="[!abc ? 'active' : 'inactive']" class="zh">中</text>
  18. /
  19. <text :class="[abc ? 'active' : 'inactive']" class="en">英</text>
  20. </view>
  21. </block>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name: "u-keyboard",
  28. props: {
  29. // 是否打乱键盘按键的顺序
  30. random: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data() {
  36. return {
  37. // 车牌输入时,abc=true为输入车牌号码,bac=false为输入省份中文简称
  38. abc: false
  39. };
  40. },
  41. computed: {
  42. areaList() {
  43. let data = [
  44. '京',
  45. '沪',
  46. '粤',
  47. '津',
  48. '冀',
  49. '豫',
  50. '云',
  51. '辽',
  52. '黑',
  53. '湘',
  54. '皖',
  55. '鲁',
  56. '苏',
  57. '浙',
  58. '赣',
  59. '鄂',
  60. '桂',
  61. '甘',
  62. '晋',
  63. '陕',
  64. '蒙',
  65. '吉',
  66. '闽',
  67. '贵',
  68. '渝',
  69. '川',
  70. '青',
  71. '琼',
  72. '宁',
  73. '挂',
  74. '藏',
  75. '港',
  76. '澳',
  77. '新',
  78. '使',
  79. '学'
  80. ];
  81. let tmp = [];
  82. // 打乱顺序
  83. if (this.random) data = this.$u.randomArray(data);
  84. // 切割成二维数组
  85. tmp[0] = data.slice(0, 10);
  86. tmp[1] = data.slice(10, 20);
  87. tmp[2] = data.slice(20, 30);
  88. tmp[3] = data.slice(30, 36);
  89. return tmp;
  90. },
  91. EngKeyBoardList() {
  92. let data = [
  93. 1,
  94. 2,
  95. 3,
  96. 4,
  97. 5,
  98. 6,
  99. 7,
  100. 8,
  101. 9,
  102. 0,
  103. 'Q',
  104. 'W',
  105. 'E',
  106. 'R',
  107. 'T',
  108. 'Y',
  109. 'U',
  110. 'I',
  111. 'O',
  112. 'P',
  113. 'A',
  114. 'S',
  115. 'D',
  116. 'F',
  117. 'G',
  118. 'H',
  119. 'J',
  120. 'K',
  121. 'L',
  122. 'Z',
  123. 'X',
  124. 'C',
  125. 'V',
  126. 'B',
  127. 'N',
  128. 'M'
  129. ];
  130. let tmp = [];
  131. if (this.random) data = this.$u.randomArray(data);
  132. tmp[0] = data.slice(0, 10);
  133. tmp[1] = data.slice(10, 20);
  134. tmp[2] = data.slice(20, 30);
  135. tmp[3] = data.slice(30, 36);
  136. return tmp;
  137. }
  138. },
  139. methods: {
  140. // 点击键盘按钮
  141. carInputClick(i, j) {
  142. let value = '';
  143. // 不同模式,获取不同数组的值
  144. if (this.abc) value = this.EngKeyBoardList[i][j];
  145. else value = this.areaList[i][j];
  146. this.$emit('change', value);
  147. },
  148. // 修改汽车牌键盘的输入模式,中文|英文
  149. changeCarInputMode() {
  150. this.abc = !this.abc;
  151. },
  152. // 点击退格键
  153. backspaceClick() {
  154. this.$emit('backspace');
  155. clearInterval(this.timer); //再次清空定时器,防止重复注册定时器
  156. this.timer = null;
  157. this.timer = setInterval(() => {
  158. this.$emit('backspace');
  159. }, 250);
  160. },
  161. clearTimer() {
  162. clearInterval(this.timer);
  163. this.timer = null;
  164. },
  165. }
  166. };
  167. </script>
  168. <style lang="scss" scoped>
  169. @import "../../libs/css/style.components.scss";
  170. .u-keyboard-grids {
  171. background: rgb(215, 215, 217);
  172. padding: 24 rpx 0;
  173. position: relative;
  174. }
  175. .u-keyboard-grids-item {
  176. @include vue-flex;
  177. align-items: center;
  178. justify-content: center;
  179. }
  180. .u-keyboard-grids-btn {
  181. text-decoration: none;
  182. width: 62 rpx;
  183. flex: 0 0 64 rpx;
  184. height: 80 rpx;
  185. /* #ifndef APP-NVUE */
  186. display: inline-flex;
  187. /* #endif */
  188. font-size: 36 rpx;
  189. text-align: center;
  190. line-height: 80 rpx;
  191. background-color: #fff;
  192. margin: 8 rpx 5 rpx;
  193. border-radius: 8 rpx;
  194. box-shadow: 0 2 rpx 0 rpx #888992;
  195. font-weight: 500;
  196. justify-content: center;
  197. }
  198. .u-carinput-hover {
  199. background-color: rgb(185, 188, 195) !important;
  200. }
  201. .u-keyboard-back {
  202. position: absolute;
  203. width: 96 rpx;
  204. right: 22 rpx;
  205. bottom: 32 rpx;
  206. height: 80 rpx;
  207. background-color: rgb(185, 188, 195);
  208. @include vue-flex;
  209. align-items: center;
  210. border-radius: 8 rpx;
  211. justify-content: center;
  212. box-shadow: 0 2 rpx 0 rpx #888992;
  213. }
  214. .u-keyboard-change {
  215. font-size: 24 rpx;
  216. box-shadow: 0 2 rpx 0 rpx #888992;
  217. position: absolute;
  218. width: 96 rpx;
  219. left: 22 rpx;
  220. line-height: 1;
  221. bottom: 32 rpx;
  222. height: 80 rpx;
  223. background-color: #ffffff;
  224. @include vue-flex;
  225. align-items: center;
  226. border-radius: 8 rpx;
  227. justify-content: center;
  228. }
  229. .u-keyboard-change .inactive.zh {
  230. transform: scale(0.85) translateY(-10rpx);
  231. }
  232. .u-keyboard-change .inactive.en {
  233. transform: scale(0.85) translateY(10 rpx);
  234. }
  235. .u-keyboard-change .active {
  236. color: rgb(237, 112, 64);
  237. font-size: 30 rpx;
  238. }
  239. .u-keyboard-change .zh {
  240. transform: translateY(-10rpx);
  241. }
  242. .u-keyboard-change .en {
  243. transform: translateY(10 rpx);
  244. }
  245. </style>