ScanEntry.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="BarCodeScannerDiv">
  3. <input required="" type="text" class="input" v-model.trim="scanEntryData" ref="scanInput">
  4. <span class="highlight"></span>
  5. <span class="bar"></span>
  6. <label>{{label}}</label>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'scanEntry',
  12. data() {
  13. return {
  14. scanEntryData: null,
  15. };
  16. },
  17. props: {
  18. label:{
  19. type: String,
  20. default: '',
  21. }
  22. },
  23. mounted() {
  24. this.setFocus();
  25. this.$refs.scanInput.addEventListener('keydown', this.handleScanInput);
  26. },
  27. beforeDestroy() {
  28. this.$refs.scanInput.removeEventListener('keydown', this.handleScanInput);
  29. },
  30. methods: {
  31. setFocus() {
  32. this.$nextTick(() => {
  33. this.$refs.scanInput.focus();
  34. });
  35. },
  36. handleScanInput(event) {
  37. const input = event.target;
  38. const inputValue = input.value;
  39. this.scanEntryData = input.value;
  40. if (event.key === 'Enter') {
  41. setTimeout(() => {
  42. input.value = '';
  43. this.scanEntryData = '';
  44. }, 100);
  45. this.$emit('scanEntryFun', inputValue);
  46. }
  47. },
  48. },
  49. }
  50. </script>
  51. <style lang="css" scoped>
  52. .BarCodeScannerDiv {
  53. position: relative;
  54. }
  55. .input {
  56. font-size: 20px;
  57. padding: 10px 10px 10px 5px;
  58. display: block;
  59. width: 100%;
  60. border: none;
  61. border-bottom: 1px solid #515151;
  62. background: transparent;
  63. }
  64. .input:focus {
  65. outline: none;
  66. }
  67. label {
  68. color: #999;
  69. font-size: 18px;
  70. font-weight: normal;
  71. position: absolute;
  72. pointer-events: none;
  73. left: 5px;
  74. top: 10px;
  75. transition: 0.2s ease all;
  76. -moz-transition: 0.2s ease all;
  77. -webkit-transition: 0.2s ease all;
  78. }
  79. .input:focus ~ label, .input:valid ~ label {
  80. top: -20px;
  81. font-size: 14px;
  82. color: #5264AE;
  83. }
  84. .bar {
  85. position: relative;
  86. display: block;
  87. width: 100%;
  88. }
  89. .bar:before, .bar:after {
  90. content: '';
  91. height: 2px;
  92. width: 0;
  93. bottom: 1px;
  94. position: absolute;
  95. background: #5264AE;
  96. transition: 0.2s ease all;
  97. -moz-transition: 0.2s ease all;
  98. -webkit-transition: 0.2s ease all;
  99. }
  100. .bar:before {
  101. left: 50%;
  102. }
  103. .bar:after {
  104. right: 50%;
  105. }
  106. .input:focus ~ .bar:before, .input:focus ~ .bar:after {
  107. width: 50%;
  108. }
  109. .highlight {
  110. position: absolute;
  111. height: 60%;
  112. width: 100px;
  113. top: 25%;
  114. left: 0;
  115. pointer-events: none;
  116. opacity: 0.5;
  117. }
  118. .input:focus ~ .highlight {
  119. animation: inputHighlighter 0.3s ease;
  120. }
  121. @keyframes inputHighlighter {
  122. from {
  123. background: #5264AE;
  124. }
  125. to {
  126. width: 0;
  127. background: transparent;
  128. }
  129. }
  130. </style>