From 2a6b875bdb385756fc9c5dec78a03c97ad17729b Mon Sep 17 00:00:00 2001 From: ccbikai Date: Sun, 2 Mar 2025 13:40:43 +0800 Subject: [PATCH 1/6] feat: consolidate time filtering and add advanced filters Refactors time-based filtering by combining startAt/endAt into a single time object Adds support for additional filter types in stats API queries Implements deep watching for both time and filter changes Improves code organization and maintainability while enabling more flexible data filtering --- components/dashboard/Counters.vue | 22 +++---- components/dashboard/DatePicker.vue | 5 +- components/dashboard/Filter.vue | 63 +++++++++++++++++++++ components/dashboard/Index.vue | 50 ++++++++++------ components/dashboard/Views.vue | 19 ++++--- components/dashboard/metrics/Locations.vue | 15 +++-- components/dashboard/metrics/Metric.vue | 19 ++++--- public/apple-touch-icon-precomposed.png | Bin 0 -> 599 bytes schemas/query.ts | 6 +- server/utils/query-filter.ts | 18 +++--- server/utils/sql-bricks.ts | 9 ++- 11 files changed, 160 insertions(+), 66 deletions(-) create mode 100644 components/dashboard/Filter.vue create mode 100644 public/apple-touch-icon-precomposed.png diff --git a/components/dashboard/Counters.vue b/components/dashboard/Counters.vue index 528de8e..3f6a78d 100644 --- a/components/dashboard/Counters.vue +++ b/components/dashboard/Counters.vue @@ -11,36 +11,38 @@ const defaultData = Object.freeze({ const counters = ref(defaultData) const id = inject('id') -const startAt = inject('startAt') -const endAt = inject('endAt') - +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: startAt.value, - endAt: endAt.value, + startAt: time.value.startAt, + endAt: time.value.endAt, + ...filters.value, }, }) counters.value = data?.[0] } -const stopWatchTime = watch([startAt, endAt], getLinkCounters) +const stopWatchQueryChange = watch([time, filters], getLinkCounters, { + deep: true, +}) onMounted(async () => { getLinkCounters() }) onBeforeUnmount(() => { - stopWatchTime() + stopWatchQueryChange() })