fix dashboard empty data and split dev scripts
This commit is contained in:
@@ -85,34 +85,45 @@ const availableActions = computed(() => actions.filter(
|
||||
(action) => userStore.role === 'root' || userStore.menuCodes.includes(action.menu),
|
||||
));
|
||||
const centsToYuan = (value: number) => value / 100;
|
||||
const safeArray = <T,>(value: T[] | null | undefined): T[] =>
|
||||
Array.isArray(value) ? value : [];
|
||||
const pieOption = (data: { name: string; value: number }[]): EChartsOption => ({
|
||||
tooltip: { trigger: 'item' }, legend: { bottom: 0 },
|
||||
series: [{ type: 'pie', radius: ['42%', '68%'], center: ['50%', '44%'], data, label: { formatter: '{b}\\n{c}' } }],
|
||||
});
|
||||
const orderStatusOption = computed(() => pieOption(overview.value.order_statuses));
|
||||
const productStatusOption = computed(() => pieOption(overview.value.product_statuses));
|
||||
const orderStatusOption = computed(() => pieOption(safeArray(overview.value.order_statuses)));
|
||||
const productStatusOption = computed(() => pieOption(safeArray(overview.value.product_statuses)));
|
||||
const orderTrendOption = computed<EChartsOption>(() => ({
|
||||
tooltip: { trigger: 'axis' }, legend: { data: ['订单数', '订单金额'] },
|
||||
grid: { left: 48, right: 58, bottom: 34 },
|
||||
xAxis: { type: 'category', data: overview.value.recent_orders.map((item) => item.date.slice(5)) },
|
||||
xAxis: { type: 'category', data: safeArray(overview.value.recent_orders).map((item) => item.date.slice(5)) },
|
||||
yAxis: [{ type: 'value', name: '单' }, { type: 'value', name: '元' }],
|
||||
series: [
|
||||
{ name: '订单数', type: 'bar', data: overview.value.recent_orders.map((item) => item.order_count) },
|
||||
{ name: '订单金额', type: 'line', yAxisIndex: 1, smooth: true, data: overview.value.recent_orders.map((item) => centsToYuan(item.order_amount)) },
|
||||
{ name: '订单数', type: 'bar', data: safeArray(overview.value.recent_orders).map((item) => item.order_count) },
|
||||
{ name: '订单金额', type: 'line', yAxisIndex: 1, smooth: true, data: safeArray(overview.value.recent_orders).map((item) => centsToYuan(item.order_amount)) },
|
||||
],
|
||||
}));
|
||||
const paymentChannelOption = computed<EChartsOption>(() => ({
|
||||
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, grid: { left: 70, right: 24, bottom: 28 },
|
||||
xAxis: { type: 'value', name: '元' },
|
||||
yAxis: { type: 'category', data: overview.value.payment_channels.map((item) => item.name || '未知渠道') },
|
||||
series: [{ type: 'bar', data: overview.value.payment_channels.map((item) => centsToYuan(item.value)) }],
|
||||
yAxis: { type: 'category', data: safeArray(overview.value.payment_channels).map((item) => item.name || '未知渠道') },
|
||||
series: [{ type: 'bar', data: safeArray(overview.value.payment_channels).map((item) => centsToYuan(item.value)) }],
|
||||
}));
|
||||
|
||||
onMounted(async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await platformApi.overview();
|
||||
overview.value = { ...data, today_order_amount: centsToYuan(data.today_order_amount), paid_amount: centsToYuan(data.paid_amount) };
|
||||
overview.value = {
|
||||
...emptyOverview(),
|
||||
...data,
|
||||
today_order_amount: centsToYuan(data.today_order_amount ?? 0),
|
||||
paid_amount: centsToYuan(data.paid_amount ?? 0),
|
||||
order_statuses: safeArray(data.order_statuses),
|
||||
product_statuses: safeArray(data.product_statuses),
|
||||
payment_channels: safeArray(data.payment_channels),
|
||||
recent_orders: safeArray(data.recent_orders),
|
||||
};
|
||||
} catch (error) {
|
||||
Message.error((error as Error).message);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user