diff --git a/backend/internal/router/admin/dashboard.go b/backend/internal/router/admin/dashboard.go index 057a151..8b06b34 100644 --- a/backend/internal/router/admin/dashboard.go +++ b/backend/internal/router/admin/dashboard.go @@ -130,8 +130,10 @@ func handleGetDashboard(c *gin.Context) { provinces := make([]gin.H, 0, len(deviceCounts)) for _, dc := range deviceCounts { provinces = append(provinces, gin.H{ - "name": dc.DeviceType, - "count": dc.Count, + "name": dc.DeviceType, + "count": dc.Count, + "online": 0, + "offline": dc.Count, }) } mu.Lock() diff --git a/frontend/src/pages/admin/index.vue b/frontend/src/pages/admin/index.vue index 752cf99..08b01ee 100644 --- a/frontend/src/pages/admin/index.vue +++ b/frontend/src/pages/admin/index.vue @@ -232,8 +232,10 @@ function fetchCurrentUser() { } async function initMapChart() { - if (!mapChart.value) + if (!mapChart.value) { + console.warn('Map chart container not found') return + } try { const [echarts, worldResponse] = await Promise.all([ @@ -241,6 +243,11 @@ async function initMapChart() { fetch('/world.json'), ]) + if (!mapChart.value) { + console.warn('Map chart container was unmounted during initialization') + return + } + if (!worldResponse.ok) { throw new Error('Failed to load world map data') } @@ -249,6 +256,11 @@ async function initMapChart() { echarts.registerMap('world', worldData) + if (chartInstance) { + chartInstance.dispose() + chartInstance = null + } + chartInstance = echarts.init(mapChart.value) updateMapOption() @@ -609,11 +621,18 @@ function updateMapOption() { } function initActivityChart() { - if (!activityChart.value) + if (!activityChart.value) { + console.warn('Activity chart container not found') return + } try { import('chart.js/auto').then(({ default: Chart }) => { + if (!activityChart.value) { + console.warn('Activity chart container was unmounted during initialization') + return + } + const ctx = activityChart.value?.getContext('2d') if (!ctx) return @@ -630,6 +649,7 @@ function initActivityChart() { if (activityChartInstance) { activityChartInstance.destroy() + activityChartInstance = null } activityChartInstance = new Chart(ctx, {