diff --git a/src/mes/scheduledTasks/machineTasks/index.js b/src/mes/scheduledTasks/machineTasks/index.js index 20e706c..c35d9ef 100644 --- a/src/mes/scheduledTasks/machineTasks/index.js +++ b/src/mes/scheduledTasks/machineTasks/index.js @@ -34,27 +34,33 @@ import timeIcon from "../assets/time.png"; import { handleOeeBtnEent } from "./common/handlePause"; import { operationFetch } from "../../productionExec/productionExecMain/operationFetch"; - + // 业务层 const useInfoEvent = props => { const { formData } = props; const [refreshCount, setRefreshCount] = useState(0); - + const [isRefreshing, setIsRefreshing] = useState(false); + useEffect( async () => { if (commonUtils.isNotEmptyArr(formData)) { - const colunmData = handleGetColumnData(formData, true); - const result = await handleGetData(formData, true); - const addState = { - ...colunmData, - ...result - }; - props.onSaveState(addState); + setIsRefreshing(true); + try { + const colunmData = handleGetColumnData(formData, true); + const result = await handleGetData(formData, true); + const addState = { + ...colunmData, + ...result + }; + props.onSaveState(addState); + } finally { + setIsRefreshing(false); + } } }, [formData, refreshCount] ); - + // 获取表头数据 const handleGetColumnData = (formData = [], isWait) => { let addState = {}; @@ -73,20 +79,20 @@ props.onSaveState(addState); } }; - + // 获取数据集 const handleGetData = async (formData = [], isWait, filter) => { let addState = {}; for (let i = 0; i < formData.length; i++) { const config = formData[i]; if (!config) continue; - + const conditonValues = props.onGetSqlConditionValues(config); - + if (config.sSqlStr === "Sp_OEE_ProductionReport") { conditonValues.sMachineId_s_pro = props.app.sMachineNameSId; } - + // 前期生产或反馈问题表必须有非空过滤条件 if ( (i === 1 && Object.values(conditonValues).includes("")) || @@ -94,7 +100,7 @@ ) { continue; } - + const bFilter = []; if (filter) { Object.keys(filter).forEach(key => { @@ -105,7 +111,7 @@ }); }); } - + const result = (await props.onGetDataSet({ name: `slave${i}`, @@ -126,20 +132,20 @@ props.onSaveState(addState); } }; - + // 查询 const handleSearch = sWorkOrderNo => { handleGetData([formData[0]], false, { sWorkOrderNo }); }; - + // 开工事件 const handleStartWork = async params => { const { sModelsId, token, app } = props; const { name, record, config, tableData, iFlag, pauseValue } = params; const { sMachineId, sId, sSlaveId } = record; - + // /* 若设置了禁止跳单 选择数据不是第一条时进行提示 */ // const iIndex = app.systemData.findIndex(item => item.sName === "CkxNoSkip"); // if (iIndex > -1) { @@ -169,7 +175,7 @@ // props.getServiceError(dataReturn); // return; // } - + // 单据可以使用 const { startWorkConfig = {} } = config; const { sAssignField } = startWorkConfig; @@ -187,21 +193,21 @@ sParentId: record.sId, tCreateDate: new Date() }; - + const valuesNew = {}; valuesNew.data = []; valuesNew.data.push( commonBusiness.mergeData(name, "plc_machinedata", [rowData], []) ); - + if ((iFlag || Object.is(iFlag, 0)) && valuesNew.data[0]) { valuesNew.data[0].iFlag = iFlag; } - + if (pauseValue) { valuesNew.data[0].sWorkOrderChangeMemo = pauseValue; } - + const BtnSave = commonFunc.showMessage( app.commonConst, "BtnSave" @@ -214,10 +220,10 @@ sModelsId, bMachineTask: true }); - + return returnData; // if (commonUtils.isEmptyObject(returnData)) return; - + // props.onSaveState( // { // [`${name}SelectedRowKeys`]: [record.sId] @@ -240,17 +246,17 @@ // ); // this.props.onSaveCurrentState(slaveData, true, undefined, undefined, 1); }; - + // 更新工单状态 const handleUpdateStatus = async params => { const { doWorkState, record } = params; - + const { sModelsId, app } = props; - + const value = { plcMachinedata: record }; - + const url = `${ commonConfig.server_host }oee/doUpdateStatus/${doWorkState}?sModelsId=${sModelsId}&sMachineId=${ @@ -261,26 +267,26 @@ value, url )).data; - + if (returnData.code !== 1) { props.getServiceError(returnData); return false; } - + return true; }; - + // 监听机台任务选中行变化 const { slave0SelectedRowKeys = [], slave0Data = [], sModelsId } = props; useEffect( () => { if (!slave0Data.length) return; - + const globalData = commonUtils.convertStrToObj( localStorage.xlybusinessglobalData ); const { currentSelectedMachineTaskDataRow = {} } = globalData; - + // 当前选中行sId,默认取缓存数据 let currentSelectedRowKey = slave0SelectedRowKeys[0]; if ( @@ -292,14 +298,14 @@ if (!currentSelectedRowKey) { currentSelectedRowKey = slave0Data[0].sId; } - + // 默认选中第一行 if (!slave0SelectedRowKeys.length) { props.onSaveState({ slave0SelectedRowKeys: [currentSelectedRowKey] }); } - + // 将当前选中行保存到全局 props.dispatch({ type: "app/saveGlobalData", @@ -311,13 +317,13 @@ } } }); - + // 前期生产或反馈问题数据根据机台任务选中行变化 handleGetData(["", formData[1]], false); }, [slave0SelectedRowKeys[0], slave0Data.length] ); - + // 监听开工任务变化 useEffect( () => { @@ -333,14 +339,14 @@ }, [JSON.stringify(props.slave0Data)] ); - + // 刷新页面 const handleRefresh = () => { setRefreshCount(pre => pre + 1); }; - + const itemClickRef = useRef(); - + // 开工、暂停事件 const handleTableBtnClick = async item => { const { tableName, index, record, tableData, config, iFlag } = item; @@ -359,7 +365,7 @@ } // const iStar = index === 0 ? 1 : 2; const { iStar } = record; - + if (iStar === 1) { // 如果只剩一条数据,询问是暂停还是完工 if (tableData.length === 1) { @@ -383,7 +389,7 @@ return; } } - + // 开工中,走暂停接口 props.onSaveState({ taskConfirmModalVisible: true, @@ -434,7 +440,7 @@ } } }; - + // 更新机台状态 const handleUpdateProductionplan = async ({ item, iFlag, pauseValue }) => { const { app } = props; @@ -455,7 +461,7 @@ message.error(dataReturn.msg, 3); } }; - + return { ...props, // 其他对象 @@ -464,10 +470,11 @@ onStartWork: handleStartWork, // 开工事件 onRefresh: handleRefresh, // 刷新页面 onTableBtnClick: handleTableBtnClick, // 开工、暂停事件 - onUpdateProductionplan: handleUpdateProductionplan // 更新机台状态 + onUpdateProductionplan: handleUpdateProductionplan, // 更新机台状态 + isRefreshing }; }; - + /** * 暂停按钮 * @param {*} params @@ -482,7 +489,7 @@ ); await handleOeeBtnEent({ props, item }); }; - + const MachineTasks = baseProps => { const props = useInfoEvent(useCommonBase({ ...baseProps })); const { @@ -491,13 +498,14 @@ slave1Column, slave1Data = [], slave2Column, - slave2Data = [] + slave2Data = [], + isRefreshing // 新增:接收刷新loading状态 } = props; - + const bStartWork = commonUtils.getAppData("userinfo", "bStartWork"); - + const [isTableLoading, setTableLoading] = useState(false); - + // const BtnTableCopyTo.startWork // 开工按钮配置 const startWorkConfig = @@ -508,7 +516,7 @@ slave0Config?.gdsconfigformslave?.find( item => item.sControlName === "BtnTableCopyTo.pauseWork" ) || {}; - + // 表格业务 const [sSrcNo, setSSrcNo] = useState(""); // 顶部表格配置 @@ -516,21 +524,21 @@ ...commonBusiness.getTableTypes("slave0", props), tableProps: { onChange: () => {}, - loading: isTableLoading + loading: isTableLoading || isRefreshing }, tableBtnsConfig: params => { const { record, index } = params; const { iStar } = record; // const iStar = index === 0 ? 1 : 2; - + // const bStart = iStar === 1; // const bPause = iStar === 2; - + // 1 :开工状态(显示暂停) 2: 暂停状态(显示开工) 3: 完工状态(显示完工,灰色) // 开工:开工接口(现在)1:正常, -7:有开工,要有提示, -1: 错误提示 // -7 :完工: iFlag:3 (完工上一条) 暂停:iFlag:2 (暂停上一条) // 暂停:新接口 - + let showName, btnBgColor, sDefault; if (iStar === 1) { showName = "暂停"; @@ -543,16 +551,16 @@ btnBgColor = "#AAA"; sDefault = "${false}"; } - + if (!bStartWork) { sDefault = "${false}"; } - + return [ { showName, btnBgColor, sDefault, startWorkConfig, pauseWorkConfig }, { showName: "完工", btnBgColor: "#1890FF", sDefault } ]; - + // return [ // { // ...startWorkConfig, @@ -599,7 +607,7 @@ const tableQuery = () => { props.onSearch(sSrcNo); }; - + // 前期生产或反馈问题业务 const [issueType, setIssueType] = useState(4); const issueObj = slave1Column?.reduce((acc, item) => { @@ -611,15 +619,15 @@ } return acc; }, {}); - + let issue = []; - + if (issueObj) { issue = Object.keys(issueObj)?.map((key, i) => { return { name: key, items: issueObj[key], id: i }; }); } - + const component = id => { if (issue?.length > 0) { return ( @@ -647,7 +655,7 @@ ); } }; - + const [carouselData, setCarouselData] = useState([ { title: "暂无通告", @@ -655,35 +663,35 @@ id: 999 } ]); - + const { slave3Data = [] } = props; - + useEffect( () => { if (!slave3Data.length) return; - + const tempData = slave3Data.map((item, index) => ({ title: `车间通告${index + 1}`, content: item.sNoticeMemo, id: index })); - + setCarouselData(tempData); }, [slave3Data.length] ); - + // 设备信息业务 const slave2OneData = slave2Data[0] || {}; const { countMapJsON } = slave2OneData; const countMap = commonUtils.convertStrToObj(countMapJsON); - + const taskInfoData = {}; slave2Column?.forEach(obj => { taskInfoData[`${obj.dataIndex}Title`] = obj.title; taskInfoData[`${obj.dataIndex}Conent`] = countMap[obj.dataIndex]; }); - + return (
@@ -814,7 +822,7 @@
); }; - + const TaskConfirmModal = props => { const { taskConfirmModalVisible, @@ -823,7 +831,7 @@ slave0Config } = props; if (!taskConfirmModalVisible) return ""; - + const handleClose = () => { props.itemClickRef.current = null; props.onSaveState({ @@ -832,15 +840,15 @@ pauseCallback: null }); }; - + const [pauseValue, setPauseValue] = useState(""); - + const viewConfigs = slave0Config?.gdsconfigformslave.filter( item => item.sName === "sPausereason" ); const sIdRef = useRef(commonUtils.createSid()); - + const viewProps = { ...props, viewConfigs, @@ -853,7 +861,7 @@ setPauseValue(args[2].sPausereason); } }; - + return ( 提示!} @@ -893,7 +901,7 @@ iFlag: 4 }); // handleClose(); - }} + }} > 完工 @@ -938,10 +946,10 @@ ); }; - + // 全屏状态 const StatusBtnComponent = () => { - + const items = [ { key: "4", @@ -1029,17 +1037,17 @@ ] } ]; - + // 全屏 const handleMenuClick = item2 => { - const newObj = { + const newObj = { ...item2, item: item2.item }; window.$wkcFullStatus(newObj , true) }; - - + + return ( <>
@@ -1052,7 +1060,7 @@ ); }; - + // const MachineMessageComponent = ({ e , shutDown , minimize}) => { // const value = e.item?.props?.value || {}; // const { current: startTime } = useRef(moment().format("YYYY-MM-DD HH:mm:ss")); @@ -1066,7 +1074,7 @@ // const getTime = () => { // const currentTimeNew = moment().format("YYYY-MM-DD HH:mm:ss"); // setCurrentTime(currentTimeNew); - + // const duration = moment.duration( // moment(currentTimeNew).diff(moment(startTime)) // ); @@ -1076,17 +1084,17 @@ // .split(".")[0]; // const minutes = (duration.asMinutes() % 60).toString().split(".")[0]; // const seconds = duration.asSeconds() % 60; - + // setDiffHours(hours); // setDiffMins(minutes); // setDiffSecs(seconds); // }; - + // getTime(); // const timer = setInterval(() => { // getTime(); // }, 1000); - + // // const handleMenuClose = () => { // // if (flagRef.current) return; // // flagRef.current++; @@ -1106,17 +1114,17 @@ // // } // // }); // // }; - + // // setInterval(() => { // // document.addEventListener("click", handleMenuClose); // // }, 1000); - + // return () => { // clearInterval(timer); // // document.removeEventListener("click", handleMenuClose); // }; // }, []); - + // const handleMenuClose = () => { // if (flagRef.current) return; // flagRef.current++; @@ -1137,7 +1145,7 @@ // } // }); // }; - + // return ( //
//
设备停机状态告知
@@ -1166,6 +1174,5 @@ //
// ); // }; - + export default MachineTasks; - \ No newline at end of file