tsg-web/src/views/gcaqjc/gcaqfx/jrx/index.js

308 lines
9.1 KiB
JavaScript
Raw Normal View History

2025-03-25 17:18:21 +08:00
import React, { useState, useEffect, useMemo, useRef } from 'react'
import { Table, Card, Button, message, Popconfirm,Spin } from 'antd';
2024-09-20 15:02:50 +08:00
import ToolBar from './toolbar';
import { useSelector } from 'react-redux';
import ReactEcharts from 'echarts-for-react';
import apiurl from '../../../../service/apiurl';
import { httppost2, httppost5 } from '../../../../utils/request';
import { exportFile } from '../../../../utils/tools.js';
import ListSelect from "../../../../components/Form/ListSelect1";
import './index.less'
import jrxOption from "./jrxOptions"
import { Rnd } from "react-rnd"
export default function Xmzlmb() {
2025-03-25 17:18:21 +08:00
const typeName = {
'大坝B0+130': '1',
'大坝B0+132': '2',
'大坝B0+250': '3',
'大坝B0+252': '4',
'大坝B0+370': '5',
'大坝B0+372': '6',
}
2024-09-20 15:02:50 +08:00
const role = useSelector(state => state.auth.role);
const [code, setCode] = useState([])
const [searchVal, setSearchVal] = useState({})
const [dataSources, setDateSources] = useState([])
const [dmList, setDmList] = useState([])
const [trData, setTrData] = useState([])
const [swiper, setSwiper] = useState(false)
const [timer, setTimer] = useState(100); // 定时器
2025-03-25 17:18:21 +08:00
const [dbType, setDbType] = useState('1');
const [dbType1, setDbType1] = useState('1');
const [loading, setLoading] = useState(false);
2024-09-20 15:02:50 +08:00
const echartsRef = useRef(null)
const jrxOptions = useMemo(() => {
2025-03-25 17:18:21 +08:00
if (dataSources && dbType && dbType1) {
return jrxOption(dataSources[0], dbType,dbType1)
2024-09-20 15:02:50 +08:00
} else {
return dataSources[0];
}
2025-03-25 17:18:21 +08:00
}, [dataSources, dbType,dbType1])
2024-09-20 15:02:50 +08:00
const columns = [
{ title: '序号', key: 'inx', dataIndex: 'inx', width: 60, align: "center" },
{ title: '时间', key: 'tm', dataIndex: 'tm', width: 150, align: "center" },
{ title: '库水位(m)', key: 'rz', dataIndex: 'rz', width: 150, align: "center" },
];
const zcColumns = [
{
title: '结果分析', key: 'status', dataIndex: 'status', width: 150, align: "center",
2025-03-25 17:18:21 +08:00
render: (rec, record) => <span style={!rec ? { color: "red" } : {}}>{rec == 1 ? "正常" : rec == 0 ? "异常" : ''}</span>
},
2024-09-20 15:02:50 +08:00
];
const columns1 = useMemo(() => {
2025-03-25 17:18:21 +08:00
if (trData.length > 0) {
let newCol = trData.map(s => ({
2024-09-20 15:02:50 +08:00
title: `${s}(m)`,
key: s,
dataIndex: s,
width: 150,
align: "center",
2025-03-25 17:18:21 +08:00
render: (rec, record) => <span>{rec || "-"}</span>
}))
return [...columns, ...newCol, ...zcColumns];
}
}, [trData])
2024-09-20 15:02:50 +08:00
const width = useMemo(() => columns1?.reduce((total, cur) => total + (cur.width), 0), [columns1]);
// 单图多线以及数据表的数据
2025-03-25 17:18:21 +08:00
const getTableData = async (params) => {
setLoading(true);
2024-09-20 15:02:50 +08:00
try {
const res = await httppost2(apiurl.gcaqjc.gcaqfx.jrx.page, params)
let newArr = [];
let newData = res.data.map((s, i) => {
2025-03-25 17:18:21 +08:00
newArr.push(s.list.map(c => ({
[c.stationCode]: c.value || '-',
tm: c.tm,
2024-09-20 15:02:50 +08:00
})))
return {
tm: s.tm,
rz: s.rz,
status: s.status || '',
2025-03-25 17:18:21 +08:00
inx: i + 1
2024-09-20 15:02:50 +08:00
}
})
let filterData = newArr.filter(s => s.length > 0).flat()
let result = newData.map(s => {
let tm1 = s.tm;
let r = filterData.filter(t => {
2025-03-25 17:18:21 +08:00
return t.tm == tm1
2024-09-20 15:02:50 +08:00
})
let obj = {};
r.forEach(s1 => {
2025-03-25 17:18:21 +08:00
obj = { ...s1, ...obj }
2024-09-20 15:02:50 +08:00
})
return {
...s,
...obj,
}
})
2025-03-25 17:18:21 +08:00
if (result.length > 0) {
setLoading(false)
}
2024-09-29 17:42:30 +08:00
// let res1 = result.map(item => ({...item,rz:(item.rz - 100).toFixed(2)})) //为了测试 最后需要删除
setDateSources(result)
2024-09-20 15:02:50 +08:00
} catch (error) {
console.log(error);
}
}
2025-03-25 17:18:21 +08:00
2024-09-20 15:02:50 +08:00
const exportExcel = () => {
let params = {
...searchVal,
profileName: dmList.find(s => s.id == code).projNm,
stationCodes: trData,
2025-03-25 17:18:21 +08:00
id: 1
2024-09-20 15:02:50 +08:00
}
httppost5(apiurl.gcaqjc.gcaqfx.jrx.export, params).then(res => {
2025-03-25 17:18:21 +08:00
exportFile(`浸润线.xlsx`, res.data)
})
2024-09-20 15:02:50 +08:00
}
const getDmList = async () => {
try {
const res = await httppost2(apiurl.gcaqjc.sjtjcx.sycx.list)
setDmList(res.data.map(s => ({ projNm: s.profileName, id: s.profileCode })));
} catch (error) {
console.log(error);
}
}
2025-03-25 17:18:21 +08:00
const getDmTree = async () => {
2024-09-20 15:02:50 +08:00
try {
const res = await httppost2(apiurl.gcaqjc.sjtjcx.czcx.tree)
let filterData = res.data.filter(s => s.profileCode == code)
2025-03-25 17:18:21 +08:00
setTrData(filterData[0]?.children)
2024-09-20 15:02:50 +08:00
} catch (error) {
console.log(error);
}
}
const InitialScroll = (data) => {
2025-03-25 17:18:21 +08:00
let index = 0;
2024-09-20 15:02:50 +08:00
const v = document.getElementsByClassName("ant-table-body")[0];
if (data.length >= Number(1)) {
// 只有当大于10条数据的时候 才会看起滚动
const time = setInterval(() => {
v.scrollTop += Number(14);
if (
Math.ceil(v.scrollTop) >= parseFloat((v.scrollHeight - v.clientHeight).toString())
) {
v.scrollTop = 0;
2025-03-25 17:18:21 +08:00
// setTimeout(() => { v.scrollTop = 0 }, 1000)
2024-09-20 15:02:50 +08:00
}
2025-03-25 17:18:21 +08:00
echartsRef.current.getEchartsInstance().setOption(jrxOption(dataSources[index % dataSources.length], dbType,dbType1))
2024-09-20 15:02:50 +08:00
index++;
}, Number(1000));
setTimer(time); // 定时器保存变量 利于停止
}
};
const [scale, setScale] = useState(1)
const scaleRef = useRef(null)
scaleRef.current = scale;
2025-03-25 17:18:21 +08:00
2024-09-20 15:02:50 +08:00
useEffect(() => {
if (trData.length > 0 && searchVal) {
let params = {
stationCodes: trData,
...searchVal
}
getTableData(params)
}
2025-03-25 17:18:21 +08:00
2024-09-20 15:02:50 +08:00
}, [trData, searchVal]);
2025-03-25 17:18:21 +08:00
2024-09-20 15:02:50 +08:00
useEffect(() => {
2025-03-25 17:18:21 +08:00
if (code.length) {
2024-09-20 15:02:50 +08:00
getDmTree()
}
if (timer) {
clearInterval(timer)
}
2025-03-25 17:18:21 +08:00
if (dmList.length > 0 && code.length) {
2024-09-20 15:02:50 +08:00
let name = dmList.find(s => s.id == code)?.projNm
2025-03-25 17:18:21 +08:00
let type = (name == "大坝B0+130" || name == "大坝B0+132") ? "1" :
(name == "大坝B0+250" || name == "大坝B0+252") ? "2" :
(name == "大坝B0+370" || name == "大坝B0+372") ? "3" : '';
let type1 = typeName[name];
2024-09-20 15:02:50 +08:00
setDbType(type)
2025-03-25 17:18:21 +08:00
setDbType1(type1)
2024-09-20 15:02:50 +08:00
}
2025-03-25 17:18:21 +08:00
}, [code, dmList])
2024-09-20 15:02:50 +08:00
useEffect(() => {
getDmList()
}, [])
2025-03-25 17:18:21 +08:00
2024-09-20 15:02:50 +08:00
useEffect(() => {
if (swiper && dataSources.length > 0) {
InitialScroll(dataSources)
} else {
clearInterval(timer)
}
return () => {
clearInterval(timer); // 停止定时器
}
}, [swiper, dataSources])
2025-03-25 17:18:21 +08:00
useEffect(() => {
2024-09-20 15:02:50 +08:00
let scale = 1
const img = document.getElementById("img");
2025-03-25 17:18:21 +08:00
if (!img) return;
2024-09-20 15:02:50 +08:00
const fun = (e) => {
// 大于0:滚轮向上滚动 小于0:滚轮向下滚动
if (e.wheelDelta > 0) {
scale += 0.05;
img.style.transform = `scale(${scale})`;
} else {
if (scale == 1) {
img.style.left = 0 + "px";
img.style.top = 0 + "px";
}
// 缩放值大于1时,可以缩小,反之亦然
if (scale > 1) {
scale -= 0.05;
img.style.transform = `scale(${scale})`;
}
}
2025-03-25 17:18:21 +08:00
}
2024-09-20 15:02:50 +08:00
img.addEventListener("wheel",fun)
return ()=>{
img.removeEventListener("wheel",fun)
}
2025-03-25 17:18:21 +08:00
},[loading])
return (
<div className='content-box' style={{ backgroundColor: '#fff', height: '100%', display: 'flex', padding: '10px' }}>
<div className='lf adcdTreeSelectorBox' style={{ height: 'calc(100vh - 110px)', width: '260px' }}>
2024-09-20 15:02:50 +08:00
<ListSelect
setAdcd={setCode}
listData={dmList}
2025-03-25 17:18:21 +08:00
/>
</div>
<div className='AdcdTreeTableBox' style={{ width: 'calc(100vw - 625px)' }}>
<Card
className='nonebox'
// onMouseOver={() => {
// clearInterval(timer)
// }}
>
<ToolBar
setSearchVal={setSearchVal}
exportFile={exportExcel}
setSwiper={setSwiper}
role={role}
/>
</Card>
{
!loading ? <div className="ant-card-body" style={{ padding: "20px 0 0 0", overflow: "hidden" }}>
<div style={{ height: 420, width: "100%",overflow:'hidden',position:'relative' }} >
<Rnd
default={{
2024-09-20 15:02:50 +08:00
x: 0,
y: 0,
2025-03-25 17:18:21 +08:00
width: 1305,
2024-09-20 15:02:50 +08:00
height: 380
2025-03-25 17:18:21 +08:00
}}
>
<div id="img">
<div style={{ textAlign: "center", marginBottom: 10, fontSize: 20 }}>断面名称:{dmList.find(s => s.id == code)?.projNm}</div>
<ReactEcharts
option={jrxOptions}
style={{ width: "100%", height: 380 }}
notMerge={true}
2024-09-20 15:02:50 +08:00
ref={echartsRef}
2025-03-25 17:18:21 +08:00
/>
</div>
</Rnd>
</div>
<div className='body-top' style={{ marginTop: 30 }}>
<Table
columns={columns1}
key="inx"
dataSource={dataSources}
pagination={false}
scroll={{ x: width, y: 250, scrollToFirstRowOnChange: true }}
onRow={record => {
return {
onClick: () => { echartsRef.current.getEchartsInstance().setOption(jrxOption(record, dbType,dbType1)) }
}
}}
2024-09-20 15:02:50 +08:00
/>
2025-03-25 17:18:21 +08:00
</div>
</div> :
<Spin size='large' style={{width:'100%',margin:'300px auto'}}></Spin>
}
</div>
</div>
)
2024-09-20 15:02:50 +08:00
}