2023-12-13 16:59:58 +08:00
|
|
|
import cls from "./index.module.css";
|
|
|
|
import GraphBase from "../GraphBase";
|
|
|
|
import ReactECharts from "echarts-for-react";
|
2023-12-14 13:57:49 +08:00
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
import { useState } from "react";
|
2023-12-14 11:06:19 +08:00
|
|
|
|
2023-12-19 15:15:10 +08:00
|
|
|
function FaultTotal(props) {
|
|
|
|
const [currentSelect, setCurrentSelect] = useState("日");
|
|
|
|
const isra = useSelector((state) => state.isra);
|
|
|
|
|
|
|
|
const currentStatistic =
|
|
|
|
currentSelect == "日"
|
|
|
|
? isra.dayStatistic
|
|
|
|
: currentSelect == "周"
|
|
|
|
? isra.weekStatistic
|
|
|
|
: currentSelect == "月"
|
|
|
|
? isra.monthStatistic
|
|
|
|
: currentSelect == "月"
|
|
|
|
? isra.yearStatistic
|
|
|
|
: [];
|
|
|
|
|
|
|
|
const series = preHandleStatisticData(currentStatistic, isra.checkType);
|
|
|
|
const options = getOptions(series, isra, currentStatistic);
|
|
|
|
|
|
|
|
function handleDateChange(v) {
|
|
|
|
setCurrentSelect(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 根据使用的页面决定背景的大小
|
|
|
|
const bgSize =
|
|
|
|
props.page == "home" ? ["middle", "short"] : ["middle", "long"];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<GraphBase
|
|
|
|
icon="chart"
|
|
|
|
title="产线缺陷统计"
|
|
|
|
dateOptions={["日", "周", "月", "年"]}
|
|
|
|
defaultSelect={currentSelect}
|
|
|
|
onDateChange={handleDateChange}
|
|
|
|
size={bgSize}
|
|
|
|
style={{ width: "600px" }}
|
|
|
|
>
|
|
|
|
<div className={cls.chart}>
|
|
|
|
{currentStatistic.length != 0 && (
|
|
|
|
<ReactECharts option={options} style={{ height: "100%" }} />
|
|
|
|
)}
|
|
|
|
{currentStatistic.length == 0 && (
|
|
|
|
<p
|
|
|
|
style={{
|
|
|
|
paddingTop: "72px",
|
|
|
|
color: "#fff6",
|
|
|
|
textAlign: "center",
|
|
|
|
fontSize: "24px",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
暂无数据
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</GraphBase>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FaultTotal;
|
|
|
|
|
2023-12-14 11:06:19 +08:00
|
|
|
function preHandleStatisticData(data, legend) {
|
2023-12-27 16:44:24 +08:00
|
|
|
console.table(data);
|
2023-12-14 11:06:19 +08:00
|
|
|
const obj = {};
|
|
|
|
data.forEach((item) => {
|
|
|
|
obj[item.name] = {};
|
|
|
|
item.data.forEach((d) => {
|
|
|
|
obj[item.name][d.checkType] = d.checkNum;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-12-27 16:44:24 +08:00
|
|
|
console.log("obj", obj)
|
2023-12-14 11:06:19 +08:00
|
|
|
const series = Array(legend.length)
|
|
|
|
.fill(1)
|
|
|
|
.map((_) => ({
|
|
|
|
name: "",
|
|
|
|
type: "bar",
|
|
|
|
stack: "true",
|
|
|
|
barWidth: 12,
|
|
|
|
emphasis: {
|
|
|
|
focus: "series",
|
|
|
|
},
|
|
|
|
data: [],
|
|
|
|
}));
|
|
|
|
|
|
|
|
legend.forEach((item, index) => {
|
|
|
|
series[index].name = item;
|
2023-12-19 15:15:10 +08:00
|
|
|
data.forEach((d, index) => {
|
|
|
|
if (index == 0) {
|
|
|
|
series[index].label = {
|
|
|
|
show: true,
|
|
|
|
position: "top",
|
|
|
|
distance: 10,
|
|
|
|
color: "#fffc",
|
|
|
|
};
|
|
|
|
}
|
2023-12-14 11:06:19 +08:00
|
|
|
series[index].data.push(obj[d.name][item] || 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return series;
|
|
|
|
}
|
2023-11-09 13:36:21 +08:00
|
|
|
|
2023-12-14 13:57:49 +08:00
|
|
|
function getOptions(series, isra, currentStatistic) {
|
|
|
|
return {
|
2023-12-14 11:06:19 +08:00
|
|
|
color: ["#2760FF", "#8167F6", "#5B9BFF", "#99D66C", "#FFD160", "#FF8A40"],
|
2023-12-13 16:59:58 +08:00
|
|
|
grid: { top: 42, right: 12, bottom: 20, left: 48 },
|
|
|
|
legend: {
|
|
|
|
top: 10,
|
|
|
|
padding: 5,
|
|
|
|
itemWidth: 12,
|
|
|
|
itemHeight: 12,
|
|
|
|
itemGap: 12,
|
|
|
|
height: 12,
|
|
|
|
textStyle: {
|
|
|
|
color: "#DFF1FE",
|
|
|
|
fontSize: 12,
|
|
|
|
},
|
2023-12-15 15:20:20 +08:00
|
|
|
data: isra.checkType,
|
2023-12-13 16:59:58 +08:00
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: "category",
|
2023-12-14 11:06:19 +08:00
|
|
|
data: currentStatistic.map((item) => item.name),
|
2023-12-13 16:59:58 +08:00
|
|
|
axisLabel: {
|
2023-12-19 15:15:10 +08:00
|
|
|
color: "#fffc",
|
2023-12-13 16:59:58 +08:00
|
|
|
fontSize: 12,
|
|
|
|
},
|
|
|
|
axisTick: { show: false },
|
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
|
|
|
width: 1,
|
|
|
|
color: "#213259",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
yAxis: {
|
|
|
|
name: "单位/个",
|
|
|
|
nameTextStyle: {
|
|
|
|
color: "#fff",
|
|
|
|
fontSize: 10,
|
|
|
|
align: "right",
|
|
|
|
},
|
|
|
|
type: "value",
|
|
|
|
axisLabel: {
|
|
|
|
color: "#fff",
|
|
|
|
fontSize: 12,
|
|
|
|
formatter: "{value}",
|
|
|
|
},
|
|
|
|
axisLine: {
|
|
|
|
show: true,
|
|
|
|
lineStyle: {
|
|
|
|
color: "#213259",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: "#213259a0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-12-14 11:06:19 +08:00
|
|
|
series,
|
2023-12-13 16:59:58 +08:00
|
|
|
tooltip: {
|
|
|
|
trigger: "axis",
|
2023-12-19 15:15:10 +08:00
|
|
|
axisPointer: {
|
|
|
|
type: "shadow",
|
|
|
|
},
|
|
|
|
className: "xc-chart-tooltip",
|
|
|
|
// backgroundColor: ''
|
2023-12-13 16:59:58 +08:00
|
|
|
},
|
|
|
|
};
|
2023-12-14 13:57:49 +08:00
|
|
|
}
|