xuchang-new/src/components/Modules/EnergyCostAnalysis/SO2/index.jsx

175 lines
4.2 KiB
React
Raw Normal View History

2023-12-29 12:47:30 +08:00
import GraphBase from "../../../Common/GraphBase";
import ReactECharts from "echarts-for-react";
// import getOptions from "../../../../hooks/getChartOption";
import { useSelector } from "react-redux";
import { useState } from "react";
import * as echarts from "echarts";
2024-01-25 10:31:51 +08:00
import dayjs from "dayjs";
2023-11-09 13:36:21 +08:00
function SO2(props) {
2023-12-29 12:47:30 +08:00
const dayTrend = useSelector((state) => state.smoke?.dayTrend);
const weekTrend = useSelector((state) => state.smoke?.weekTrend);
const monthTrend = useSelector((state) => state.smoke?.monthTrend);
const yearTrend = useSelector((state) => state.smoke?.yearTrend);
const [period, setPeriod] = useState("日");
2023-11-09 13:36:21 +08:00
2023-12-29 12:47:30 +08:00
const currentTrend =
period === "日"
? dayTrend
: period === "周"
? weekTrend
: period === "月"
? monthTrend
: yearTrend;
2024-01-25 10:31:51 +08:00
const [timestr, setTimestr] = useState(
dayjs().subtract(7, "day").format("YYYY.MM.DD") +
" - " +
dayjs().subtract(1, "day").format("YYYY.MM.DD")
);
2023-12-29 12:47:30 +08:00
const options = getOptions("SO2_float", period, currentTrend);
2024-04-15 13:50:49 +08:00
function handleSwitch(v) {}
2023-12-29 12:47:30 +08:00
2024-01-25 10:31:51 +08:00
function handleDateChange(value) {
2024-04-15 13:50:49 +08:00
setPeriod(value);
2024-01-25 10:31:51 +08:00
setTimestr(
{
:
dayjs().subtract(1, "day").format("YYYY.MM.DD") +
" 7点 - " +
dayjs().format("YYYY.MM.DD") +
" 7点",
:
dayjs().subtract(1, "year").endOf("year").format("YYYY.MM.") +
"29 - " +
dayjs().endOf("year").format("YYYY.MM.") +
"28",
:
dayjs().subtract(7, "day").format("YYYY.MM.DD") +
" - " +
dayjs().subtract(1, "day").format("YYYY.MM.DD"),
:
dayjs().subtract(1, "month").format("YYYY.MM.") +
"29 - " +
dayjs().format("YYYY.MM.") +
"28",
}[value]
);
2023-12-29 12:47:30 +08:00
}
2024-01-25 10:31:51 +08:00
2023-12-29 12:47:30 +08:00
return (
<GraphBase
2024-01-02 17:00:35 +08:00
icon="smoke"
2023-12-29 12:47:30 +08:00
title="二氧化硫"
2024-01-25 10:31:51 +08:00
desc={`能耗趋势图 ${timestr}`}
2023-12-29 12:47:30 +08:00
switchOptions={false}
defaultSelect={period}
onSwitch={handleSwitch}
dateOptions={["日", "周", "月", "年"]}
onDateChange={handleDateChange}
size={["long", "middle"]}
>
2024-01-02 14:33:21 +08:00
{options && (
<ReactECharts
key={Math.random()}
option={options}
style={{ height: "100%" }}
/>
)}
{!options && (
<p
style={{
color: "#cccf",
fontSize: "24px",
userSelect: "none",
textAlign: "center",
paddingTop: "96px",
}}
>
暂无数据
</p>
)}
2023-12-29 12:47:30 +08:00
</GraphBase>
);
2023-11-09 13:36:21 +08:00
}
export default SO2;
2023-12-29 12:47:30 +08:00
function getOptions(source, period, trend) {
2024-01-11 16:03:33 +08:00
if (
trend[source].length == 0 ||
trend[source].filter((item) => item.value).length == 0
)
return null;
2023-12-29 12:47:30 +08:00
return {
color: ["#FFD160", "#12FFF5", "#2760FF"],
2024-01-08 13:28:03 +08:00
grid: { top: 40, right: 12, bottom: 20, left: 64 },
2023-12-29 12:47:30 +08:00
xAxis: {
type: "category",
data: trend[source].map((item) => item.time),
axisLabel: {
color: "#fff",
fontSize: 12,
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: "#213259",
},
},
},
yAxis: {
2024-01-04 10:58:20 +08:00
name: "单位mg/m³",
2023-12-29 12:47:30 +08:00
nameTextStyle: {
color: "#fff",
2024-01-04 10:58:20 +08:00
fontSize: 12,
2023-12-29 12:47:30 +08:00
align: "right",
},
type: "value",
axisLabel: {
color: "#fff",
fontSize: 12,
2024-01-04 10:58:20 +08:00
formatter: "{value}",
2023-12-29 12:47:30 +08:00
},
axisLine: {
show: true,
lineStyle: {
color: "#213259",
},
},
splitLine: {
lineStyle: {
color: "#213259a0",
},
},
},
series: [
{
2024-01-04 10:58:20 +08:00
data: trend[source].map((item) =>
!(item.value == null || isNaN(+item.value))
? (+item.value).toFixed(2)
: null
),
2023-12-29 12:47:30 +08:00
type: "line",
2024-01-03 17:00:31 +08:00
symbol: "circle",
symbolSize: 6,
2023-12-29 12:47:30 +08:00
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: "#FFD16040" },
{ offset: 0.5, color: "#FFD16020" },
{ offset: 1, color: "#FFD16010" },
]),
},
},
],
tooltip: {
trigger: "axis",
2024-01-03 17:00:31 +08:00
axisPointer: {
type: "shadow",
},
className: "xc-chart-tooltip",
2023-12-29 12:47:30 +08:00
},
};
}