-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathCounters.vue
78 lines (71 loc) · 2.26 KB
/
Counters.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script setup>
import NumberFlow from '@number-flow/vue'
import { Flame, MousePointerClick, Users } from 'lucide-vue-next'
const defaultData = Object.freeze({
visits: 0,
visitors: 0,
referers: 0,
})
const counters = ref(defaultData)
const id = inject('id')
const time = inject('time')
const filters = inject('filters')
async function getLinkCounters() {
counters.value = defaultData
const { data } = await useAPI('/api/stats/counters', {
query: {
id: id.value,
startAt: time.value.startAt,
endAt: time.value.endAt,
...filters.value,
},
})
counters.value = data?.[0]
}
const stopWatchQueryChange = watch([time, filters], getLinkCounters, {
deep: true,
})
onMounted(async () => {
getLinkCounters()
})
onBeforeUnmount(() => {
stopWatchQueryChange()
})
</script>
<template>
<div class="grid gap-4 sm:gap-3 lg:gap-4 sm:grid-cols-3">
<Card>
<CardHeader class="flex flex-row justify-between items-center pb-2 space-y-0">
<CardTitle class="text-sm font-medium">
{{ $t('dashboard.visits') }}
</CardTitle>
<MousePointerClick class="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<NumberFlow class="text-2xl font-bold" :class="{ 'blur-md opacity-60': !counters.visits }" :value="counters.visits" />
</CardContent>
</Card>
<Card>
<CardHeader class="flex flex-row justify-between items-center pb-2 space-y-0">
<CardTitle class="text-sm font-medium">
{{ $t('dashboard.visitors') }}
</CardTitle>
<Users class="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<NumberFlow class="text-2xl font-bold" :class="{ 'blur-md opacity-60': !counters.visitors }" :value="counters.visitors" />
</CardContent>
</Card>
<Card>
<CardHeader class="flex flex-row justify-between items-center pb-2 space-y-0">
<CardTitle class="text-sm font-medium">
{{ $t('dashboard.referers') }}
</CardTitle>
<Flame class="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<NumberFlow class="text-2xl font-bold" :class="{ 'blur-md opacity-60': !counters.referers }" :value="counters.referers" />
</CardContent>
</Card>
</div>
</template>