index.js 2.4 KB
/*
 * @Author: Sakura
 * @LastEditors: Sakura
 * @Date: 2024-02-28 8:55:50
 * @Description: 路由组件配置界面
 */
import React, { useEffect, useState } from "react";
import * as commonUtils from "@/utils/utils";
import CommonModelComponent from "@/mes/common/commonModelComponent";
import MachineTasks from "@/mes/scheduledTasks/machineTasks";
import ProcessInstructionBook from "@/mes/scheduledTasks/processInstructionBook";
import PrenatalReminderInfo from "@/mes/scheduledTasks/prenatalReminderInfo";
import ProductionExecMain from "@/mes/productionExec/productionExecMain";
import AbnormalEventReporting from "@/mes/scheduledTasks/abnormalEventReporting";
import RunningStatus from "@/mes/common/RunningStatus";

// 枚举所有特殊定义页面
const types = {
  // 计划任务 ---- 机台任务
  machineTasks: ({ sModelsId, props }) => (
    <MachineTasks key={sModelsId} {...props} />
  ),
  // 计划任务 ---- 工艺作业指导书
  processInstructionBook: ({ sModelsId, props }) => (
    <ProcessInstructionBook key={sModelsId} {...props} />
  ),
  // 计划任务 ---- 产前提醒信息
  prenatalReminderInfo: ({ sModelsId, props }) => (
    <PrenatalReminderInfo key={sModelsId} {...props} />
  ),

  // 生产执行 ---- 生产执行
  productionExec: ({ sModelsId, props }) => (
    <ProductionExecMain key={sModelsId} {...props} />
  ),
  abnormalEventReporting: ({ sModelsId, props }) => (
    <AbnormalEventReporting key={sModelsId} {...props} />
  )
};

const RouterComponent = props => {
  const { sModelType = "", sModelsId } = props;
  const [keyId, setKeyId] = useState(sModelsId);
  const userinfo = commonUtils.getAppData("userinfo");
  const { bRefreshPage } = userinfo;

  useEffect(
    () => {
      if (sModelsId) {
        setKeyId(sModelsId);
      }
    },
    [sModelsId]
  );

  useEffect(
    () => {
      if (!bRefreshPage) return;
      setKeyId(commonUtils.createSid());
      props.dispatch({
        type: "app/saveUserinfo",
        payload: { ...userinfo, bRefreshPage: false }
      });
    },
    [bRefreshPage]
  );

  const selectedType = Object.keys(types).find(type =>
    sModelType?.includes(type)
  );

  if (selectedType) {
    return types[selectedType]({ sModelsId: keyId, props });
  } else if (sModelsId === "12710101117126502477360") {
    return <RunningStatus {...props} />;
  } else {
    return <CommonModelComponent key={keyId} {...props} />;
  }
};

export default RouterComponent;