new_file.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="content">
  3. <view class="uni-form-item uni-column">
  4. <input type="text" v-model="value2" @focus="focusFunc" />
  5. <view class="title">实时获取请扫描输入值:{{ value }}</view>
  6. <u--input
  7. class="inputsss"
  8. v-model="value"
  9. placeholder="请扫描"
  10. clearable
  11. confirm-type="next"
  12. @input="onInput"
  13. @confirm="moveNext('b')"
  14. @blur="blur" />
  15. <view class="title">实时获取请扫描输入值2:{{ b }}</view>
  16. <u--input
  17. class="input"
  18. v-model="b"
  19. placeholder="请扫描"
  20. :focus="focusList['b']"
  21. clearable
  22. @input="onInputr"
  23. @confirm="confirmr"
  24. @blur="blurr" />
  25. <!-- <input
  26. v-model="a"
  27. type="text"
  28. confirm-type="next"
  29. @confirm="moveNext('b')" />
  30. <input v-model="b" :focus="focusList['b']" /> -->
  31. </view>
  32. <xw-scan></xw-scan>
  33. </view>
  34. </template>
  35. <script>
  36. // 广播模式激光扫码
  37. // import xwScan from "@/components/padDevice/scan-code.vue";
  38. export default {
  39. components: {
  40. // xwScan,
  41. },
  42. data() {
  43. return {
  44. a: "",
  45. b: "",
  46. focusList: {
  47. b: false,
  48. },
  49. value: "",
  50. inputTagsValue: "",
  51. value2: "",
  52. focus: false,
  53. focusss: false,
  54. searchFocus: false,
  55. searchValue: "",
  56. textInput: "",
  57. isInputFocused: false,
  58. isHidden: true,
  59. isFocused: false,
  60. scanTitle: "扫描结果",
  61. };
  62. },
  63. onLoad() {},
  64. onUnload() {
  65. // 移除监听事件
  66. uni.$off("xwscan");
  67. },
  68. onShow() {
  69. const activeNode = document.activeElement;
  70. console.log(activeNode);
  71. uni.$off("xwscan"); // 每次进来先 移除全局自定义事件监听器
  72. uni.$on("xwscan", (res) => {
  73. console.log("扫码结果:", res.code);
  74. this.scanTitle = "激光扫码结果";
  75. // this.value = res.code;
  76. if (this.value == "") {
  77. this.value = res.code;
  78. } else {
  79. this.b = res.code;
  80. }
  81. });
  82. },
  83. methods: {
  84. focusFunc(e) {
  85. uni.$off("xwscan"); // 每次进来先 移除全局自定义事件监听器
  86. uni.$on("xwscan", (res) => {
  87. console.log("扫码结果:", res.code);
  88. // this.scanTitle = "激光扫码结果";
  89. this.value2 = res.code;
  90. });
  91. console.log("focus事件");
  92. },
  93. moveNext(dom) {
  94. this.focusList[dom] = true;
  95. console.log(dom);
  96. },
  97. focusInterestInput() {
  98. this.inputFocus = true;
  99. },
  100. handleInputBlur() {
  101. this.inputFocus = false;
  102. },
  103. focusHide(val) {
  104. let that = this;
  105. // setTimeout(() => {
  106. that.focus = true;
  107. // }, 100)
  108. console.log("eeeee");
  109. // 这是隐藏自动弹出软键盘 (好像没有用)
  110. setTimeout(() => {
  111. uni.hideKeyboard();
  112. }, 100);
  113. },
  114. blur() {
  115. this.focus = false;
  116. },
  117. blurr() {
  118. this.focusss = false;
  119. },
  120. confirm(value) {
  121. // 自动多次扫码
  122. let that = this;
  123. // that.value = ''
  124. setTimeout(() => {
  125. that.focus = false;
  126. that.$nextTick(() => {
  127. that.focus = true;
  128. });
  129. // that.value = ''
  130. }, 350);
  131. console.log("扫码结果:", value);
  132. },
  133. confirmr(value) {
  134. // 自动多次扫码
  135. let that = this;
  136. // that.value = ''
  137. setTimeout(() => {
  138. that.focusss = false;
  139. that.$nextTick(() => {
  140. that.focusss = true;
  141. });
  142. // that.value = ''
  143. }, 350);
  144. console.log("扫码结果:", value);
  145. },
  146. onInput(value) {
  147. console.log(value);
  148. this.value = value;
  149. },
  150. onInputr(value) {
  151. this.b = value;
  152. },
  153. },
  154. };
  155. </script>
  156. <style scoped>
  157. input {
  158. border: 1rpx solid #ccc;
  159. height: 80rpx;
  160. border-radius: 10rpx;
  161. font-size: 24rpx;
  162. padding: 0 10rpx;
  163. }
  164. .custom-input input.focused {
  165. background-color: rgb(111, 141, 255, 0.2); /* 设置输入框获得焦点时的背景色 */
  166. border: 1rpx solid rgb(111, 141, 255);
  167. }
  168. </style>