| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <script lang="ts" setup> |
| | | import type { EChartsOption, EchartsUIType } from '#/packages/effects/plugins/src/echarts'; |
| | | |
| | | import { nextTick, onMounted, ref } from 'vue'; |
| | | |
| | | import { EchartsUI, useEcharts } from '#/packages/effects/plugins/src/echarts'; |
| | | |
| | | import { Card, Select } from 'ant-design-vue'; |
| | | |
| | | import { |
| | | getMessageTrend, |
| | | getUserTrend, |
| | | } from '#/api/im/manager/statistics'; |
| | | |
| | | const props = defineProps<{ |
| | | type: 'message' | 'user'; |
| | | }>(); |
| | | |
| | | const title = |
| | | props.type === 'message' |
| | | ? 'æ¶æ¯è¶å¿ï¼ç§è + 群èï¼' |
| | | : 'ç¨æ·è¶å¿ï¼æ°å¢æ³¨å + æ¥æ´»ï¼'; |
| | | |
| | | const days = ref(7); |
| | | const loading = ref(false); |
| | | const chartRef = ref<EchartsUIType>(); |
| | | const { renderEcharts } = useEcharts(chartRef); |
| | | |
| | | /** è·åå¾è¡¨é
ç½® */ |
| | | function buildOptions( |
| | | dates: string[], |
| | | series: Record<string, number[]>, |
| | | ): EChartsOption { |
| | | if (props.type === 'message') { |
| | | return { |
| | | tooltip: { trigger: 'axis' }, |
| | | legend: { data: ['ç§èæ¶æ¯', 'ç¾¤èæ¶æ¯'], top: 0 }, |
| | | grid: { left: 24, right: 24, bottom: 16, top: 42, containLabel: true }, |
| | | xAxis: { |
| | | type: 'category', |
| | | data: dates, |
| | | axisLabel: { formatter: (value: string) => value.slice(5, 10) }, |
| | | }, |
| | | yAxis: { type: 'value', name: 'æ¶æ¯é' }, |
| | | series: [ |
| | | { |
| | | name: 'ç§èæ¶æ¯', |
| | | type: 'line', |
| | | smooth: true, |
| | | data: series.private || [], |
| | | itemStyle: { color: '#2f7df6' }, |
| | | areaStyle: { color: 'rgba(47,125,246,0.12)' }, |
| | | }, |
| | | { |
| | | name: 'ç¾¤èæ¶æ¯', |
| | | type: 'line', |
| | | smooth: true, |
| | | data: series.group || [], |
| | | itemStyle: { color: '#18a058' }, |
| | | areaStyle: { color: 'rgba(24,160,88,0.12)' }, |
| | | }, |
| | | ], |
| | | }; |
| | | } |
| | | return { |
| | | tooltip: { trigger: 'axis' }, |
| | | legend: { data: ['æ°å¢æ³¨å', 'æ¥æ´»'], top: 0 }, |
| | | grid: { left: 24, right: 32, bottom: 16, top: 42, containLabel: true }, |
| | | xAxis: { |
| | | type: 'category', |
| | | data: dates, |
| | | axisLabel: { formatter: (value: string) => value.slice(5, 10) }, |
| | | }, |
| | | yAxis: [ |
| | | { type: 'value', name: 'æ°å¢æ³¨å', position: 'left' }, |
| | | { type: 'value', name: 'æ¥æ´»', position: 'right' }, |
| | | ], |
| | | series: [ |
| | | { |
| | | name: 'æ°å¢æ³¨å', |
| | | type: 'bar', |
| | | yAxisIndex: 0, |
| | | data: series.register || [], |
| | | itemStyle: { color: '#f59e0b' }, |
| | | barMaxWidth: 24, |
| | | }, |
| | | { |
| | | name: 'æ¥æ´»', |
| | | type: 'line', |
| | | yAxisIndex: 1, |
| | | smooth: true, |
| | | data: series.active || [], |
| | | itemStyle: { color: '#ef4444' }, |
| | | }, |
| | | ], |
| | | }; |
| | | } |
| | | |
| | | /** å è½½å¾è¡¨æ°æ® */ |
| | | async function loadData() { |
| | | loading.value = true; |
| | | try { |
| | | const data = |
| | | props.type === 'message' |
| | | ? await getMessageTrend(days.value) |
| | | : await getUserTrend(days.value); |
| | | await nextTick(); |
| | | await renderEcharts(buildOptions(data.dates, data.series)); |
| | | } finally { |
| | | loading.value = false; |
| | | } |
| | | } |
| | | |
| | | onMounted(loadData); |
| | | </script> |
| | | |
| | | <template> |
| | | <Card :body-style="{ padding: '12px 16px 16px' }"> |
| | | <template #title> |
| | | <div class="flex items-center justify-between"> |
| | | <span>{{ title }}</span> |
| | | <Select |
| | | v-model:value="days" |
| | | :options="[ |
| | | { label: 'è¿ 7 天', value: 7 }, |
| | | { label: 'è¿ 15 天', value: 15 }, |
| | | { label: 'è¿ 30 天', value: 30 }, |
| | | ]" |
| | | class="w-28" |
| | | size="small" |
| | | @change="loadData" |
| | | /> |
| | | </div> |
| | | </template> |
| | | <div class="relative min-h-[320px]"> |
| | | <EchartsUI ref="chartRef" height="320px" /> |
| | | <div |
| | | v-if="loading" |
| | | class="absolute inset-0 flex items-center justify-center bg-card/70 text-sm text-muted-foreground" |
| | | > |
| | | å è½½ä¸ |
| | | </div> |
| | | </div> |
| | | </Card> |
| | | </template> |