Sink/app/components/dashboard/realtime/Logs.vue
ccbikai 9106881448 fix: clean up globe arcs and prevent empty stats display
- Adds cleanup timer for globe arcs to prevent accumulation
- Conditionally renders chart header when stats are available
- Improves event handling in AnimatedList by passing props
- Fixes traffic event animation by clearing previous timeouts

These changes improve visualization performance and user experience by preventing memory leaks from accumulated arcs and ensuring smoother animations.
2025-05-18 21:17:19 +08:00

50 lines
1.1 KiB
Vue

<script setup>
import AnimatedList from '@/components/spark-ui/AnimatedList.vue'
import Notification from '@/components/spark-ui/Notification.vue'
const time = inject('time')
const filters = inject('filters')
const logs = ref([])
const logskey = ref(0)
async function getEvents() {
const data = await useAPI('/api/logs/events', {
query: {
startAt: time.value.startAt,
endAt: time.value.endAt,
...filters.value,
},
})
logs.value = data?.reverse()
logskey.value = Date.now()
}
watch([time, filters], getEvents, {
deep: true,
})
onMounted(async () => {
getEvents()
})
function onUpdateItems(...args) {
globalTrafficEvent.emit(...args)
}
</script>
<template>
<AnimatedList v-if="logs.length" :key="logskey" class="md:w-72" @update:items="onUpdateItems">
<template #default>
<Notification
v-for="item in logs"
:key="item.id"
:name="item.slug"
:description="[item.os, item.browser].filter(Boolean).join(' ')"
:icon="getFlag(item.country)"
:time="item.timestamp"
:item="item"
class="w-full"
/>
</template>
</AnimatedList>
</template>