uv-keyboard-car.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view
  3. class="uv-keyboard"
  4. @touchmove.stop.prevent="noop"
  5. >
  6. <view
  7. v-for="(group, i) in abc ? engKeyBoardList : areaList"
  8. :key="i"
  9. class="uv-keyboard__button"
  10. :index="i"
  11. :class="[i + 1 === 4 && 'uv-keyboard__button--center']"
  12. >
  13. <view
  14. v-if="i === 3"
  15. class="uv-keyboard__button__inner-wrapper"
  16. >
  17. <view
  18. class="uv-keyboard__button__inner-wrapper__left"
  19. hover-class="uv-hover-class"
  20. :hover-stay-time="200"
  21. @tap="changeCarInputMode"
  22. >
  23. <text
  24. class="uv-keyboard__button__inner-wrapper__left__lang"
  25. :class="[!abc && 'uv-keyboard__button__inner-wrapper__left__lang--active']"
  26. >中</text>
  27. <text class="uv-keyboard__button__inner-wrapper__left__line">/</text>
  28. <text
  29. class="uv-keyboard__button__inner-wrapper__left__lang"
  30. :class="[abc && 'uv-keyboard__button__inner-wrapper__left__lang--active']"
  31. >英</text>
  32. </view>
  33. </view>
  34. <view
  35. class="uv-keyboard__button__inner-wrapper"
  36. v-for="(item, j) in group"
  37. :key="j"
  38. >
  39. <view
  40. class="uv-keyboard__button__inner-wrapper__inner"
  41. :hover-stay-time="200"
  42. @tap="carInputClick(i, j)"
  43. hover-class="uv-hover-class"
  44. >
  45. <text class="uv-keyboard__button__inner-wrapper__inner__text">{{ item }}</text>
  46. </view>
  47. </view>
  48. <view
  49. v-if="i === 3"
  50. @touchstart="backspaceClick"
  51. @touchend="clearTimer"
  52. class="uv-keyboard__button__inner-wrapper"
  53. >
  54. <view
  55. class="uv-keyboard__button__inner-wrapper__right"
  56. hover-class="uv-hover-class"
  57. :hover-stay-time="200"
  58. >
  59. <uv-icon
  60. size="28"
  61. name="backspace"
  62. color="#303133"
  63. ></uv-icon>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  71. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  72. import props from './props.js';
  73. /**
  74. * keyboard 键盘组件
  75. * @description 此为uvui自定义的键盘面板,内含了数字键盘,车牌号键,身份证号键盘3种模式,都有可以打乱按键顺序的选项。
  76. * @tutorial https://www.uvui.cn/components/keyboard.html
  77. * @property {Boolean} random 是否打乱键盘的顺序
  78. * @event {Function} change 点击键盘触发
  79. * @event {Function} backspace 点击退格键触发
  80. * @example <uv-keyboard ref="uKeyboard" mode="car" v-model="show"></uv-keyboard>
  81. */
  82. export default {
  83. name: "uv-keyboard",
  84. mixins: [mpMixin, mixin, props],
  85. emits: ['backspace','change'],
  86. data() {
  87. return {
  88. // 车牌输入时,abc=true为输入车牌号码,bac=false为输入省份中文简称
  89. abc: false
  90. };
  91. },
  92. computed: {
  93. areaList() {
  94. let data = [
  95. '京',
  96. '沪',
  97. '粤',
  98. '津',
  99. '冀',
  100. '豫',
  101. '云',
  102. '辽',
  103. '黑',
  104. '湘',
  105. '皖',
  106. '鲁',
  107. '苏',
  108. '浙',
  109. '赣',
  110. '鄂',
  111. '桂',
  112. '甘',
  113. '晋',
  114. '陕',
  115. '蒙',
  116. '吉',
  117. '闽',
  118. '贵',
  119. '渝',
  120. '川',
  121. '青',
  122. '琼',
  123. '宁',
  124. '挂',
  125. '藏',
  126. '港',
  127. '澳',
  128. '新',
  129. '使',
  130. '学'
  131. ];
  132. let tmp = [];
  133. // 打乱顺序
  134. if (this.random) data = this.$uv.randomArray(data);
  135. // 切割成二维数组
  136. tmp[0] = data.slice(0, 10);
  137. tmp[1] = data.slice(10, 20);
  138. tmp[2] = data.slice(20, 30);
  139. tmp[3] = data.slice(30, 36);
  140. return tmp;
  141. },
  142. engKeyBoardList() {
  143. let data = [
  144. 1,
  145. 2,
  146. 3,
  147. 4,
  148. 5,
  149. 6,
  150. 7,
  151. 8,
  152. 9,
  153. 0,
  154. 'Q',
  155. 'W',
  156. 'E',
  157. 'R',
  158. 'T',
  159. 'Y',
  160. 'U',
  161. 'I',
  162. 'O',
  163. 'P',
  164. 'A',
  165. 'S',
  166. 'D',
  167. 'F',
  168. 'G',
  169. 'H',
  170. 'J',
  171. 'K',
  172. 'L',
  173. 'Z',
  174. 'X',
  175. 'C',
  176. 'V',
  177. 'B',
  178. 'N',
  179. 'M'
  180. ];
  181. let tmp = [];
  182. if (this.random) data = this.$uv.randomArray(data);
  183. tmp[0] = data.slice(0, 10);
  184. tmp[1] = data.slice(10, 20);
  185. tmp[2] = data.slice(20, 30);
  186. tmp[3] = data.slice(30, 36);
  187. return tmp;
  188. }
  189. },
  190. methods: {
  191. // 点击键盘按钮
  192. carInputClick(i, j) {
  193. let value = '';
  194. // 不同模式,获取不同数组的值
  195. if (this.abc) value = this.engKeyBoardList[i][j];
  196. else value = this.areaList[i][j];
  197. // 如果允许自动切换,则将中文状态切换为英文
  198. if (!this.abc && this.autoChange) this.$uv.sleep(200).then(() => this.abc = true)
  199. this.$emit('change', value);
  200. },
  201. // 修改汽车牌键盘的输入模式,中文|英文
  202. changeCarInputMode() {
  203. this.abc = !this.abc;
  204. },
  205. // 点击退格键
  206. backspaceClick() {
  207. this.$emit('backspace');
  208. clearInterval(this.timer); //再次清空定时器,防止重复注册定时器
  209. this.timer = null;
  210. this.timer = setInterval(() => {
  211. this.$emit('backspace');
  212. }, 250);
  213. },
  214. clearTimer() {
  215. clearInterval(this.timer);
  216. this.timer = null;
  217. },
  218. }
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. $show-hover: 1;
  223. @import '@/uni_modules/uv-ui-tools/libs/css/variable.scss';
  224. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  225. @import '@/uni_modules/uv-ui-tools/libs/css/color.scss';
  226. $uv-car-keyboard-background-color: rgb(224, 228, 230) !default;
  227. $uv-car-keyboard-padding:6px 0 6px !default;
  228. $uv-car-keyboard-button-inner-width:64rpx !default;
  229. $uv-car-keyboard-button-inner-background-color:#FFFFFF !default;
  230. $uv-car-keyboard-button-height:80rpx !default;
  231. $uv-car-keyboard-button-inner-box-shadow:0 1px 0px #999992 !default;
  232. $uv-car-keyboard-button-border-radius:4px !default;
  233. $uv-car-keyboard-button-inner-margin:8rpx 5rpx !default;
  234. $uv-car-keyboard-button-text-font-size:16px !default;
  235. $uv-car-keyboard-button-text-color:$uv-main-color !default;
  236. $uv-car-keyboard-center-inner-margin: 0 4rpx !default;
  237. $uv-car-keyboard-special-button-width:134rpx !default;
  238. $uv-car-keyboard-lang-font-size:16px !default;
  239. $uv-car-keyboard-lang-color:$uv-main-color !default;
  240. $uv-car-keyboard-active-color:$uv-primary !default;
  241. $uv-car-keyboard-line-font-size:15px !default;
  242. $uv-car-keyboard-line-color:$uv-main-color !default;
  243. $uv-car-keyboard-line-margin:0 1px !default;
  244. $uv-car-keyboard-uv-hover-class-background-color:#BBBCC6 !default;
  245. .uv-keyboard {
  246. @include flex(column);
  247. justify-content: space-around;
  248. background-color: $uv-car-keyboard-background-color;
  249. align-items: stretch;
  250. padding: $uv-car-keyboard-padding;
  251. &__button {
  252. @include flex;
  253. justify-content: center;
  254. flex: 1;
  255. /* #ifndef APP-NVUE */
  256. /* #endif */
  257. &__inner-wrapper {
  258. box-shadow: $uv-car-keyboard-button-inner-box-shadow;
  259. margin: $uv-car-keyboard-button-inner-margin;
  260. border-radius: $uv-car-keyboard-button-border-radius;
  261. &__inner {
  262. @include flex;
  263. justify-content: center;
  264. align-items: center;
  265. width: $uv-car-keyboard-button-inner-width;
  266. background-color: $uv-car-keyboard-button-inner-background-color;
  267. height: $uv-car-keyboard-button-height;
  268. border-radius: $uv-car-keyboard-button-border-radius;
  269. &__text {
  270. font-size: $uv-car-keyboard-button-text-font-size;
  271. color: $uv-car-keyboard-button-text-color;
  272. }
  273. }
  274. &__left,
  275. &__right {
  276. border-radius: $uv-car-keyboard-button-border-radius;
  277. width: $uv-car-keyboard-special-button-width;
  278. height: $uv-car-keyboard-button-height;
  279. background-color: $uv-car-keyboard-uv-hover-class-background-color;
  280. @include flex;
  281. justify-content: center;
  282. align-items: center;
  283. box-shadow: $uv-car-keyboard-button-inner-box-shadow;
  284. }
  285. &__left {
  286. &__line {
  287. font-size: $uv-car-keyboard-line-font-size;
  288. color: $uv-car-keyboard-line-color;
  289. margin: $uv-car-keyboard-line-margin;
  290. }
  291. &__lang {
  292. font-size: $uv-car-keyboard-lang-font-size;
  293. color: $uv-car-keyboard-lang-color;
  294. &--active {
  295. color: $uv-car-keyboard-active-color;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. .uv-hover-class {
  303. background-color: $uv-car-keyboard-uv-hover-class-background-color;
  304. }
  305. </style>