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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import { appService } from '@/api';
import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons';
import { message, Button } from 'antd';
import classNames from 'classnames';
import { debounce } from 'lodash';
import React, { useRef, useEffect, useState, useMemo } from 'react';
import backImg from '@/assets/images/demonstration/返回.png';
import arrowLeftImg from '@/assets/images/demonstration/左箭头.png';
import LoadPage from '@/components/LoadPage';
import icon1 from '@/assets/images/integration/taihu2/综合管控_arrow.png';
import icon2 from '@/assets/images/integration/taihu2/智慧应用_arrow.png';
import icon3 from '@/assets/images/integration/taihu2/支撑平台_arrow.png';
import useFullScreen from '../../demonstration/components/useFullScreen';
import defaultConfig from './data.json';
import styles from './index.less';
import Iframe from '../../demonstration/components/Iframe';
const boxWidth = 1920;
const boxHeight = 930;
const IntegrationTaihu = props => {
const [ref, isFullscreen, handleFullScreen, handleExitFullScreen] = useFullScreen(false);
const timer2 = useRef(null);
const timer3 = useRef(null);
const progressRef2 = useRef(0);
// 退出
const exit = () => {
if (isFullscreen) {
handleExitFullScreen && handleExitFullScreen();
} else {
handleFullScreen && handleFullScreen();
}
};
const [boxSize, setBoxSize] = useState({
scale: 1,
boxHeight: 930,
});
const [linkUrl, setLinkUrl] = useState('');
const [jumpLoading, setJumpLoading] = useState(false);
const [progressValue2, setProgressValue2] = useState(0);
const [showBackBtn, setShowBackBtn] = useState(true); // 是否显示iframe 返回按钮,三维平台用
const configName = '太湖集成配置文件';
const [configData, setConfigData] = useState(defaultConfig);
const jumpProgressStart = () => {
if (timer2.current) {
clearInterval(timer2.current);
timer2.current = null;
}
progressRef2.current = 0;
setProgressValue2(0);
timer2.current = setInterval(() => {
if (progressRef2.current < 97.5) {
progressRef2.current += 2.5;
setProgressValue2(progressRef2.current);
} else {
setProgressValue2(99);
timer2.current && clearInterval(timer2.current);
timer2.current = null;
}
}, 100);
};
const jumpProgressEnd = () => {
setProgressValue2(100);
timer2.current && clearInterval(timer2.current);
timer2.current = null;
};
const getData = async () => {
appService
.GetConfigJson({
config: configName,
})
.then(res => {
if (res.code === 0 && res.data) {
const data = JSON.parse(res.data) || defaultConfig;
setConfigData(data);
}
});
};
const onResize = () => {
if (ref?.current) {
const { clientWidth, clientHeight } = ref.current;
if (!boxWidth || !boxHeight) return;
const xScale = clientWidth / boxWidth;
const yScale = clientHeight / boxHeight;
const poor = clientHeight / clientWidth - boxHeight / boxWidth;
let n = Math.min(xScale, yScale);
let bHeight = boxHeight;
if (poor > 0.05) {
bHeight = boxHeight + 30;
}
// 高度为偶数
bHeight = parseInt(bHeight, 10);
if (bHeight % 2 !== 0) {
bHeight += 1;
}
n = Number(n.toFixed(4));
setBoxSize({
scale: n,
boxHeight: bHeight,
});
}
};
const handError = err => {
if (err) {
message.error(err);
}
setLinkUrl('');
setJumpLoading(false);
jumpProgressEnd();
};
const onMessageBack = data => {
if (!data?.type) return;
console.log('onMessageBack ~ data:', data);
switch (data?.type) {
// 页面加载完成
// 登录成功
case 'runAfterFirstMounted':
case 'loginSuccess':
jumpProgressEnd();
setTimeout(() => {
setJumpLoading(false);
}, 100);
break;
case 'loginError':
message.warning('登录失败,请联系管理人员');
handError();
break;
case '无法连接':
message.warning('该站点无法连接,请联系管理人员');
setTimeout(() => {
handError();
}, 100);
break;
case 'showBack':
setShowBackBtn(true);
break;
case 'hideBack':
setShowBackBtn(false);
break;
default:
break;
}
};
const iframeItem = useMemo(() => {
if (!linkUrl) return null;
return (
<>
<div className={classNames(!jumpLoading ? styles.scaleInCenter : styles.hide, 'animate__animated')}>
<Iframe linkUrl={linkUrl} onMessageBack={onMessageBack} />
</div>
</>
);
}, [linkUrl, jumpLoading]);
const startTiming = (time = 2) => {
if (timer3.current) {
clearInterval(timer3.current);
timer3.current = null;
}
timer3.current = setTimeout(() => {
setJumpLoading(false);
timer2.current && clearInterval(timer2.current);
timer2.current = null;
}, time * 1000);
};
const onLink = url => {
if (!url) return message.warning('未配置功能路径');
setJumpLoading(true);
jumpProgressStart();
setLinkUrl(url);
let time = 15;
if (!url.includes('user/noscret')) {
time = 4;
}
startTiming(time);
};
useEffect(() => {
getData();
window.addEventListener('resize', debounce(onResize, 300));
onResize();
return () => {
window.removeEventListener('resize', onResize);
timer2.current && clearInterval(timer2.current);
timer2.current = null;
timer3.current && clearInterval(timer3.current);
timer3.current = null;
};
}, []);
return (
<div className={classNames(styles.integrationTaihu, 'integrationTaihu')} ref={ref}>
{jumpLoading ? (
<div className={styles.integrationJumpLoad} key="jumpLoading">
<div style={{ width: '285px' }}>
<LoadPage percent={progressValue2 / 100} text="页面加载中~" />
</div>
</div>
) : null}
{!linkUrl ? (
<div className={styles.integrationTaihu_exit} onClick={exit}>
<Button type="text" style={{ color: '#fff', fontSize: '24px' }}>
{isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
</Button>
</div>
) : null}
<div
className={styles.integration_content}
style={{
width: boxWidth,
height: boxSize.boxHeight,
transform: `scale(${boxSize.scale}) translate(-50%,-50%)`,
}}
>
<div className={styles.integrationTaihu_title}>
{/* <div className={styles.integrationTaihu_title_left} /> */}
<div className={styles.integrationTaihu_title_text}>
<span>{configData?.['标题'] || '智慧水务综合监控平台'}</span>
</div>
{/* <div className={styles.integrationTaihu_title_right} /> */}
</div>
<div className={styles.integration_row} type="综合管控">
<div className={styles.integration_row_title} type="综合管控">
综合管控
<img src={icon1} alt="" />
</div>
<div className={styles.integration_row_list}>
<div className={styles.integration_row_grid} type="综合管控">
{configData['综合管控'] &&
configData['综合管控'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type="综合管控"
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text} type="综合管控">
{item.label || item.name}
</div>
<div className={styles.integration_row_col_sub}>{item.english || ''}</div>
</div>
</div>
))}
</div>
</div>
</div>
<div className={styles.integration_row} type="智慧应用">
<div className={styles.integration_row_title} type="智慧应用">
智慧应用
<img src={icon2} alt="" />
</div>
<div className={styles.integration_row_right2}>
<div className={styles.integration_row_list} type="智慧生产调度">
<div className={styles.integration_row_list_title} type="智慧生产调度">
- 智慧生产调度 -
</div>
<div className={styles.integration_row_grid} type="智慧生产调度">
{configData['智慧生产调度'] &&
configData['智慧生产调度'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type={item.name}
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text}>{item.label || item.name}</div>
</div>
</div>
))}
</div>
</div>
<div className={styles.integration_row_list_right}>
<div className={styles.integration_row_list} type="智慧管网管理">
<div className={styles.integration_row_list_title} type="智慧管网管理">
- 智慧管网管理 -
</div>
<div className={styles.integration_row_grid} type="智慧管网管理">
{configData['智慧管网管理'] &&
configData['智慧管网管理'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type={item.name}
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text}>{item.label || item.name}</div>
</div>
</div>
))}
</div>
</div>
<div className={styles.integration_row_list} type="智慧漏损控制">
<div className={styles.integration_row_list_title} type="智慧漏损控制">
- 智慧漏损控制 -
</div>
<div className={styles.integration_row_grid} type="智慧漏损控制">
{configData['智慧漏损控制'] &&
configData['智慧漏损控制'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type={item.name}
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text}>{item.label || item.name}</div>
{item.english ? (
<div className={styles.integration_row_col_sub}>
/ {item.english || ''}
</div>
) : null}
</div>
</div>
))}
</div>
</div>
</div>
</div>
</div>
<div className={styles.integration_row} type="支撑平台">
<div className={styles.integration_row_title} type="支撑平台">
支撑平台
<img src={icon3} alt="" />
</div>
<div className={styles.integration_row_right}>
<div className={styles.integration_row_list} type="数据支撑">
<div className={styles.integration_row_list_title} type="数据支撑">
- 数据支撑 -
</div>
<div className={styles.integration_row_grid} type="数据支撑">
{configData['数据支撑'] &&
configData['数据支撑'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type={item.name}
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text}>{item.label || item.name}</div>
</div>
</div>
))}
</div>
</div>
<div className={styles.integration_row_list} type="业务支撑">
<div className={styles.integration_row_list_title} type="业务支撑">
- 业务支撑 -
</div>
<div className={styles.integration_row_grid} type="业务支撑">
{configData['业务支撑'] &&
configData['业务支撑'].map(item => (
<div
key={item.name}
className={styles.integration_row_col}
type={item.name}
onClick={() => onLink(item.url)}
>
<div
className={classNames(
styles.integration_row_col_hover,
'animate__fadeIn animate__animated duration-100ms',
)}
/>
<div className={styles.integration_row_col_content} name={item.name}>
<div className={styles.integration_row_col_text}>{item.label || item.name}</div>
</div>
</div>
))}
</div>
</div>
</div>
</div>
</div>
{linkUrl && showBackBtn ? (
<div
className={classNames(styles.iframeExit, 'animate__animated', 'animate__fadeIn')}
onClick={() => setLinkUrl('')}
>
<div className={styles.iframeBackLeft}>
<img src={arrowLeftImg} alt="返回" />
</div>
<div className={styles.iframeExitIcon}>
<img src={backImg} alt="返回" />
返回
</div>
</div>
) : null}
{iframeItem}
</div>
);
};
export default IntegrationTaihu;