blob: 84b14678e2e82fd200ef6c15930f415a8d4df1df [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<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" class="u-keyboard-grids-btn"
7 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" @tap="changeCarInputMode">
16 <text class="zh" :class="[!abc ? 'active' : 'inactive']"></text>
17 /
18 <text class="en" :class="[abc ? 'active' : 'inactive']"></text>
19 </view>
20 </block>
21 </view>
22 </view>
23</template>
24
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
169<style lang="scss" scoped>
170 @import "../../libs/css/style.components.scss";
171
172 .u-keyboard-grids {
173 background: rgb(215, 215, 217);
174 padding: 24rpx 0;
175 position: relative;
176 }
177
178 .u-keyboard-grids-item {
179 @include vue-flex;
180 align-items: center;
181 justify-content: center;
182 }
183
184 .u-keyboard-grids-btn {
185 text-decoration: none;
186 width: 62rpx;
187 flex: 0 0 64rpx;
188 height: 80rpx;
189 /* #ifndef APP-NVUE */
190 display: inline-flex;
191 /* #endif */
192 font-size: 36rpx;
193 text-align: center;
194 line-height: 80rpx;
195 background-color: #fff;
196 margin: 8rpx 5rpx;
197 border-radius: 8rpx;
198 box-shadow: 0 2rpx 0rpx #888992;
199 font-weight: 500;
200 justify-content: center;
201 }
202
203 .u-carinput-hover {
204 background-color: rgb(185, 188, 195) !important;
205 }
206
207 .u-keyboard-back {
208 position: absolute;
209 width: 96rpx;
210 right: 22rpx;
211 bottom: 32rpx;
212 height: 80rpx;
213 background-color: rgb(185, 188, 195);
214 @include vue-flex;
215 align-items: center;
216 border-radius: 8rpx;
217 justify-content: center;
218 box-shadow: 0 2rpx 0rpx #888992;
219 }
220
221 .u-keyboard-change {
222 font-size: 24rpx;
223 box-shadow: 0 2rpx 0rpx #888992;
224 position: absolute;
225 width: 96rpx;
226 left: 22rpx;
227 line-height: 1;
228 bottom: 32rpx;
229 height: 80rpx;
230 background-color: #ffffff;
231 @include vue-flex;
232 align-items: center;
233 border-radius: 8rpx;
234 justify-content: center;
235 }
236
237 .u-keyboard-change .inactive.zh {
238 transform: scale(0.85) translateY(-10rpx);
239 }
240
241 .u-keyboard-change .inactive.en {
242 transform: scale(0.85) translateY(10rpx);
243 }
244
245 .u-keyboard-change .active {
246 color: rgb(237, 112, 64);
247 font-size: 30rpx;
248 }
249
250 .u-keyboard-change .zh {
251 transform: translateY(-10rpx);
252 }
253
254 .u-keyboard-change .en {
255 transform: translateY(10rpx);
256 }
257</style>