feat(inspection): 集成 Luckysheet 并优化检验任务功能
- 优化设备名称和编码的同步更新机制
已修改2个文件
138 ■■■■■ 文件已修改
public/index.html 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/business/inspectionTask/inspection.vue 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
public/index.html
@@ -230,12 +230,13 @@
        <div class="load_title">正在加载系统资源,请耐心等待</div>
      </div>
    </div>
    <!-- Luckysheet 必须先于自动注入的 Vue 应用脚本加载 -->
    <script src="<%= BASE_URL %>luckysheet/plugins/js/plugin.js"></script>
    <script src="<%= BASE_URL %>luckysheet/luckysheet.umd.js"></script>
  </body>
  <script
    type="text/javascript"
    src="http://192.168.21.53:9001/web-apps/apps/api/documents/api.js"
  ></script>
  <script src="<%= BASE_URL %>luckysheet/plugins/js/plugin.js"></script>
  <script src="<%= BASE_URL %>luckysheet/luckysheet.umd.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.16.105/pdf.min.js"></script>
</html>
src/views/business/inspectionTask/inspection.vue
@@ -310,7 +310,7 @@
                    <template v-else-if="
                      n.v.ps != undefined && n.v.ps.value === '设备名称'
                    ">
                      <el-select v-model="n.v.v" :disabled="state > 1" class="table_input" filterable multiple
                      <el-select v-model="n.v.v" :disabled="state > 1" class="table_input" filterable multiple clearable
                        placeholder="设备" remote @change="(val) => changeEquip(val, n)"
                        @visible-change="(e) => getEquipOptions(e, n.i)">
                        <el-option v-for="item in equipOptions" :key="item.value" :label="item.label"
@@ -1913,6 +1913,24 @@
    handleTableData() {
      this.excelMethodList = []; //excel函数列表
      this.widthList = this.tableList[0].style.columnlen; //页面宽度--根据模板来的
      // 对照接口返回的检验项模板 ID 与页面实际参与匹配的模板 ID。
      this.tableList.forEach((template) => {
        console.log("[templateId核对]", {
          sampleId: this.currentSample.id,
          currentTable: this.currentTable,
          templateName: template.templateName,
        });
        console.table(this.currentSample.insProduct.map((product) => ({
          检验项ID: product.id,
          检验项: product.inspectionItem,
          检验子项: product.inspectionItemSubclass,
          "检验项templateId(接口返回)": product.templateId,
          检验项ID类型: typeof product.templateId,
          "当前模板templateId": template.templateId,
          模板ID类型: typeof template.templateId,
          "是否一致(严格比较)": product.templateId === template.templateId,
        })));
      });
      // 本次循环主要做页面渲染层面的处理--单元格合并预处理
      this.tableList.forEach((a) => {
        let mcList = a.template.filter(
@@ -2117,6 +2135,37 @@
                count2++;
              }
              if (count2 == this.currentSample.insProduct.length) {
                console.warn("[模板行未匹配] 即将隐藏该行", {
                  sampleId: this.currentSample.id,
                  templateId: a.templateId,
                  templateName: a.templateName,
                  模板行号: b.r + 1,
                  模板拼接名称: str,
                  模板标记单元格: a.template
                    .filter((cell) => cell.r === b.r && cell.v.ps != undefined)
                    .map((cell) => ({
                      列号: cell.c + 1,
                      标记: cell.v.ps.value,
                      文字: cell.v.v,
                    })),
                });
                console.table(this.currentSample.insProduct
                  .filter((product) => product.templateId === a.templateId)
                  .map((product) => {
                    const name = [product.inspectionItemClass, product.inspectionItem,
                      product.inspectionItemSubclass]
                      .map((value) => value == null ? "" : value.replace(/\s*/g, ""))
                      .join("");
                    return {
                      检验项ID: product.id,
                      检验项分类: product.inspectionItemClass,
                      检验项: product.inspectionItem,
                      检验子项: product.inspectionItemSubclass,
                      接口拼接名称: name,
                      模板拼接名称: str,
                      名称是否一致: name === str,
                    };
                  }));
                dels.add(b.r);
              }
            }
@@ -2281,9 +2330,11 @@
      });
      // 本次循环主要是对页面及后端传参进行初始化赋值
      this.currentSample.insProduct.forEach(async (a) => {
        // 尚无检验结果时,保留前面初始化的空值。
        const savedResult = a.insProductResult || {};
        try {
          // 计算值赋值
          let comValue = JSON.parse(a.insProductResult.comValue);
          let comValue = JSON.parse(savedResult.comValue || "[]");
          for (var i = 0; i < comValue.length; i++) {
            if (
              this.param[a.id].comValue.find(
@@ -2308,7 +2359,7 @@
        } catch (e) { }
        try {
          // 检验值赋值
          let insValue = JSON.parse(a.insProductResult.insValue);
          let insValue = JSON.parse(savedResult.insValue || "[]");
          for (let i = 0; i < insValue.length; i++) {
            if (
              this.param[a.id].insValue.find(
@@ -2333,7 +2384,7 @@
        } catch (e) { }
        try {
          // 设备编号赋值
          let equipValue = JSON.parse(a.insProductResult.equipValue);
          let equipValue = JSON.parse(savedResult.equipValue || "[]");
          for (let i = 0; i < equipValue.length; i++) {
            // 普通设备赋值
            this.param[a.id].equipValue[i].v.v = equipValue[i].v;
@@ -2341,7 +2392,7 @@
        } catch (e) { }
        try {
          // 设备名称赋值
          let equipName = JSON.parse(a.insProductResult.equipName);
          let equipName = JSON.parse(savedResult.equipName || "[]");
          for (let i = 0; i < equipName.length; i++) {
            equipName[i].v !== "" &&
              equipName[i].v.map((val) => {
@@ -2934,53 +2985,37 @@
      }
    },
    // 设备改变
    changeEquip(val, n, v) {
      try {
        // this.$set(n.v,'v',val)
        this.tableList[0].arr.forEach((item, index) => {
          item.forEach((m, i) => {
            if (this.param[m.i]) {
              this.param[m.i].state = 1;
    changeEquip(val, n) {
      const itemParam = this.param[n.i];
      if (!itemParam) {
        this.$message.error("设备未关联检验项,请刷新页面后重试");
        return;
      }
      const selectedDevices = Array.isArray(val) ? [...val] : [];
      const deviceCodes = selectedDevices.join(",");
      this.$set(n.v, "v", selectedDevices);
      // 名称与编码单元格可能数量不同,分别更新,避免下标越界中断保存。
      (itemParam.equipName || []).forEach((cell) => {
        this.$set(cell.v, "v", [...selectedDevices]);
      });
      (itemParam.equipValue || []).forEach((cell) => {
        this.$set(cell.v, "v", deviceCodes);
      });
      this.tableList.forEach((table) => {
        (table.arr || []).forEach((row) => {
          row.forEach((cell) => {
            if (cell.i == n.i && cell.v.ps) {
              if (cell.v.ps.value === "设备名称") {
                this.$set(cell.v, "v", [...selectedDevices]);
              } else if (cell.v.ps.value === "设备编码") {
                this.$set(cell.v, "v", deviceCodes);
              }
            }
            // if(m.i==n.i&&m.v.ps&&m.v.ps.value=='设备名称'&&v){
            //   this.$set(m.v,'v',v)
            // }
          });
        });
        for (let i in this.param) {
          if (this.param[i].state != 1) {
            delete this.param[i];
          }
        }
        // this.equipOptions为设备名称下拉框选项数据
        for (let i1 in this.param[n.i].equipName) {
          if (
            this.param[n.i].equipName[i1].i === n.i &&
            this.param[n.i].equipName[i1].r === n.r
          ) {
            this.$delete(this.param[n.i].equipValue[i1].v, "v");
            // 将数组赋值给设备编码
            this.$set(this.param[n.i].equipValue[i1].v, "v", val.join(","));
            this.$delete(this.param[n.i].equipName[i1].v, "v");
            // 将数组赋值给设备编码
            this.$set(this.param[n.i].equipName[i1].v, "v", val);
            this.tableList[0].arr.forEach((item, index) => {
              item.forEach((m) => {
                if (m.i == n.i && m.v.ps && m.v.ps.value == "设备编码") {
                  this.$set(m.v, "v", val.join(","));
                }
                if (m.i == n.i && m.v.ps && m.v.ps.value == "设备名称") {
                  this.$set(m.v, "v", val);
                }
              });
            });
          }
        }
        // 保存数据
        this.saveInsContext(n.i);
      } catch (e) {
        console.log("changeEquip----", e);
      }
      });
      // 选择、移除、清空均由 change 事件触发,立即保存当前检验项。
      this.saveInsContext(n.i);
    },
    getAuthorizedPerson() {
      selectUserCondition({ type: 1 }).then((res) => {