2023-12-28 16:16:31 +08:00
|
|
|
import cls from "./index.module.css";
|
|
|
|
import * as echarts from "echarts";
|
2024-01-25 10:24:08 +08:00
|
|
|
import { Select } from "antd";
|
2023-12-28 16:16:31 +08:00
|
|
|
import ReactECharts from "echarts-for-react";
|
2024-01-24 17:01:29 +08:00
|
|
|
import { useEffect, useState } from "react";
|
2023-12-28 16:16:31 +08:00
|
|
|
import { useSelector } from "react-redux";
|
2024-01-24 15:58:16 +08:00
|
|
|
import triangle from "../../../../assets/Icon/triangle.svg";
|
2024-01-24 17:01:29 +08:00
|
|
|
import dayjs from "dayjs";
|
2023-11-09 13:36:21 +08:00
|
|
|
|
|
|
|
const SmokeTrendChart = (props) => {
|
2023-12-28 16:16:31 +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 [source, setSource] = useState("O2_float");
|
|
|
|
const [period, setPeriod] = useState("day");
|
2023-11-09 13:36:21 +08:00
|
|
|
|
2023-12-28 16:16:31 +08:00
|
|
|
const currentTrend =
|
|
|
|
period === "day"
|
|
|
|
? dayTrend
|
|
|
|
: period === "week"
|
|
|
|
? weekTrend
|
|
|
|
: period === "month"
|
|
|
|
? monthTrend
|
|
|
|
: yearTrend;
|
2023-11-09 13:36:21 +08:00
|
|
|
|
2023-12-28 16:16:31 +08:00
|
|
|
const options = getOptions(source, period, currentTrend);
|
2023-11-09 13:36:21 +08:00
|
|
|
|
2024-01-24 17:01:29 +08:00
|
|
|
const [desc, setDesc] = useState("");
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
switch (period) {
|
|
|
|
case "day":
|
|
|
|
setDesc(
|
2024-04-22 16:58:15 +08:00
|
|
|
dayjs().format("YYYY.MM.DD") +
|
2024-01-24 17:01:29 +08:00
|
|
|
" 7点 - " +
|
2024-04-22 16:58:15 +08:00
|
|
|
dayjs().add(1, "day").format("YYYY.MM.DD") +
|
2024-01-24 17:01:29 +08:00
|
|
|
" 7点"
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "month":
|
|
|
|
setDesc(
|
|
|
|
dayjs().subtract(1, "month").format("YYYY.MM.") +
|
|
|
|
"29 - " +
|
|
|
|
dayjs().format("YYYY.MM.") +
|
|
|
|
"28"
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "week":
|
|
|
|
setDesc(
|
|
|
|
dayjs().subtract(7, "day").format("YYYY.MM.DD") +
|
|
|
|
" - " +
|
|
|
|
dayjs().subtract(1, "day").format("YYYY.MM.DD")
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "year":
|
|
|
|
setDesc(
|
|
|
|
dayjs().subtract(1, "year").endOf("year").format("YYYY.MM.") +
|
|
|
|
"29 - " +
|
|
|
|
dayjs().endOf("year").format("YYYY.MM.") +
|
|
|
|
"28"
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, [period]);
|
|
|
|
|
2024-01-24 15:58:16 +08:00
|
|
|
function handleDateChange(value) {
|
2024-01-24 17:01:29 +08:00
|
|
|
setPeriod(
|
|
|
|
{
|
|
|
|
日: "day",
|
|
|
|
周: "week",
|
|
|
|
月: "month",
|
|
|
|
年: "year",
|
|
|
|
}[value]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
function handleSourceChange(value) {
|
2024-04-15 13:50:49 +08:00
|
|
|
setSource(
|
2024-01-24 17:01:29 +08:00
|
|
|
{
|
|
|
|
氧气: "O2_float",
|
|
|
|
氮氧化物: "NOX_float",
|
|
|
|
二氧化硫: "SO2_float",
|
|
|
|
颗粒物: "dust_float",
|
|
|
|
}[value]
|
|
|
|
);
|
2024-01-24 15:58:16 +08:00
|
|
|
}
|
|
|
|
|
2023-12-28 16:16:31 +08:00
|
|
|
return (
|
|
|
|
<div className={cls.energyCostChart}>
|
|
|
|
<div className={cls.titleBar}>
|
|
|
|
<h2>烟气趋势图</h2>
|
|
|
|
{/* <Switch defaultChecked onChange={handleSwitchChange} /> */}
|
|
|
|
{/* <div className={cls.legend}>
|
|
|
|
<span className="legend__title">班次详情</span>
|
|
|
|
<ul className="legend__list">
|
|
|
|
<li>总量</li>
|
|
|
|
<li>白班</li>
|
|
|
|
<li>夜班</li>
|
|
|
|
</ul>
|
|
|
|
</div> */}
|
|
|
|
</div>
|
2023-11-09 13:36:21 +08:00
|
|
|
|
2023-12-28 16:16:31 +08:00
|
|
|
<div className={`${cls.choiceBar} flex items-center justify-between`}>
|
2024-01-24 17:01:29 +08:00
|
|
|
{/* <Radio.Group
|
2023-12-28 16:16:31 +08:00
|
|
|
value={source}
|
|
|
|
onChange={(e) => setSource(e.target.value)}
|
|
|
|
buttonStyle="solid"
|
|
|
|
className={`${cls.radioGroup} flex items-center justify-between`}
|
|
|
|
>
|
|
|
|
<Radio.Button value="O2_float" className="radio-group__item">
|
|
|
|
氧气
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="NOX_float" className="radio-group__item">
|
|
|
|
氮氧化物
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="SO2_float" className="radio-group__item">
|
|
|
|
二氧化硫
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="dust_float" className="radio-group__item">
|
|
|
|
颗粒物
|
|
|
|
</Radio.Button>
|
2024-01-24 17:01:29 +08:00
|
|
|
</Radio.Group> */}
|
|
|
|
<Select
|
|
|
|
defaultValue={"氧气"}
|
|
|
|
style={{ width: 100 }}
|
|
|
|
popupClassName="xc-date-selector-menu"
|
|
|
|
className={cls.radioGroupShort}
|
|
|
|
options={["氧气", "氮氧化物", "二氧化硫", "颗粒物"].map((item) => ({
|
|
|
|
label: item,
|
|
|
|
value: item,
|
|
|
|
}))}
|
|
|
|
suffixIcon={<img src={triangle} alt="#" />}
|
|
|
|
notFoundContent={
|
|
|
|
<span
|
|
|
|
style={{
|
|
|
|
color: "#fff",
|
|
|
|
fontSize: "14px",
|
|
|
|
lineHeight: 1,
|
|
|
|
paddingLeft: "12px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
- 无 -
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
onChange={(value, option) => handleSourceChange(value)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className={cls.graphBaseDesc}>{desc}</div>
|
2023-12-28 16:16:31 +08:00
|
|
|
|
2024-01-24 15:58:16 +08:00
|
|
|
{/* <Radio.Group
|
2023-12-28 16:16:31 +08:00
|
|
|
value={period}
|
|
|
|
onChange={(e) => setPeriod(e.target.value)}
|
|
|
|
buttonStyle="solid"
|
|
|
|
className={cls.radioGroup}
|
|
|
|
>
|
|
|
|
<Radio.Button value="day" className="radio-group__item">
|
|
|
|
日
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="week" className="radio-group__item">
|
|
|
|
周
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="month" className="radio-group__item">
|
|
|
|
月
|
|
|
|
</Radio.Button>
|
|
|
|
<Radio.Button value="year" className="radio-group__item">
|
|
|
|
年
|
|
|
|
</Radio.Button>
|
2024-01-24 15:58:16 +08:00
|
|
|
</Radio.Group> */}
|
|
|
|
|
|
|
|
<Select
|
|
|
|
defaultValue={"日"}
|
|
|
|
style={{ width: 60 }}
|
|
|
|
popupClassName="xc-date-selector-menu"
|
|
|
|
className={cls.radioGroupShort}
|
2024-01-24 17:01:29 +08:00
|
|
|
options={["日", "周", "月", "年"].map((item) => ({
|
2024-01-24 15:58:16 +08:00
|
|
|
label: item,
|
|
|
|
value: item,
|
|
|
|
}))}
|
|
|
|
suffixIcon={<img src={triangle} alt="#" />}
|
|
|
|
notFoundContent={
|
|
|
|
<span
|
|
|
|
style={{
|
|
|
|
color: "#fff",
|
|
|
|
fontSize: "14px",
|
|
|
|
lineHeight: 1,
|
|
|
|
paddingLeft: "12px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
- 无 -
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
onChange={(value, option) => handleDateChange(value)}
|
|
|
|
/>
|
2023-12-28 16:16:31 +08:00
|
|
|
</div>
|
2024-01-25 10:24:08 +08:00
|
|
|
{options && <ReactECharts option={options} style={{ height: "220px" }} />}
|
2024-01-02 14:33:21 +08:00
|
|
|
{!options && (
|
|
|
|
<p
|
|
|
|
style={{
|
|
|
|
color: "#cccf",
|
|
|
|
fontSize: "24px",
|
|
|
|
userSelect: "none",
|
|
|
|
textAlign: "center",
|
|
|
|
paddingTop: "96px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
暂无数据
|
|
|
|
</p>
|
|
|
|
)}
|
2023-12-28 16:16:31 +08:00
|
|
|
</div>
|
|
|
|
);
|
2023-11-09 13:36:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default SmokeTrendChart;
|
2023-12-28 16:16:31 +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-28 16:16:31 +08:00
|
|
|
return {
|
|
|
|
color: ["#FFD160", "#12FFF5", "#2760FF"],
|
2024-01-08 13:28:03 +08:00
|
|
|
grid: {
|
|
|
|
top: 40,
|
|
|
|
right: 12,
|
|
|
|
bottom: 20,
|
|
|
|
left: source == "O2_float" ? 56 : 72,
|
|
|
|
},
|
2023-12-28 16:16:31 +08:00
|
|
|
xAxis: {
|
|
|
|
type: "category",
|
|
|
|
// data: Array(7)
|
|
|
|
// .fill(1)
|
|
|
|
// .map((_, index) => {
|
|
|
|
// const today = new Date();
|
|
|
|
// const dtimestamp = today - index * 24 * 60 * 60 * 1000;
|
|
|
|
// return `${new Date(dtimestamp).getMonth() + 1}.${new Date(
|
|
|
|
// dtimestamp
|
|
|
|
// ).getDate()}`;
|
|
|
|
// })
|
|
|
|
// .reverse(),
|
|
|
|
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: source == "O2_float" ? "单位:%" : "单位mg/m³",
|
2023-12-28 16:16:31 +08:00
|
|
|
nameTextStyle: {
|
|
|
|
color: "#fff",
|
2024-01-08 13:28:03 +08:00
|
|
|
fontSize: 13,
|
2023-12-28 16:16:31 +08:00
|
|
|
align: "right",
|
|
|
|
},
|
|
|
|
type: "value",
|
|
|
|
axisLabel: {
|
|
|
|
color: "#fff",
|
2024-01-04 10:58:20 +08:00
|
|
|
fontSize: 14,
|
2024-01-08 13:28:03 +08:00
|
|
|
formatter: "{value}",
|
2023-12-28 16:16:31 +08:00
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
show: true,
|
|
|
|
lineStyle: {
|
|
|
|
color: "#213259",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: "#213259a0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: [
|
|
|
|
{
|
2024-01-08 13:28:03 +08:00
|
|
|
data: trend[source].map((item) =>
|
|
|
|
!(item.value == null || isNaN(+item.value))
|
|
|
|
? (+item.value).toFixed(2)
|
|
|
|
: null
|
|
|
|
),
|
2023-12-28 16:16:31 +08:00
|
|
|
type: "line",
|
|
|
|
areaStyle: {
|
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
{ offset: 0, color: "#FFD16040" },
|
|
|
|
{ offset: 0.5, color: "#FFD16020" },
|
|
|
|
{ offset: 1, color: "#FFD16010" },
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
// smooth: true,
|
|
|
|
},
|
|
|
|
// {
|
|
|
|
// data: Array(7)
|
|
|
|
// .fill(1)
|
|
|
|
// .map((_) => {
|
|
|
|
// return randomInt(60, 100);
|
|
|
|
// }),
|
|
|
|
// type: "line",
|
|
|
|
// areaStyle: {
|
|
|
|
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
// { offset: 0, color: "#12FFF540" },
|
|
|
|
// { offset: 0.5, color: "#12FFF520" },
|
|
|
|
// { offset: 1, color: "#12FFF510" },
|
|
|
|
// ]),
|
|
|
|
// },
|
|
|
|
// // smooth: true,
|
|
|
|
// },
|
|
|
|
// {
|
|
|
|
// data: Array(7)
|
|
|
|
// .fill(1)
|
|
|
|
// .map((_) => {
|
|
|
|
// return randomInt(60, 100);
|
|
|
|
// }),
|
|
|
|
// type: "line",
|
|
|
|
// areaStyle: {
|
|
|
|
// color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
// { offset: 0, color: "#2760FF40" },
|
|
|
|
// { offset: 0.5, color: "#2760FF20" },
|
|
|
|
// { offset: 1, color: "#2760FF10" },
|
|
|
|
// ]),
|
|
|
|
// },
|
|
|
|
// // smooth: true,
|
|
|
|
// },
|
|
|
|
],
|
|
|
|
tooltip: {
|
|
|
|
trigger: "axis",
|
2024-01-04 10:58:20 +08:00
|
|
|
axisPointer: {
|
|
|
|
type: "shadow",
|
|
|
|
},
|
|
|
|
className: "xc-chart-tooltip",
|
2023-12-28 16:16:31 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|