修复大屏的一些BUG

This commit is contained in:
wzclm 2025-03-13 09:28:23 +08:00
parent e661974160
commit f081d836af
4 changed files with 387 additions and 646 deletions

View File

@ -8,23 +8,7 @@ import { getDeviceList, deleteDevice } from "@/api/device";
const loading = ref(false);
//
const sensorList = ref([
{
id: 1,
device_name: "RK500-13-水质传感器-01",
device_code: "RK500-001",
device_type: 0,
status: 0,
install_location: "湿地区域A",
updated_at: new Date().toISOString(),
data: {
temp: null,
ph: null,
conductivity: null,
turbidity: null,
},
},
]);
const sensorList = ref([]);
//
const pagination = ref({
@ -34,41 +18,41 @@ const pagination = ref({
});
//
// const getSensorList = async () => {
// loading.value = true;
// try {
// const res = await getDeviceList({
// page: pagination.value.page,
// page_size: pagination.value.page_size,
// device_type: 0,
// });
// if (res.success) {
// sensorList.value = res.data.list || [];
// if (res.data.pagination) {
// pagination.value.total = res.data.pagination.total;
// }
// } else {
// ElMessage.error(res.message || "");
// }
// } catch (error) {
// console.error("", error);
// ElMessage.error("");
// } finally {
// loading.value = false;
// }
// };
const getSensorList = async () => {
loading.value = true;
try {
const res = await getDeviceList({
page: pagination.value.page,
page_size: pagination.value.page_size,
device_type: 0, // 0
});
if (res.success) {
sensorList.value = res.data.list || [];
if (res.data.pagination) {
pagination.value.total = res.data.pagination.total;
}
} else {
ElMessage.error(res.message || "获取传感器列表失败");
}
} catch (error) {
console.error("获取传感器列表失败:", error);
ElMessage.error("获取传感器列表失败");
} finally {
loading.value = false;
}
};
//
const handleCurrentChange = (page) => {
pagination.value.page = page;
// getSensorList();
getSensorList();
};
//
const handleSizeChange = (size) => {
pagination.value.page_size = size;
pagination.value.page = 1;
// getSensorList();
getSensorList();
};
//
@ -80,7 +64,7 @@ const handleDelete = async (id) => {
const res = await deleteDevice(id);
if (res.success) {
ElMessage.success("删除成功");
// getSensorList();
getSensorList();
} else {
ElMessage.error(res.message || "删除失败");
}
@ -130,17 +114,8 @@ const getTypeInfo = (type) => {
//
const formatValue = (value, unit = "") => {
if (value === "---") return value;
if (value === null || value === undefined) return "暂无数据";
//
if (unit === "°C") {
return `${value.toFixed(1)}${unit}`;
} else if (unit === "%") {
return `${value.toFixed(0)}${unit}`;
} else if (unit === "μS/cm") {
return `${value.toFixed(0)}${unit}`;
}
return `${value.toFixed(0)}${unit}`;
return `${value}${unit}`;
};
//
@ -152,144 +127,54 @@ const getSensorTypeName = (type, name) => {
//
const getSensorDataItems = (sensor) => {
// 线"---"
if (sensor.status === 0) {
return [{ label: "TDS值", value: "---", unit: "" }];
if (sensor.device_name.includes("CS616")) {
//
return [
{ label: "温度", value: sensor.data?.temp, unit: "°C" },
{ label: "湿度", value: sensor.data?.humi, unit: "%" },
{ label: "土壤湿度", value: sensor.data?.soil_adc, unit: "" },
{ label: "光照强度", value: sensor.data?.light_adc, unit: "" },
];
} else if (sensor.device_name.includes("RK500-13")) {
//
return [
{ label: "温度", value: sensor.data?.temp, unit: "°C" },
{ label: "湿度", value: sensor.data?.humi, unit: "%" },
{ label: "水质电导率", value: sensor.data?.soil_adc, unit: "μS/cm" },
{ label: "光照强度", value: sensor.data?.light_adc, unit: "" },
];
}
// 线
return [{ label: "TDS值", value: sensor.data?.tds, unit: "mg/L" }];
//
return [
{ label: "温度", value: sensor.data?.temp, unit: "°C" },
{ label: "湿度", value: sensor.data?.humi, unit: "%" },
{ label: "光照强度", value: sensor.data?.light_adc, unit: "" },
{ label: "传感器值", value: sensor.data?.soil_adc, unit: "" },
];
};
//
const dataRefreshTimers = ref({
h: null,
c: null,
f: null,
});
//
const handleKeyPress = (event) => {
const key = event.key.toLowerCase();
//
if (key === "l") {
const isOnline = sensorList.value[0].status === 1;
sensorList.value = sensorList.value.map((sensor) => ({
...sensor,
status: isOnline ? 0 : 1,
updated_at: new Date().toISOString(),
data: {
tds: null,
},
}));
//
Object.entries(dataRefreshTimers.value).forEach(([timerKey, timer]) => {
if (timer) {
clearInterval(timer);
dataRefreshTimers.value[timerKey] = null;
}
});
if (event.key.toLowerCase() === "v") {
ElNotification({
title: isOnline ? "设备离线" : "设备上线",
message: isOnline ? "设备已停止工作" : "设备开始工作",
type: isOnline ? "warning" : "success",
duration: 2000,
title: "设备状态更新",
message: "设备已上线",
type: "success",
position: "top-right",
duration: 3000,
});
return;
}
// 线
if (sensorList.value.some((sensor) => sensor.status === 0)) {
return;
}
//
const substanceData = {
h: {
// (1000-1370)
tds: 1185,
},
c: {
// (200-248)
tds: 224,
},
f: {
// (450-490)
tds: 470,
},
};
if (key === "h" || key === "c" || key === "f") {
//
if (dataRefreshTimers.value[key]) {
clearInterval(dataRefreshTimers.value[key]);
dataRefreshTimers.value[key] = null;
// ---
sensorList.value = sensorList.value.map((sensor) => ({
...sensor,
data: {
tds: null,
},
}));
return;
}
//
Object.entries(dataRefreshTimers.value).forEach(([timerKey, timer]) => {
if (timer) {
clearInterval(timer);
dataRefreshTimers.value[timerKey] = null;
}
});
//
const startData = substanceData[key];
dataRefreshTimers.value[key] = setInterval(() => {
//
let randomValue;
switch (key) {
case "h":
// 1000-1370
randomValue = 1000 + Math.random() * 370;
break;
case "c":
// 200-248
randomValue = 200 + Math.random() * 48;
break;
case "f":
// 450-490
randomValue = 450 + Math.random() * 40;
break;
}
//
sensorList.value = sensorList.value.map((sensor) => ({
...sensor,
status: 1,
updated_at: new Date().toISOString(),
data: {
tds: randomValue,
},
}));
}, 1000); //
}
};
//
onMounted(() => {
getSensorList();
window.addEventListener("keypress", handleKeyPress);
});
//
onUnmounted(() => {
window.removeEventListener("keypress", handleKeyPress);
//
Object.values(dataRefreshTimers.value).forEach((timer) => {
if (timer) clearInterval(timer);
});
});
</script>
@ -349,28 +234,9 @@ onUnmounted(() => {
v-for="(item, index) in getSensorDataItems(sensor)"
:key="index"
class="data-item"
style="
grid-column: 1 / -1;
background: #fff;
padding: 20px 40px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
"
>
<div
class="data-value"
style="font-size: 32px; color: #1890ff; text-align: center"
>
{{ formatValue(item.value, item.unit) }}
</div>
<div
class="data-label"
style="font-size: 14px; margin-top: 8px; text-align: center"
>
{{ item.label }}
</div>
<div class="data-value">{{ formatValue(item.value, item.unit) }}</div>
<div class="data-label">{{ item.label }}</div>
</div>
</div>
</div>
@ -383,6 +249,12 @@ onUnmounted(() => {
: "暂无数据"
}}
</div>
<div class="actions">
<el-button type="primary" link>编辑</el-button>
<el-button type="danger" link @click="handleDelete(sensor.id)"
>删除</el-button
>
</div>
</div>
</div>
</div>
@ -452,6 +324,11 @@ onUnmounted(() => {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}
&.offline {
opacity: 0.8;
background: #f5f7fa;
}
.card-header {
padding: 16px 20px;
border-bottom: 1px solid #f0f2f5;
@ -545,11 +422,6 @@ onUnmounted(() => {
padding: 12px;
border-radius: 8px;
text-align: center;
height: 76px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.data-value {
font-size: 20px;
@ -557,18 +429,11 @@ onUnmounted(() => {
color: #409eff;
margin-bottom: 4px;
font-family: "DIN Alternate", sans-serif;
transition: all 0.3s ease;
min-height: 30px;
line-height: 30px;
width: 100%;
}
.data-label {
font-size: 12px;
color: #909399;
min-height: 18px;
line-height: 18px;
width: 100%;
}
}
}
@ -592,25 +457,10 @@ onUnmounted(() => {
font-size: 14px;
}
}
}
}
&.offline {
opacity: 0.8;
background: #f5f7fa;
.data-section {
.data-grid {
.data-item {
.data-value {
color: #909399 !important;
font-size: 18px !important;
letter-spacing: 2px;
display: flex;
justify-content: center;
align-items: center;
}
}
.actions {
display: flex;
gap: 12px;
}
}
}

View File

@ -1,15 +1,15 @@
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import * as echarts from "echarts";
import { markRaw } from "vue";
import { markRaw } from 'vue'
import {
Monitor,
DataAnalysis,
Location,
Document,
Warning,
Warning
} from "@element-plus/icons-vue";
import { getSpeciesStatistics, getPatrolStatistics, getDeviceList } from "@/api/dashboard";
import { getSpeciesStatistics, getPatrolStatistics, getDeviceList } from '@/api/dashboard'
// 使 markRaw
const icons = {
@ -17,341 +17,334 @@ const icons = {
DataAnalysis: markRaw(DataAnalysis),
Location: markRaw(Location),
Document: markRaw(Document),
Warning: markRaw(Warning),
Warning: markRaw(Warning)
};
//
const categoryOptions = [
{ label: "鸟类", value: "bird" },
{ label: "哺乳类", value: "mammal" },
{ label: "鱼类", value: "fish" },
{ label: "两栖类", value: "amphibian" },
{ label: "爬行类", value: "reptile" },
{ label: "昆虫类", value: "insect" },
{ label: "植物", value: "plant" },
];
{ label: '鸟类', value: 'bird' },
{ label: '哺乳类', value: 'mammal' },
{ label: '鱼类', value: 'fish' },
{ label: '两栖类', value: 'amphibian' },
{ label: '爬行类', value: 'reptile' },
{ label: '昆虫类', value: 'insect' },
{ label: '植物', value: 'plant' }
]
//
const protectionLevelOptions = [
{ label: "国家一级", value: "national_first" },
{ label: "国家二级", value: "national_second" },
{ label: "省级", value: "provincial" },
{ label: "普通", value: "normal" },
];
{ label: '国家一级', value: 'national_first' },
{ label: '国家二级', value: 'national_second' },
{ label: '省级', value: 'provincial' },
{ label: '普通', value: 'normal' }
]
//
const categoryChartRef = ref(null);
let categoryChart = null;
const protectionChartRef = ref(null);
let protectionChart = null;
const categoryChartRef = ref(null)
let categoryChart = null
const protectionChartRef = ref(null)
let protectionChart = null
//
const statsCards = ref([
{
title: "物种监测",
title: '物种监测',
icon: icons.Monitor,
value: "0",
unit: "种",
change: { value: "0", label: "今日新增" },
color: "#1890FF",
bgColor: "linear-gradient(120deg, #0072FF 0%, #00C6FF 100%)",
features: ["实时监测", "智能识别", "行为分析", "分布追踪"],
value: '0',
unit: '种',
change: { value: '0', label: '今日新增' },
color: '#1890FF',
bgColor: 'linear-gradient(120deg, #0072FF 0%, #00C6FF 100%)',
features: ['实时监测', '智能识别', '行为分析', '分布追踪']
},
{
title: "环境监测",
title: '环境监测',
icon: icons.DataAnalysis,
value: "2",
unit: "点",
change: { value: "2", label: "异常" },
color: "#F5222D",
bgColor: "linear-gradient(120deg, #FF416C 0%, #FF4B2B 100%)",
features: ["水质监测", "空气监测", "土壤监测", "气象监测"],
value: '2',
unit: '点',
change: { value: '2', label: '异常' },
color: '#F5222D',
bgColor: 'linear-gradient(120deg, #FF416C 0%, #FF4B2B 100%)',
features: ['水质监测', '空气监测', '土壤监测', '气象监测']
},
{
title: "巡护任务",
title: '巡护任务',
icon: icons.Location,
value: "0",
unit: "个",
change: { value: "0%", label: "完成率" },
color: "#52C41A",
bgColor: "linear-gradient(120deg, #00B09B 0%, #96C93D 100%)",
features: ["智能派单", "轨迹记录", "实时通讯", "数据采集"],
value: '0',
unit: '个',
change: { value: '0%', label: '完成率' },
color: '#52C41A',
bgColor: 'linear-gradient(120deg, #00B09B 0%, #96C93D 100%)',
features: ['智能派单', '轨迹记录', '实时通讯', '数据采集']
},
{
title: "设备状态",
title: '设备状态',
icon: icons.Monitor,
value: "0",
unit: "台",
change: { value: "0%", label: "在线率" },
color: "#722ED1",
bgColor: "linear-gradient(120deg, #7F00FF 0%, #E100FF 100%)",
features: ["状态监控", "故障预警", "维护管理", "性能分析"],
},
value: '0',
unit: '台',
change: { value: '0%', label: '在线率' },
color: '#722ED1',
bgColor: 'linear-gradient(120deg, #7F00FF 0%, #E100FF 100%)',
features: ['状态监控', '故障预警', '维护管理', '性能分析']
}
]);
//
const deviceData = ref({
total: 0,
online: 0,
});
online: 0
})
//
const initCategoryChart = () => {
if (!categoryChartRef.value) return;
if (!categoryChartRef.value) return
categoryChart = echarts.init(categoryChartRef.value);
categoryChart = echarts.init(categoryChartRef.value)
const option = {
tooltip: {
trigger: "item",
formatter: "{b}: {c}种 ({d}%)",
trigger: 'item',
formatter: '{b}: {c}种 ({d}%)'
},
legend: {
orient: "vertical",
left: "left",
top: "middle",
orient: 'vertical',
left: 'left',
top: 'middle',
textStyle: {
color: "#303133",
},
color: '#303133'
}
},
series: [
{
name: "物种数量",
type: "pie",
radius: ["40%", "70%"],
center: ["60%", "50%"],
name: '物种数量',
type: 'pie',
radius: ['40%', '70%'],
center: ['60%', '50%'],
avoidLabelOverlap: true,
itemStyle: {
borderRadius: 10,
borderColor: "#fff",
borderWidth: 2,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: true,
formatter: "{b}: {c}种",
formatter: '{b}: {c}种'
},
emphasis: {
label: {
show: true,
fontSize: 14,
fontWeight: "bold",
fontWeight: 'bold'
},
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
},
data: [],
},
],
};
data: []
}
]
}
categoryChart.setOption(option);
};
categoryChart.setOption(option)
}
//
const updateCategoryChart = (data) => {
if (!categoryChart) return;
if (!categoryChart) return
//
const categoryData = Object.entries(data.categories)
.filter(([_, count]) => count.total_count > 0)
.map(([category, count]) => ({
name: categoryOptions.find((item) => item.value === category)?.label || category,
value: parseInt(count.total_count),
name: categoryOptions.find(item => item.value === category)?.label || category,
value: parseInt(count.total_count)
}))
.sort((a, b) => b.value - a.value);
.sort((a, b) => b.value - a.value)
categoryChart.setOption({
series: [
{
data: categoryData,
},
],
});
};
series: [{
data: categoryData
}]
})
}
//
const fetchSpeciesData = async () => {
try {
const res = await getSpeciesStatistics();
const res = await getSpeciesStatistics()
if (res.success && res.data) {
//
const totalSpecies = Object.values(res.data.categories).reduce(
(sum, category) => sum + (parseInt(category.total_count) || 0),
0
);
const todayNew = Object.values(res.data.categories).reduce(
(sum, category) => sum + (parseInt(category.today_count) || 0),
0
);
const totalSpecies = Object.values(res.data.categories).reduce((sum, category) =>
sum + (parseInt(category.total_count) || 0), 0)
const todayNew = Object.values(res.data.categories).reduce((sum, category) =>
sum + (parseInt(category.today_count) || 0), 0)
//
statsCards.value[0].value = String(totalSpecies || 0);
statsCards.value[0].change.value = `+${todayNew || 0}`;
statsCards.value[0].value = String(totalSpecies || 0)
statsCards.value[0].change.value = `+${todayNew || 0}`
//
updateCategoryChart(res.data);
updateCategoryChart(res.data)
}
} catch (error) {
console.error("获取物种统计数据失败:", error);
console.error('获取物种统计数据失败:', error)
}
};
}
//
const fetchPatrolData = async () => {
try {
const res = await getPatrolStatistics();
const res = await getPatrolStatistics()
if (res.success && res.data) {
const { overview } = res.data;
const progress = ((overview.completed_count / overview.total_count) * 100).toFixed(1);
const { overview } = res.data
const progress = ((overview.completed_count / overview.total_count) * 100).toFixed(1)
//
statsCards.value[2].value = String(overview.total_count);
statsCards.value[2].change.value = `${progress}%`;
statsCards.value[2].value = String(overview.total_count)
statsCards.value[2].change.value = `${progress}%`
}
} catch (error) {
console.error("获取巡护任务统计数据失败:", error);
console.error('获取巡护任务统计数据失败:', error)
}
};
}
//
const fetchDeviceData = async () => {
try {
const res = await getDeviceList();
const res = await getDeviceList()
if (res.success && res.data?.list) {
const deviceList = res.data.list;
const deviceList = res.data.list
deviceData.value = {
total: deviceList.length,
online: deviceList.filter((device) => device.status?.code === 1).length,
};
online: deviceList.filter(device => device.status?.code === 1).length
}
//
statsCards.value[3].value = String(deviceData.value.total);
statsCards.value[3].change.value = `${(
(deviceData.value.online / deviceData.value.total) *
100
).toFixed(1)}%`;
statsCards.value[3].value = String(deviceData.value.total)
statsCards.value[3].change.value = `${((deviceData.value.online / deviceData.value.total) * 100).toFixed(1)}%`
//
statsCards.value[3].features = [
`在线: ${deviceData.value.online}`,
`离线: ${deviceData.value.total - deviceData.value.online}`,
"故障预警",
"性能分析",
];
'故障预警',
'性能分析'
]
}
} catch (error) {
console.error("获取设备列表数据失败:", error);
console.error('获取设备列表数据失败:', error)
}
};
}
//
const initProtectionChart = () => {
if (!protectionChartRef.value) return;
if (!protectionChartRef.value) return
protectionChart = echarts.init(protectionChartRef.value);
protectionChart = echarts.init(protectionChartRef.value)
const option = {
title: {
text: "保护等级统计",
text: '保护等级统计',
textStyle: {
fontSize: 16,
fontWeight: 500,
color: "#303133",
},
color: '#303133'
}
},
tooltip: {
trigger: "axis",
trigger: 'axis',
axisPointer: {
type: "shadow",
type: 'shadow'
},
formatter: "{b}: {c}种",
formatter: '{b}: {c}种'
},
grid: {
left: "3%",
right: "4%",
bottom: "10%",
containLabel: true,
left: '3%',
right: '4%',
bottom: '10%',
containLabel: true
},
xAxis: {
type: "category",
type: 'category',
data: [],
axisLabel: {
interval: 0,
rotate: 30,
},
rotate: 30
}
},
yAxis: {
type: "value",
name: "物种数量",
minInterval: 1,
type: 'value',
name: '物种数量',
minInterval: 1
},
series: [
{
name: "物种数量",
type: "bar",
barWidth: "40%",
name: '物种数量',
type: 'bar',
barWidth: '40%',
data: [],
label: {
show: true,
position: "top",
formatter: "{c}种",
},
},
],
};
position: 'top',
formatter: '{c}种'
}
}
]
}
protectionChart.setOption(option);
};
protectionChart.setOption(option)
}
//
const updateProtectionChart = (data) => {
if (!protectionChart) return;
if (!protectionChart) return
//
const protectionData = Object.entries(data.protection_levels)
.filter(([_, count]) => count > 0)
.map(([level, count]) => ({
name: protectionLevelOptions.find((item) => item.value === level)?.label || level,
value: count,
name: protectionLevelOptions.find(item => item.value === level)?.label || level,
value: count
}))
.sort((a, b) => b.value - a.value);
.sort((a, b) => b.value - a.value)
protectionChart.setOption({
xAxis: {
data: protectionData.map((item) => item.name),
data: protectionData.map(item => item.name)
},
series: [
{
data: protectionData.map((item) => ({
value: item.value,
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: "#83bff6" },
{ offset: 0.5, color: "#409EFF" },
{ offset: 1, color: "#2c76c5" },
]),
},
})),
},
],
});
};
series: [{
data: protectionData.map(item => ({
value: item.value,
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#83bff6' },
{ offset: 0.5, color: '#409EFF' },
{ offset: 1, color: '#2c76c5' }
])
}
}))
}]
})
}
//
const initData = async () => {
try {
await Promise.all([fetchSpeciesData(), fetchPatrolData(), fetchDeviceData()]);
await Promise.all([
fetchSpeciesData(),
fetchPatrolData(),
fetchDeviceData()
])
} catch (error) {
console.error("初始化数据失败:", error);
console.error('初始化数据失败:', error)
}
};
}
//
let timer = null;
let timer = null
const startAutoRefresh = () => {
fetchStatisticsData();
timer = setInterval(fetchStatisticsData, 60000); //
};
fetchStatisticsData()
timer = setInterval(fetchStatisticsData, 60000) //
}
//
const initTrendChart = () => {
@ -365,129 +358,129 @@ const initTrendChart = () => {
textStyle: {
fontSize: 16,
fontWeight: 500,
color: "#303133",
},
color: '#303133'
}
},
tooltip: {
trigger: "axis",
backgroundColor: "rgba(255, 255, 255, 0.95)",
borderColor: "#eee",
trigger: 'axis',
backgroundColor: 'rgba(255, 255, 255, 0.95)',
borderColor: '#eee',
padding: [10, 15],
textStyle: {
color: "#666",
},
color: '#666'
}
},
legend: {
data: ["物种数量", "监测数据"],
data: ['物种数量', '监测数据'],
right: 20,
top: 10,
textStyle: {
color: "#666",
color: '#666'
},
itemWidth: 12,
itemHeight: 12,
itemGap: 20,
itemGap: 20
},
grid: {
left: "3%",
right: "4%",
bottom: "3%",
containLabel: true,
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: "category",
type: 'category',
boundaryGap: false,
data: ["3-14", "3-15", "3-16", "3-17", "3-18", "3-19", "3-20"],
data: ['2-14', '2-15', '2-16', '2-17', '2-18', '2-19', '2-20'],
axisLine: {
lineStyle: {
color: "#DCDFE6",
},
color: '#DCDFE6'
}
},
axisTick: {
show: false,
show: false
},
axisLabel: {
color: "#909399",
},
color: '#909399'
}
},
yAxis: {
type: "value",
type: 'value',
splitLine: {
lineStyle: {
color: "#EBEEF5",
type: "dashed",
},
color: '#EBEEF5',
type: 'dashed'
}
},
axisLabel: {
color: "#909399",
},
color: '#909399'
}
},
series: [
{
name: "物种数量",
type: "line",
name: '物种数量',
type: 'line',
smooth: true,
symbolSize: 8,
lineStyle: {
width: 3,
color: "#409EFF",
color: '#409EFF'
},
itemStyle: {
color: "#409EFF",
borderColor: "#fff",
borderWidth: 2,
color: '#409EFF',
borderColor: '#fff',
borderWidth: 2
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: "rgba(64, 158, 255, 0.2)" },
{ offset: 1, color: "rgba(64, 158, 255, 0)" },
]),
{ offset: 0, color: 'rgba(64, 158, 255, 0.2)' },
{ offset: 1, color: 'rgba(64, 158, 255, 0)' }
])
},
emphasis: {
itemStyle: {
borderWidth: 3,
shadowColor: "rgba(64, 158, 255, 0.5)",
shadowBlur: 10,
},
shadowColor: 'rgba(64, 158, 255, 0.5)',
shadowBlur: 10
}
},
data: [120, 132, 101, 134, 90, 230, 210],
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: "监测数据",
type: "line",
name: '监测数据',
type: 'line',
smooth: true,
symbolSize: 8,
lineStyle: {
width: 3,
color: "#67C23A",
color: '#67C23A'
},
itemStyle: {
color: "#67C23A",
borderColor: "#fff",
borderWidth: 2,
color: '#67C23A',
borderColor: '#fff',
borderWidth: 2
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: "rgba(103, 194, 58, 0.2)" },
{ offset: 1, color: "rgba(103, 194, 58, 0)" },
]),
{ offset: 0, color: 'rgba(103, 194, 58, 0.2)' },
{ offset: 1, color: 'rgba(103, 194, 58, 0)' }
])
},
emphasis: {
itemStyle: {
borderWidth: 3,
shadowColor: "rgba(103, 194, 58, 0.5)",
shadowBlur: 10,
},
shadowColor: 'rgba(103, 194, 58, 0.5)',
shadowBlur: 10
}
},
data: [220, 182, 191, 234, 290, 330, 310],
},
],
data: [220, 182, 191, 234, 290, 330, 310]
}
]
};
myChart.setOption(option);
//
window.addEventListener("resize", () => {
window.addEventListener('resize', () => {
myChart.resize();
});
};
@ -603,72 +596,68 @@ const initDistributionChart = () => {
//
const fetchStatisticsData = async () => {
try {
const res = await getSpeciesStatistics();
const res = await getSpeciesStatistics()
if (res.success && res.data) {
//
const totalSpecies = Object.values(res.data.categories).reduce(
(sum, item) => sum + (parseInt(item.total_count) || 0),
0
);
(sum, item) => sum + (parseInt(item.total_count) || 0), 0
)
const newSpecies = Object.values(res.data.categories).reduce(
(sum, item) => sum + (parseInt(item.today_count) || 0),
0
);
statsCards.value[0].value = String(totalSpecies || 0);
statsCards.value[0].change.value = `+${newSpecies || 0}`;
(sum, item) => sum + (parseInt(item.today_count) || 0), 0
)
statsCards.value[0].value = String(totalSpecies || 0)
statsCards.value[0].change.value = `+${newSpecies || 0}`
//
updateCategoryChart(res.data);
updateCategoryChart(res.data)
//
updateProtectionChart(res.data);
updateProtectionChart(res.data)
}
} catch (error) {
console.error("获取统计数据失败:", error);
console.error('获取统计数据失败:', error)
}
};
}
onMounted(() => {
initData();
startAutoRefresh();
initTrendChart();
initDistributionChart();
initCategoryChart();
initProtectionChart();
window.addEventListener("resize", () => {
categoryChart?.resize();
protectionChart?.resize();
});
initData()
startAutoRefresh()
initTrendChart()
initDistributionChart()
initCategoryChart()
initProtectionChart()
window.addEventListener('resize', () => {
categoryChart?.resize()
protectionChart?.resize()
})
});
onUnmounted(() => {
if (timer) {
clearInterval(timer);
clearInterval(timer)
}
if (categoryChart) {
categoryChart.dispose();
categoryChart = null;
categoryChart.dispose()
categoryChart = null
}
if (protectionChart) {
protectionChart.dispose();
protectionChart = null;
protectionChart.dispose()
protectionChart = null
}
window.removeEventListener("resize", () => {
categoryChart?.resize();
protectionChart?.resize();
});
});
window.removeEventListener('resize', () => {
categoryChart?.resize()
protectionChart?.resize()
})
})
</script>
<template>
<div class="dashboard-container">
<div class="stats-grid">
<div
v-for="card in statsCards"
:key="card.title"
class="stats-card"
:style="{ backgroundColor: card.bgColor }"
>
<div v-for="card in statsCards"
:key="card.title"
class="stats-card"
:style="{ backgroundColor: card.bgColor }">
<div class="card-header">
<div class="title">
<el-icon :size="20" :color="card.color">
@ -682,22 +671,17 @@ onUnmounted(() => {
{{ card.value }}
<span class="unit">{{ card.unit }}</span>
</div>
<div
class="change-value"
:style="{
color: card.change.value.includes('+')
? '#67C23A'
: card.change.value.includes('%')
? card.color
: '#F56C6C',
}"
>
<div class="change-value"
:style="{ color: card.change.value.includes('+') ? '#67C23A' :
card.change.value.includes('%') ? card.color : '#F56C6C' }">
{{ card.change.value }}
<span class="label">{{ card.change.label }}</span>
</div>
</div>
<div class="card-footer">
<div v-for="feature in card.features" :key="feature" class="feature-item">
<div v-for="feature in card.features"
:key="feature"
class="feature-item">
{{ feature }}
</div>
</div>
@ -719,66 +703,6 @@ onUnmounted(() => {
<div ref="protectionChartRef" class="chart-content"></div>
</div>
</div>
<div class="bottom-stats-grid">
<div class="stat-card">
<div class="stat-header">
<span class="stat-title">实时监测数据</span>
</div>
<div class="stat-content">
<div class="stat-item">
<span class="label">水质指标</span>
<span class="value good"></span>
</div>
<div class="stat-item">
<span class="label">空气质量</span>
<span class="value normal"></span>
</div>
<div class="stat-item">
<span class="label">土壤湿度</span>
<span class="value">42%</span>
</div>
</div>
</div>
<div class="stat-card">
<div class="stat-header">
<span class="stat-title">今日巡护概况</span>
</div>
<div class="stat-content">
<div class="stat-item">
<span class="label">巡护人员</span>
<span class="value">8</span>
</div>
<div class="stat-item">
<span class="label">巡护里程</span>
<span class="value">12.5km</span>
</div>
<div class="stat-item">
<span class="label">记录上报</span>
<span class="value">26</span>
</div>
</div>
</div>
<div class="stat-card">
<div class="stat-header">
<span class="stat-title">物种活动</span>
</div>
<div class="stat-content">
<div class="stat-item">
<span class="label">活动区域</span>
<span class="value">A3B5区</span>
</div>
<div class="stat-item">
<span class="label">活跃物种</span>
<span class="value">15</span>
</div>
<div class="stat-item">
<span class="label">监测频次</span>
<span class="value">4/</span>
</div>
</div>
</div>
</div>
</div>
</template>
@ -959,64 +883,7 @@ onUnmounted(() => {
}
}
}
.bottom-stats-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
margin-top: 40px;
padding-bottom: 20px;
.stat-card {
background: #fff;
border-radius: 8px;
padding: 16px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
.stat-header {
margin-bottom: 16px;
padding-bottom: 12px;
border-bottom: 1px solid #f0f2f5;
.stat-title {
font-size: 16px;
font-weight: 500;
color: #303133;
}
}
.stat-content {
.stat-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
&:last-child {
margin-bottom: 0;
}
.label {
color: #909399;
font-size: 14px;
}
.value {
font-size: 14px;
font-weight: 500;
color: #303133;
&.good {
color: #67c23a;
}
&.normal {
color: #e6a23c;
}
}
}
}
}
}
}
</style>

View File

@ -9,6 +9,14 @@ const chartRef = ref(null)
//
const alertData = ref({
total: 0,
level1: {
name: '低微预警',
total: 0,
color: '#909399',
pending: 0,
processed: 0,
ignored: 0
},
level2: {
name: '中等预警',
total: 0,
@ -75,7 +83,7 @@ const initChart = async () => {
},
xAxis: {
type: 'category',
data: ['严重预警', '中等预警'],
data: ['严重预警', '中等预警', '低微预警'],
axisLine: {
lineStyle: {
color: 'rgba(255, 255, 255, 0.3)'
@ -135,7 +143,7 @@ const initChart = async () => {
])
}
},
data: [0, 0]
data: [0, 0, 0]
},
{
name: '已处理',
@ -156,7 +164,7 @@ const initChart = async () => {
])
}
},
data: [0, 0]
data: [0, 0, 0]
},
{
name: '已忽略',
@ -177,7 +185,7 @@ const initChart = async () => {
])
}
},
data: [0, 0]
data: [0, 0, 0]
}
]
}
@ -192,6 +200,7 @@ const fetchAlertData = async () => {
if (res.success && res.data) {
//
let total = 0
let level1Data = { pending: 0, processed: 0, ignored: 0 }
let level2Data = { pending: 0, processed: 0, ignored: 0 }
let level3Data = { pending: 0, processed: 0, ignored: 0 }
@ -199,7 +208,13 @@ const fetchAlertData = async () => {
const count = Number(item.total_count) || 0
total += count
if (item.alert_level === 2) {
if (item.alert_level === 1) {
level1Data = {
pending: Number(item.pending_count) || 0,
processed: Number(item.processed_count) || 0,
ignored: Number(item.ignored_count) || 0
}
} else if (item.alert_level === 2) {
level2Data = {
pending: Number(item.pending_count) || 0,
processed: Number(item.processed_count) || 0,
@ -221,15 +236,15 @@ const fetchAlertData = async () => {
series: [
{
name: '待处理',
data: [level3Data.pending, level2Data.pending]
data: [level3Data.pending, level2Data.pending, level1Data.pending]
},
{
name: '已处理',
data: [level3Data.processed, level2Data.processed]
data: [level3Data.processed, level2Data.processed, level1Data.processed]
},
{
name: '已忽略',
data: [level3Data.ignored, level2Data.ignored]
data: [level3Data.ignored, level2Data.ignored, level1Data.ignored]
}
]
})

View File

@ -34,10 +34,10 @@ const initChart = async () => {
}
},
grid: {
top: '3%',
top: '8%',
right: '15%',
bottom: '3%',
left: '5%',
bottom: '15%',
left: '15%',
containLabel: true
},
xAxis: {
@ -46,7 +46,7 @@ const initChart = async () => {
nameTextStyle: {
color: 'rgba(255, 255, 255, 0.7)',
fontSize: 12,
padding: [0, 0, 0, 20]
padding: [15, 0, 0, 20]
},
axisLine: {
show: false
@ -62,7 +62,9 @@ const initChart = async () => {
},
axisLabel: {
color: 'rgba(255, 255, 255, 0.7)',
fontSize: 12
fontSize: 12,
margin: 12,
padding: [8, 0, 0, 0]
}
},
yAxis: {
@ -78,15 +80,21 @@ const initChart = async () => {
},
axisLabel: {
color: '#fff',
fontSize: 12,
margin: 16
fontSize: 14,
margin: 20,
formatter: function (value) {
if (value.length > 6) {
return value.substring(0, 6) + '...'
}
return value
}
}
},
series: [
{
name: '预警次数',
type: 'bar',
barWidth: 16,
barWidth: 12,
showBackground: true,
backgroundStyle: {
color: 'rgba(255, 255, 255, 0.05)',
@ -98,8 +106,9 @@ const initChart = async () => {
label: {
show: true,
position: 'right',
distance: 15,
color: '#fff',
fontSize: 12,
fontSize: 14,
formatter: '{c}次'
},
data: []