feat(shop-overview): 添加店铺运营数据表格展示及导出功能

- 后端: ShopOverviewStatisticsVO 新增 GMV/订单/转化率等 15 个指标字段
- 后端: ShopOverviewStatisticsServiceImpl 支持按店铺 ID 或全量查询聚合数据
- 后端: ExportController 支持按时间范围和店铺 ID 导出 Excel
- 前端: 店铺总览表格页展示 15 列核心运营指标,列宽固定,tbody 独立滚动
- 前端: 新增导出功能,支持按时间和店铺筛选导出 Excel
This commit is contained in:
小蟑螂
2026-04-21 21:26:31 +08:00
parent 00e53a20e3
commit 8f092f38d8
5 changed files with 517 additions and 70 deletions
@@ -49,6 +49,11 @@ const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
const exportLoading = ref(false);
const overviewData = ref<null | ShopVO.OverviewStatistics>(null);
// 品类导出相关
const categoryExportMode = ref(false);
const selectedExportCategoryIds = ref<number[]>([]);
const categoryExportLoading = ref(false);
// 日期范围
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().subtract(7, 'day'),
@@ -300,6 +305,40 @@ const handleExportShopOverview = async () => {
}
};
// 品类导出相关
const handleCategoryExportToggle = (enabled: boolean) => {
categoryExportMode.value = enabled;
if (enabled) selectedExportCategoryIds.value = [];
};
const handleCategoryExport = async () => {
try {
categoryExportLoading.value = true;
const params: {
categoryIds?: number[];
dateRange: string[];
taxRate: number;
} = {
dateRange: dateRange.value.map((d) => d.format('YYYY-MM-DD')),
taxRate: taxRate.value,
};
if (selectedExportCategoryIds.value.length > 0) {
params.categoryIds = selectedExportCategoryIds.value;
}
await exportByPost('/ec/shop/export-category', params, '门店品类对比.xlsx');
} finally {
categoryExportLoading.value = false;
}
};
const handleCategorySelectAllChange = (event: Event) => {
const target = event.target as HTMLInputElement | null;
if (!target) return;
selectedExportCategoryIds.value = target.checked
? (overviewData.value?.categoryComparisons?.map((c) => c.categoryId) ?? [])
: [];
};
const refreshOverviewByCurrentParams = async (force = false) => {
applyDateRangeFromRouteQuery();
if (!shopId.value) return;
@@ -1134,13 +1173,33 @@ onActivated(async () => {
</Button>
</div>
<div class="max-h-[420px] overflow-auto">
<!-- 表头(固定不滚动) -->
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<colgroup>
<col style="width: 220px; min-width: 220px;" />
<col style="width: 140px; min-width: 140px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 130px; min-width: 130px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 130px; min-width: 130px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 140px; min-width: 140px;" />
</colgroup>
<thead
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
style="position: sticky; top: 0; z-index: 20;"
>
<tr>
<th
rowspan="2"
class="sticky-col z-10 border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/80%)] dark:text-[hsl(0deg_0%_95%)]"
style="left: 0"
>
@@ -1186,15 +1245,11 @@ onActivated(async () => {
</th>
</tr>
</thead>
</table>
<!-- 表体(独立滚动) -->
<div
class="table-container overflow-x-auto"
style="max-height: 420px; overflow-y: auto;"
>
<table class="w-full whitespace-nowrap text-left text-sm">
<tbody class="divide-y divide-slate-100">
<!-- 表体(纵向滚动) -->
<tbody
class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]"
>
<tr
v-for="product in overviewData?.productComparisons"
:key="product.productId"
@@ -1221,104 +1276,235 @@ onActivated(async () => {
{{ product.orderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="px-6 py-4">
{{
product.averageOrderValue
? formatAmount(product.averageOrderValue)
: '-'
}}
{{ product.averageOrderValue ? formatAmount(product.averageOrderValue) : '-' }}
</td>
<!-- 成本 -->
<td class="px-6 py-4">
{{
product.productCost
? formatAmount(product.productCost)
: '-'
}}
{{ product.productCost ? formatAmount(product.productCost) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.shippingCost
? formatAmount(product.shippingCost)
: '-'
}}
{{ product.shippingCost ? formatAmount(product.shippingCost) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.otherCost
? formatAmount(product.otherCost)
: '-'
}}
{{ product.otherCost ? formatAmount(product.otherCost) : '-' }}
</td>
<td class="px-6 py-4 font-bold text-rose-500 dark:text-rose-400">
{{
product.refundAmount
? formatAmount(product.refundAmount)
: '-'
}}
{{ product.refundAmount ? formatAmount(product.refundAmount) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.totalPromotionFee
? formatAmount(product.totalPromotionFee)
: '-'
}}
{{ product.totalPromotionFee ? formatAmount(product.totalPromotionFee) : '-' }}
</td>
<td class="px-6 py-4 text-amber-500 dark:text-amber-400">
{{
product.brushFee ? formatAmount(product.brushFee) : '-'
}}
{{ product.brushFee ? formatAmount(product.brushFee) : '-' }}
</td>
<!-- 损益 -->
<td class="px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.feeRatio !== undefined
? formatPercentPlain(product.feeRatio)
: '-'
}}
{{ product.feeRatio !== undefined ? formatPercentPlain(product.feeRatio) : '-' }}
</td>
<td class="px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">
{{ product.roi?.toFixed(2) || '-' }}
</td>
<td class="px-6 py-4 font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.totalProfitBeforeTax
? formatAmount(product.totalProfitBeforeTax)
: '-'
}}
{{ product.totalProfitBeforeTax ? formatAmount(product.totalProfitBeforeTax) : '-' }}
</td>
<td class="px-6 py-4 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.salesTaxAmount
? formatAmount(product.salesTaxAmount)
: '-'
}}
{{ product.salesTaxAmount ? formatAmount(product.salesTaxAmount) : '-' }}
</td>
<td
class="bg-emerald-50/30 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-6 py-4 text-base font-black"
:class="
product.profitAfterTax && product.profitAfterTax < 0
? 'text-rose-500 dark:text-rose-400'
: 'text-emerald-600 dark:text-emerald-400'
"
:class="product.profitAfterTax && product.profitAfterTax < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
>
{{
product.profitAfterTax
? formatAmount(product.profitAfterTax)
: '-'
}}
{{ product.profitAfterTax ? formatAmount(product.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!overviewData?.productComparisons?.length">
<td colspan="15" class="p-8 text-center text-gray-400">
<td colspan="14" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
</table>
</table>
</div>
</div>
<!-- 第四层:店铺订单列表 -->
<!-- 第五层:门店品类多维度损益对比表 -->
<div
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div
class="flex items-center justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8"
>
<div>
<h3 class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
品类多维度损益对比
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
当前时间范围内的品类经营数据汇总,支持按品类导出
</p>
</div>
<div class="flex gap-2">
<template v-if="categoryExportMode">
<Button
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
@click="handleCategoryExportToggle(false)"
>
取消选择
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-blue-600 !px-8 !py-3 !text-sm !font-bold !text-white !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
:loading="categoryExportLoading"
:disabled="selectedExportCategoryIds.length === 0"
@click="handleCategoryExport"
>
导出选中 ({{ selectedExportCategoryIds.length }})
</Button>
</template>
<template v-else>
<Button
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
@click="handleCategoryExportToggle(true)"
>
指定品类导出
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-black !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
:loading="categoryExportLoading"
@click="handleCategoryExport"
>
导出全部
</Button>
</template>
</div>
</div>
<!-- 表头(固定不滚动) -->
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<thead
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<tr>
<th
v-if="categoryExportMode"
rowspan="2"
class="border-b border-r border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
<input
type="checkbox"
:checked="Boolean(overviewData?.categoryComparisons?.length) && selectedExportCategoryIds.length === (overviewData?.categoryComparisons?.length ?? 0)"
:indeterminate="selectedExportCategoryIds.length > 0 && selectedExportCategoryIds.length < (overviewData?.categoryComparisons?.length ?? 0)"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="handleCategorySelectAllChange"
/>
</th>
<th
rowspan="2"
class="sticky-col border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)] border-r-2 border-slate-100 bg-white shadow-sm dark:shadow-none"
:style="categoryExportMode ? 'left: 40px' : 'left: 0'"
>
品类名称
</th>
<th
colspan="3"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
经营规模维度
</th>
<th
colspan="7"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center text-orange-700 dark:text-orange-400"
>
成本费用维度
</th>
<th
colspan="5"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center text-emerald-700 dark:text-emerald-400"
>
盈利分析维度
</th>
</tr>
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)]">
实际销售额
</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">单量</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">客单价</th>
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">商品成本</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">运费</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-rose-400">退款金额</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">推广费</th>
<th class="border-b px-6 py-4 text-orange-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-orange-400">刷单费用</th>
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 text-slate-400 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
<th class="border-b px-6 py-4 font-bold dark:bg-[hsl(142deg_71.8%_29%/20%)]">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-rose-400">
{{ (taxRate * 100).toFixed(0) }}%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-indigo-400">
ROI
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">
税后盈亏
</th>
</tr>
</thead>
<!-- 表体(独立滚动) -->
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="cat in overviewData?.categoryComparisons"
:key="cat.categoryId ?? 'uncategorized'"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)]"
>
<td
v-if="categoryExportMode"
class="border-b border-r border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white p-3 text-center dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
<input
v-model="selectedExportCategoryIds"
type="checkbox"
:value="cat.categoryId"
class="h-4 w-4 cursor-pointer accent-blue-600"
/>
</td>
<td class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none">
<span class="text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline">
{{ cat.categoryName || '未分类' }}
</span>
</td>
<td class="p-6 font-black">{{ formatAmount(cat.salesAmount) }}</td>
<td class="p-6">{{ cat.orderCount?.toLocaleString('zh-CN') || '-' }}</td>
<td class="p-6">{{ cat.averageOrderValue ? `¥${cat.averageOrderValue.toFixed(2)}` : '-' }}</td>
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.productCost ? formatAmount(cat.productCost) : '-' }}</td>
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.shippingCost ? formatAmount(cat.shippingCost) : '-' }}</td>
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.otherCost ? formatAmount(cat.otherCost) : '-' }}</td>
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 font-bold text-rose-600 dark:text-rose-400">{{ cat.refundAmount ? formatAmount(cat.refundAmount) : '-' }}</td>
<td class="p-6 text-amber-600 dark:text-amber-400">{{ cat.totalPromotionFee ? formatAmount(cat.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cat.brushFee ? formatAmount(cat.brushFee) : '-' }}</td>
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-400">{{ cat.feeRatio !== undefined ? formatPercentPlain(cat.feeRatio) : '-' }}</td>
<td class="p-6 font-bold">{{ cat.totalProfitBeforeTax ? formatAmount(cat.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-rose-500 dark:text-rose-400">{{ cat.salesTaxAmount ? formatAmount(cat.salesTaxAmount) : '-' }}</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ cat.roi?.toFixed(2) || '-' }}</td>
<td
class="border-l bg-emerald-50/30 p-6 text-base font-black dark:bg-[hsl(142deg_71.8%_29%/20%)]"
:class="(cat.profitAfterTax ?? 0) < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
>
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!overviewData?.categoryComparisons?.length">
<td :colspan="categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
</table>
</div>
<!-- 第六层:店铺订单列表 -->
<div
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>