uv-keyboard-car.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. <slot>
  24. <template v-if="!customabc">
  25. <text
  26. class="uv-keyboard__button__inner-wrapper__left__lang"
  27. :class="[!abc && 'uv-keyboard__button__inner-wrapper__left__lang--active']"
  28. >中</text>
  29. <text class="uv-keyboard__button__inner-wrapper__left__line">/</text>
  30. <text
  31. class="uv-keyboard__button__inner-wrapper__left__lang"
  32. :class="[abc && 'uv-keyboard__button__inner-wrapper__left__lang--active']"
  33. >英</text>
  34. </template>
  35. </slot>
  36. </view>
  37. </view>
  38. <view
  39. class="uv-keyboard__button__inner-wrapper"
  40. v-for="(item, j) in group"
  41. :key="j"
  42. >
  43. <view
  44. :class="['uv-keyboard__button__inner-wrapper__inner',{'uv-keyboard__button__inner-wrapper__inner--disabled': isDisabled(i,j)}]"
  45. :hover-stay-time="200"
  46. @tap="carInputClick(i, j)"
  47. :hover-class="isDisabled(i,j)?'none':'uv-hover-class'"
  48. >
  49. <text class="uv-keyboard__button__inner-wrapper__inner__text">{{ item }}</text>
  50. </view>
  51. <view class="uv-keyboard__button__inner-wrapper__disabled--mask" v-if="isDisabled(i,j)"></view>
  52. </view>
  53. <view
  54. v-if="i === 3"
  55. @touchstart="backspaceClick"
  56. @touchend="clearTimer"
  57. class="uv-keyboard__button__inner-wrapper"
  58. >
  59. <view
  60. class="uv-keyboard__button__inner-wrapper__right"
  61. hover-class="uv-hover-class"
  62. :hover-stay-time="200"
  63. >
  64. <uv-icon
  65. size="28"
  66. name="backspace"
  67. color="#303133"
  68. ></uv-icon>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  76. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  77. import props from './props.js';
  78. /**
  79. * keyboard 键盘组件
  80. * @description 此为uvui自定义的键盘面板,内含了数字键盘,车牌号键,身份证号键盘3种模式,都有可以打乱按键顺序的选项。
  81. * @tutorial https://www.uvui.cn/components/keyboard.html
  82. * @property {Boolean} random 是否打乱键盘的顺序
  83. * @event {Function} change 点击键盘触发
  84. * @event {Function} backspace 点击退格键触发
  85. * @example <uv-keyboard ref="uKeyboard" mode="car" v-model="show"></uv-keyboard>
  86. */
  87. export default {
  88. name: "uv-keyboard",
  89. mixins: [mpMixin, mixin, props],
  90. emits: ['backspace','change','changeCarInputMode'],
  91. data() {
  92. return {
  93. // 车牌输入时,abc=true为输入车牌号码,bac=false为输入省份中文简称
  94. abc: false
  95. };
  96. },
  97. computed: {
  98. areaList() {
  99. let data = [
  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. '澳',
  133. '新',
  134. '使',
  135. '学'
  136. ];
  137. let tmp = [];
  138. // 打乱顺序
  139. if (this.random) data = this.$uv.randomArray(data);
  140. // 切割成二维数组
  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. engKeyBoardList() {
  148. let data = [
  149. 1,
  150. 2,
  151. 3,
  152. 4,
  153. 5,
  154. 6,
  155. 7,
  156. 8,
  157. 9,
  158. 0,
  159. 'Q',
  160. 'W',
  161. 'E',
  162. 'R',
  163. 'T',
  164. 'Y',
  165. 'U',
  166. 'I',
  167. 'O',
  168. 'P',
  169. 'A',
  170. 'S',
  171. 'D',
  172. 'F',
  173. 'G',
  174. 'H',
  175. 'J',
  176. 'K',
  177. 'L',
  178. 'Z',
  179. 'X',
  180. 'C',
  181. 'V',
  182. 'B',
  183. 'N',
  184. 'M'
  185. ];
  186. let tmp = [];
  187. if (this.random) data = this.$uv.randomArray(data);
  188. tmp[0] = data.slice(0, 10);
  189. tmp[1] = data.slice(10, 20);
  190. tmp[2] = data.slice(20, 30);
  191. tmp[3] = data.slice(30, 36);
  192. return tmp;
  193. },
  194. isDisabled(i,j) {
  195. return (i,j)=>{
  196. let value = '';
  197. if (this.abc) value = this.engKeyBoardList[i][j];
  198. else value = this.areaList[i][j];
  199. return this.disKeys.indexOf(value) > -1;
  200. }
  201. }
  202. },
  203. methods: {
  204. // 点击键盘按钮
  205. carInputClick(i, j) {
  206. if(this.isDisabled(i,j)) return;
  207. let value = '';
  208. // 不同模式,获取不同数组的值
  209. if (this.abc) value = this.engKeyBoardList[i][j];
  210. else value = this.areaList[i][j];
  211. // 如果允许自动切换,则将中文状态切换为英文
  212. if (!this.abc && this.autoChange) this.$uv.sleep(200).then(() => this.abc = true)
  213. this.$emit('change', value);
  214. },
  215. // 修改汽车牌键盘的输入模式,中文|英文
  216. changeCarInputMode() {
  217. this.abc = !this.abc;
  218. this.$emit('changeCarInputMode',this.abc);
  219. },
  220. // 点击退格键
  221. backspaceClick() {
  222. this.$emit('backspace');
  223. clearInterval(this.timer); //再次清空定时器,防止重复注册定时器
  224. this.timer = null;
  225. this.timer = setInterval(() => {
  226. this.$emit('backspace');
  227. }, 250);
  228. },
  229. clearTimer() {
  230. clearInterval(this.timer);
  231. this.timer = null;
  232. },
  233. }
  234. };
  235. </script>
  236. <style lang="scss" scoped>
  237. $show-hover: 1;
  238. @import '@/uni_modules/uv-ui-tools/libs/css/variable.scss';
  239. @import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
  240. @import '@/uni_modules/uv-ui-tools/libs/css/color.scss';
  241. $uv-car-keyboard-background-color: rgb(224, 228, 230) !default;
  242. $uv-car-keyboard-padding:6px 0 6px !default;
  243. $uv-car-keyboard-button-inner-width:64rpx !default;
  244. $uv-car-keyboard-button-inner-background-color:#FFFFFF !default;
  245. $uv-car-keyboard-button-height:80rpx !default;
  246. $uv-car-keyboard-button-inner-box-shadow:0 1px 0px #999992 !default;
  247. $uv-car-keyboard-button-border-radius:4px !default;
  248. $uv-car-keyboard-button-inner-margin:8rpx 5rpx !default;
  249. $uv-car-keyboard-button-text-font-size:16px !default;
  250. $uv-car-keyboard-button-text-color:$uv-main-color !default;
  251. $uv-car-keyboard-center-inner-margin: 0 4rpx !default;
  252. $uv-car-keyboard-special-button-width:134rpx !default;
  253. $uv-car-keyboard-lang-font-size:16px !default;
  254. $uv-car-keyboard-lang-color:$uv-main-color !default;
  255. $uv-car-keyboard-active-color:$uv-primary !default;
  256. $uv-car-keyboard-line-font-size:15px !default;
  257. $uv-car-keyboard-line-color:$uv-main-color !default;
  258. $uv-car-keyboard-line-margin:0 1px !default;
  259. $uv-car-keyboard-uv-hover-class-background-color:#BBBCC6 !default;
  260. .uv-keyboard {
  261. @include flex(column);
  262. justify-content: space-around;
  263. background-color: $uv-car-keyboard-background-color;
  264. align-items: stretch;
  265. padding: $uv-car-keyboard-padding;
  266. &__button {
  267. @include flex;
  268. justify-content: center;
  269. flex: 1;
  270. /* #ifndef APP-NVUE */
  271. /* #endif */
  272. &__inner-wrapper {
  273. position: relative;
  274. box-shadow: $uv-car-keyboard-button-inner-box-shadow;
  275. margin: $uv-car-keyboard-button-inner-margin;
  276. border-radius: $uv-car-keyboard-button-border-radius;
  277. &__disabled--mask {
  278. position: absolute;
  279. left: 0;
  280. top: 0;
  281. bottom: 0;
  282. right: 0;
  283. width: $uv-car-keyboard-button-inner-width;
  284. height: $uv-car-keyboard-button-height;
  285. }
  286. &__inner {
  287. @include flex;
  288. justify-content: center;
  289. align-items: center;
  290. width: $uv-car-keyboard-button-inner-width;
  291. background-color: $uv-car-keyboard-button-inner-background-color;
  292. height: $uv-car-keyboard-button-height;
  293. border-radius: $uv-car-keyboard-button-border-radius;
  294. &--disabled {
  295. opacity: 0.5;
  296. }
  297. &__text {
  298. font-size: $uv-car-keyboard-button-text-font-size;
  299. color: $uv-car-keyboard-button-text-color;
  300. }
  301. }
  302. &__left,
  303. &__right {
  304. border-radius: $uv-car-keyboard-button-border-radius;
  305. width: $uv-car-keyboard-special-button-width;
  306. height: $uv-car-keyboard-button-height;
  307. background-color: $uv-car-keyboard-uv-hover-class-background-color;
  308. @include flex;
  309. justify-content: center;
  310. align-items: center;
  311. box-shadow: $uv-car-keyboard-button-inner-box-shadow;
  312. }
  313. &__left {
  314. &__line {
  315. font-size: $uv-car-keyboard-line-font-size;
  316. color: $uv-car-keyboard-line-color;
  317. margin: $uv-car-keyboard-line-margin;
  318. }
  319. &__lang {
  320. font-size: $uv-car-keyboard-lang-font-size;
  321. color: $uv-car-keyboard-lang-color;
  322. &--active {
  323. color: $uv-car-keyboard-active-color;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. .uv-hover-class {
  331. background-color: $uv-car-keyboard-uv-hover-class-background-color;
  332. }
  333. </style>