tab.js
5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import React from 'react';
import { connect } from 'dva';
import { Icon as LegacyIcon } from '@ant-design/compatible';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { Tabs, Modal } from 'antd';
import IndexCenter from '@/routes/indexCenter/indexCenter';/* 首页 */
import TabComponent from '@/components/Tab/TabComponent';
import styles from '@/index.less';
import { sendWebSocketMessage } from '@/components/Common/commonFunc';
import { isNotEmptyObject, isNotEmptyArr } from '@/utils/utils'; /* 通用方法 */
/* 计算方案s */
const { confirm } = Modal;
const { TabPane } = Tabs;
function Tab({ dispatch, app }) {
const { panes } = app;
let paneType = '';
const tagArr = panes.filter(item => item.newRecordFlag !== undefined);
const tagLastKey = tagArr !== undefined && tagArr.length > 0 ? tagArr[tagArr.length - 1].key : '';
const tabpanes = panes.map((pane) => {
const bRecordFlagDisabled = (tagArr.length > 0 && pane.key !== tagLastKey);
const content = <IndexCenter />;
if (pane.paneType) {
paneType = <span><LegacyIcon type={pane.paneType} />{pane.title}</span>;
} else {
paneType = <span>{pane.title}</span>;
}
return (
<TabPane tab={paneType} closable={pane.paneType !== 'home'} disabled={bRecordFlagDisabled} key={pane.key} className={styles.tabPane}>
{content}
</TabPane>
);
});
const totalProps = {
tabpanes,
app,
onSaveCurrentPane: saveCurrentPane,
onRemove: removePane,
};
const handleSendSocketMessage = (flag, showType, sId, sendTo, msgInfo, param) => {
const { token } = app;
const sendws = handleSendWebSocketMsg;
if (isNotEmptyObject(token)) {
if (app.webSocket !== null && app.webSocket.readyState === WebSocket.OPEN) {
sendws(flag, showType, msgInfo, sId, sendTo, param);
} else {
dispatch({ type: 'app/createWebSocket', payload: { reStart: true, dispatch } });
setTimeout(() => {
sendws(flag, showType, msgInfo, sId, sendTo, param);
}, 30000);
}
}
};
const handleSendWebSocketMsg = (flag, showType, msgInfo, sId, sendTo, param) => {
const { webSocket, userinfo, currentPane } = app;
const { key } = currentPane;
sendWebSocketMessage(webSocket, key, flag, showType, userinfo.sId, msgInfo, sId, sendTo, param);
};
function saveCurrentPane(currentPane) {
dispatch({ type: 'app/saveCurrentPane', payload: { currentPane } });
}
const clearWebSocketMsg = (i) => {
const { userinfo } = app;
const { copyTo } = i;
if (isNotEmptyObject(copyTo)) {
const {
slaveData, srcFormRoute, copyOtherData, masterData, copyToDataSid,
} = copyTo;
const sIdArray = [...copyToDataSid || []];
if (!i?.checkedId) {
if (isNotEmptyObject(srcFormRoute) && srcFormRoute.includes('materialRequirementsPlanning')) { /* 物料需求计划用sWorkOrderMaterialId作为唯一键 */
if (isNotEmptyArr(copyOtherData) && copyOtherData[0]?.name === 'detail' && isNotEmptyArr(copyOtherData[0]?.data)) {
const slaveDetailData = copyOtherData[0].data;
slaveDetailData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
} else { /* 变更单、采购申请单 */
slaveData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
}
}
}
if (isNotEmptyObject(masterData) &&
isNotEmptyObject(masterData.sSrcSlaveId)) {
sIdArray.push(masterData.sSrcSlaveId);
}
if (Array.isArray(slaveData)) {
slaveData.forEach((item) => {
const redisKey = item.sSlaveId;
sIdArray.push(redisKey);
});
}
const sId = [...new Set(sIdArray)].filter(Boolean).toString();
handleSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
}
handleSendSocketMessage('release', 'noAction', i?.checkedId || '', userinfo.sId, null, null);
handleSendSocketMessage('release', 'noAction', i?.formId || '', userinfo.sId, null, null);
};
function removePane(changePanes, currentPane, removePane) {
const removeData = Array.isArray(removePane) ? removePane.filter(Boolean) : [];
if (removePane && removePane.length === 1 && removePane[0] && removePane[0].fromKey) {
const currentPaneNew = changePanes.find(item => item.key === removePane[0].fromKey);
if (currentPaneNew) {
currentPane = currentPaneNew;
}
}
if (removePane && removePane[0]) {
const isProductionScheduleTree = removePane[0].route.indexOf('systemPermission') > -1 ||
(removePane[0].route.indexOf('production') > -1);
if (isProductionScheduleTree) {
removeData.forEach((i) => {
clearWebSocketMsg(i);
});
dispatch({ type: 'app/removePane', payload: { changePanes, currentPane } });
return;
}
}
if (app.diffMap && removePane[0] && app.diffMap.get(removePane[0].key)) {
confirm({
icon: <ExclamationCircleOutlined />,
content: '内容未保存,是否离开?',
onOk() {
removeData.forEach((i) => {
clearWebSocketMsg(i);
});
dispatch({ type: 'app/removePane', payload: { changePanes, currentPane } });
},
onCancel() {
console.log('取消关闭');
},
});
} else {
removeData.forEach((i) => {
clearWebSocketMsg(i);
});
dispatch({ type: 'app/removePane', payload: { changePanes, currentPane } });
}
}
return (
<div style={{ height: '100%' }}>
<TabComponent {...totalProps} />
</div>
);
}
export default connect(({ app }) => ({ app }))(Tab);