ScanEntry.vue 3.5 KB

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