zouyu
2025-08-14 adacd2dc7ea6fd0c989b15f8f7beb06e69810d74
src/views/business/inspectionTask/inspection.vue
@@ -406,24 +406,24 @@
        <el-button :loading="submitLoading" type="primary" @click="submit()">确 定</el-button>
      </span>
    </el-dialog>
     <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false"
    :visible.sync="dataGetDia" title="数据采集" width="80%">
    <div>
      <table border="1" cellpadding="10" class="thermal-table">
        <tr>
          <td style="width: 120px">检验项分类</td>
          <td style="width: 120px">检验项</td>
          <td style="width: 120px">检验子项</td>
          <td>数采数据</td>
        </tr>
        <template v-for="(item, index) in getData">
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false"
      :visible.sync="dataGetDia" title="数据采集" width="80%">
      <div>
        <table border="1" cellpadding="10" class="thermal-table">
          <tr>
            <td :rowspan="item.child.length">{{ item.sortName }}</td>
            <td :rowspan="item.child.length">{{ item.faName }}</td>
            <td>{{ item.child[0].name }}</td>
            <td style="text-align: left">
              <!-- 添加容器 div -->
              <div class="data-collection-items">
            <td style="width: 120px">检验项分类</td>
            <td style="width: 120px">检验项</td>
            <td style="width: 120px">检验子项</td>
            <td>数采数据</td>
          </tr>
          <template v-for="(item, index) in getData">
            <tr>
              <td :rowspan="item.child.length">{{ item.sortName }}</td>
              <td :rowspan="item.child.length">{{ item.faName }}</td>
              <td>{{ item.child[0].name }}</td>
              <td style="text-align: left">
                <!-- 添加容器 div -->
                <div class="data-collection-items">
                <el-select v-if="item.child[0].isShowSelect" v-model="item.child[0].getDataIndex1"
                  :multiple-limit="item.child[0].maxNum" clearable filterable multiple placeholder="请选择"
                  @change="setData(item)">
@@ -447,7 +447,7 @@
                <el-checkbox-group v-if="!item.child[0].isShowSelect" v-model="item.child[0].getDataIndex1"
                  :max="item.child[0].maxNum">
                  <el-checkbox v-for="(n, j) in item.child[0].arr" :key="index + '-' + j + 'aaaaaa'" :label="j + '^' + n"
                  @change="handleGroupSelect(item.child[0], j)" >{{ n }}</el-checkbox>
                  @change="handleGroupSelect(item.child[0], j, item.child[0].arr.length)" >{{ n }}</el-checkbox>
                </el-checkbox-group>
              </div>
            </td>
@@ -478,7 +478,7 @@
                </el-select>
                <el-checkbox-group v-if="!m.isShowSelect" v-model="m.getDataIndex1" :max="m.maxNum">
                  <el-checkbox v-for="(n, j) in m.arr" :key="index + '-' + j + 'dddddddd'" :label="j + '^' + n"
                  @change="handleGroupSelect(m, j)" >{{ n }}</el-checkbox>
                  @change="handleGroupSelect(m, j, m.arr.length)" >{{ n }}</el-checkbox>
                </el-checkbox-group>
              </div>
            </td>
@@ -536,7 +536,7 @@
import AddUnPass from "../unpass/components/addUnPass.vue";
import InspectionWord from "./components/InspectionWord.vue";
import PurchaseVerification from "../unpass/components/PurchaseVerification.vue";
import { connect,disconnect } from "@/utils/connect.js";
import {
  doInsOrder,
@@ -561,6 +561,7 @@
import DataWorker from '@/workers/DataWorker.worker.js';
import html2canvas from "html2canvas";
import { mapGetters } from "vuex";
import { connect,disconnect,weightList } from "@/utils/connect.js";
import viewManHourDia from "@/views/business/inspectionTask/components/viewManHourDia.vue";
export default {
  name: 'Inspection',
@@ -598,6 +599,8 @@
        sampleName: null,
        state: null,
      },
      isSerialConnected: false, // 新增状态变量,串口连接状态
      serialPort: null, // 存储串口对象
      id: null,
      changeType: null,
      insOrder: {},
@@ -663,18 +666,10 @@
            {
              name: "1285nm~1330nm",
              arr: [12, 13, 14, 15],
              // 初始化 getDataIndex1 为数组
              getDataIndex1: [],
              isShowSelect: false,
              maxNum: 5
            },
            {
              name: "1525nm~1575nm",
              arr: [12, 13, 14, 15],
              // 初始化 getDataIndex1 为数组
              getDataIndex1: [],
              isShowSelect: false,
              maxNum: 5
            },
          ],
        },
@@ -684,10 +679,6 @@
            {
              name: "截至波长",
              arr: [12, 13, 14, 15],
              // 初始化 getDataIndex1 为数组
              getDataIndex1: [],
              isShowSelect: false,
              maxNum: 5
            },
          ],
        },
@@ -820,7 +811,6 @@
    this.startWorker();
    // this.getList0() // 任务切换
    this.scrollInit();
    disconnect()
  },
  activated() {
    this.getTypeDicts(); // 获取紧急程度下拉框选项
@@ -900,9 +890,16 @@
  beforeDestroy() {
    // 在组件销毁前确保停止 Worker,避免内存泄漏
    this.stopWorker();
    disconnect()
    disconnect();
    // 调用前先判断方法是否存在,避免报错
    if (this.closeSerialPort) {
      this.closeSerialPort();// 组件销毁前关闭串口
    }
  },
  methods: {
    sss() {
      console.log(this.$store.state.weightList) //
    },
    // 文件管理--开始
    getList() {
      this.tableLoading = true;
@@ -938,14 +935,19 @@
      }).catch(() => { });
    },
    // 文件管理--结束
  // 处理整组勾选逻辑的方法
    handleGroupSelect(childItem, clickedIndex) {
    // 处理整组勾选逻辑的方法
    handleGroupSelect(childItem, clickedIndex, groupSize = 5) {
      if(groupSize == 6){
        groupSize = 6;
      }else{
        groupSize = 5;
      }
      // 计算所在组的起始索引
      const groupStartIndex = Math.floor(clickedIndex / 5) * 5;
      const groupStartIndex = Math.floor(clickedIndex / groupSize) * groupSize;
      // 清空当前已选
      childItem.getDataIndex1 = [];
      // 遍历当前组的 5 个元素,添加到选中列表
      for (let i = groupStartIndex; i < groupStartIndex + 5 && i < childItem.arr.length; i++) {
      // 遍历当前组的 groupSize 个元素,添加到选中列表
      for (let i = groupStartIndex; i < groupStartIndex + groupSize && i < childItem.arr.length; i++) {
        childItem.getDataIndex1.push(i + '^' + childItem.arr[i]);
      }
    },
@@ -1130,33 +1132,59 @@
      this.$refs.purchaseDialog.$refs["purchaseForm"].resetFields();
      this.purchaseDialog = false;
    },
    // 数据采集
    getDataAcquisitionDevice() {
      // connect()
      // return
      let itemIds = [];
      this.currentSample.insProduct.forEach((item) => {
        if (item.inspectionItemType === "1") {
          itemIds.push(item.id);
  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);
        }
      });
      const params = {
        entrustCode: this.insOrder.entrustCode,
        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;
      })().then(() => {
        let itemIds = [];
        this.currentSample.insProduct.forEach((item) => {
          if (item.inspectionItemType === "1") {
            itemIds.push(item.id);
          }
        });
        const params = {
          entrustCode: this.insOrder.entrustCode,
          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) {
@@ -1287,7 +1315,6 @@
              }
            };
            let list = this.tableList[0].arr;
            console.log(this.tableList[0]);
            let maxNum = 0;
            list.forEach((item, index) => {
              let num0 = 0;
@@ -1392,7 +1419,6 @@
      } else {
        // 如果都不存在,则,进入处理数采线程里去处理数据
        try {
          console.log(this.dataAcquisitionInfo);
          // 向 Worker 发送消息,开始处理逻辑
          this.getDataIndexLoading = false;
          this.dataGetDia = false;
@@ -3199,11 +3225,11 @@
.data-collection-items {
  display: flex;
  flex-wrap: wrap;
  flex-wrap: wrap;
}
.data-collection-items .el-select,
.data-collection-items .el-checkbox {
  flex-basis: 20% ;
  flex-basis: 20% ;
  box-sizing: border-box;
  padding: 5px 2%;
}