浏览代码

切换项目更新

ZaiZai 11 月之前
父节点
当前提交
509c7a39f0
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      src/views/tentative/material/sampling.vue

+ 11 - 6
src/views/tentative/material/sampling.vue

@@ -267,7 +267,7 @@
 </template>
 
 <script setup>
-import { onActivated, ref, watch } from 'vue'
+import { onActivated, onUnmounted, ref, watch } from 'vue'
 import { useAppStore } from '~src/store'
 import TestTree from './components/TestTree.vue'
 import HcDragUpload from './components/HcDragUpload.vue'
@@ -510,6 +510,7 @@ const requestDevice = async () => {
     // 电脑接收到来自设备的消息回调
     deviceTable.value = []
     device.oninputreport = (event) => {
+        if (!addEditFormModal.value) return
         const { isRfid, rfId } = addEditFormModel.value
         if (isRfid !== 1 ) return
         const array = new Uint8Array(event.data.buffer)
@@ -543,11 +544,6 @@ const formRfidChange = () => {
 const addEditFormModalClose = async () => {
     addEditFormModal.value = false
     addEditFormModel.value = {}
-    if (!isNullES(device)) {
-        await device.close() // 关闭设备
-        await device.forget() // 遗忘设备
-        device = null
-    }
 }
 
 //新增/编辑 表单
@@ -1012,6 +1008,15 @@ const delegateModalClose = () => {
     delegateHtmlLoading.value = false
     creatingDelegateLoading.value = false
 }
+
+//页面卸载
+onUnmounted(async () => {
+    if (!isNullES(device)) {
+        await device.close() // 关闭设备
+        await device.forget() // 遗忘设备
+        device = null
+    }
+})
 </script>
 
 <style lang="scss" scoped>