yaowanxin
昨天 cb2a01ee7dea28a2661720060b03c41dc372acb5
src/views/business/inspectionTask/inspection.vue
@@ -141,7 +141,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">{{ dataAcquisitionEidtAble ? "关闭编辑" : "编辑数采"
            @click="dataAcquisitionEidtAble = !dataAcquisitionEidtAble,disconnect()">{{ dataAcquisitionEidtAble ? "关闭编辑" : "编辑数采"
            }}</el-button>
        </div>
      </div>
@@ -406,83 +406,92 @@
        <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">
     <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">
          <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">
            <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">
            <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)">
                  <el-option v-for="(item, index) in item.child[0].arr" :key="index" :filter-method="filterMethod"
                    :label="index + 1 + '^' + item.result" :value="index + '^' + item.result">
                  <el-option v-for="(subItem, subIndex) in item.child[0].arr" :key="index + '-' + subIndex" :filter-method="filterMethod"
                    :label="subIndex + 1 + '^' + subItem.result" :value="subIndex + '^' + subItem.result">
                    <span>{{
                      "序号:" +
                      (index + 1) +
                      (subIndex + 1) +
                      "," +
                      "结果:" +
                      item.result +
                      subItem.result +
                      "," +
                      "厚度:" +
                      item.thickness +
                      subItem.thickness +
                      "," +
                      "时间:" +
                      item.mergedDateTime
                      subItem.mergedDateTime
                    }}</span>
                  </el-option>
                </el-select>
                <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="j" :label="j + '^' + n">{{ n }}</el-checkbox>
                  <el-checkbox v-for="(n, j) in item.child[0].arr" :key="index + '-' + j + 'aaaaaa'" :label="j + '^' + n"
                  @change="handleGroupSelect(item.child[0], j, item.child[0].arr.length)" >{{ n }}</el-checkbox>
                </el-checkbox-group>
              </td>
            </tr>
            <tr v-for="(m, i) in item.child" v-show="i > 0" :key="i + 'bbbbbbbbbbbbbb'">
              <td>{{ m.name }}</td>
              <td style="text-align: left">
              </div>
            </td>
          </tr>
          <tr v-for="(m, i) in item.child" v-show="i > 0" :key="index + '-' + i + 'bbbbbbbbbbbbbb'">
            <td>{{ m.name }}</td>
            <td style="text-align: left">
              <!-- 添加容器 div -->
              <div class="data-collection-items">
                <el-select v-if="m.isShowSelect" v-model="m.getDataIndex1" :multiple-limit="m.maxNum" clearable
                  filterable multiple placeholder="请选择">
                  <el-option v-for="(item, index1) in m.arr" :key="index1" :label="index + 1 + '^' + item.result"
                    :value="index1 + '^' + item.result">
                  <el-option v-for="(subItem, index1) in m.arr" :key="index + '-' + index1 + 'cccccccc'"
                    :label="index1 + 1 + '^' + subItem.result" :value="index1 + '^' + subItem.result">
                    <span>{{
                      "序号:" +
                      (index1 + 1) +
                      "," +
                      "结果:" +
                      item.result +
                      subItem.result +
                      "," +
                      "厚度:" +
                      item.thickness +
                      subItem.thickness +
                      "," +
                      "时间:" +
                      item.mergedDateTime
                      subItem.mergedDateTime
                    }}</span>
                  </el-option>
                </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="j" :label="j + '^' + n">{{ n }}</el-checkbox>
                  <el-checkbox v-for="(n, j) in m.arr" :key="index + '-' + j + 'dddddddd'" :label="j + '^' + n"
                  @change="handleGroupSelect(m, j, m.arr.length)" >{{ n }}</el-checkbox>
                </el-checkbox-group>
              </td>
            </tr>
          </template>
        </table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dataGetDia = false">取 消</el-button>
        <el-button :loading="getDataIndexLoading" type="primary" @click="submitDataGet()">确 定</el-button>
      </span>
    </el-dialog>
              </div>
            </td>
          </tr>
        </template>
      </table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dataGetDia = false">取 消</el-button>
      <el-button :loading="getDataIndexLoading" type="primary" @click="submitDataGet()">确 定</el-button>
    </span>
  </el-dialog>
    <el-dialog :close-on-click-modal="false" :visible.sync="addCheck" title="指定报告审核人员" width="400px"
      @close="closeAddVerifyDia">
      <div class="body" style="display: flex; padding: 10px; align-items: center">
@@ -501,17 +510,23 @@
        <el-button :loading="reviewLoading" type="primary" @click="upInsReview(1)">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 添加不合格复测弹框-->
    <add-un-pass v-if="addUnPassDialog" ref="addUnPassDialog" :addUnPassDialog="addUnPassDialog"
      @resetAddUnPass="resetAddUnPass"></add-un-pass>
    <!-- 不合格处理弹框-->
    <UnPassDialog v-if="unPassDialog" ref="unPassDialog" :orderId="orderId" :unPassDialog="unPassDialog"
      @resetForm="resetForm"></UnPassDialog>
    <!-- 不合格复测弹框-->
    <InspectionWord v-if="unPassCheck" :inspectorList="inspectorList" :orderId="orderId"
                    :cableTag="temCableTag" :repetitionTag="repetitionTag"
      :rawMaterialTag="rawMaterialTag" :sonLaboratory="sonLaboratory" :state="state" :typeSource="typeSource"
      :unPassCheck="unPassCheck" @closeUnPassCheckDialog="closeUnPassCheckDialog" @refreshView="refreshView" />
    <!-- 进货验证弹框-->
    <purchase-verification v-if="purchaseDialog" ref="purchaseDialog" :orderId="orderId"
      :purchaseDialog="purchaseDialog" @resetPurchaseDialog="resetPurchaseDialog"></purchase-verification>
    <!--查看工时弹框-->
    <viewManHourDia ref="viewManHourDia" @submit="openAddVerifyDia"></viewManHourDia>
    <button @click="sss">连接串口</button>
  </div>
</template>
@@ -522,6 +537,8 @@
import AddUnPass from "../unpass/components/addUnPass.vue";
import InspectionWord from "./components/InspectionWord.vue";
import PurchaseVerification from "../unpass/components/PurchaseVerification.vue";
import {
  doInsOrder,
  getCableTag,
@@ -541,10 +558,11 @@
  delfile,
  inspectionOrderDetailsTaskSwitching
} from "@/api/business/inspectionTask.js";
import InspectionWorker from '../../../InspectionWorker.worker';
import DataWorker from '../../../DataWorker.worker';
import InspectionWorker from '@/workers/InspectionWorker.worker.js';
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',
@@ -582,6 +600,8 @@
        sampleName: null,
        state: null,
      },
      isSerialConnected: false, // 新增状态变量,串口连接状态
      serialPort: null, // 存储串口对象
      id: null,
      changeType: null,
      insOrder: {},
@@ -647,10 +667,18 @@
            {
              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
            },
          ],
        },
@@ -660,6 +688,10 @@
            {
              name: "截至波长",
              arr: [12, 13, 14, 15],
              // 初始化 getDataIndex1 为数组
              getDataIndex1: [],
              isShowSelect: false,
              maxNum: 5
            },
          ],
        },
@@ -792,6 +824,7 @@
    this.startWorker();
    // this.getList0() // 任务切换
    this.scrollInit();
    disconnect()
  },
  activated() {
    this.getTypeDicts(); // 获取紧急程度下拉框选项
@@ -871,8 +904,16 @@
  beforeDestroy() {
    // 在组件销毁前确保停止 Worker,避免内存泄漏
    this.stopWorker();
    disconnect();
    // 调用前先判断方法是否存在,避免报错
    if (this.closeSerialPort) {
      this.closeSerialPort();// 组件销毁前关闭串口
    }
  },
  methods: {
    sss() {
      console.log(this.$store.state.weightList) //
    },
    // 文件管理--开始
    getList() {
      this.tableLoading = true;
@@ -908,6 +949,22 @@
      }).catch(() => { });
    },
    // 文件管理--结束
    // 处理整组勾选逻辑的方法
    handleGroupSelect(childItem, clickedIndex, groupSize = 5) {
      if(groupSize == 6){
        groupSize = 6;
      }else{
        groupSize = 5;
      }
      // 计算所在组的起始索引
      const groupStartIndex = Math.floor(clickedIndex / groupSize) * groupSize;
      // 清空当前已选
      childItem.getDataIndex1 = [];
      // 遍历当前组的 groupSize 个元素,添加到选中列表
      for (let i = groupStartIndex; i < groupStartIndex + groupSize && i < childItem.arr.length; i++) {
        childItem.getDataIndex1.push(i + '^' + childItem.arr[i]);
      }
    },
    // 任务切换--开始
    getList0() {
@@ -1038,8 +1095,9 @@
        id: this.currentSample.id,
        type: this.type,
        laboratory: this.sonLaboratory,
        cableTag: "",
        cableTag: this.temCableTag,
        rawMaterialTag: this.rawMaterialTag,
        repetitionTag: this.repetitionTag,
      };
      this.$nextTick(() => {
        this.$refs.addUnPassDialog.getInsOrder(info);
@@ -1088,33 +1146,89 @@
      this.$refs.purchaseDialog.$refs["purchaseForm"].resetFields();
      this.purchaseDialog = false;
    },
    // 数据采集
    getDataAcquisitionDevice() {
      let itemIds = [];
      this.currentSample.insProduct.forEach((item) => {
        if (item.inspectionItemType === "1") {
          itemIds.push(item.id);
  getDataAcquisitionDevice() {
      (async () => {
        try {
          // 检查是否支持 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;
        });
      });
    },
    // getDataAcquisitionDevice() {
    //   if (this.isSerialConnected) {
    //     connect();
    //   }
    //   // return
    //   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;
    //   });
    // },
    // 假设存在一个方法用于更新串口连接状态
    // updateSerialConnectionStatus(status) {
    //   this.isSerialConnected = status;
    // },
    objectOrder(obj) {
      let newkey = Object.keys(obj).sort();
      let newObj = {};
@@ -1124,6 +1238,7 @@
      return newObj;
    },
    handleDataAcquisition(data, noDialog) {
      console.log(data);
      // 是否可以编辑数采数据
      if (this.dataAcquisitionEidtAble) {
        this.getDataType = 1;
@@ -1133,7 +1248,6 @@
      this.dataAcquisitionInfo = {};
      this.getData = [];
      for (let i in this.objectOrder(data)) {
        console.log("i---", i);
        let obj = {};
        if (i.includes("@")) {
          obj = {
@@ -1177,6 +1291,7 @@
              };
            }
            let list = this.tableList[0].arr;
            console.log(this.tableList[0]);
            // 循环页面列表信息,判断数采数据对应页面列表信息的检验项是哪个,并给当前检验项绑定设备信息
            list.forEach((item, index) => {
              let num0 = 0;
@@ -1242,8 +1357,9 @@
              } else {
                str0 = i + "," + j;
              }
            }
            };
            let list = this.tableList[0].arr;
            console.log(this.tableList[0]);
            let maxNum = 0;
            list.forEach((item, index) => {
              let num0 = 0;
@@ -1275,6 +1391,7 @@
                  }
                  let num = 0;
                  list[index].forEach((n) => {
                    // console.log(n.v.ps.value);
                    if (
                      n.v.ps &&
                      n.v.ps.value &&
@@ -1347,6 +1464,7 @@
      } else {
        // 如果都不存在,则,进入处理数采线程里去处理数据
        try {
          console.log(this.dataAcquisitionInfo);
          // 向 Worker 发送消息,开始处理逻辑
          this.getDataIndexLoading = false;
          this.dataGetDia = false;
@@ -1476,7 +1594,6 @@
    },
    // 保存湿度、温度数据
    subOtherForm(m, type) {
      console.log("m---", m);
      write({
        [type]: type === "remark" ? m : Number(m),
        id: this.insOrder.id,
@@ -1637,20 +1754,6 @@
        this.comparisonList = this.dictToValue(response.data);
      });
    },
    // 获取检验值为下拉时的下拉列表
    // selectEnumByCategoryOfSelect(val) {
    //   this.enumList = [];
    //   if (val === undefined || val === null) {
    //     return;
    //   }
    //   this.$axios
    //     .post(this.$api.enums.selectEnumByCategory, {
    //       category: val,
    //     })
    //     .then((res) => {
    //       this.enumList = res.data;
    //     });
    // },
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
@@ -2673,12 +2776,23 @@
          } else {
            param = this.param;
          }
          let isNoTestValue = ''
          for (let key in param) {
            if (param[key]) {
              if (param[key].insValue?.length === 0) {
                isNoTestValue = 1
              } else {
                isNoTestValue = ''
              }
            }
          }
          saveInsContext({
            param: JSON.stringify(param),
            currentTable: this.currentTable,
            sampleId: this.currentSample.id,
            orderId: this.orderId,
            sonLaboratory: this.sonLaboratory
            sonLaboratory: this.sonLaboratory,
            isNoTestValue: isNoTestValue
          }).then((res) => {
            this.$message.success("已保存");
          });
@@ -2877,6 +2991,9 @@
    goback() {
      this.$router.go(-1)
    }
  },
  destroyed() {
    disconnect()
  },
};
</script>
@@ -3150,4 +3267,16 @@
  max-width: 1000px;
  /* 设置最大宽度 */
}
.data-collection-items {
  display: flex;
  flex-wrap: wrap;
}
.data-collection-items .el-select,
.data-collection-items .el-checkbox {
  flex-basis: 20% ;
  box-sizing: border-box;
  padding: 5px 2%;
}
</style>