spring
7 天以前 646135b9c54d6ccf5d47af30bf208bdfe5005017
fix: 二维码内容简化,只传一个id。根据id查询详细信息。
已修改7个文件
236 ■■■■■ 文件已修改
src/api/product/outbound.ts 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/product/twist.ts 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/manifest.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/index/index.vue 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/outbound/index.vue 178 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/components/StatisticsModal.vue 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/monofil.vue 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/product/outbound.ts
@@ -10,6 +10,15 @@
      data: data,
    });
  },
  // 绞线二维码查询
  getTagByIdJx(params: { outPutId: string | number }) {
    return request<BaseResult<any>>({
      url: "/app/getTagByIdJx",
      method: "GET",
      data: params,
    });
  },
};
export default OutboundApi;
src/api/product/twist.ts
@@ -29,6 +29,15 @@
    });
  },
  // 拉丝二维码查询
  getTagByIdLs(params: { outPutId: string | number }) {
    return request<BaseResult<any>>({
      url: "/app/getTagByIdLs",
      method: "GET",
      data: params,
    });
  },
  addStrandedWireDish(data: any) {
    return request<BaseResult<any>>({
      url: "/app/addStrandedWireDish",
src/manifest.json
@@ -2,7 +2,7 @@
    "name" : "线缆上报",
    "appid" : "__UNI__F64E0A4",
    "description" : "",
    "versionName" : "1.0.22",
    "versionName" : "1.0.24",
    "versionCode" : "100",
    "transformPx" : false,
    /* 5+App特有相关 */
src/pages/index/index.vue
@@ -201,12 +201,12 @@
    url: "/pages/routingInspection/index",
    show: false,
  },
  // {
  //   icon: "/static/icons/log.png",
  //   title: "出库",
  //   url: "/pages/outbound/index",
  //   show: true,
  // },
  {
    icon: "/static/icons/log.png",
    title: "出库",
    url: "/pages/outbound/index",
    show: true,
  },
]);
// 加载访问统计数据
src/pages/outbound/index.vue
@@ -25,6 +25,18 @@
              <text class="outbound_item_value">{{ item.model || "-" }}</text>
            </view>
            <view class="outbound_item_row">
              <text class="outbound_item_label">重量:</text>
              <text class="outbound_item_value">{{ item.weight || "-" }} kg</text>
            </view>
            <view class="outbound_item_row">
              <text class="outbound_item_label">厂家:</text>
              <text class="outbound_item_value">{{ item.clienteleName || "-" }}</text>
            </view>
            <view class="outbound_item_row">
              <text class="outbound_item_label">段长:</text>
              <text class="outbound_item_value">{{ item.actuallyLength || "-" }} M</text>
            </view>
            <view class="outbound_item_row">
              <text class="outbound_item_label">生产日期:</text>
              <text class="outbound_item_value">{{ item.productionDate || "-" }}</text>
            </view>
@@ -68,121 +80,9 @@
  return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
};
// 解析扫码内容
const parseScanCode = (scanCode: string) => {
  try {
    // 第一次解析:解析外层JSON
    const outerParsed = JSON.parse(scanCode);
    // 如果外层有 code 字段,且是字符串,需要再次解析
    let innerData = null;
    if (outerParsed.code && typeof outerParsed.code === "string") {
      try {
        const innerParsed = JSON.parse(outerParsed.code);
        // 查找所有数字key(如 "12480"),这个数字key就是id
        const keys = Object.keys(innerParsed);
        // 找到所有数字key,排除 "code" 字段
        const numberKeys = keys.filter((key) => !isNaN(Number(key)) && key !== "code");
        if (numberKeys.length > 0) {
          // 取第一个数字key(这个就是id)
          const dataKey = numberKeys[0];
          const idValue = Number(dataKey); // 数字key就是id值
          // 提取数字key对应的数据对象
          const extractedData = innerParsed[dataKey];
          if (extractedData) {
            innerData = { ...extractedData }; // 复制数据对象
            // 确保数据对象中有id字段,如果没有则使用数字key作为id
            if (!innerData.id) {
              innerData.id = idValue;
            }
          }
        } else {
          // 如果没有数字key,尝试直接使用对象(排除 code 字段)
          const { code, ...rest } = innerParsed;
          if (Object.keys(rest).length > 0) {
            innerData = rest;
          }
        }
      } catch (e) {
        console.error("内层JSON解析失败:", e);
      }
    } else {
      // 如果没有 code 字段,直接使用外层数据
      innerData = outerParsed;
    }
    // 如果 innerData 仍然为空,尝试直接解析
    if (!innerData) {
      innerData = outerParsed;
    }
    // 如果 innerData 仍然包含数字key结构(如 { "12480": {...}, "code": "..." }),需要再次提取
    if (innerData && typeof innerData === "object" && !innerData.id && !innerData.contractno) {
      const keys = Object.keys(innerData);
      const numberKeys = keys.filter((key) => !isNaN(Number(key)) && key !== "code");
      if (numberKeys.length > 0) {
        const dataKey = numberKeys[0];
        const extractedData = innerData[dataKey];
        if (extractedData) {
          innerData = { ...extractedData };
        }
      }
    }
    // 提取数据字段(根据二维码实际字段名统一)
    const data = {
      id: innerData?.id,
      contractNo: innerData?.contractno,
      batchNo: innerData?.monofilamentnumber,
      model: innerData?.model,
      weight: innerData?.actuallyweight,
      productionDate: innerData?.producttime,
      projectId: innerData?.projectid,
      // 保留原始数据(保存提取后的数据对象)
      rawData: innerData,
      scanCode: scanCode,
    };
    // 如果扫码数据中有 projectId,保存它
    if (data.projectId && !projectId.value) {
      projectId.value = data.projectId;
    }
    return data;
  } catch (error) {
    console.error("JSON解析失败:", error);
    // 如果不是JSON,尝试按逗号分割(可能是CSV格式)
    const parts = scanCode.split(",");
    if (parts.length >= 5) {
      return {
        id: parts[0] || "-", // 假设第一个是id
        contractNo: parts[1] || "-",
        batchNo: parts[2] || "-",
        model: parts[3] || "-",
        weight: parts[4] || "-",
        productionDate: parts[5] || "-",
        projectId: projectId.value || "-",
        scanCode: scanCode,
      };
    }
    // 如果都无法解析,返回原始字符串
    return {
      id: scanCode, // 使用原始字符串作为id
      contractNo: scanCode,
      batchNo: "-",
      model: "-",
      weight: "-",
      productionDate: "-",
      projectId: projectId.value || "-",
      scanCode: scanCode,
    };
  }
};
// 扫码回调
const getScanCode = (code: any) => {
const getScanCode = async (code: any) => {
  try {
  // 如果 code 是对象且有 code 字段,使用 code.code;否则直接使用 code
  let scanCode = code.code || code;
@@ -201,27 +101,57 @@
    return;
  }
  // 解析扫码内容
  const parsedData = parseScanCode(scanCode);
    // 解析扫码数据,现在二维码只包含id
    let scanData;
    try {
      scanData = JSON.parse(scanCode);
    } catch (e) {
      toast.error("二维码格式错误");
      return;
    }
  // 使用id作为唯一标识
  const uniqueId = parsedData.id;
    const outPutId = scanData.id;
  // 如果没有id,提示错误
  if (!uniqueId || uniqueId === "-" || uniqueId === null || uniqueId === undefined) {
    toast.error("扫码内容缺少唯一标识,无法添加");
    if (!outPutId) {
      toast.error("二维码格式错误,缺少id信息");
    return;
  }
  // 检查是否已存在(根据id判断)
  const exists = outboundList.value.some((item) => {
    const itemId = item.id;
    return itemId && itemId === uniqueId && itemId !== "-";
      return itemId && itemId === outPutId && itemId !== "-";
  });
  if (exists) {
    toast.error("该条码已存在,请勿重复扫码");
    return;
    }
    // 调用接口获取绞线详细信息
    const { data: tagData } = await OutboundApi.getTagByIdJx({
      outPutId: outPutId,
    });
    // 提取数据字段(根据接口返回的数据结构)
    const parsedData = {
      id: tagData?.id || outPutId,
      contractNo: tagData?.contractno || tagData?.contractNo || "-",
      batchNo: tagData?.systemno || tagData?.systemNo || tagData?.batchNo || "-",
      model: tagData?.model || "-",
      weight: tagData?.actuallyweight || tagData?.actuallyWeight || tagData?.weight || "-",
      clienteleName: tagData?.clientelename || tagData?.clienteleName || "-",
      actuallyLength: tagData?.actuallylength || tagData?.actuallyLength || "-",
      productionDate: tagData?.producttime || tagData?.productionDate || "-",
      projectId: tagData?.projectid || tagData?.projectId || projectId.value || "",
      // 保留原始数据
      rawData: tagData,
      scanCode: scanCode,
    };
    // 如果接口返回的数据中有 projectId,保存它
    if (parsedData.projectId && !projectId.value) {
      projectId.value = parsedData.projectId;
  }
  // 添加到列表
@@ -232,6 +162,10 @@
  outboundList.value.push(newItem);
  toast.success("扫码成功");
  } catch (error: any) {
    console.error("扫码处理失败:", error);
    toast.error(error.msg || "二维码异常,请更换二维码!");
  }
};
// 触发扫码
src/pages/production/twist/components/StatisticsModal.vue
@@ -47,7 +47,7 @@
              </view>
              <view class="layer-details">
                <text class="detail-text">重量:{{ layer.weight.toFixed(2) }} kg</text>
                <text class="detail-text">长度:{{ layer.length.toFixed(2) }} M</text>
                <text class="detail-text">&nbsp;&nbsp;长度:{{ layer.length.toFixed(2) }} M</text>
              </view>
            </view>
          </view>
@@ -111,7 +111,7 @@
      node.strandedWireDish.forEach((item: any) => {
        stats[layerName].count++;
        stats[layerName].weight += parseFloat(item.actuallyWeight || 0);
        stats[layerName].length += parseFloat(item.amount || 0);
        stats[layerName].length += parseFloat(item.actuallyLength || 0);
      });
    }
  });
src/pages/production/twist/receive/monofil.vue
@@ -129,19 +129,31 @@
      return;
    }
    // 解析扫码数据
    // 解析扫码数据,现在二维码只包含id
    const scanData = JSON.parse(code.code);
    const outPutId = scanData.id;
    // 判断层级是否匹配
    if (scanData.layer && scanData.layer !== currentLayer.twistedLayer) {
    if (!outPutId) {
      toast.error("二维码格式错误,缺少id信息");
      return;
    }
    // 调用接口获取拉丝详细信息
    const { data: tagData } = await TwistApi.getTagByIdLs({
      outPutId: outPutId,
    });
    // 判断层级是否匹配(如果接口返回的数据中有layer字段)
    if (tagData.layer && tagData.layer !== currentLayer.twistedLayer) {
      toast.error(
        `领用层级不对,当前层是:${currentLayer.twistedLayer},领用单丝层是:${scanData.layer}`
        `领用层级不对,当前层是:${currentLayer.twistedLayer},领用单丝层是:${tagData.layer}`
      );
      // return;
    }
    // 调用单丝领用扫码接口
    const { data } = await TwistApi.getScarn({
      outPutId: scanData.id,
      outPutId: outPutId,
      twistId: currentLayer.twistId,
    });