u-car-keyboard.vue 5.2 KB

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