Commit 036bd08079b183d3547a615657c75ab5af32266f

Authored by Min
1 parent a1aad727

1.劲嘉---机台任务,完工按钮操作添加loading

src/mes/scheduledTasks/machineTasks/index.js
... ... @@ -34,27 +34,33 @@
34 34 import timeIcon from "../assets/time.png";
35 35 import { handleOeeBtnEent } from "./common/handlePause";
36 36 import { operationFetch } from "../../productionExec/productionExecMain/operationFetch";
37   -
  37 +
38 38 // 业务层
39 39 const useInfoEvent = props => {
40 40 const { formData } = props;
41 41 const [refreshCount, setRefreshCount] = useState(0);
42   -
  42 + const [isRefreshing, setIsRefreshing] = useState(false);
  43 +
43 44 useEffect(
44 45 async () => {
45 46 if (commonUtils.isNotEmptyArr(formData)) {
46   - const colunmData = handleGetColumnData(formData, true);
47   - const result = await handleGetData(formData, true);
48   - const addState = {
49   - ...colunmData,
50   - ...result
51   - };
52   - props.onSaveState(addState);
  47 + setIsRefreshing(true);
  48 + try {
  49 + const colunmData = handleGetColumnData(formData, true);
  50 + const result = await handleGetData(formData, true);
  51 + const addState = {
  52 + ...colunmData,
  53 + ...result
  54 + };
  55 + props.onSaveState(addState);
  56 + } finally {
  57 + setIsRefreshing(false);
  58 + }
53 59 }
54 60 },
55 61 [formData, refreshCount]
56 62 );
57   -
  63 +
58 64 // 获取表头数据
59 65 const handleGetColumnData = (formData = [], isWait) => {
60 66 let addState = {};
... ... @@ -73,20 +79,20 @@
73 79 props.onSaveState(addState);
74 80 }
75 81 };
76   -
  82 +
77 83 // 获取数据集
78 84 const handleGetData = async (formData = [], isWait, filter) => {
79 85 let addState = {};
80 86 for (let i = 0; i < formData.length; i++) {
81 87 const config = formData[i];
82 88 if (!config) continue;
83   -
  89 +
84 90 const conditonValues = props.onGetSqlConditionValues(config);
85   -
  91 +
86 92 if (config.sSqlStr === "Sp_OEE_ProductionReport") {
87 93 conditonValues.sMachineId_s_pro = props.app.sMachineNameSId;
88 94 }
89   -
  95 +
90 96 // 前期生产或反馈问题表必须有非空过滤条件
91 97 if (
92 98 (i === 1 && Object.values(conditonValues).includes("")) ||
... ... @@ -94,7 +100,7 @@
94 100 ) {
95 101 continue;
96 102 }
97   -
  103 +
98 104 const bFilter = [];
99 105 if (filter) {
100 106 Object.keys(filter).forEach(key => {
... ... @@ -105,7 +111,7 @@
105 111 });
106 112 });
107 113 }
108   -
  114 +
109 115 const result =
110 116 (await props.onGetDataSet({
111 117 name: `slave${i}`,
... ... @@ -126,20 +132,20 @@
126 132 props.onSaveState(addState);
127 133 }
128 134 };
129   -
  135 +
130 136 // 查询
131 137 const handleSearch = sWorkOrderNo => {
132 138 handleGetData([formData[0]], false, {
133 139 sWorkOrderNo
134 140 });
135 141 };
136   -
  142 +
137 143 // 开工事件
138 144 const handleStartWork = async params => {
139 145 const { sModelsId, token, app } = props;
140 146 const { name, record, config, tableData, iFlag, pauseValue } = params;
141 147 const { sMachineId, sId, sSlaveId } = record;
142   -
  148 +
143 149 // /* 若设置了禁止跳单 选择数据不是第一条时进行提示 */
144 150 // const iIndex = app.systemData.findIndex(item => item.sName === "CkxNoSkip");
145 151 // if (iIndex > -1) {
... ... @@ -169,7 +175,7 @@
169 175 // props.getServiceError(dataReturn);
170 176 // return;
171 177 // }
172   -
  178 +
173 179 // 单据可以使用
174 180 const { startWorkConfig = {} } = config;
175 181 const { sAssignField } = startWorkConfig;
... ... @@ -187,21 +193,21 @@
187 193 sParentId: record.sId,
188 194 tCreateDate: new Date()
189 195 };
190   -
  196 +
191 197 const valuesNew = {};
192 198 valuesNew.data = [];
193 199 valuesNew.data.push(
194 200 commonBusiness.mergeData(name, "plc_machinedata", [rowData], [])
195 201 );
196   -
  202 +
197 203 if ((iFlag || Object.is(iFlag, 0)) && valuesNew.data[0]) {
198 204 valuesNew.data[0].iFlag = iFlag;
199 205 }
200   -
  206 +
201 207 if (pauseValue) {
202 208 valuesNew.data[0].sWorkOrderChangeMemo = pauseValue;
203 209 }
204   -
  210 +
205 211 const BtnSave = commonFunc.showMessage(
206 212 app.commonConst,
207 213 "BtnSave"
... ... @@ -214,10 +220,10 @@
214 220 sModelsId,
215 221 bMachineTask: true
216 222 });
217   -
  223 +
218 224 return returnData;
219 225 // if (commonUtils.isEmptyObject(returnData)) return;
220   -
  226 +
221 227 // props.onSaveState(
222 228 // {
223 229 // [`${name}SelectedRowKeys`]: [record.sId]
... ... @@ -240,17 +246,17 @@
240 246 // );
241 247 // this.props.onSaveCurrentState(slaveData, true, undefined, undefined, 1);
242 248 };
243   -
  249 +
244 250 // 更新工单状态
245 251 const handleUpdateStatus = async params => {
246 252 const { doWorkState, record } = params;
247   -
  253 +
248 254 const { sModelsId, app } = props;
249   -
  255 +
250 256 const value = {
251 257 plcMachinedata: record
252 258 };
253   -
  259 +
254 260 const url = `${
255 261 commonConfig.server_host
256 262 }oee/doUpdateStatus/${doWorkState}?sModelsId=${sModelsId}&sMachineId=${
... ... @@ -261,26 +267,26 @@
261 267 value,
262 268 url
263 269 )).data;
264   -
  270 +
265 271 if (returnData.code !== 1) {
266 272 props.getServiceError(returnData);
267 273 return false;
268 274 }
269   -
  275 +
270 276 return true;
271 277 };
272   -
  278 +
273 279 // 监听机台任务选中行变化
274 280 const { slave0SelectedRowKeys = [], slave0Data = [], sModelsId } = props;
275 281 useEffect(
276 282 () => {
277 283 if (!slave0Data.length) return;
278   -
  284 +
279 285 const globalData = commonUtils.convertStrToObj(
280 286 localStorage.xlybusinessglobalData
281 287 );
282 288 const { currentSelectedMachineTaskDataRow = {} } = globalData;
283   -
  289 +
284 290 // 当前选中行sId,默认取缓存数据
285 291 let currentSelectedRowKey = slave0SelectedRowKeys[0];
286 292 if (
... ... @@ -292,14 +298,14 @@
292 298 if (!currentSelectedRowKey) {
293 299 currentSelectedRowKey = slave0Data[0].sId;
294 300 }
295   -
  301 +
296 302 // 默认选中第一行
297 303 if (!slave0SelectedRowKeys.length) {
298 304 props.onSaveState({
299 305 slave0SelectedRowKeys: [currentSelectedRowKey]
300 306 });
301 307 }
302   -
  308 +
303 309 // 将当前选中行保存到全局
304 310 props.dispatch({
305 311 type: "app/saveGlobalData",
... ... @@ -311,13 +317,13 @@
311 317 }
312 318 }
313 319 });
314   -
  320 +
315 321 // 前期生产或反馈问题数据根据机台任务选中行变化
316 322 handleGetData(["", formData[1]], false);
317 323 },
318 324 [slave0SelectedRowKeys[0], slave0Data.length]
319 325 );
320   -
  326 +
321 327 // 监听开工任务变化
322 328 useEffect(
323 329 () => {
... ... @@ -333,14 +339,14 @@
333 339 },
334 340 [JSON.stringify(props.slave0Data)]
335 341 );
336   -
  342 +
337 343 // 刷新页面
338 344 const handleRefresh = () => {
339 345 setRefreshCount(pre => pre + 1);
340 346 };
341   -
  347 +
342 348 const itemClickRef = useRef();
343   -
  349 +
344 350 // 开工、暂停事件
345 351 const handleTableBtnClick = async item => {
346 352 const { tableName, index, record, tableData, config, iFlag } = item;
... ... @@ -359,7 +365,7 @@
359 365 }
360 366 // const iStar = index === 0 ? 1 : 2;
361 367 const { iStar } = record;
362   -
  368 +
363 369 if (iStar === 1) {
364 370 // 如果只剩一条数据,询问是暂停还是完工
365 371 if (tableData.length === 1) {
... ... @@ -383,7 +389,7 @@
383 389 return;
384 390 }
385 391 }
386   -
  392 +
387 393 // 开工中,走暂停接口
388 394 props.onSaveState({
389 395 taskConfirmModalVisible: true,
... ... @@ -434,7 +440,7 @@
434 440 }
435 441 }
436 442 };
437   -
  443 +
438 444 // 更新机台状态
439 445 const handleUpdateProductionplan = async ({ item, iFlag, pauseValue }) => {
440 446 const { app } = props;
... ... @@ -455,7 +461,7 @@
455 461 message.error(dataReturn.msg, 3);
456 462 }
457 463 };
458   -
  464 +
459 465 return {
460 466 ...props,
461 467 // 其他对象
... ... @@ -464,10 +470,11 @@
464 470 onStartWork: handleStartWork, // 开工事件
465 471 onRefresh: handleRefresh, // 刷新页面
466 472 onTableBtnClick: handleTableBtnClick, // 开工、暂停事件
467   - onUpdateProductionplan: handleUpdateProductionplan // 更新机台状态
  473 + onUpdateProductionplan: handleUpdateProductionplan, // 更新机台状态
  474 + isRefreshing
468 475 };
469 476 };
470   -
  477 +
471 478 /**
472 479 * 暂停按钮
473 480 * @param {*} params
... ... @@ -482,7 +489,7 @@
482 489 );
483 490 await handleOeeBtnEent({ props, item });
484 491 };
485   -
  492 +
486 493 const MachineTasks = baseProps => {
487 494 const props = useInfoEvent(useCommonBase({ ...baseProps }));
488 495 const {
... ... @@ -491,13 +498,14 @@
491 498 slave1Column,
492 499 slave1Data = [],
493 500 slave2Column,
494   - slave2Data = []
  501 + slave2Data = [],
  502 + isRefreshing // 新增:接收刷新loading状态
495 503 } = props;
496   -
  504 +
497 505 const bStartWork = commonUtils.getAppData("userinfo", "bStartWork");
498   -
  506 +
499 507 const [isTableLoading, setTableLoading] = useState(false);
500   -
  508 +
501 509 // const BtnTableCopyTo.startWork
502 510 // 开工按钮配置
503 511 const startWorkConfig =
... ... @@ -508,7 +516,7 @@
508 516 slave0Config?.gdsconfigformslave?.find(
509 517 item => item.sControlName === "BtnTableCopyTo.pauseWork"
510 518 ) || {};
511   -
  519 +
512 520 // 表格业务
513 521 const [sSrcNo, setSSrcNo] = useState("");
514 522 // 顶部表格配置
... ... @@ -516,21 +524,21 @@
516 524 ...commonBusiness.getTableTypes("slave0", props),
517 525 tableProps: {
518 526 onChange: () => {},
519   - loading: isTableLoading
  527 + loading: isTableLoading || isRefreshing
520 528 },
521 529 tableBtnsConfig: params => {
522 530 const { record, index } = params;
523 531 const { iStar } = record;
524 532 // const iStar = index === 0 ? 1 : 2;
525   -
  533 +
526 534 // const bStart = iStar === 1;
527 535 // const bPause = iStar === 2;
528   -
  536 +
529 537 // 1 :开工状态(显示暂停) 2: 暂停状态(显示开工) 3: 完工状态(显示完工,灰色)
530 538 // 开工:开工接口(现在)1:正常, -7:有开工,要有提示, -1: 错误提示
531 539 // -7 :完工: iFlag:3 (完工上一条) 暂停:iFlag:2 (暂停上一条)
532 540 // 暂停:新接口
533   -
  541 +
534 542 let showName, btnBgColor, sDefault;
535 543 if (iStar === 1) {
536 544 showName = "暂停";
... ... @@ -543,16 +551,16 @@
543 551 btnBgColor = "#AAA";
544 552 sDefault = "${false}";
545 553 }
546   -
  554 +
547 555 if (!bStartWork) {
548 556 sDefault = "${false}";
549 557 }
550   -
  558 +
551 559 return [
552 560 { showName, btnBgColor, sDefault, startWorkConfig, pauseWorkConfig },
553 561 { showName: "完工", btnBgColor: "#1890FF", sDefault }
554 562 ];
555   -
  563 +
556 564 // return [
557 565 // {
558 566 // ...startWorkConfig,
... ... @@ -599,7 +607,7 @@
599 607 const tableQuery = () => {
600 608 props.onSearch(sSrcNo);
601 609 };
602   -
  610 +
603 611 // 前期生产或反馈问题业务
604 612 const [issueType, setIssueType] = useState(4);
605 613 const issueObj = slave1Column?.reduce((acc, item) => {
... ... @@ -611,15 +619,15 @@
611 619 }
612 620 return acc;
613 621 }, {});
614   -
  622 +
615 623 let issue = [];
616   -
  624 +
617 625 if (issueObj) {
618 626 issue = Object.keys(issueObj)?.map((key, i) => {
619 627 return { name: key, items: issueObj[key], id: i };
620 628 });
621 629 }
622   -
  630 +
623 631 const component = id => {
624 632 if (issue?.length > 0) {
625 633 return (
... ... @@ -647,7 +655,7 @@
647 655 );
648 656 }
649 657 };
650   -
  658 +
651 659 const [carouselData, setCarouselData] = useState([
652 660 {
653 661 title: "暂无通告",
... ... @@ -655,35 +663,35 @@
655 663 id: 999
656 664 }
657 665 ]);
658   -
  666 +
659 667 const { slave3Data = [] } = props;
660   -
  668 +
661 669 useEffect(
662 670 () => {
663 671 if (!slave3Data.length) return;
664   -
  672 +
665 673 const tempData = slave3Data.map((item, index) => ({
666 674 title: `车间通告${index + 1}`,
667 675 content: item.sNoticeMemo,
668 676 id: index
669 677 }));
670   -
  678 +
671 679 setCarouselData(tempData);
672 680 },
673 681 [slave3Data.length]
674 682 );
675   -
  683 +
676 684 // 设备信息业务
677 685 const slave2OneData = slave2Data[0] || {};
678 686 const { countMapJsON } = slave2OneData;
679 687 const countMap = commonUtils.convertStrToObj(countMapJsON);
680   -
  688 +
681 689 const taskInfoData = {};
682 690 slave2Column?.forEach(obj => {
683 691 taskInfoData[`${obj.dataIndex}Title`] = obj.title;
684 692 taskInfoData[`${obj.dataIndex}Conent`] = countMap[obj.dataIndex];
685 693 });
686   -
  694 +
687 695 return (
688 696 <div className={styles.tasksBox}>
689 697 <Row className={`tasksBg tasksTable`}>
... ... @@ -814,7 +822,7 @@
814 822 </div>
815 823 );
816 824 };
817   -
  825 +
818 826 const TaskConfirmModal = props => {
819 827 const {
820 828 taskConfirmModalVisible,
... ... @@ -823,7 +831,7 @@
823 831 slave0Config
824 832 } = props;
825 833 if (!taskConfirmModalVisible) return "";
826   -
  834 +
827 835 const handleClose = () => {
828 836 props.itemClickRef.current = null;
829 837 props.onSaveState({
... ... @@ -832,15 +840,15 @@
832 840 pauseCallback: null
833 841 });
834 842 };
835   -
  843 +
836 844 const [pauseValue, setPauseValue] = useState("");
837   -
  845 +
838 846 const viewConfigs = slave0Config?.gdsconfigformslave.filter(
839 847 item => item.sName === "sPausereason"
840 848 );
841 849  
842 850 const sIdRef = useRef(commonUtils.createSid());
843   -
  851 +
844 852 const viewProps = {
845 853 ...props,
846 854 viewConfigs,
... ... @@ -853,7 +861,7 @@
853 861 setPauseValue(args[2].sPausereason);
854 862 }
855 863 };
856   -
  864 +
857 865 return (
858 866 <Modal
859 867 title={<span style={{ fontSize: 22 }}>提示!</span>}
... ... @@ -893,7 +901,7 @@
893 901 iFlag: 4
894 902 });
895 903 // handleClose();
896   - }}
  904 + }}
897 905 >
898 906 完工
899 907 </Button>
... ... @@ -938,10 +946,10 @@
938 946 </Modal>
939 947 );
940 948 };
941   -
  949 +
942 950 // 全屏状态
943 951 const StatusBtnComponent = () => {
944   -
  952 +
945 953 const items = [
946 954 {
947 955 key: "4",
... ... @@ -1029,17 +1037,17 @@
1029 1037 ]
1030 1038 }
1031 1039 ];
1032   -
  1040 +
1033 1041 // 全屏
1034 1042 const handleMenuClick = item2 => {
1035   - const newObj = {
  1043 + const newObj = {
1036 1044 ...item2,
1037 1045 item: item2.item
1038 1046 };
1039 1047 window.$wkcFullStatus(newObj , true)
1040 1048 };
1041   -
1042   -
  1049 +
  1050 +
1043 1051 return (
1044 1052 <>
1045 1053 <div className={styles.statusBtn}>
... ... @@ -1052,7 +1060,7 @@
1052 1060 </>
1053 1061 );
1054 1062 };
1055   -
  1063 +
1056 1064 // const MachineMessageComponent = ({ e , shutDown , minimize}) => {
1057 1065 // const value = e.item?.props?.value || {};
1058 1066 // const { current: startTime } = useRef(moment().format("YYYY-MM-DD HH:mm:ss"));
... ... @@ -1066,7 +1074,7 @@
1066 1074 // const getTime = () => {
1067 1075 // const currentTimeNew = moment().format("YYYY-MM-DD HH:mm:ss");
1068 1076 // setCurrentTime(currentTimeNew);
1069   -
  1077 +
1070 1078 // const duration = moment.duration(
1071 1079 // moment(currentTimeNew).diff(moment(startTime))
1072 1080 // );
... ... @@ -1076,17 +1084,17 @@
1076 1084 // .split(".")[0];
1077 1085 // const minutes = (duration.asMinutes() % 60).toString().split(".")[0];
1078 1086 // const seconds = duration.asSeconds() % 60;
1079   -
  1087 +
1080 1088 // setDiffHours(hours);
1081 1089 // setDiffMins(minutes);
1082 1090 // setDiffSecs(seconds);
1083 1091 // };
1084   -
  1092 +
1085 1093 // getTime();
1086 1094 // const timer = setInterval(() => {
1087 1095 // getTime();
1088 1096 // }, 1000);
1089   -
  1097 +
1090 1098 // // const handleMenuClose = () => {
1091 1099 // // if (flagRef.current) return;
1092 1100 // // flagRef.current++;
... ... @@ -1106,17 +1114,17 @@
1106 1114 // // }
1107 1115 // // });
1108 1116 // // };
1109   -
  1117 +
1110 1118 // // setInterval(() => {
1111 1119 // // document.addEventListener("click", handleMenuClose);
1112 1120 // // }, 1000);
1113   -
  1121 +
1114 1122 // return () => {
1115 1123 // clearInterval(timer);
1116 1124 // // document.removeEventListener("click", handleMenuClose);
1117 1125 // };
1118 1126 // }, []);
1119   -
  1127 +
1120 1128 // const handleMenuClose = () => {
1121 1129 // if (flagRef.current) return;
1122 1130 // flagRef.current++;
... ... @@ -1137,7 +1145,7 @@
1137 1145 // }
1138 1146 // });
1139 1147 // };
1140   -
  1148 +
1141 1149 // return (
1142 1150 // <div className={styles.machineStatusContent} style={{ backgroundColor }}>
1143 1151 // <div className="conent1">设备停机状态告知</div>
... ... @@ -1166,6 +1174,5 @@
1166 1174 // </div>
1167 1175 // );
1168 1176 // };
1169   -
  1177 +
1170 1178 export default MachineTasks;
1171   -
1172 1179 \ No newline at end of file
... ...