@steedos-labs/plugin-workflow 3.0.93 → 3.0.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -96,11 +96,74 @@ window.waitForThing(window, 'socket').then(()=>{
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
// 监控箱列表轮询
|
|
100
|
+
// 只在 side_listview_id=monitor 路由下启用,仅刷新中间列表
|
|
101
|
+
const MONITOR_POLL_INTERVAL = 5 * 60 * 1000;
|
|
102
|
+
let monitorPollTimer = null;
|
|
103
|
+
let monitorPollStartedAt = 0;
|
|
104
|
+
let lastMonitorReloadAt = 0;
|
|
105
|
+
let monitorHiddenAt = null;
|
|
106
|
+
|
|
107
|
+
const reloadMonitorList = (reason) => {
|
|
108
|
+
lastMonitorReloadAt = Date.now();
|
|
109
|
+
console.log(LOG_PREFIX, `monitor poll: reloading list (${reason})`);
|
|
110
|
+
window.$(".list-view-btn-reload").click();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const startMonitorPoll = () => {
|
|
114
|
+
if (monitorPollTimer) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
stopMonitorPoll();
|
|
118
|
+
monitorPollStartedAt = Date.now();
|
|
119
|
+
console.log(LOG_PREFIX, `monitor poll: started (interval=${MONITOR_POLL_INTERVAL}ms)`);
|
|
120
|
+
monitorPollTimer = setInterval(() => {
|
|
121
|
+
if (document.hidden) return;
|
|
122
|
+
reloadMonitorList('interval');
|
|
123
|
+
}, MONITOR_POLL_INTERVAL);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const stopMonitorPoll = () => {
|
|
127
|
+
if (monitorPollTimer) {
|
|
128
|
+
clearInterval(monitorPollTimer);
|
|
129
|
+
monitorPollTimer = null;
|
|
130
|
+
monitorPollStartedAt = 0;
|
|
131
|
+
lastMonitorReloadAt = 0;
|
|
132
|
+
monitorHiddenAt = null;
|
|
133
|
+
console.log(LOG_PREFIX, 'monitor poll: stopped');
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const isMonitorRoute = (search) => search && search.indexOf('side_listview_id=monitor') >= 0;
|
|
138
|
+
|
|
139
|
+
document.addEventListener('visibilitychange', () => {
|
|
140
|
+
if (document.hidden) {
|
|
141
|
+
monitorHiddenAt = Date.now();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (monitorPollTimer && isMonitorRoute(window.location.search)) {
|
|
146
|
+
const now = Date.now();
|
|
147
|
+
const hiddenDuration = monitorHiddenAt ? now - monitorHiddenAt : 0;
|
|
148
|
+
const elapsedSinceRefresh = now - (lastMonitorReloadAt || monitorPollStartedAt || now);
|
|
149
|
+
if (hiddenDuration >= MONITOR_POLL_INTERVAL || elapsedSinceRefresh >= MONITOR_POLL_INTERVAL) {
|
|
150
|
+
reloadMonitorList('visible');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
monitorHiddenAt = null;
|
|
154
|
+
});
|
|
155
|
+
|
|
99
156
|
window.addEventListener('message', (event)=>{
|
|
100
157
|
const data = event.data;
|
|
101
158
|
// 判断是不是我们发的路由变化消息
|
|
102
159
|
if (data && data.type === 'ROUTE_CHANGE') {
|
|
103
160
|
console.log('📬 收到路由变化消息:', data);
|
|
161
|
+
|
|
162
|
+
// 离开 monitor 路由时停止轮询
|
|
163
|
+
if (!isMonitorRoute(data.search)) {
|
|
164
|
+
stopMonitorPoll();
|
|
165
|
+
}
|
|
166
|
+
|
|
104
167
|
if(data.path.startsWith('/app/approve_workflow/instances/view/')){
|
|
105
168
|
const recordId = _.last(_.split(data.path, '/'));
|
|
106
169
|
socket.emit(SocketCommands.subscribe, {
|
|
@@ -112,8 +175,13 @@ window.waitForThing(window, 'socket').then(()=>{
|
|
|
112
175
|
$(".steedos-workflow-reload-btn").trigger('click')
|
|
113
176
|
}
|
|
114
177
|
}
|
|
115
|
-
})
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// 进入 monitor 路由时启动轮询
|
|
181
|
+
if (isMonitorRoute(data.search)) {
|
|
182
|
+
startMonitorPoll();
|
|
183
|
+
}
|
|
116
184
|
}
|
|
117
185
|
}
|
|
118
186
|
});
|
|
119
|
-
})
|
|
187
|
+
})
|