fix(store-overview): 修复重命名后的类型报错

- shopComparisons 类型修正(ShopOverview 非数组)
- Segmented options 移除 readonly约束
- 删除未使用的 toggleSort/sortIcon/route/useRoute
- 修复 profitAfterTax 可能为 undefined 的比较
- 删除废弃的 product/overview/tabs/OverviewTab.vue
This commit is contained in:
小蟑螂
2026-04-28 01:18:21 +08:00
parent 9adc8567b3
commit b25e01a15c
5 changed files with 7 additions and 203 deletions
@@ -1,185 +0,0 @@
<script lang="ts" setup>
import type { ProductOverviewVO } from '#/api/ecommerce/product-overview/types';
import { onMounted, ref, watch } from 'vue';
import { Card, Col, DatePicker, message, Row, Space, Typography } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getProductOverviewApi } from '#/api/ecommerce/product-overview';
import ChartCard from '../../../shop/details/components/ChartCard.vue';
defineOptions({ name: 'ProductOverviewTab' });
const props = defineProps<Props>();
interface Props {
productId: number;
}
// 响应式数据
const loading = ref(false);
const overviewData = ref<null | ProductOverviewVO.Overview>(null);
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().subtract(30, 'day'),
dayjs(),
]);
// 格式化金额
function formatCurrency(value: number): string {
return `¥${value.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}
// 格式化百分比
function formatPercent(value: number): string {
return `${(value * 100).toFixed(2)}%`;
}
// 获取商品总览数据
async function fetchProductOverview() {
if (!props.productId || !dateRange.value) return;
try {
loading.value = true;
const data = await getProductOverviewApi({
productId: props.productId,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
});
overviewData.value = data;
} catch (error) {
console.error('获取商品总览失败:', error);
message.error('获取商品总览失败');
} finally {
loading.value = false;
}
}
// 处理日期范围变化
function handleDateRangeChange() {
fetchProductOverview();
}
// 监听 productId 变化
watch(
() => props.productId,
(newProductId) => {
if (newProductId) {
fetchProductOverview();
}
},
);
// 初始化数据
onMounted(() => {
if (props.productId) {
fetchProductOverview();
}
});
</script>
<template>
<div class="flex h-full flex-col">
<!-- 日期选择器 -->
<Card :loading="loading" class="mb-4 flex-shrink-0">
<Space>
<span>选择日期范围:</span>
<DatePicker.RangePicker
v-model:value="dateRange"
format="YYYY-MM-DD"
@change="handleDateRangeChange"
/>
</Space>
</Card>
<!-- 商品名称标题 -->
<Card v-if="overviewData" :loading="loading" class="mb-4 flex-shrink-0">
<Typography.Title :level="4" style="margin: 0">
{{ overviewData.productName }}
</Typography.Title>
</Card>
<!-- 图表展示 -->
<div v-if="overviewData" class="min-h-0 flex-1 overflow-auto">
<Row :gutter="[16, 16]">
<!-- 销售额 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.salesAmount"
:formatter="formatCurrency"
title="销售额"
/>
</Col>
<!-- 订单数 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.orderCount"
:formatter="(v) => v.toLocaleString()"
chart-type="bar"
color="#019680"
title="订单数"
/>
</Col>
<!-- 客单价 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.averageOrderValue"
:formatter="formatCurrency"
color="#ff9800"
title="客单价"
/>
</Col>
<!-- 成本 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.costAmount"
:formatter="formatCurrency"
color="#f56c6c"
title="成本"
/>
</Col>
<!-- 退款金额 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.refundAmount"
:formatter="formatCurrency"
color="#e6a23c"
title="退款金额"
/>
</Col>
<!-- 推广费 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.promotionFee"
:formatter="formatCurrency"
color="#909399"
title="推广费"
/>
</Col>
<!-- 费比 -->
<Col :lg="12" :md="24" :sm="24" :xl="8" :xxl="8" :xs="24">
<ChartCard
:data="overviewData.feeRatio"
:formatter="formatPercent"
color="#67c23a"
title="费比"
/>
</Col>
</Row>
</div>
<!-- 空状态 -->
<div v-else class="flex flex-1 items-center justify-center">
<span class="text-gray-400">暂无数据</span>
</div>
</div>
</template>