update dashboard
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
DollarOutlined,
|
||||
DatabaseOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
import type { Component } from 'vue'
|
||||
import type { DataTypeCount } from '@/types/api'
|
||||
|
||||
defineProps<{
|
||||
@@ -12,7 +13,7 @@ defineProps<{
|
||||
loading: boolean
|
||||
}>()
|
||||
|
||||
const iconMap: Record<string, ReturnType<typeof ShoppingCartOutlined>> = {
|
||||
const iconMap: Record<string, Component> = {
|
||||
order: ShoppingCartOutlined,
|
||||
product: ShoppingOutlined,
|
||||
refund: DollarOutlined,
|
||||
|
||||
@@ -66,11 +66,16 @@ function handleDataTypeChange(val: unknown) {
|
||||
emit('update:dataType', (val as string) || undefined)
|
||||
}
|
||||
|
||||
watch(flatData, () => {
|
||||
if (chart) {
|
||||
chart.changeData(flatData.value)
|
||||
watch(flatData, (newData) => {
|
||||
if (newData.length === 0 && chart) {
|
||||
chart.destroy()
|
||||
chart = null
|
||||
} else if (!chart && chartRef.value && newData.length > 0) {
|
||||
nextTick(() => createChart())
|
||||
} else if (chart) {
|
||||
chart.changeData(newData)
|
||||
}
|
||||
})
|
||||
}, { flush: 'post' })
|
||||
|
||||
onMounted(() => {
|
||||
if (props.data.length > 0) {
|
||||
@@ -78,15 +83,6 @@ onMounted(() => {
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.data,
|
||||
(newVal) => {
|
||||
if (newVal.length > 0 && !chart) {
|
||||
nextTick(() => createChart())
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (chart) {
|
||||
chart.destroy()
|
||||
|
||||
@@ -2,9 +2,7 @@ import { api } from '@/utils/request'
|
||||
import type {
|
||||
DashboardOverview,
|
||||
DashboardTrendPoint,
|
||||
DashboardTrendParams,
|
||||
DashboardBreakdownItem,
|
||||
DashboardBreakdownParams,
|
||||
} from '@/types/api'
|
||||
|
||||
export const useDashboardStore = defineStore('dashboard', () => {
|
||||
@@ -49,7 +47,7 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
trendLoading.value = true
|
||||
trendError.value = ''
|
||||
try {
|
||||
const params: DashboardTrendParams = {
|
||||
const params: Record<string, unknown> = {
|
||||
group_by: trendGroupBy.value,
|
||||
data_type: trendDataType.value,
|
||||
from: trendFrom.value,
|
||||
@@ -57,7 +55,7 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
}
|
||||
trendData.value = await api.get<DashboardTrendPoint[]>(
|
||||
'/api/v1/dashboard/trend',
|
||||
params as unknown as Record<string, unknown>,
|
||||
params,
|
||||
)
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : '获取趋势数据失败'
|
||||
@@ -72,7 +70,7 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
breakdownLoading.value = true
|
||||
breakdownError.value = ''
|
||||
try {
|
||||
const params: DashboardBreakdownParams = {
|
||||
const params: Record<string, unknown> = {
|
||||
dimension: breakdownDimension.value,
|
||||
data_type: breakdownDataType.value,
|
||||
from: breakdownFrom.value,
|
||||
@@ -80,7 +78,7 @@ export const useDashboardStore = defineStore('dashboard', () => {
|
||||
}
|
||||
breakdownData.value = await api.get<DashboardBreakdownItem[]>(
|
||||
'/api/v1/dashboard/breakdown',
|
||||
params as unknown as Record<string, unknown>,
|
||||
params,
|
||||
)
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : '获取分维度数据失败'
|
||||
|
||||
Reference in New Issue
Block a user