1111 <div class =" h-60 flex overflow-hidden" >
1212 <div class =" w-1/2 px-1" >
1313 <PieChart
14- :labels =" ['a', 'b', 'c', 'd']"
15- :series =" [1, 2, 3, 4]"
14+ :key =" JSON.stringify(mainLabels) + periodType"
15+ :labels =" mainLabels"
16+ :series =" mainSeries"
1617 @on-click =" changeMainCategory" />
1718 </div >
1819 <div class =" w-1/2 px-1" >
1920 <PieChart
20- :key =" mainCategory"
21- :labels ="
22- mainCategory
23- ? [`${mainCategory}-1`, `${mainCategory}-2`, `${mainCategory}-3`, `${mainCategory}-4`]
24- : ['카테고리를 선택해주세요']
25- "
26- :series =" mainCategory ? [1, 2, 3, 4] : []" />
21+ :key =" JSON.stringify(subLabels) + mainCategory + periodType"
22+ :labels =" subLabels"
23+ :series =" subSeries" />
2724 </div >
2825 </div >
2926 </div >
3027</template >
3128
3229<script setup lang="ts">
33- import { ref } from ' vue'
30+ import { computed , ref } from ' vue'
3431import PieChart from ' ../PieChart.vue'
3532import PeriodButtons from ' ./PeriodButtons.vue'
3633import type { PeriodType } from ' @/types/manager'
34+ import axiosInstance from ' @/utils/axios'
35+ import { useQuery } from ' @tanstack/vue-query'
36+ import type { StatisticsData } from ' @/types/admin'
3737
3838const periodType = ref <PeriodType >(' DAY' )
3939const changePeriod = (newPeriodType : PeriodType ) => {
@@ -42,4 +42,53 @@ const changePeriod = (newPeriodType: PeriodType) => {
4242
4343const mainCategory = ref (' ' )
4444const changeMainCategory = (value : string ) => (mainCategory .value = value )
45+
46+ const fetchMainStatistics = async () => {
47+ const response = await axiosInstance .get (' /api/tasks/statistics' , {
48+ headers: {
49+ Authorization: ` Bearer ${import .meta .env .VITE_ACCESS_TOKEN } `
50+ },
51+ params: {
52+ periodType: periodType .value ,
53+ statisticsType: ' REQUEST_BY_CATEGORY'
54+ }
55+ })
56+
57+ return response .data
58+ }
59+ const { data : mainData } = useQuery <StatisticsData []>({
60+ queryKey: [' REQUEST_BY_CATEGORY' , periodType ],
61+ queryFn: fetchMainStatistics
62+ })
63+ const mainLabels = computed (() => {
64+ return mainData .value ?.map (el => el .key ) || []
65+ })
66+ const mainSeries = computed (() => {
67+ return mainData .value ?.map (el => el .count ) || []
68+ })
69+
70+ const fetchSubStatistics = async () => {
71+ const response = await axiosInstance .get (' /api/tasks/statistics/subcategory' , {
72+ headers: {
73+ Authorization: ` Bearer ${import .meta .env .VITE_ACCESS_TOKEN } `
74+ },
75+ params: {
76+ periodType: periodType .value ,
77+ mainCategory: mainCategory .value
78+ }
79+ })
80+
81+ return response .data
82+ }
83+ const { data : subData } = useQuery <StatisticsData []>({
84+ queryKey: [mainCategory .value , periodType ],
85+ queryFn: fetchSubStatistics ,
86+ enabled: computed (() => mainCategory .value !== ' ' )
87+ })
88+ const subLabels = computed (() => {
89+ return subData .value ?.map (el => el .key ) || []
90+ })
91+ const subSeries = computed (() => {
92+ return subData .value ?.map (el => el .count ) || []
93+ })
4594 </script >
0 commit comments