spring
2025-11-13 bfbea958be8afe7e0522dc19f8a468eb35a3f9b9
src/pages/production/twist/receive/monofil.vue
@@ -79,7 +79,7 @@
import MonofilCard from "../components/MonofilCard.vue";
import StatisticsModal from "../components/StatisticsModal.vue";
import { useToast } from "wot-design-uni";
import { onLoad, onUnload } from "@dcloudio/uni-app";
import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import Scan from "@/components/scan/index.vue";
import ManageApi from "@/api/product/manage";
import TwistApi from "@/api/product/twist";
@@ -95,20 +95,21 @@
const showStatisticsModal = ref(false);
const showManualInput = ref(false);
const manualOutPutId = ref("");
const isPageVisible = ref(false); // 标记页面是否可见
// 监听标签切换
watch(tab, () => {
  if (tab.value) {
    console.log("tab.value:===========1", tab.value);
    getList();
  }
});
const getScanCode = async (code: any) => {
  console.log("自定义扫描的结果回调函数:", code);
  // let parseData = code.trim();
  console.log("code:===========", JSON.parse(code.code));
  console.log("id:=============", JSON.parse(code.code).id);
  // 检查页面是否可见,如果不可见则不处理扫码数据
  if (!isPageVisible.value) {
    return;
  }
  try {
    // 检查是否已选择标签
    if (!tab.value) {
@@ -117,13 +118,11 @@
    }
    // 找到当前选中的层
    console.log("tab.value:===========2", tab.value);
    const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
    if (!currentLayer) {
      toast.error("未找到当前选中的层");
      return;
    }
    console.log("tab.value:===========3", currentLayer);
    const { data } = await TwistApi.getScarn({
      outPutId: JSON.parse(code.code).id,
      twistId: currentLayer.twistId,
@@ -259,7 +258,6 @@
    // 设置默认第一层
    if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
      tab.value = nodeList.value[0].twistedLayer;
      console.log("设置默认第一层:", tab.value);
      // 设置默认标签后,加载第一层的数据
      getList();
    }
@@ -344,9 +342,21 @@
  getRootNumber(options.id);
  // getRootNumber(118);
});
onShow(() => {
  // 页面显示时标记为可见
  isPageVisible.value = true;
});
onHide(() => {
  // 页面隐藏时标记为不可见
  isPageVisible.value = false;
});
onUnload(() => {
  // 开启广播监听事件
  // 取消广播监听事件
  uni.$off("scanMono", getScanCode);
  isPageVisible.value = false;
});
</script>