Files
safePower/src/view/largeScreen2/ttes.js

341 lines
6.9 KiB
JavaScript
Raw Normal View History

2026-04-29 09:15:49 +08:00
import * as echarts from 'echarts'
2026-06-12 11:16:10 +08:00
import {
techChartAxisLabel,
techChartAxisLine,
techChartCenterText,
techChartLegend,
techChartSeriesColors,
techChartSplitLine,
techChartTooltip
} from '@/utils/techChartTheme'
const chartNameTextStyle = {
color: techChartAxisLabel.color,
fontSize: 10
}
const dashedSplitLine = {
lineStyle: {
...techChartSplitLine.lineStyle,
type: 'dashed'
}
}
const compactAxisLabel = {
...techChartAxisLabel,
fontSize: 10
}
const pieItemStyle = {
borderRadius: 8,
borderColor: 'rgba(5, 16, 32, 0.96)',
borderWidth: 2
}
const createCenterLabelRich = (totalFontSize, nameFontSize) => ({
total: {
fontSize: totalFontSize,
fontWeight: 'bold',
color: techChartCenterText.primary,
lineHeight: 35
},
name: {
fontSize: nameFontSize,
color: techChartCenterText.secondary
}
})
2026-04-29 09:15:49 +08:00
export const getAlarmPendingOption = () => ({
tooltip: {
trigger: 'axis',
2026-06-12 11:16:10 +08:00
...techChartTooltip
2026-04-29 09:15:49 +08:00
},
grid: {
top: '15%',
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: ['02-17', '02-22', '02-27', '03-04', '03-09', '03-14'],
2026-06-12 11:16:10 +08:00
axisLine: techChartAxisLine,
axisLabel: compactAxisLabel
2026-04-29 09:15:49 +08:00
},
yAxis: {
type: 'value',
name: '次数',
2026-06-12 11:16:10 +08:00
nameTextStyle: chartNameTextStyle,
splitLine: dashedSplitLine,
axisLine: techChartAxisLine,
axisLabel: compactAxisLabel
2026-04-29 09:15:49 +08:00
},
series: [
{
name: '待处理报警',
data: [1, 3, 2, 5, 2, 3],
type: 'line',
smooth: true,
lineStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[0],
2026-04-29 09:15:49 +08:00
width: 2
},
itemStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[0]
2026-04-29 09:15:49 +08:00
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(0, 212, 255, 0.3)' },
{ offset: 1, color: 'rgba(0, 212, 255, 0)' }
])
},
markPoint: {
data: [
{
type: 'max',
name: 'Max'
},
{
type: 'min',
name: 'Min'
}
]
}
}
]
})
export const getAlertDistributionOption = (alertTypes) => ({
series: [
{
type: 'pie',
radius: ['45%', '70%'],
center: ['50%', '50%'],
avoidLabelOverlap: false,
2026-06-12 11:16:10 +08:00
itemStyle: pieItemStyle,
2026-04-29 09:15:49 +08:00
label: {
show: true,
position: 'center',
formatter: '{total|15}\n{name|报警总数}',
2026-06-12 11:16:10 +08:00
rich: createCenterLabelRich(28, 14)
2026-04-29 09:15:49 +08:00
},
labelLine: {
show: false
},
data: alertTypes.map((item) => ({
value: item.count,
name: item.name,
itemStyle: {
color: item.color
}
}))
}
]
})
export const getDeviceStatOption = (deviceTypes) => {
const total = deviceTypes.reduce((sum, item) => sum + (item.count || item.value || 0), 0)
return {
grid: {
top: 0,
left: 0,
right: 0,
bottom: 0,
containLabel: false
},
series: [
{
type: 'pie',
2026-06-12 17:07:17 +08:00
radius: ['42%', '68%'],
2026-04-29 09:15:49 +08:00
center: ['50%', '50%'],
avoidLabelOverlap: false,
2026-06-12 11:16:10 +08:00
itemStyle: pieItemStyle,
2026-04-29 09:15:49 +08:00
label: {
show: true,
position: 'center',
formatter: `{total|${total}}\n{name|设备总数}`,
2026-06-12 17:07:17 +08:00
rich: createCenterLabelRich(16, 10)
2026-04-29 09:15:49 +08:00
},
labelLine: {
show: false
},
data: deviceTypes.map((item) => ({
value: item.count || 0,
name: item.cb_type_name || '未知',
itemStyle: {
color: item.color
}
}))
}
]
}
}
export const getProjectBarOption = (projectData) => ({
tooltip: {
trigger: 'axis',
2026-06-12 11:16:10 +08:00
...techChartTooltip
2026-04-29 09:15:49 +08:00
},
grid: {
top: '10%',
left: '10%',
right: '5%',
bottom: '15%',
containLabel: true
},
xAxis: {
type: 'category',
data: projectData.map((item) => item.projectName || item.name || '未知'),
2026-06-12 11:16:10 +08:00
axisLine: techChartAxisLine,
2026-04-29 09:15:49 +08:00
axisLabel: {
2026-06-12 11:16:10 +08:00
...compactAxisLabel,
2026-04-29 09:15:49 +08:00
rotate: 30,
interval: 0,
overflow: 'truncate',
width: 60,
margin: 8
}
},
yAxis: {
type: 'value',
name: '数量',
2026-06-12 11:16:10 +08:00
nameTextStyle: chartNameTextStyle,
splitLine: dashedSplitLine,
axisLine: techChartAxisLine,
axisLabel: compactAxisLabel
2026-04-29 09:15:49 +08:00
},
series: [
{
name: '网关数量',
data: projectData.map((item) => item.gatewayNum || item.count || 0),
type: 'bar',
barWidth: '40%',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
2026-06-12 11:16:10 +08:00
{ offset: 0, color: techChartSeriesColors[0] },
{ offset: 1, color: techChartSeriesColors[4] }
2026-04-29 09:15:49 +08:00
]),
borderRadius: [4, 4, 0, 0]
}
}
]
})
export const getAlertTrendOption = () => ({
tooltip: {
trigger: 'axis',
2026-06-12 11:16:10 +08:00
...techChartTooltip
2026-04-29 09:15:49 +08:00
},
legend: {
data: ['二级报警', '报警', '预警'],
right: 10,
top: 0,
2026-06-12 11:16:10 +08:00
...techChartLegend,
2026-04-29 09:15:49 +08:00
textStyle: {
2026-06-12 11:16:10 +08:00
...techChartLegend.textStyle,
2026-04-29 09:15:49 +08:00
fontSize: 10
},
itemWidth: 10,
itemHeight: 10
},
grid: {
top: '15%',
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
data: ['01', '05', '10', '15', '20', '25', '30'],
2026-06-12 11:16:10 +08:00
axisLine: techChartAxisLine,
axisLabel: compactAxisLabel
2026-04-29 09:15:49 +08:00
},
yAxis: {
type: 'value',
name: '数量',
2026-06-12 11:16:10 +08:00
nameTextStyle: chartNameTextStyle,
splitLine: dashedSplitLine,
axisLine: techChartAxisLine,
axisLabel: compactAxisLabel
2026-04-29 09:15:49 +08:00
},
series: [
{
name: '二级报警',
data: [0, 1, 1, 2, 0, 0, 3],
type: 'line',
smooth: true,
lineStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[5],
2026-04-29 09:15:49 +08:00
width: 2
},
itemStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[5]
2026-04-29 09:15:49 +08:00
},
markPoint: {
data: [
{
type: 'max',
name: 'Max'
},
{
type: 'min',
name: 'Min'
}
]
}
},
{
name: '报警',
data: [1, 0, 0, 1, 1, 1, 0],
type: 'line',
smooth: true,
lineStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[3],
2026-04-29 09:15:49 +08:00
width: 2
},
itemStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[3]
2026-04-29 09:15:49 +08:00
},
markPoint: {
data: [
{
type: 'max',
name: 'Max'
},
{
type: 'min',
name: 'Min'
}
]
}
},
{
name: '预警',
data: [0, 1, 1, 0, 1, 1, 1],
type: 'line',
smooth: true,
lineStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[2],
2026-04-29 09:15:49 +08:00
width: 2
},
itemStyle: {
2026-06-12 11:16:10 +08:00
color: techChartSeriesColors[2]
2026-04-29 09:15:49 +08:00
},
markPoint: {
data: [
{
type: 'max',
name: 'Max'
},
{
type: 'min',
name: 'Min'
}
]
}
}
]
})