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