Ben Lin
2025-01-01 3f3817a39238b262155cd5ec76fa351bb344602d
src/views/tigerprojects/mes/eng/route/index.vue
@@ -8,6 +8,8 @@
          @add-lf="handleAddlf"
          @select-node="handleSelect"
          @click-blank="clickBlank"
          @anchor-drop="AnchorDrop"
          @anchor-dragend="AnchorDragend"
          @init="init"
        />
      </LayoutContent>
@@ -110,12 +112,16 @@
  provide<Ref<MES_ROUTE>>('mesRoute', currRoute);
  const selectnode = ref({} as node);
  const currRotId = ref(route.params?.id);
  const prodCode = ref('');
  const custCode = ref('');
  const colSlots = ref<any>([]);
  const crudColSlots = ref<any>([]);
  const entityName = ref<any>('MES_POSITION');
  const props = defineProps({
    rotId: { type: String, default: '' },
    rotType: { type: String, default: 'Route' },
    prodCode: { type: String, default: '' },
    custCode: { type: String, default: '' },
  });
  const IsOperation = ref(false);
  const title = ref('');
@@ -123,10 +129,10 @@
  let _num = 1;
  let _numEdge = 1;
  watch(
    () => props.rotId,
    [() => props.rotId, () => props.prodCode, () => props.custCode],
    (v) => {
      if (!isNullOrEmpty(v) && v !== currRotId.value) {
        currRotId.value = v;
      if (!isNullOrEmpty(v[0]) && v[0] !== currRotId.value) {
        currRotId.value = v[0];
        if (!isNullOrUnDef(unref(currlf))) {
          unref(currlf).render({});
          routeData.value = {
@@ -135,6 +141,12 @@
          };
          init(currlf);
        }
      }
      if (!isNullOrEmpty(v[1]) && v[1] !== prodCode.value) {
        prodCode.value = v[1];
      }
      if (!isNullOrEmpty(v[2]) && v[2] !== custCode.value) {
        custCode.value = v[2];
      }
    },
    { deep: true },
@@ -165,6 +177,16 @@
      currRoute.value = _data.Data.route;
      if (!isNullOrEmpty(currRotId.value) && isNullOrEmpty(props.rotId)) {
        setTitle('设计:工艺路线-' + currRoute.value.ROT_CODE);
      }
      if (!isNullOrEmpty(prodCode.value)) {
        currRoute.value.PROD_CODE = !isNullOrEmpty(currRoute.value.PROD_CODE)
          ? currRoute.value.PROD_CODE
          : prodCode.value;
      }
      if (!isNullOrEmpty(custCode.value)) {
        currRoute.value.CUST_CODE = !isNullOrEmpty(currRoute.value.CUST_CODE)
          ? currRoute.value.CUST_CODE
          : custCode.value;
      }
      _data.Data.nodes.forEach((n) => {
        n.node.properties = JSON.parse(n.node.properties);
@@ -210,7 +232,7 @@
        AUTH_WH: '',
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
        CUST_CODE: '',
      },
      nodes: [],
      edges: [],
@@ -280,6 +302,15 @@
        });
        routeConfig.routeData.acts = _diffacts;
      } else {
        let _nodeName = '';
        switch (n.properties.operType) {
          case 'End':
            _nodeName = `${n.text.value}`;
            break;
          default:
            _nodeName = `${n.text.value}_${_num}`;
            break;
        }
        var _diffnodes = diffnodes.length > 0 ? diffnodes : routeConfig.routeData.nodes;
        _diffnodes.forEach((nd) => {
          if (nd.ID == n.id) {
@@ -290,10 +321,10 @@
              UPDATE_TIME: currRotData.route.UPDATE_TIME,
              UPDATE_USER: useUserStore().getUserInfo.userId as string,
              GHOST_ROW: false,
              NODE_NAME: isNullOrEmpty(nd.NODE_NAME) ? `${n.text.value}_${_num}` : nd.NODE_NAME,
              NODE_NAME: isNullOrEmpty(nd.NODE_NAME) ? _nodeName : nd.NODE_NAME,
              ROT_ID: currRotData.route.ID,
              SEGMENT: nd.SEGMENT,
              OPER_CODE: isNullOrEmpty(nd.OPER_CODE) ? n.type : nd.OPER_CODE,
              OPER_CODE: isNullOrEmpty(nd.OPER_CODE) ? n.properties.operCode : nd.OPER_CODE,
              GPH_TYPE: n.type,
              GPH_X: n.x,
              GPH_Y: n.y,
@@ -328,6 +359,8 @@
            if (unref(lf).getNodeIncomingNode(n.id).length == 0) {
              node.IS_FIRST_NODE = 'Y';
              nd.IS_FIRST_NODE = 'Y';
              node.IS_INPUT = 'Y';
              nd.IS_INPUT = 'Y';
            }
            currRotData.nodes.push(node);
          }
@@ -394,20 +427,34 @@
      });
    } else {
      var hasError = false;
      let msg = '';
      unref(lf)
        .getGraphData()
        .nodes.forEach((n) => {
          /* 判断是否有Node未连接 */
          if (
            unref(lf).getNodeIncomingEdge(n.id).length == 0 &&
            unref(lf).getNodeOutgoingEdge(n.id).length == 0
          ) {
            hasError = true;
            msg = '有节点未连线,请重新设计工艺路线再保存数据!';
          }
          if (
            unref(lf)
              .getNodeOutgoingNode(n.id)
              .some((q) => q.properties.operType == 'End') &&
            unref(lf)
              .getNodeOutgoingNode(n.id)
              .some((q) => q.properties.operType != 'End' && q.properties.operType != 'Action')
          ) {
            hasError = true;
            msg = '完工节点不是唯一的最后节点,请重新设计工艺路线再保存数据!';
          }
        });
      if (hasError) {
        createErrorModal({
          title: t('警告'),
          content: t('有节点未连线,请重新设计工艺路线再保存数据!'),
          content: t(msg),
          getContainer: () => document.body,
        });
      } else {
@@ -442,98 +489,162 @@
  function handleSelect(data, lf) {
    lf.graphModel.clearSelectElements();
    lf.graphModel.getNodeModelById(data.data.id).setSelected(true);
    let nnn = lf.graphModel.getNodeIncomingNode(data.data.id);
    selectnode.value = data.data;
    if (isNullOrUnDef(routeConfig.routeData)) {
      //先初始化routeData
      routeConfig.routeData = {};
      routeConfig.routeData.route = currRoute.value;
      routeConfig.routeData.nodes = [];
      routeConfig.routeData.edges = [];
      routeConfig.routeData.acts = [];
      //再返回具体数据
      routeConfig.routeData = GetRotData(lf);
    }
    var _node = routeConfig.routeData.nodes.filter((x) => x.ID == selectnode.value.id)[0];
    if (isNullOrUnDef(_node)) {
      _node = {
        ID: selectnode.value.id,
        CREATE_TIME: currRoute.value.CREATE_TIME,
        CREATE_USER: useUserStore().getUserInfo.userId as string,
        UPDATE_TIME: currRoute.value.UPDATE_TIME,
        UPDATE_USER: useUserStore().getUserInfo.userId as string,
        GHOST_ROW: false,
        NODE_NAME: `${selectnode.value.text.value}_${_num}`,
        ROT_ID: currRoute.value.ID,
        SEGMENT: '',
        OPER_CODE: selectnode.value.type,
        GPH_TYPE: selectnode.value.type,
        GPH_X: selectnode.value.x,
        GPH_Y: selectnode.value.y,
        GPH_PROP: '',
        GPH_TEXT: selectnode.value.text.value,
        IS_ACTIVE: 'Y',
        IS_CALC_FPY: 'N',
        CAN_SKIP: 'N',
        REMARK: '',
        AUTH_ORG: useUserStore().getUserInfo.orgCode,
        AUTH_PROD: '',
        AUTH_WH: '',
        IS_FIRST_NODE: '',
        ALLOW_DFT_IN: '',
        IS_INPUT: '',
        IS_OUTPUT: '',
        OPTION_1: '',
        OPTION_2: '',
        OPTION_3: '',
        OPTION_4: '',
        OPTION_5: '',
        node: {} as node,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
      };
      routeConfig.routeData.nodes.push(_node);
      _num++;
    }
    //是行为
    if (
      selectnode.value.properties['operType'] &&
      selectnode.value.properties['operType'] == 'Action'
      unref(lf)
        .getGraphData()
        .nodes.some((q) => q.properties.operCode == 'EndNode' && q.id != selectnode.value.id) &&
      selectnode.value.properties.operType == 'End'
    ) {
      var _act = routeConfig.routeData.acts.filter((x) => x.ID == selectnode.value.id)[0];
      routeConfig.activeKey = 2;
      IsOperation.value = false;
      title.value = '行为';
      posttitle.value = '';
      if (isNullOrUnDef(_act)) {
        _act = {
      lf.graphModel.deleteNode(selectnode.value.id);
      createErrorModal({
        title: t('警告'),
        content: t('已经存在完工节点,不能再拖入完工节点!'),
        getContainer: () => document.body,
      });
    } else {
      if (isNullOrUnDef(routeConfig.routeData)) {
        //先初始化routeData
        routeConfig.routeData = {};
        routeConfig.routeData.route = currRoute.value;
        routeConfig.routeData.nodes = [];
        routeConfig.routeData.edges = [];
        routeConfig.routeData.acts = [];
        //再返回具体数据
        routeConfig.routeData = GetRotData(lf);
      }
      var _node = routeConfig.routeData.nodes.filter((x) => x.ID == selectnode.value.id)[0];
      if (isNullOrUnDef(_node)) {
        let _nodeName = '';
        switch (selectnode.value.properties.operType) {
          case 'End':
            _nodeName = `${selectnode.value.text.value}`;
            break;
          default:
            _nodeName = `${selectnode.value.text.value}_${_num}`;
            break;
        }
        _node = {
          ID: selectnode.value.id,
          CREATE_TIME: currRoute.value.CREATE_TIME,
          CREATE_USER: useUserStore().getUserInfo.userId as string,
          UPDATE_TIME: currRoute.value.UPDATE_TIME,
          UPDATE_USER: useUserStore().getUserInfo.userId as string,
          GHOST_ROW: false,
          AUTH_ORG: useUserStore().getUserInfo.orgCode,
          AUTH_PROD: '',
          AUTH_WH: '',
          ACT_NAME: `${selectnode.value.text.value}_${_numEdge}`,
          ACT_CODE: '',
          NODE_NAME: _nodeName,
          ROT_ID: currRoute.value.ID,
          NODE_ID: '',
          ACT_TYPE: 0,
          SEGMENT: '',
          OPER_CODE: selectnode.value.properties.operCode,
          GPH_TYPE: selectnode.value.type,
          GPH_X: selectnode.value.x,
          GPH_Y: selectnode.value.y,
          GPH_PROP: JSON.stringify(selectnode.value.properties),
          GPH_TEXT: selectnode.value.text.value,
          NEED_SETUP: 'Y',
          NEED_RESET: 'N',
          // DO_TYPE: 0,
          // DO_METHOD: '',
          // DO_IF_PASS: '',
          // DO_IF_FAIL: '',
          IS_ACTIVE: '',
          IS_ACTIVE: 'Y',
          IS_CALC_FPY: 'N',
          CAN_SKIP: 'N',
          REMARK: '',
          AUTH_ORG: useUserStore().getUserInfo.orgCode,
          AUTH_PROD: '',
          AUTH_WH: '',
          IS_FIRST_NODE: '',
          ALLOW_DFT_IN: '',
          IS_INPUT: '',
          IS_OUTPUT: '',
          OPTION_1: '',
          OPTION_2: '',
          OPTION_3: '',
          OPTION_4: '',
          OPTION_5: '',
          node: {} as node,
          WORK_ORDER: currRoute.value.WORK_ORDER,
          PROD_CODE: currRoute.value.PROD_CODE,
          CUST_CODE: '',
        };
        routeConfig.routeData.nodes.push(_node);
        _num++;
      }
      //是行为
      if (
        selectnode.value.properties['operType'] &&
        selectnode.value.properties['operType'] == 'Action'
      ) {
        var _act = routeConfig.routeData.acts.filter((x) => x.ID == selectnode.value.id)[0];
        routeConfig.activeKey = 2;
        IsOperation.value = false;
        title.value = '行为';
        posttitle.value = '';
        if (isNullOrUnDef(_act)) {
          _act = {
            ID: selectnode.value.id,
            CREATE_TIME: currRoute.value.CREATE_TIME,
            CREATE_USER: useUserStore().getUserInfo.userId as string,
            UPDATE_TIME: currRoute.value.UPDATE_TIME,
            UPDATE_USER: useUserStore().getUserInfo.userId as string,
            GHOST_ROW: false,
            AUTH_ORG: useUserStore().getUserInfo.orgCode,
            AUTH_PROD: '',
            AUTH_WH: '',
            ACT_NAME: `${selectnode.value.text.value}_${_numEdge}`,
            ACT_CODE: '',
            ROT_ID: currRoute.value.ID,
            NODE_ID: '',
            ACT_TYPE: 0,
            GPH_TYPE: selectnode.value.type,
            GPH_X: selectnode.value.x,
            GPH_Y: selectnode.value.y,
            GPH_PROP: JSON.stringify(selectnode.value.properties),
            GPH_TEXT: selectnode.value.text.value,
            NEED_SETUP: 'Y',
            NEED_RESET: 'N',
            // DO_TYPE: 0,
            // DO_METHOD: '',
            // DO_IF_PASS: '',
            // DO_IF_FAIL: '',
            IS_ACTIVE: '',
            OPTION_1: '',
            OPTION_2: '',
            OPTION_3: '',
            OPTION_4: '',
            OPTION_5: '',
            REMARK: '',
            node: {} as node,
            WORK_ORDER: currRoute.value.WORK_ORDER,
            PROD_CODE: currRoute.value.PROD_CODE,
            CUST_CODE: '',
          };
          routeConfig.routeData.acts.push(_act);
          _numEdge++;
        }
        routeConfig.currentAct = {
          ID: selectnode.value.id,
          CREATE_TIME: currRoute.value.CREATE_TIME,
          CREATE_USER: useUserStore().getUserInfo.userId as string,
          UPDATE_TIME: currRoute.value.UPDATE_TIME,
          UPDATE_USER: useUserStore().getUserInfo.userId as string,
          GHOST_ROW: false,
          AUTH_ORG: _act.AUTH_ORG,
          AUTH_PROD: _act.AUTH_PROD,
          AUTH_WH: _act.AUTH_WH,
          ACT_NAME: _act.ACT_NAME,
          ACT_CODE: _act.ACT_CODE,
          ROT_ID: currRoute.value.ID,
          NODE_ID: _act.NODE_ID,
          ACT_TYPE: _act.ACT_TYPE,
          GPH_TYPE: selectnode.value.type,
          GPH_X: selectnode.value.x,
          GPH_Y: selectnode.value.y,
          GPH_PROP: JSON.stringify(selectnode.value.properties),
          GPH_TEXT: selectnode.value.text.value,
          NEED_SETUP: _act.NEED_SETUP,
          NEED_RESET: _act.NEED_RESET,
          // DO_TYPE: _act.DO_TYPE,
          // DO_METHOD: _act.DO_METHOD,
          // DO_IF_PASS: _act.DO_IF_PASS,
          // DO_IF_FAIL: _act.DO_IF_FAIL,
          IS_ACTIVE: _act.IS_ACTIVE,
          OPTION_1: '',
          OPTION_2: '',
          OPTION_3: '',
@@ -543,100 +654,60 @@
          node: {} as node,
          WORK_ORDER: currRoute.value.WORK_ORDER,
          PROD_CODE: currRoute.value.PROD_CODE,
          CUST_CODE: currRoute.value.CUST_CODE,
          CUST_CODE: '',
        };
        routeConfig.routeData.acts.push(_act);
        _numEdge++;
        const actModel = lf.getNodeModelById(selectnode.value.id);
        actModel.updateText(routeConfig.currentAct?.ACT_NAME);
      } else {
        //是工序
        IsOperation.value = false;
        routeConfig.currentItem = {
          ID: selectnode.value.id,
          CREATE_TIME: currRoute.value.CREATE_TIME,
          CREATE_USER: useUserStore().getUserInfo.userId as string,
          UPDATE_TIME: currRoute.value.UPDATE_TIME,
          UPDATE_USER: useUserStore().getUserInfo.userId as string,
          GHOST_ROW: false,
          AUTH_ORG: _node.AUTH_ORG,
          AUTH_PROD: _node.AUTH_PROD,
          AUTH_WH: _node.AUTH_WH,
          NODE_NAME: _node.NODE_NAME ?? '',
          ROT_ID: currRoute.value.ID,
          SEGMENT: _node.SEGMENT,
          OPER_CODE: selectnode.value.properties.operCode,
          GPH_TYPE: selectnode.value.type,
          GPH_X: selectnode.value.x,
          GPH_Y: selectnode.value.y,
          GPH_PROP: JSON.stringify(selectnode.value.properties),
          GPH_TEXT: selectnode.value.text.value,
          IS_ACTIVE: _node.IS_ACTIVE,
          IS_CALC_FPY: _node.IS_CALC_FPY,
          CAN_SKIP: _node.CAN_SKIP,
          IS_INPUT: _node.IS_INPUT,
          ALLOW_DFT_IN: _node.ALLOW_DFT_IN,
          IS_OUTPUT: _node.IS_OUTPUT,
          REMARK: _node.REMARK,
          WORK_ORDER: currRoute.value.WORK_ORDER,
          PROD_CODE: currRoute.value.PROD_CODE,
          CUST_CODE: '',
          node: {} as node,
        };
        const nodeModel = lf.getNodeModelById(selectnode.value.id);
        nodeModel.updateText(_node.NODE_NAME);
        routeConfig.isCalcFpy = _node.IS_CALC_FPY == 'Y';
        routeConfig.canSkip = _node.CAN_SKIP == 'Y';
        routeConfig.isActive = _node.IS_ACTIVE == 'Y';
        routeConfig.allowDftIn = _node.ALLOW_DFT_IN == 'Y';
        routeConfig.isInput = _node.IS_INPUT == 'Y';
        routeConfig.isOutput = _node.IS_OUTPUT == 'Y';
        setTimeout(() => {
          console.log(routeConfig.currentItem);
          routeConfig.activeKey = 2;
          IsOperation.value = true;
          title.value = '工序';
          posttitle.value = '岗位';
        }, 100);
      }
      routeConfig.currentAct = {
        ID: selectnode.value.id,
        CREATE_TIME: currRoute.value.CREATE_TIME,
        CREATE_USER: useUserStore().getUserInfo.userId as string,
        UPDATE_TIME: currRoute.value.UPDATE_TIME,
        UPDATE_USER: useUserStore().getUserInfo.userId as string,
        GHOST_ROW: false,
        AUTH_ORG: _act.AUTH_ORG,
        AUTH_PROD: _act.AUTH_PROD,
        AUTH_WH: _act.AUTH_WH,
        ACT_NAME: _act.ACT_NAME,
        ACT_CODE: _act.ACT_CODE,
        ROT_ID: currRoute.value.ID,
        NODE_ID: _act.NODE_ID,
        ACT_TYPE: _act.ACT_TYPE,
        GPH_TYPE: selectnode.value.type,
        GPH_X: selectnode.value.x,
        GPH_Y: selectnode.value.y,
        GPH_PROP: JSON.stringify(selectnode.value.properties),
        GPH_TEXT: selectnode.value.text.value,
        NEED_SETUP: _act.NEED_SETUP,
        NEED_RESET: _act.NEED_RESET,
        // DO_TYPE: _act.DO_TYPE,
        // DO_METHOD: _act.DO_METHOD,
        // DO_IF_PASS: _act.DO_IF_PASS,
        // DO_IF_FAIL: _act.DO_IF_FAIL,
        IS_ACTIVE: _act.IS_ACTIVE,
        OPTION_1: '',
        OPTION_2: '',
        OPTION_3: '',
        OPTION_4: '',
        OPTION_5: '',
        REMARK: '',
        node: {} as node,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
      };
      const actModel = lf.getNodeModelById(selectnode.value.id);
      actModel.updateText(routeConfig.currentAct?.ACT_NAME);
    } else {
      //是工序
      IsOperation.value = false;
      routeConfig.currentItem = {
        ID: selectnode.value.id,
        CREATE_TIME: currRoute.value.CREATE_TIME,
        CREATE_USER: useUserStore().getUserInfo.userId as string,
        UPDATE_TIME: currRoute.value.UPDATE_TIME,
        UPDATE_USER: useUserStore().getUserInfo.userId as string,
        GHOST_ROW: false,
        AUTH_ORG: _node.AUTH_ORG,
        AUTH_PROD: _node.AUTH_PROD,
        AUTH_WH: _node.AUTH_WH,
        NODE_NAME: _node.NODE_NAME ?? '',
        ROT_ID: currRoute.value.ID,
        SEGMENT: _node.SEGMENT,
        OPER_CODE: _node.OPER_CODE,
        GPH_TYPE: selectnode.value.type,
        GPH_X: selectnode.value.x,
        GPH_Y: selectnode.value.y,
        GPH_PROP: '',
        GPH_TEXT: selectnode.value.text.value,
        IS_ACTIVE: _node.IS_ACTIVE,
        IS_CALC_FPY: _node.IS_CALC_FPY,
        CAN_SKIP: _node.CAN_SKIP,
        IS_INPUT: _node.IS_INPUT,
        ALLOW_DFT_IN: _node.ALLOW_DFT_IN,
        IS_OUTPUT: _node.IS_OUTPUT,
        REMARK: _node.REMARK,
        WORK_ORDER: currRoute.value.WORK_ORDER,
        PROD_CODE: currRoute.value.PROD_CODE,
        CUST_CODE: currRoute.value.CUST_CODE,
        node: {} as node,
      };
      const nodeModel = lf.getNodeModelById(selectnode.value.id);
      nodeModel.updateText(_node.NODE_NAME);
      routeConfig.isCalcFpy = _node.IS_CALC_FPY == 'Y';
      routeConfig.canSkip = _node.CAN_SKIP == 'Y';
      routeConfig.isActive = _node.IS_ACTIVE == 'Y';
      routeConfig.allowDftIn = _node.ALLOW_DFT_IN == 'Y';
      routeConfig.isInput = _node.IS_INPUT == 'Y';
      routeConfig.isOutput = _node.IS_OUTPUT == 'Y';
      setTimeout(() => {
        console.log(routeConfig.currentItem);
        routeConfig.activeKey = 2;
        IsOperation.value = true;
        title.value = '工序';
        posttitle.value = '岗位';
      }, 100);
    }
  }
@@ -644,6 +715,50 @@
    unref(lfInstance).render({});
  }
  /**
   * @description: 拖动边放开时事件
   * @param {*} data
   * @param {*} lf
   * @return {*}
   */
  function AnchorDrop(data, lf) {
    let targetNode = lf.graphModel.getNodeModelById(data.edgeModel.targetNodeId);
    if (targetNode.properties['operType'] == 'End') {
      if (data.nodeModel.properties['operType'] == 'Action') {
        lf.graphModel.deleteEdgeById(data.edgeModel.id);
        createErrorModal({
          title: t('警告'),
          content: t('行为节点不能连接完工节点!'),
          getContainer: () => document.body,
        });
      } else {
        if (
          unref(lf).getNodeIncomingNode(data.nodeModel.id).length == 0 &&
          unref(lf)
            .getNodeOutgoingNode(data.nodeModel.id)
            .some((q) => q.properties.operType == 'Node')
        ) {
          lf.graphModel.deleteEdgeById(data.edgeModel.id);
          createErrorModal({
            title: t('警告'),
            content: t('开始节点不能直接连接完工节点!'),
            getContainer: () => document.body,
          });
        }
      }
    }
  }
  /**
   * @description: 锚点连线结束,不管是否创建连线都会触发。
   * @param {*} data
   * @param {*} e
   * @param {*} nodeModel
   * @param {*} lf
   * @return {*}
   */
  function AnchorDragend(data, e, nodeModel, lf) {}
  /*
   *点击画布事件
   */