feat(systemResource): 增加系统资源大屏显示
parent
c229615e66
commit
2b5b6b3894
Binary file not shown.
|
After Width: | Height: | Size: 403 B |
Binary file not shown.
|
After Width: | Height: | Size: 572 B |
@ -0,0 +1,38 @@
|
|||||||
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
|
|
||||||
|
const SystemResource = () => {
|
||||||
|
const iframeRef = useRef(null);
|
||||||
|
|
||||||
|
// 根据当前访问的 hostname 动态生成服务器 URL
|
||||||
|
const getServerUrl = () => {
|
||||||
|
const currentHostname = window.location.hostname;
|
||||||
|
|
||||||
|
// 如果是 localhost 或 127.0.0.1,使用固定的 IP
|
||||||
|
if (currentHostname === 'localhost' || currentHostname === '127.0.0.1') {
|
||||||
|
return 'http://192.168.5.119:5001/';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 否则使用当前的 IP 加 5001 端口
|
||||||
|
return `http://${currentHostname}:5001/`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const [serverUrl, setServerUrl] = useState(getServerUrl());
|
||||||
|
|
||||||
|
// 监听 URL 变化(如果需要动态更新)
|
||||||
|
useEffect(() => {
|
||||||
|
const handleLocationChange = () => {
|
||||||
|
setServerUrl(getServerUrl());
|
||||||
|
};
|
||||||
|
|
||||||
|
// 监听 popstate 事件(浏览器前进后退)
|
||||||
|
window.addEventListener('popstate', handleLocationChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('popstate', handleLocationChange);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <iframe width="100%" height="100%" frameBorder={0} src={serverUrl} ref={iframeRef} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SystemResource;
|
||||||
Loading…
Reference in New Issue