Ucarkeyboard-mod.vue 5.1 KB

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