import { getPendingList } from '@/services/message';
import { getComparisonData } from '@/services/OperationManagement';
import { queryConditionSnapshot } from '@/services/SmartOps';
import { getToken, UnityAction } from '@/utils/utils';
import { LoadingOutlined } from '@ant-design/icons';
import { connect, useParams, useRequest } from '@umijs/max';
import { Popover } from 'antd';
import dayjs from 'dayjs';
import { useEffect, useState } from 'react';
import { getScadaPage } from '../../services/OperationManagement';
import styles from './index.less';
const HomePage = (props) => {
const { projectId } = useParams();
const { data } = useRequest(queryConditionSnapshot, {
defaultParams: [{ project_id: projectId }],
pollingInterval: 10 * 1000,
});
const getPositionPst = (e) => {
const width = document.body.clientWidth;
const height = document.body.clientHeight;
const xPst = (e.clientX / width).toFixed(2);
const yPst = (e.clientY / height).toFixed(2);
return xPst + '-' + yPst;
};
const webMouseEvent = {
onMouseUp: (e) => {
UnityAction.sendMsg('PointerOut', getPositionPst(e));
},
onMouseDown: (e) => {
UnityAction.sendMsg('PointerIn', getPositionPst(e));
},
};
useEffect(() => {
localStorage.width = document.documentElement.getBoundingClientRect().width;
window.refreshRem();
document.body.style.backgroundColor = 'transparent';
}, []);
return (
);
};
const LeftContent = (props) => {
const { data } = props;
return (
{/* */}
{/* */}
);
};
const CenterContent = (props) => {
const { data } = props;
return (
{/*
*/}
);
};
const RightContent = (props) => {
const { data } = props;
return (
{/* */}
{/* */}
);
};
const getValue = (str) => {
const result = str?.match(/.*?(\d+(?:\.\d+)?)\D*$/);
if (result && result[1]) return result[1];
return 0;
};
// 水厂工况
const SmartWork = (props) => {
const { data } = props;
return (
UnityAction.sendMsg('menuItem', '工况管理')}
>
{data?.score}
{data?.grade}
当前运行{data?.grade},可继续优化
{dayjs(data?.clac_time).format('YYYY-MM-DD HH:mm')}
);
};
// 水量监测
const WaterAmt = (props) => {
const { data } = props;
const { projectId } = useParams();
return (
UnityAction.sendMsg('menuItem', '水量监测')}
>
当前进水稳定,出水稳定
-
{getValue(data?.fwa)}
进水量(m³/h)
-
{getValue(data?.dwa)}
产水量(m³/h)
);
};
// 水质监测
const WaterQuality = (props) => {
const { data } = props;
const { projectId } = useParams();
return (
UnityAction.sendMsg('menuItem', '水质监测')}
>
水质监测较好
-
{getValue(data?.dtds)}
外供水电导率(µs/cm)
-
{data?.dph || 0}
外供水(PH)
);
};
// 系统自检
const SelfInspection = connect(({ eqSelfInspection, loading }) => ({
autoReport: eqSelfInspection.autoReport,
loading: loading.models['eqSelfInspection'],
}))((props) => {
const { autoReport, dispatch, loading } = props;
const { projectId } = useParams();
const renderStatus = () => {
if (loading) return ;
if (autoReport.Status > 0) {
return (
异常
);
}
return (
正常
);
};
useEffect(() => {
dispatch({
type: 'eqSelfInspection/getAutoPatrol',
payload: {
projectId,
},
});
}, []);
return (
UnityAction.sendMsg('menuItem', '系统自检')}
>
{dayjs(autoReport.CreatedTime).format('YYYY-MM-DD HH:mm')}
{/*
自检中
*/}
{/*
{renderStatus()}
{dayjs(autoReport.CreatedTime).format('YYYY-MM-DD HH:mm')}
*/}
);
});
// 能耗监测
const Electric = (props) => {
const { data } = props;
const [open, setOpen] = useState(false);
const content = (
理论值规则:
分为高/中/低温3档,
高温为≥25℃,低温为<20℃,中温为≥20且<25℃
当前温度为近一天平均温度
);
return (
UnityAction.sendMsg('menuItem', '能耗监测')}
>
{
e.stopPropagation();
setOpen(!open);
}}
>
);
};
// 药耗监测
const Medicine = () => {
const { projectId } = useParams();
const time = dayjs().format('YYYY-MM');
const [open, setOpen] = useState(false);
const { data } = useRequest(getComparisonData, {
defaultParams: [
{
project_id: projectId,
start: time,
end: time,
type: 1,
flag: 1,
},
],
formatResult(res) {
return res[0];
},
});
const content = (
理论值规则:
分为高/中/低温3档,
高温为≥25℃,低温为<20℃,中温为≥20且<25℃
当前温度为近一天平均温度
);
return (
UnityAction.sendMsg('menuItem', '药耗监测')}
>
{
e.stopPropagation();
setOpen(!open);
}}
>
);
};
// 工艺监控
const Scada = () => {
const { projectId } = useParams();
const { data } = useRequest(getScadaPage, {
defaultParams: [{ project_id: projectId }],
formatResult: (res) => {
let domain = location.host.includes('pad.greentech.com.cn')
? 'https://metawant.greentech.com.cn/'
: 'http://47.96.12.136:8788/';
const token = getToken();
const pageList = res?.filter((item) => item.hide);
const urls = pageList.map(
(item) =>
`${domain}smart-water/scada/index.html#/3dview/${projectId}/${item.id}?JWT-TOKEN=${token}&hideTitle=true&pauseLoadRealTimeData=true`,
);
return urls.splice(0, 1);
},
});
return (
UnityAction.sendMsg('menuItem', '工艺监控')}
>
{data?.map((url) => (
))}
);
};
// 待办事项
const Backlog = (props) => {
const { projectId } = useParams();
const { data, loading } = useRequest(getPendingList, {
defaultParams: [{ project_id: projectId }],
});
const handleClick = (item) => {
if (item.type === 0) {
// task
UnityAction.sendMsg('OpenTaskModal', `mandate_id=${item.origin_id}`);
} else {
// order
UnityAction.sendMsg(
'OpenWorkOrderModal',
`order_id=${item.origin_id}&order_type=${item.origin_type}`,
);
}
};
return (
UnityAction.sendMsg('menuItem', '待办事项')}
>
待办事项} />
{data?.map((item) => (
{
e.stopPropagation();
handleClick(item);
}}
>
{dayjs(item.time).format('MM-DD HH:mm')}
{item.content}
))}
);
};
const Title = ({ title }) => {
return (
);
};
const Box = ({ title, children, onClick, small }) => {
return (
{/*
{title}
*/}
{children}
);
};
export default HomePage;