zouyu
3 天以前 8fc1138d2f2115121fd15b679ca1a20fc2ba838a
src/views/business/inspectionTask/inspection.vue
@@ -188,7 +188,7 @@
          <el-button :loading="dataAcquisitionLoading" v-if="state == 1" size="small" type="primary"
            @click="getDataAcquisitionDevice">数据采集</el-button>
          <el-button :type="dataAcquisitionEidtAble ? '' : 'primary'" v-if="state == 1" size="small"
            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble,disconnect()">{{ dataAcquisitionEidtAble ? "关闭编辑" : "编辑数采"
            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble">{{ dataAcquisitionEidtAble ? "关闭编辑" : "编辑数采"
            }}</el-button>
        </div>
      </div>
@@ -650,7 +650,6 @@
import html2canvas from "html2canvas";
import { mapGetters } from "vuex";
import viewManHourDia from "@/views/business/inspectionTask/components/viewManHourDia.vue";
import {connect,disconnect,weightList} from "@/utils/connect";
import {getOneByIfsId,saveOrUpdateProps} from "@/api/business/ifsPartProps.js";
import {getDicts} from "@/api/system/dict/data";
export default {
@@ -704,8 +703,6 @@
        sampleName: null,
        state: null,
      },
      isSerialConnected: false, // 新增状态变量,串口连接状态
      serialPort: null, // 存储串口对象
      id: null,
      changeType: null,
      insOrder: {},
@@ -996,11 +993,6 @@
  beforeDestroy() {
    // 在组件销毁前确保停止 Worker,避免内存泄漏
    this.stopWorker();
    disconnect();
    // 调用前先判断方法是否存在,避免报错
    if (this.closeSerialPort) {
      this.closeSerialPort();// 组件销毁前关闭串口
    }
  },
  methods: {
    validateQuality(){
@@ -1084,9 +1076,6 @@
      this.$nextTick(()=>{
        this.ifsMaterialPropsVisible = true;
      })
    },
    disconnect() {
      return disconnect
    },
    // 文件管理--开始
    getList() {
@@ -1328,58 +1317,32 @@
    // 数据采集
  getDataAcquisitionDevice() {
      (async () => {
        try {
          // 检查页面中检测项是否包含密度
          const hasDensityItem = this.currentSample.insProduct.some(item => {
            // 假设密度相关的检测项名称包含 "密度" 关键字,可按需修改
            return item.inspectionItem && item.inspectionItem.includes('密度');
          });
          if (hasDensityItem) {
            // 检查是否支持 Web Serial API
            if ('serial' in navigator) {
              // 请求可用串口
              const ports = await navigator.serial.getPorts();
              if (ports.length > 0) {
                await connect();
              } else {
                console.log('没有可用的串口');
              }
            } else {
              console.log('当前浏览器不支持 Web Serial API');
            }
          }
        } catch (error) {
          console.error('检测串口时出错:', error);
        }
      })().then(() => {
        let itemIds = [];
        this.currentSample.insProduct.forEach((item) => {
          if (item.inspectionItemType === "1") {
            itemIds.push(item.id);
          }
        });
        const params = {
          entrustCode: this.insOrder.entrustCode,
          lotBatchNo: this.insOrder.lotBatchNo,
          sampleCode: this.currentSample.sampleCode,
          id: this.currentSample.id,
          itemIds: itemIds,
        };
        this.dataAcquisitionLoading = true;
        dataCollection(params).then((res) => {
          this.dataAcquisitionLoading = false;
          if (res.code != 200) {
            return;
          }
          this.dataAcquisitionInfoNew = this.HaveJson(res.data);
          // 对数采回来的值进行处理
          this.handleDataAcquisition(res.data);
        }).catch(err => {
          this.dataAcquisitionLoading = false;
        });
      });
    },
    let itemIds = [];
    this.currentSample.insProduct.forEach((item) => {
      if (item.inspectionItemType === "1") {
        itemIds.push(item.id);
      }
    });
    const params = {
      entrustCode: this.insOrder.entrustCode,
      lotBatchNo: this.insOrder.lotBatchNo,
      sampleCode: this.currentSample.sampleCode,
      id: this.currentSample.id,
      itemIds: itemIds,
    };
    this.dataAcquisitionLoading = true;
    dataCollection(params).then((res) => {
      this.dataAcquisitionLoading = false;
      if (res.code != 200) {
        return;
      }
      this.dataAcquisitionInfoNew = this.HaveJson(res.data);
      // 对数采回来的值进行处理
      this.handleDataAcquisition(res.data);
    }).catch(err => {
      this.dataAcquisitionLoading = false;
    });
  },
    objectOrder(obj) {
      let newkey = Object.keys(obj).sort();
      let newObj = {};
@@ -3155,9 +3118,6 @@
    goback() {
      this.$router.go(-1)
    }
  },
  destroyed() {
    disconnect()
  },
};
</script>