index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <van-nav-bar
  3. :title="$t('forward.name')"
  4. left-text=""
  5. left-arrow
  6. @click-left="onClickLeft"
  7. @click-right="onClickRight"
  8. >
  9. <template #right>
  10. <div v-show="!isShowVideo">扫码</div>
  11. <div v-show="isShowVideo">关闭</div>
  12. </template>
  13. </van-nav-bar>
  14. <van-search
  15. v-model="req.keyword"
  16. :placeholder="$t('common.pleaseEnterKeywords')"
  17. @search="onRefresh"
  18. />
  19. <van-pull-refresh v-model="loading" @refresh="onRefresh">
  20. <div class="list">
  21. <van-list
  22. v-model:loading="loading"
  23. :finished="finished"
  24. :finished-text="$t('common.noMore')"
  25. @load="onLoad"
  26. style="margin-bottom: 60px"
  27. >
  28. <commonList
  29. :data="listData"
  30. :config="listConfig"
  31. :showMore="true"
  32. @onClick="toDtl"
  33. ></commonList>
  34. </van-list>
  35. </div>
  36. </van-pull-refresh>
  37. <video
  38. ref="video"
  39. id="video"
  40. class="scan-video"
  41. autoplay
  42. v-show="isShowVideo"
  43. ></video>
  44. </template>
  45. <script setup>
  46. import { ref, getCurrentInstance, onMounted } from "vue";
  47. import commonList from "@/components/common-list.vue";
  48. import { useRoute } from "vue-router";
  49. import { showSuccessToast, showFailToast } from "vant";
  50. import { BrowserMultiFormatReader } from "@zxing/library";
  51. const loading = ref(false);
  52. const router = useRoute();
  53. const req = ref({
  54. pageNum: 1,
  55. keyword: null,
  56. });
  57. const finished = ref(false);
  58. const proxy = getCurrentInstance().proxy;
  59. const listData = ref([]);
  60. const listConfig = ref([
  61. {
  62. label: proxy.t("forward.productName"),
  63. prop: "productName",
  64. },
  65. {
  66. label: "规格型号",
  67. prop: "productSpec",
  68. },
  69. {
  70. label: proxy.t("forward.productSN"),
  71. prop: "productSn",
  72. },
  73. {
  74. label: proxy.t("forward.currentProcess"),
  75. prop: "productionProcessesName",
  76. },
  77. ]);
  78. const onRefresh = () => {
  79. req.value.pageNum = 1;
  80. finished.value = false;
  81. getList("refresh");
  82. };
  83. const onLoad = () => {
  84. getList();
  85. };
  86. const onClickLeft = () => proxy.$router.push("/main/working");
  87. // const onClickRight = () => {
  88. // proxy.$router.push("jxskForwardAdd");
  89. // };
  90. const toDtl = (row) => {
  91. let type = "";
  92. if (
  93. row.nextProductionProcessesId == "" ||
  94. row.nextProductionProcessesId == "-1"
  95. ) {
  96. type = "20";
  97. } else {
  98. type = "10";
  99. }
  100. proxy.$router.push({
  101. path: "jxskForwardAdd",
  102. query: {
  103. ...row,
  104. type: type,
  105. },
  106. });
  107. };
  108. const getList = (type) => {
  109. loading.value = true;
  110. proxy
  111. .post("/productionTaskDetail/circulationPage", req.value)
  112. .then((res) => {
  113. listData.value =
  114. type === "refresh"
  115. ? res.data.rows
  116. : listData.value.concat(res.data.rows);
  117. if (req.value.pageNum * 10 >= res.data.total) {
  118. finished.value = true;
  119. }
  120. req.value.pageNum++;
  121. loading.value = false;
  122. })
  123. .catch((err) => {
  124. loading.value = false;
  125. });
  126. };
  127. getList();
  128. const isShowVideo = ref(false);
  129. const codeReader = new BrowserMultiFormatReader();
  130. const onClickRight = () => {
  131. if (isShowVideo.value) {
  132. codeReader.reset();
  133. isShowVideo.value = false;
  134. } else {
  135. handleScanCode();
  136. }
  137. };
  138. const showScanData = (text) => {
  139. console.log(text, "aweaw");
  140. };
  141. const decodeFromInputVideoFunc = (firstDeviceId) => {
  142. codeReader.reset(); // 重置
  143. isShowVideo.value = true;
  144. codeReader.decodeFromInputVideoDeviceContinuously(
  145. firstDeviceId,
  146. "video",
  147. (result, err) => {
  148. if (result) {
  149. codeReader.reset();
  150. showSuccessToast(proxy.t("manualInbound.scanSuccess"));
  151. isShowVideo.value = false;
  152. showScanData(result.text);
  153. }
  154. if (err && !err) {
  155. console.error(err);
  156. isShowVideo.value = false;
  157. }
  158. }
  159. );
  160. };
  161. const handleScanCode = () => {
  162. codeReader
  163. .getVideoInputDevices()
  164. .then((videoInputDevices) => {
  165. // 默认获取第一个摄像头设备id
  166. let firstDeviceId = videoInputDevices[0].deviceId;
  167. // 获取第一个摄像头设备的名称
  168. const videoInputDeviceslablestr = JSON.stringify(
  169. videoInputDevices[0].label
  170. );
  171. if (videoInputDevices.length > 1) {
  172. // 判断是否后置摄像头
  173. if (videoInputDeviceslablestr.indexOf("back") > -1) {
  174. firstDeviceId = videoInputDevices[0].deviceId;
  175. } else {
  176. firstDeviceId = videoInputDevices[1].deviceId;
  177. }
  178. }
  179. decodeFromInputVideoFunc(firstDeviceId);
  180. })
  181. .catch((err) => {
  182. console.error(err, "错误");
  183. });
  184. };
  185. </script>
  186. <style lang="scss" scoped>
  187. .list {
  188. min-height: 70vh;
  189. }
  190. .scan-video {
  191. width: 100vw;
  192. position: absolute;
  193. z-index: 1000;
  194. top: 60px;
  195. }
  196. </style>