refactor: company-overview 更名为 store-overview (全店概览)

- 目录 rename: company-overview → store-overview
- API/views/router 同步更新路径
- 删除废弃组件和配置
- 修复 README 和 preferences 配置
This commit is contained in:
小蟑螂
2026-04-28 01:02:56 +08:00
parent 51e78fbddb
commit 9adc8567b3
21 changed files with 24 additions and 24 deletions
@@ -0,0 +1,272 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { computed } from 'vue';
defineOptions({ name: 'CategoryComparisonTable' });
interface Props {
categoryComparisons?: CompanyOverviewVO.CategoryOverview;
taxRate: number;
categoryExportMode?: boolean;
selectedExportCategoryIds?: number[];
}
interface Emits {
(e: 'update:selectedExportCategoryIds', ids: number[]): void;
(e: 'toggleCategoryExportMode', enabled: boolean): void;
(e: 'export'): void;
}
const props = withDefaults(defineProps<Props>(), {
categoryExportMode: false,
selectedExportCategoryIds: () => [],
});
const emit = defineEmits<Emits>();
const allCategoriesSelected = computed(() => {
const total = props.categoryComparisons?.categories?.length || 0;
return total > 0 && props.selectedExportCategoryIds.length === total;
});
const someCategoriesSelected = computed(() => {
return props.selectedExportCategoryIds.length > 0;
});
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
</script>
<template>
<div
class="overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] p-8 md:flex-row md:items-center"
>
<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 items-center gap-3">
<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="emit('toggleCategoryExportMode', false)"
>
取消选择
</button>
<button
class="rounded-2xl bg-blue-600 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
:disabled="selectedExportCategoryIds.length === 0"
@click="emit('export')"
>
导出已选品类 ({{ 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="emit('toggleCategoryExportMode', true)"
>
指定品类导出
</button>
<button
class="rounded-2xl bg-slate-900 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
@click="emit('export')"
>
导出全部
</button>
</template>
</div>
</div>
<div class="table-container overflow-x-auto">
<table class="w-full whitespace-nowrap text-left text-sm">
<thead
class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-xs font-black uppercase 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%_15.9%)] p-3 text-center"
>
<input
type="checkbox"
:checked="allCategoriesSelected"
:indeterminate="someCategoriesSelected && !allCategoriesSelected"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="
emit(
'update:selectedExportCategoryIds',
allCategoriesSelected
? []
: (categoryComparisons?.categories ?? []).map((c) => c.categoryId!)
)
"
/>
</th>
<th
rowspan="2"
class="sticky-col border-b p-6 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-sm dark:shadow-none"
>
品类名称
</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%)] dark:border-[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%)] dark:border-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/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%)] dark:border-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] 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 px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
实际销售额
</th>
<th class="border-b px-6 py-4">单量</th>
<th class="border-b px-6 py-4">客单价</th>
<th class="border-b border-l px-6 py-4">商品成本</th>
<th class="border-b px-6 py-4">运费</th>
<th class="border-b px-6 py-4">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:text-rose-400">
退款金额
</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4 text-orange-600 dark:text-orange-400">刷单费用</th>
<th class="border-b px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
<th class="border-b border-l px-6 py-4 font-bold">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:text-rose-400">
{{ (taxRate * 100).toFixed(0) }}%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 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 (categoryComparisons?.categories || [])"
:key="cat.categoryId ?? 'uncategorized'"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
>
<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
type="checkbox"
:checked="selectedExportCategoryIds.includes(cat.categoryId!)"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="
(e) => {
const checked = (e.target as HTMLInputElement).checked;
emit(
'update:selectedExportCategoryIds',
checked
? [...selectedExportCategoryIds, cat.categoryId!]
: selectedExportCategoryIds.filter((id) => id !== cat.categoryId)
);
}
"
/>
</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 font-medium">{{ cat.orderCount?.toLocaleString('zh-CN') || '-' }}</td>
<td class="p-6 font-medium">
{{
cat.averageOrderValue ? formatAmount(cat.averageOrderValue) : '-'
}}
</td>
<td class="p-6">{{ cat.productCost ? formatAmount(cat.productCost) : '-' }}</td>
<td class="p-6">{{ cat.shippingCost ? formatAmount(cat.shippingCost) : '-' }}</td>
<td class="p-6">{{ cat.otherCost ? formatAmount(cat.otherCost) : '-' }}</td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cat.refundAmount ? formatAmount(cat.refundAmount) : '-' }}
</td>
<td class="p-6">{{ 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="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ 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-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ 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="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black text-emerald-600">
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!categoryComparisons?.categories?.length">
<td :colspan="categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="categoryComparisons?.total" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="p-6 text-base">合计</td>
<!-- 规模 -->
<td class="p-6">{{ categoryComparisons?.total?.salesAmount ? formatAmount(categoryComparisons?.total?.salesAmount) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.orderCount ? categoryComparisons?.total?.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ categoryComparisons?.total?.productCost ? formatAmount(categoryComparisons?.total?.productCost) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.shippingCost ? formatAmount(categoryComparisons?.total?.shippingCost) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.otherCost ? formatAmount(categoryComparisons?.total?.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ categoryComparisons?.total?.refundAmount ? formatAmount(categoryComparisons?.total?.refundAmount) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.totalPromotionFee ? formatAmount(categoryComparisons?.total?.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ categoryComparisons?.total?.brushFee ? formatAmount(categoryComparisons?.total?.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categoryComparisons?.total?.feeRatio !== undefined ? formatPercentPlain(categoryComparisons?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ categoryComparisons?.total?.totalProfitBeforeTax ? formatAmount(categoryComparisons?.total?.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categoryComparisons?.total?.salesTaxAmount ? formatAmount(categoryComparisons?.total?.salesTaxAmount) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ categoryComparisons?.total?.roi?.toFixed(2) || '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base text-emerald-600">{{ categoryComparisons?.total?.profitAfterTax ? formatAmount(categoryComparisons?.total?.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -0,0 +1,159 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { ref, watch } from 'vue';
import { Segmented } from 'ant-design-vue';
import CategoryComparisonTable from './CategoryComparisonTable.vue';
import PlatformSummaryCard from './PlatformSummaryCard.vue';
import ShopComparisonTable from './ShopComparisonTable.vue';
defineOptions({ name: 'ComparisonSwitcher' });
interface Props {
taxRate: number;
platformSummary?: CompanyOverviewVO.PlatformOverview;
platformExportMode: boolean;
selectedExportPlatformIds: number[];
shopComparisons?: CompanyOverviewVO.ShopOverview;
shopExportMode: boolean;
selectedExportShopIds: number[];
categoryComparisons?: CompanyOverviewVO.CategoryOverview;
categoryExportMode: boolean;
selectedExportCategoryIds: number[];
}
interface Emits {
(e: 'update:selectedExportPlatformIds', ids: number[]): void;
(e: 'togglePlatformExportMode', enabled: boolean): void;
(e: 'platformExport'): void;
(e: 'update:selectedExportShopIds', ids: number[]): void;
(e: 'toggleShopExportMode', enabled: boolean): void;
(e: 'shopExport'): void;
(e: 'navigate', shopId: number): void;
(e: 'update:selectedExportCategoryIds', ids: number[]): void;
(e: 'toggleCategoryExportMode', enabled: boolean): void;
(e: 'categoryExport'): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const STORAGE_KEY = 'store-overview-tab';
const getDefaultMode = (): 'platform' | 'shop' | 'category' => {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored === 'platform' || stored === 'shop' || stored === 'category') return stored;
return 'platform';
};
const activeMode = ref<'platform' | 'shop' | 'category'>(getDefaultMode());
watch(activeMode, (val) => localStorage.setItem(STORAGE_KEY, val));
const modeOptions = [
{ label: '平台汇总', value: 'platform' },
{ label: '店铺汇总', value: 'shop' },
{ label: '品类汇总', value: 'category' },
] as const;
</script>
<template>
<div class="space-y-4">
<div class="flex justify-end">
<Segmented
v-model:value="activeMode"
:options="modeOptions"
class="comparison-segmented"
/>
</div>
<PlatformSummaryCard
v-if="activeMode === 'platform'"
:platform-summary="props.platformSummary"
:tax-rate="props.taxRate"
:platform-export-mode="props.platformExportMode"
:selected-export-platform-ids="props.selectedExportPlatformIds"
@update:selected-export-platform-ids="
(ids) => emit('update:selectedExportPlatformIds', ids)
"
@toggle-platform-export-mode="
(enabled) => emit('togglePlatformExportMode', enabled)
"
@export="emit('platformExport')"
/>
<ShopComparisonTable
v-if="activeMode === 'shop'"
:shop-comparisons="props.shopComparisons"
:tax-rate="props.taxRate"
:shop-export-mode="props.shopExportMode"
:selected-export-shop-ids="props.selectedExportShopIds"
@update:selected-export-shop-ids="
(ids) => emit('update:selectedExportShopIds', ids)
"
@toggle-shop-export-mode="(enabled) => emit('toggleShopExportMode', enabled)"
@export="emit('shopExport')"
@navigate="(shopId) => emit('navigate', shopId)"
/>
<CategoryComparisonTable
v-if="activeMode === 'category'"
:category-comparisons="props.categoryComparisons"
:tax-rate="props.taxRate"
:category-export-mode="props.categoryExportMode"
:selected-export-category-ids="props.selectedExportCategoryIds"
@toggle-category-export-mode="
(enabled) => emit('toggleCategoryExportMode', enabled)
"
@update:selected-export-category-ids="
(ids) => emit('update:selectedExportCategoryIds', ids)
"
@export="emit('categoryExport')"
/>
</div>
</template>
<style scoped>
:deep(.ant-segmented-thumb) {
border-radius: 999px !important;
}
:deep(.comparison-segmented) {
background: rgb(148 163 184 / 16%);
border-radius: 999px;
padding: 4px;
}
:deep(.comparison-segmented .ant-segmented-item) {
border-radius: 999px;
}
:deep(.comparison-segmented .ant-segmented-item-label) {
font-weight: 700;
padding: 6px 16px;
border-radius: 999px;
}
:deep(.comparison-segmented .ant-segmented-item-selected) {
background: white;
color: #1d4ed8;
box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}
:global(html.dark) :deep(.comparison-segmented) {
background: hsl(240deg 3.7% 22% / 70%);
}
:global(html.dark) :deep(.comparison-segmented .ant-segmented-item) {
border-radius: 999px;
}
:global(html.dark) :deep(.comparison-segmented .ant-segmented-item) {
color: hsl(240deg 5% 64.9%);
}
:global(html.dark) :deep(.comparison-segmented .ant-segmented-item-selected) {
background: hsl(220deg 13% 18%);
color: #60a5fa;
box-shadow: 0 1px 3px hsl(0 0 0% / 30%);
}
</style>
@@ -0,0 +1,139 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
defineOptions({ name: 'KpiCards' });
interface Props {
overviewData: CompanyOverviewVO.Info | null;
taxRate: number;
}
const props = defineProps<Props>();
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const formatPercent = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
};
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
</script>
<template>
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
<!-- 销售额 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div class="mb-4 flex items-start justify-between">
<span class="text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
全店总销售额
</span>
<span
v-if="overviewData?.monthOverMonthGrowth !== undefined"
class="rounded bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-2 py-1 text-xs font-bold text-emerald-600"
>
{{ formatPercent(overviewData.monthOverMonthGrowth) }} 较上月
</span>
</div>
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
{{
overviewData?.totalSalesAmount
? formatAmount(overviewData.totalSalesAmount)
: '-'
}}
</div>
<div
v-if="overviewData?.salesAmountAchievementRate !== undefined"
class="mt-6 flex items-center justify-between border-t border-slate-100 dark:border-t-[hsl(240deg_3.7%_22%)] pt-4"
>
<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
销售额目标达成率
</span>
>
<span class="text-sm font-black text-blue-600 dark:text-blue-400 dark:text-blue-400">
{{
formatPercentPlain(overviewData.salesAmountAchievementRate)
}}
</span>
</div>
</div>
<!-- ROI效率 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
投资回报率 (ROI)
</div>
<div class="text-4xl font-black leading-none text-indigo-600 dark:text-indigo-400">
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
</div>
<div
v-if="overviewData?.averageFeeRatio !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 dark:border-t-[hsl(240deg_3.7%_22%)] pt-4 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span>全店平均费比</span>
<span class="text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
{{ formatPercentPlain(overviewData.averageFeeRatio) }}
</span>
</div>
</div>
<!-- 订单达成 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
销量目标达成率 (订单数)
</div>
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
{{
overviewData?.orderCountAchievementRate !== undefined
? formatPercentPlain(overviewData.orderCountAchievementRate)
: '-'
}}
</div>
<div
v-if="overviewData?.orderCountAchievementRate !== undefined"
class="mt-6 h-2 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]"
>
<div
class="h-full bg-indigo-500"
:style="{
width: `${Math.min(overviewData.orderCountAchievementRate, 100)}%`,
}"
></div>
</div>
</div>
<!-- 税后利润 -->
<div
class="rounded-2xl border-l-4 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] border-l-emerald-500 dark:border-l-emerald-500 bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-emerald-600 dark:text-emerald-400">
全店总净利润 (税后)
</div>
<div class="text-4xl font-black leading-none text-emerald-600 dark:text-emerald-400">
{{
overviewData?.totalNetProfitAfterTax
? formatAmount(overviewData.totalNetProfitAfterTax)
: '-'
}}
</div>
<div
v-if="overviewData?.totalTaxAmount !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 dark:border-t-[hsl(240deg_3.7%_22%)] pt-4 text-[11px] font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span>已扣除预扣税额 ({{ (taxRate * 100).toFixed(0) }}%)</span>
<span>{{ formatAmount(overviewData.totalTaxAmount) }}</span>
</div>
</div>
</div>
</template>
@@ -0,0 +1,356 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
defineOptions({ name: 'PlatformSummaryCard' });
interface Props {
taxRate?: number;
platformSummary?: CompanyOverviewVO.PlatformOverview;
platformExportMode?: boolean;
selectedExportPlatformIds?: number[];
}
interface Emits {
(e: 'update:selectedExportPlatformIds', ids: number[]): void;
(e: 'togglePlatformExportMode', enabled: boolean): void;
(e: 'export'): void;
}
const props = withDefaults(defineProps<Props>(), {
platformExportMode: false,
selectedExportPlatformIds: () => [],
});
const emit = defineEmits<Emits>();
const allPlatformsSelected = computed(() => {
const total = platformData.value.length;
return total > 0 && props.selectedExportPlatformIds.length === total;
});
const somePlatformsSelected = computed(() => {
return props.selectedExportPlatformIds.length > 0;
});
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
const taxRateNum = computed(() => (props.taxRate ?? 0.04) * 100);
// 使用后端返回的平台列表数据
const platformData = computed(() => {
if (props.platformSummary?.platforms && props.platformSummary.platforms.length > 0) {
return props.platformSummary.platforms.map(p => ({
platformId: p.platformId,
platformName: p.platformName,
targetOrderCount: p.targetOrderCount ?? 0,
orderCountAchievementRate: p.orderCountAchievementRate ?? 0,
targetAmount: p.targetAmount ?? 0,
salesAmountAchievementRate: p.salesAmountAchievementRate ?? 0,
salesAmount: p.salesAmount ?? 0,
orderCount: p.orderCount ?? 0,
averageOrderValue: p.averageOrderValue ?? 0,
productCost: p.productCost ?? 0,
shippingCost: p.shippingCost ?? 0,
otherCost: p.otherCost ?? 0,
refundAmount: p.refundAmount ?? 0,
totalPromotionFee: p.totalPromotionFee ?? 0,
brushFee: p.brushFee ?? 0,
feeRatio: p.feeRatio ?? 0,
totalProfitBeforeTax: p.totalProfitBeforeTax ?? 0,
salesTaxAmount: p.salesTaxAmount ?? 0,
roi: p.roi ?? 0,
profitAfterTax: p.profitAfterTax ?? 0,
}));
}
return [];
});
// 后端返回的合计行数据
const totalData = computed(() => props.platformSummary?.total ?? null);
// 表格排序
const sortField = ref<string>('salesAmount');
const sortOrder = ref<'asc' | 'desc'>('desc');
const sortedData = computed(() => {
return [...platformData.value].sort((a: any, b: any) => {
const diff = b[sortField.value] - a[sortField.value];
return sortOrder.value === 'desc' ? diff : -diff;
});
});
const toggleSort = (field: string) => {
if (sortField.value === field) {
sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc';
} else {
sortField.value = field;
sortOrder.value = 'desc';
}
};
const sortIcon = (field: string) => {
if (sortField.value !== field) return '';
return sortOrder.value === 'desc' ? '↓' : '↑';
};
</script>
<template>
<div
class="overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<!-- Header -->
<div
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] p-8 md:flex-row md:items-center"
>
<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 items-center gap-3">
<template v-if="platformExportMode">
<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="emit('togglePlatformExportMode', false)"
>
取消选择
</button>
<button
class="rounded-2xl bg-blue-600 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
:disabled="selectedExportPlatformIds.length === 0"
@click="emit('export')"
>
导出已选平台 ({{ selectedExportPlatformIds.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="emit('togglePlatformExportMode', true)"
>
指定平台导出
</button>
<button
class="rounded-2xl bg-slate-900 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
@click="emit('export')"
>
导出全部
</button>
</template>
</div>
</div>
<!-- 表格 -->
<div class="overflow-x-auto">
<table class="w-full whitespace-nowrap text-left text-sm">
<thead
class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-xs font-black uppercase text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<tr>
<th
v-if="platformExportMode"
rowspan="2"
class="border-b border-r-2 border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-100 p-3 text-center dark:bg-[hsl(240deg_3.7%_22%)]"
>
<input
type="checkbox"
class="h-4 w-4 cursor-pointer accent-blue-600"
:checked="allPlatformsSelected"
:indeterminate="somePlatformsSelected && !allPlatformsSelected"
@change="
(e) => {
if ((e.target as HTMLInputElement).checked) {
emit(
'update:selectedExportPlatformIds',
platformData.map((p) => p.platformId) || [],
);
} else {
emit('update:selectedExportPlatformIds', []);
}
}
"
/>
</th>
<!-- 平台名著 -->
<th
rowspan="2"
class="sticky-col border-b border-r-2 border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] shadow-sm dark:shadow-none"
>
平台名称
</th>
<!-- 目标达成 -->
<th
colspan="4"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] p-3 text-center bg-blue-50/50 dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)] text-blue-700 dark:text-blue-400"
>
目标达成维度
</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%)] p-3 text-center bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50%)]"
>
经营规模维度
</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%)] p-3 text-center bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50%)] 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%)] p-3 text-center bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] 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 border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">目标单量</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-blue-600 dark:text-blue-400">单量达成率</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">目标额</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-blue-600 dark:text-blue-400">销售达成率</th>
<!-- 规模子列 -->
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">实际销售额</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">单量</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">客单价</th>
<!-- 成本子列 -->
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">商品成本</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">运费</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">其他成本</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold text-rose-600 dark:text-rose-400">退款金额</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">推广费</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-orange-600 dark:text-orange-400">刷单费用</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">费比%</th>
<!-- 盈利子列 -->
<th class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold">税前盈亏</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ taxRateNum.toFixed(0) }}%税额</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-indigo-700 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="p in sortedData"
:key="p.platformId"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
>
<td
v-if="platformExportMode"
class="border-r border-slate-100 dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-50/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
<input
type="checkbox"
class="h-4 w-4 cursor-pointer accent-blue-600"
:checked="selectedExportPlatformIds.includes(p.platformId)"
@change="
(e) => {
const checked = (e.target as HTMLInputElement).checked;
const newIds = checked
? [...selectedExportPlatformIds, p.platformId]
: selectedExportPlatformIds.filter((id) => id !== p.platformId);
emit('update:selectedExportPlatformIds', newIds);
}
"
/>
</td>
<!-- 平台名 -->
<td
class="sticky-col border-r-2 border-slate-100 bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none"
>
<span class="rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400">
{{ p.platformName }}
</span>
</td>
<!-- 目标 -->
<td class="p-6 font-medium">{{ p.targetOrderCount.toLocaleString('zh-CN') }}</td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.orderCountAchievementRate) }}</td>
<td class="p-6 font-medium">{{ formatAmount(p.targetAmount) }}</td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.salesAmountAchievementRate) }}</td>
<!-- 规模 -->
<td class="p-6 font-black">{{ formatAmount(p.salesAmount) }}</td>
<td class="p-6 font-medium">{{ p.orderCount.toLocaleString('zh-CN') }}</td>
<td class="p-6 font-medium">{{ formatAmount(p.averageOrderValue) }}</td>
<!-- 成本 -->
<td class="p-6">{{ formatAmount(p.productCost) }}</td>
<td class="p-6">{{ formatAmount(p.shippingCost) }}</td>
<td class="p-6">{{ formatAmount(p.otherCost) }}</td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">{{ formatAmount(p.refundAmount) }}</td>
<td class="p-6">{{ formatAmount(p.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(p.brushFee) }}</td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercentPlain(p.feeRatio) }}</td>
<!-- 盈利 -->
<td class="p-6 font-bold" :class="p.totalProfitBeforeTax >= 0 ? 'text-slate-800 dark:text-[hsl(0deg_0%_95%)]' : 'text-rose-600 dark:text-rose-400'">
{{ formatAmount(p.totalProfitBeforeTax) }}
</td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(p.salesTaxAmount) }}</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ p.roi.toFixed(2) }}</td>
<td
class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black"
:class="p.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
>
{{ formatAmount(p.profitAfterTax) }}
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="totalData" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="sticky-col border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] p-6 text-base">合计</td>
<!-- 目标 -->
<td class="p-6">{{ totalData.targetOrderCount?.toLocaleString() }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<td class="p-6">{{ totalData.targetAmount ? formatAmount(totalData.targetAmount) : '-' }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<!-- 规模 -->
<td class="p-6">{{ totalData.salesAmount ? formatAmount(totalData.salesAmount) : '-' }}</td>
<td class="p-6">{{ totalData.orderCount ? totalData.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ totalData.productCost ? formatAmount(totalData.productCost) : '-' }}</td>
<td class="p-6">{{ totalData.shippingCost ? formatAmount(totalData.shippingCost) : '-' }}</td>
<td class="p-6">{{ totalData.otherCost ? formatAmount(totalData.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ totalData.refundAmount ? formatAmount(totalData.refundAmount) : '-' }}</td>
<td class="p-6">{{ totalData.totalPromotionFee ? formatAmount(totalData.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ totalData.brushFee ? formatAmount(totalData.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ totalData.feeRatio !== undefined ? formatPercentPlain(totalData.feeRatio) : '-' }}
</td>
<!-- 盈利 -->
<td class="p-6">
{{ totalData.totalProfitBeforeTax ? formatAmount(totalData.totalProfitBeforeTax) : '-' }}
</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ totalData.salesTaxAmount ? formatAmount(totalData.salesTaxAmount) : '-' }}
</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">
{{ totalData.roi !== undefined ? totalData.roi.toFixed(2) : '-' }}
</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base"
:class="totalData.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
>
{{ totalData.profitAfterTax ? formatAmount(totalData.profitAfterTax) : '-' }}
</td>
</tr>
</tfoot>
<tfoot v-else class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
<td :colspan="platformExportMode ? 20 : 19" class="p-6">暂无数据</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -0,0 +1,322 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { nextTick, onMounted, ref, watch } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
defineOptions({ name: 'ShopCharts' });
interface Props {
shopSalesRatios?: CompanyOverviewVO.ShopSalesRatio[];
shopComparisons?: CompanyOverviewVO.ShopOverview;
shopEfficiencyQuadrants?: CompanyOverviewVO.ShopEfficiencyQuadrant[];
}
const props = defineProps<Props>();
const barChartRef = ref<EchartsUIType>();
const scatterChartRef = ref<EchartsUIType>();
const { renderEcharts: renderBarChart } = useEcharts(barChartRef);
const { renderEcharts: renderScatterChart } = useEcharts(scatterChartRef);
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const safeNumber = (value: number | string | undefined) => {
const num = Number(value);
return Number.isFinite(num) ? num : 0;
};
// 渲染店铺销售占比排行图表
const renderShopBarChart = () => {
if (!barChartRef.value || !props.shopSalesRatios) return;
const ratios = props.shopSalesRatios;
const shopNames = ratios.map((r) => r.shopName).reverse();
const salesAmounts = ratios.map((r) => r.salesAmount).reverse();
renderBarChart({
grid: {
left: '3%',
right: '12%',
bottom: '3%',
top: '3%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
formatter: (params: any) => {
const param = Array.isArray(params) ? params[0] : params;
const index = param.dataIndex;
const shop = ratios[ratios.length - 1 - index];
if (!shop) return '';
return `${shop.shopName}<br/>销售额: ${formatAmount(shop.salesAmount)}<br/>占比: ${shop.ratio.toFixed(2)}%`;
},
},
xAxis: {
type: 'value',
axisLabel: { show: false },
splitLine: { show: false },
},
yAxis: {
type: 'category',
data: shopNames,
axisLine: { show: false },
axisTick: { show: false },
axisLabel: {
fontWeight: 'bold',
color: 'hsl(240deg 5% 64.9%)',
fontSize: 13,
},
},
series: [
{
type: 'bar',
data: salesAmounts,
barWidth: 20,
itemStyle: {
borderRadius: [0, 10, 10, 0],
color: {
type: 'linear',
x: 1,
y: 0,
x2: 0,
y2: 0,
colorStops: [
{ offset: 0, color: '#6366f1' },
{ offset: 1, color: '#a5b4fc' },
],
},
},
label: {
show: true,
position: 'right',
formatter: (params: any) =>
`¥${params.value.toLocaleString('zh-CN')}`,
fontWeight: 900,
color:
document.documentElement.classList.contains('dark')
? 'hsl(0deg 0% 95%)'
: '#334155',
},
},
],
});
};
// 渲染店铺经营健康度分层图(效率 × 结果 × 规模)
const renderShopScatterChart = () => {
if (!scatterChartRef.value || !props.shopComparisons) return;
const source = props.shopComparisons?.shops || [];
const data: Array<[number, number, string, number, number, number, number]> =
source.map((shop) => [
// x: 销售额达成率(%)
safeNumber(shop.salesAmountAchievementRate),
// y: 税后盈亏(万元)
safeNumber(shop.profitAfterTax) / 10_000,
// label: 店铺名
shop.shopName,
// size: 销售额(元)
safeNumber(shop.salesAmount),
// color metric: 费比(0~1)
safeNumber(shop.feeRatio),
// tooltip metric: ROI
safeNumber(shop.roi),
// tooltip metric: 订单达成率
safeNumber(shop.orderCountAchievementRate),
]);
if (data.length === 0) {
renderScatterChart({
title: {
text: '暂无店铺经营数据',
left: 'center',
top: 'middle',
textStyle: {
color: document.documentElement.classList.contains('dark')
? 'hsl(240deg 5% 64.9%)'
: '#64748b',
fontSize: 14,
fontWeight: 'bold',
},
},
xAxis: { show: false },
yAxis: { show: false },
series: [],
});
return;
}
const achieveValues = data.map((item) => item[0]);
const profitValues = data.map((item) => item[1]);
const salesValues = data.map((item) => item[3]);
const minAchieve = Math.min(...achieveValues);
const maxAchieve = Math.max(...achieveValues);
const minProfit = Math.min(...profitValues);
const maxProfit = Math.max(...profitValues);
const minSales = Math.min(...salesValues);
const maxSales = Math.max(...salesValues);
const achievePadding =
minAchieve === maxAchieve ? 10 : (maxAchieve - minAchieve) * 0.2;
const profitPadding =
minProfit === maxProfit ? 1 : (maxProfit - minProfit) * 0.2;
const calcBubbleSize = (salesAmount: number) => {
if (maxSales === minSales) return 36;
const ratio = (salesAmount - minSales) / (maxSales - minSales);
return 28 + ratio * 26;
};
const getFeeRatioColor = (feeRatio: number) => {
if (feeRatio <= 0.08) return '#10b981'; // 低费比-健康
if (feeRatio <= 0.15) return '#6366f1'; // 中费比-可控
return '#f43f5e'; // 高费比-风险
};
renderScatterChart({
grid: {
left: '6%',
right: '4%',
top: '8%',
bottom: '16%',
containLabel: true,
},
tooltip: {
trigger: 'item',
formatter: (params: any) => {
const item = params.data;
if (!item) return '';
const feeRatioPercent = (item[4] * 100).toFixed(2);
return `<div style="padding:4px; font-weight:bold">${item[2]}</div><hr/>销售额达成率: ${item[0].toFixed(2)}%<br/>税后盈亏: ¥${item[1].toFixed(2)}万<br/>销售额: ¥${item[3].toLocaleString('zh-CN')}<br/>费比: ${feeRatioPercent}%<br/>ROI: ${item[5].toFixed(2)}<br/>订单达成率: ${item[6].toFixed(2)}%`;
},
},
xAxis: {
type: 'value',
min: Math.min(minAchieve - achievePadding, 0),
max: Math.max(maxAchieve + achievePadding, 120),
name: '销售额达成率 (%)',
nameLocation: 'middle',
nameGap: 35,
axisLabel: {
fontWeight: 'bold',
formatter: '{value}%',
},
splitLine: {
lineStyle: { type: 'dashed' },
},
},
yAxis: {
type: 'value',
min: minProfit - profitPadding,
max: maxProfit + profitPadding,
name: '税后盈亏 (单位: 万元)',
nameLocation: 'middle',
nameGap: 50,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: { type: 'dashed' },
},
},
series: [
{
type: 'scatter',
symbolSize: (val: any) => calcBubbleSize(Number(val[3] ?? 0)),
data,
label: {
show: true,
position: 'top',
color:
document.documentElement.classList.contains('dark')
? 'hsl(0deg 0% 95%)'
: '#334155',
fontWeight: 700,
formatter: (params: any) => params.data?.[2] ?? '',
},
itemStyle: {
color: (params: any) => getFeeRatioColor(Number(params.data?.[4] ?? 0)),
shadowBlur: 15,
shadowColor: 'rgba(0,0,0,0.1)',
},
markLine: {
silent: true,
lineStyle: { type: 'dashed', color: '#94a3b8' },
data: [{ xAxis: 100 }, { yAxis: 0 }],
},
},
],
});
};
const rerenderCharts = async () => {
await nextTick();
renderShopBarChart();
renderShopScatterChart();
};
watch(
() => [props.shopSalesRatios, props.shopComparisons],
() => {
rerenderCharts();
},
{ deep: true, immediate: true },
);
onMounted(() => {
rerenderCharts();
});
// 暴露方法给父组件调用
defineExpose({ renderShopBarChart, renderShopScatterChart });
</script>
<template>
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
<!-- 销售占比排行 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
各店铺销售贡献排行
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="barChartRef" />
</div>
</div>
<!-- 效率象限图 -->
<div
class="rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
店铺经营健康度分层 (达成率 vs 税后盈亏)
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="scatterChartRef" />
</div>
<div class="mt-4 flex justify-center gap-6">
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-emerald-500"></span>
低费比(健康)
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-blue-500"></span>
中费比(可控)
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="h-3 w-3 rounded-full bg-rose-500"></span>
高费比(风险)
</div>
</div>
</div>
</div>
</template>
@@ -0,0 +1,368 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { computed } from 'vue';
defineOptions({ name: 'ShopComparisonTable' });
interface Props {
shopComparisons?: CompanyOverviewVO.ShopOverview;
taxRate: number;
shopExportMode: boolean;
selectedExportShopIds: number[];
}
interface Emits {
(e: 'update:selectedExportShopIds', ids: number[]): void;
(e: 'toggleShopExportMode', enabled: boolean): void;
(e: 'export'): void;
(e: 'navigate', shopId: number): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const allShopsSelected = computed(() => {
const total = props.shopComparisons?.shops?.length || 0;
return total > 0 && props.selectedExportShopIds.length === total;
});
const someShopsSelected = computed(() => {
return props.selectedExportShopIds.length > 0;
});
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
</script>
<template>
<div
class="overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]"
>
<div
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] p-8 md:flex-row md:items-center"
>
<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 items-center gap-3">
<template v-if="shopExportMode">
<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="emit('toggleShopExportMode', false)"
>
取消选择
</button>
<button
class="rounded-2xl bg-blue-600 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
:disabled="selectedExportShopIds.length === 0"
@click="emit('export')"
>
导出已选店铺 ({{ selectedExportShopIds.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="emit('toggleShopExportMode', true)"
>
指定店铺导出
</button>
<button
class="rounded-2xl bg-slate-900 px-8 py-3 text-sm font-bold text-white shadow-xl shadow-slate-200 transition-all hover:scale-105 active:scale-95 dark:shadow-none"
@click="emit('export')"
>
导出全部
</button>
</template>
</div>
</div>
<div class="table-container overflow-x-auto">
<table class="w-full whitespace-nowrap text-left text-sm">
<thead
class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-xs font-black uppercase text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<tr>
<th
v-if="shopExportMode"
rowspan="2"
class="sticky-col border-b border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] p-3 text-center"
>
<input
type="checkbox"
class="h-4 w-4 cursor-pointer accent-blue-600"
:checked="allShopsSelected"
:indeterminate="someShopsSelected && !allShopsSelected"
@change="
(e) => {
if ((e.target as HTMLInputElement).checked) {
emit(
'update:selectedExportShopIds',
shopComparisons?.shops?.map((s) => s.shopId) || [],
);
} else {
emit('update:selectedExportShopIds', []);
}
}
"
/>
</th>
<th
rowspan="2"
class="sticky-col border-b p-6 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] shadow-sm"
:class="
shopExportMode
? 'border-l-0 bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)]'
: 'border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)]'
"
>
店铺名称
</th>
<th
colspan="4"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] dark:border-[hsl(240deg_3.7%_22%)] bg-blue-50/50 dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)] p-3 text-center text-blue-700 dark:text-blue-400"
>
目标达成维度
</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%)] dark:border-[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%)] dark:border-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/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%)] dark:border-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] 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 px-6 py-4">目标单量</th>
<th class="border-b px-6 py-4 text-blue-600 dark:text-blue-400">单量达成率</th>
<th class="border-b px-6 py-4">目标额</th>
<th class="border-b px-6 py-4 text-blue-600 dark:text-blue-400">销售达成率</th>
<!-- 规模 -->
<th class="border-b border-l px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
实际销售额
</th>
<th class="border-b px-6 py-4">单量</th>
<th class="border-b px-6 py-4">客单价</th>
<!-- 成本 -->
<th class="border-b border-l px-6 py-4">商品成本</th>
<th class="border-b px-6 py-4">运费</th>
<th class="border-b px-6 py-4">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:text-rose-400">
退款金额
</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4 text-orange-600 dark:text-orange-400">刷单费用</th>
<th class="border-b px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
<!-- 盈利 -->
<th class="border-b border-l px-6 py-4 font-bold">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:text-rose-400">
{{ (taxRate * 100).toFixed(0) }}%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 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="shop in (shopComparisons?.shops || [])"
:key="shop.shopId"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
>
<td
v-if="shopExportMode"
class="sticky-col border-r bg-slate-50/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
<input
type="checkbox"
:value="shop.shopId"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="
(e) => {
const checked = (e.target as HTMLInputElement).checked;
const newIds = checked
? [...selectedExportShopIds, shop.shopId]
: selectedExportShopIds.filter((id) => id !== shop.shopId);
emit('update:selectedExportShopIds', newIds);
}
"
/>
</td>
<td
class="sticky-col border-r-2 border-slate-100 bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none"
:class="shopExportMode ? 'border-l-0' : ''"
>
<span
class="cursor-pointer text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline"
@click="emit('navigate', shop.shopId)"
>
{{ shop.shopName }}
</span>
</td>
<!-- 目标 -->
<td class="p-6 font-medium">
{{ shop.targetOrderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">
{{
shop.orderCountAchievementRate !== undefined
? formatPercentPlain(shop.orderCountAchievementRate)
: '-'
}}
</td>
<td class="p-6 font-medium">
{{
shop.targetAmount ? formatAmount(shop.targetAmount) : '-'
}}
</td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">
{{
shop.salesAmountAchievementRate !== undefined
? formatPercentPlain(shop.salesAmountAchievementRate)
: '-'
}}
</td>
<!-- 规模 -->
<td class="p-6 font-black">
{{ formatAmount(shop.salesAmount) }}
</td>
<td class="p-6 font-medium">
{{ shop.orderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-6 font-medium">
{{
shop.averageOrderValue
? formatAmount(shop.averageOrderValue)
: '-'
}}
</td>
<!-- 成本 -->
<td class="p-6">
{{
shop.productCost ? formatAmount(shop.productCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.shippingCost ? formatAmount(shop.shippingCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.otherCost ? formatAmount(shop.otherCost) : '-'
}}
</td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{
shop.refundAmount ? formatAmount(shop.refundAmount) : '-'
}}
</td>
<td class="p-6">
{{
shop.totalPromotionFee
? formatAmount(shop.totalPromotionFee)
: '-'
}}
</td>
<td class="p-6 text-orange-600 dark:text-orange-400">
{{ shop.brushFee ? formatAmount(shop.brushFee) : '-' }}
</td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
shop.feeRatio !== undefined
? formatPercentPlain(shop.feeRatio)
: '-'
}}
</td>
<!-- 盈利 -->
<td class="p-6 font-bold">
{{
shop.totalProfitBeforeTax
? formatAmount(shop.totalProfitBeforeTax)
: '-'
}}
</td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
shop.salesTaxAmount
? formatAmount(shop.salesTaxAmount)
: '-'
}}
</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">
{{ shop.roi?.toFixed(2) || '-' }}
</td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black text-emerald-600">
{{
shop.profitAfterTax
? formatAmount(shop.profitAfterTax)
: '-'
}}
</td>
</tr>
<tr v-if="!shopComparisons?.shops?.length">
<td colspan="17" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="shopComparisons?.total" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="p-6 text-base" :class="shopExportMode ? 'border-l-0' : ''">合计</td>
<!-- 目标 -->
<td class="p-6">{{ shopComparisons?.total?.targetOrderCount?.toLocaleString() }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<td class="p-6">{{ shopComparisons?.total?.targetAmount ? formatAmount(shopComparisons?.total?.targetAmount) : '-' }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<!-- 规模 -->
<td class="p-6">{{ shopComparisons?.total?.salesAmount ? formatAmount(shopComparisons?.total?.salesAmount) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.orderCount ? shopComparisons?.total?.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ shopComparisons?.total?.productCost ? formatAmount(shopComparisons?.total?.productCost) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.shippingCost ? formatAmount(shopComparisons?.total?.shippingCost) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.otherCost ? formatAmount(shopComparisons?.total?.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ shopComparisons?.total?.refundAmount ? formatAmount(shopComparisons?.total?.refundAmount) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.totalPromotionFee ? formatAmount(shopComparisons?.total?.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ shopComparisons?.total?.brushFee ? formatAmount(shopComparisons?.total?.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopComparisons?.total?.feeRatio !== undefined ? formatPercentPlain(shopComparisons?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ shopComparisons?.total?.totalProfitBeforeTax ? formatAmount(shopComparisons?.total?.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopComparisons?.total?.salesTaxAmount ? formatAmount(shopComparisons?.total?.salesTaxAmount) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ shopComparisons?.total?.roi !== undefined ? shopComparisons?.total?.roi.toFixed(2) : '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base text-emerald-600">{{ shopComparisons?.total?.profitAfterTax ? formatAmount(shopComparisons?.total?.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -0,0 +1,605 @@
<script lang="ts" setup>
import type {
CompanyOverviewDTO,
CompanyOverviewVO,
} from '#/api/ecommerce/store-overview';
import {
onActivated,
onMounted,
onUnmounted,
ref,
watch,
} from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { Button, DatePicker, InputNumber, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getCompanyOverviewApi } from '#/api/ecommerce/store-overview/apis';
import { getShopPageApi } from '#/api/ecommerce/shop';
import { exportByPost } from '#/utils/export';
import ComparisonSwitcher from './components/ComparisonSwitcher.vue';
import KpiCards from './components/KpiCards.vue';
import ShopCharts from './components/ShopCharts.vue';
defineOptions({ name: 'CompanyOverview' });
// 路由
const router = useRouter();
const route = useRoute();
// 响应式数据
const loading = ref(false);
const exportLoading = ref(false);
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
const shopCount = ref(0);
// 指定店铺导出模式
const shopExportMode = ref(false);
const selectedExportShopIds = ref<number[]>([]);
// 指定平台导出模式
const platformExportMode = ref(false);
const selectedExportPlatformIds = ref<number[]>([]);
// 日期范围
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().subtract(30, 'day'),
dayjs(),
]);
// 品类导出相关
const categoryExportMode = ref(false);
const selectedExportCategoryIds = ref<number[]>([]);
const handleCategoryExportToggle = (enabled: boolean) => {
categoryExportMode.value = enabled;
selectedExportCategoryIds.value = [];
};
const handleCategoryExport = async () => {
const params = {
dateRange: dateRange.value.map((d) => d.format('YYYY-MM-DD')),
taxRate: taxRate.value,
};
if (selectedExportCategoryIds.value.length > 0) {
Object.assign(params, { categoryIds: selectedExportCategoryIds.value });
}
await exportByPost('/ec/category-overview/export', params, '品类多维度经营明细.xlsx');
};
// 税率(公司/店铺概览共用持久化)
const TAX_RATE_KEY = 'overview-tax-rate';
const taxRate = ref<number>(0.04);
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
watch(taxRate, (val) => {
localStorage.setItem(TAX_RATE_KEY, String(val));
loadOverviewData();
});
const formatTaxRate = (value: null | number | string | undefined) => {
if (value === null || value === undefined || value === '') return '';
const num = Number(value);
if (!Number.isFinite(num)) return '';
return `${num * 100}%`;
};
const parseTaxRate = (value: string | undefined) => {
if (!value) return 0;
const num = Number(value.replace('%', '').trim());
return Number.isFinite(num) ? num / 100 : 0;
};
// 当前选中的时间范围类型
const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
>('30days');
// 自定义日期范围
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
dateRange.value[0],
dateRange.value[1],
]);
const lastRequestKey = ref('');
const isRequesting = ref(false);
// 图表引用
const shopChartsRef = ref<{ renderShopBarChart: () => void; renderShopScatterChart: () => void }>();
// 切换时间范围
const switchTimeRange = async (
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
) => {
activeTimeRange.value = type;
let startDate: dayjs.Dayjs;
let endDate: dayjs.Dayjs = dayjs();
switch (type) {
case '7days': {
startDate = dayjs().subtract(7, 'day');
break;
}
case '30days': {
startDate = dayjs().subtract(30, 'day');
break;
}
case 'custom': {
if (customDateRange.value) {
dateRange.value = customDateRange.value;
}
return;
}
case 'today': {
startDate = dayjs();
endDate = dayjs();
break;
}
case 'yesterday': {
startDate = dayjs().subtract(1, 'day');
endDate = dayjs().subtract(1, 'day');
break;
}
}
dateRange.value = [startDate, endDate];
customDateRange.value = [startDate, endDate];
// 手动切换时间时清除请求缓存,确保强制刷新
lastRequestKey.value = '';
syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
};
// 自定义日期范围变化
const handleCustomDateRangeChange = async (
value: [dayjs.Dayjs, dayjs.Dayjs] | [string, string] | null,
_dateString?: [string, string],
) => {
if (value && Array.isArray(value) && value.length === 2) {
const dates = [
dayjs.isDayjs(value[0]) ? value[0] : dayjs(value[0]),
dayjs.isDayjs(value[1]) ? value[1] : dayjs(value[1]),
] as [dayjs.Dayjs, dayjs.Dayjs];
customDateRange.value = dates;
activeTimeRange.value = 'custom';
dateRange.value = dates;
lastRequestKey.value = '';
syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
}
};
const setTimeRangeTypeByDates = (
startDate: dayjs.Dayjs,
endDate: dayjs.Dayjs,
) => {
const today = dayjs();
const daysDiff = endDate.diff(startDate, 'day');
const isEndDateToday = endDate.isSame(today, 'day');
const isStartDate7DaysAgo = startDate.isSame(
dayjs().subtract(7, 'day'),
'day',
);
const isStartDate30DaysAgo = startDate.isSame(
dayjs().subtract(30, 'day'),
'day',
);
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
activeTimeRange.value = 'today';
customDateRange.value = [startDate, endDate];
return;
}
if (daysDiff === 0 && startDate.isSame(dayjs().subtract(1, 'day'), 'day')) {
activeTimeRange.value = 'yesterday';
customDateRange.value = [startDate, endDate];
return;
}
if (isEndDateToday && isStartDate7DaysAgo) {
activeTimeRange.value = '7days';
customDateRange.value = [startDate, endDate];
return;
}
if (isEndDateToday && isStartDate30DaysAgo) {
activeTimeRange.value = '30days';
customDateRange.value = [startDate, endDate];
return;
}
activeTimeRange.value = 'custom';
customDateRange.value = [startDate, endDate];
};
const applyDateRangeFromRouteQuery = () => {
// 用 window.location 而非 route.query,因为 syncDateRangeToRouteQuery 用的是 history.replaceState
const url = new URL(window.location.href);
const startDate = url.searchParams.get('startDate');
const endDate = url.searchParams.get('endDate');
if (!startDate || !endDate) return false;
const parsedStartDate = dayjs(startDate);
const parsedEndDate = dayjs(endDate);
if (!parsedStartDate.isValid() || !parsedEndDate.isValid()) return false;
const isSameRange =
dateRange.value[0].isSame(parsedStartDate, 'day') &&
dateRange.value[1].isSame(parsedEndDate, 'day');
if (!isSameRange) {
dateRange.value = [parsedStartDate, parsedEndDate];
}
setTimeRangeTypeByDates(parsedStartDate, parsedEndDate);
return true;
};
const syncDateRangeToRouteQuery = async () => {
const startDate = dateRange.value[0].format('YYYY-MM-DD');
const endDate = dateRange.value[1].format('YYYY-MM-DD');
// 从 window.location 读取(history.replaceState 不会更新 route.query)
const url = new URL(window.location.href);
const curStart = url.searchParams.get('startDate');
const curEnd = url.searchParams.get('endDate');
if (curStart === startDate && curEnd === endDate) {
return;
}
const newUrl = new URL(window.location.href);
newUrl.searchParams.set('startDate', startDate);
newUrl.searchParams.set('endDate', endDate);
window.history.replaceState({}, '', newUrl.toString());
};
// 加载店铺数量
const loadShopCount = async () => {
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1,
filters: {},
});
shopCount.value = response.total || 0;
} catch (error) {
console.error('获取店铺数量失败:', error);
}
};
// 加载概览数据
const loadOverviewData = async () => {
if (isRequesting.value) return;
isRequesting.value = true;
try {
loading.value = true;
const params: CompanyOverviewDTO.Query = {
dateRange: [
dateRange.value[0].format('YYYY-MM-DD'),
dateRange.value[1].format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
};
const data = await getCompanyOverviewApi(params);
overviewData.value = data;
} catch (error) {
console.error('获取全店概览数据失败:', error);
} finally {
loading.value = false;
isRequesting.value = false;
}
};
const refreshOverviewByCurrentParams = async (force = false) => {
applyDateRangeFromRouteQuery();
const requestKey = `${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}`;
if (!force && lastRequestKey.value === requestKey) {
return;
}
lastRequestKey.value = requestKey;
await loadOverviewData();
};
// 监听数据变化,重新渲染图表
watch(
() => overviewData.value,
() => {
if (overviewData.value) {
setTimeout(() => {
shopChartsRef.value?.renderShopBarChart();
shopChartsRef.value?.renderShopScatterChart();
}, 100);
}
},
{ deep: true },
);
// 深色模式 class 变化时重绘图表
let darkThemeObserver: MutationObserver | null = null;
onMounted(async () => {
await loadShopCount();
await refreshOverviewByCurrentParams(true);
darkThemeObserver = new MutationObserver(() => {
if (overviewData.value) {
shopChartsRef.value?.renderShopBarChart();
shopChartsRef.value?.renderShopScatterChart();
}
});
darkThemeObserver.observe(document.documentElement, {
attributes: true,
attributeFilter: ['class'],
});
});
onUnmounted(() => {
darkThemeObserver?.disconnect();
darkThemeObserver = null;
});
onActivated(async () => {
await refreshOverviewByCurrentParams(true);
});
// 导出公司概览
const handleExportCompanyOverview = async () => {
try {
exportLoading.value = true;
const [startDate, endDate] = dateRange.value;
let dataToExport: CompanyOverviewVO.ShopComparison[] = [];
if (overviewData.value?.shopComparisons) {
dataToExport =
selectedExportShopIds.value.length > 0
? overviewData.value.shopComparisons.filter((s) =>
selectedExportShopIds.value.includes(s.shopId),
)
: overviewData.value.shopComparisons;
}
let shopIds: number[] | undefined;
if (dataToExport.length === 0) {
shopIds =
selectedExportShopIds.value.length > 0
? selectedExportShopIds.value
: undefined;
}
const filename = `公司概览_${startDate.format('YYYYMMDD')}_${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/store-overview/export',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
shopIds,
taxRate: taxRate.value,
},
filename,
);
shopExportMode.value = false;
} finally {
exportLoading.value = false;
}
};
// 切换行选择模式
const toggleShopExportMode = (enabled: boolean) => {
shopExportMode.value = enabled;
if (!enabled) {
selectedExportShopIds.value = [];
}
};
// 切换平台导出模式
const togglePlatformExportMode = (enabled: boolean) => {
platformExportMode.value = enabled;
if (!enabled) {
selectedExportPlatformIds.value = [];
}
};
// 导出平台维度汇总
const handlePlatformExport = async () => {
try {
exportLoading.value = true;
const [startDate, endDate] = dateRange.value;
const filename = `平台维度汇总_${startDate.format('YYYYMMDD')}_${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/platform-overview/export',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
platformIds: selectedExportPlatformIds.value.length > 0
? selectedExportPlatformIds.value
: undefined,
taxRate: taxRate.value,
},
filename,
);
platformExportMode.value = false;
} finally {
exportLoading.value = false;
}
};
// 跳转到店铺详情页
const navigateToShopOverview = (shopId: number) => {
router.push({
path: `/ecom/shop/overview/${shopId}`,
query: {
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
},
});
};
</script>
<template>
<Page title="全店铺经营概览大盘" auto-content-height class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
<template #description>
<div class="mt-1 text-sm font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
数据范围:公司旗下所有店铺汇总统计 · 共 {{ shopCount }} 家在营店铺
</div>
</template>
<template #extra>
<!-- 税率 + 时间选择器 -->
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-2">
<!-- 税率输入 -->
<div
class="flex h-[42px] items-center gap-2 rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-200/50 dark:bg-[hsl(240deg_3.7%_15.9%/30%)] px-3"
>
<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">税率</span>
<InputNumber
v-model:value="taxRate"
:min="0"
:max="1"
:step="0.01"
:precision="2"
size="small"
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-white/30 dark:!bg-[hsl(240deg_3.7%_22%/30%)] !text-sm !font-bold !text-center"
:formatter="formatTaxRate"
:parser="parseTaxRate"
/>
</div>
<!-- 时间选择器容器 -->
<div
class="flex h-[42px] flex-col gap-2 rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-200/50 dark:bg-[hsl(240deg_3.7%_15.9%/30%)] p-1.5 sm:flex-row sm:items-center sm:gap-2"
>
<!-- 快速选择按钮组 -->
<div
class="flex items-center gap-1 overflow-x-auto rounded-xl bg-white/30 dark:bg-[hsl(240deg_3.7%_22%/30%)] p-1"
>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === 'today'
? '!bg-white !text-blue-600 dark:!bg-blue-900/30 dark:!text-blue-400 !shadow-sm dark:!shadow-none'
: '!bg-transparent !text-slate-600 dark:!bg-[hsl(222.34deg_10.43%_12.27%/50%)] dark:!text-[hsl(240deg_5%_64.9%)] hover:!bg-[hsl(240deg_3.7%_22%)]'
"
@click="switchTimeRange('today')"
>
今日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === 'yesterday'
? '!bg-white !text-blue-600 dark:!bg-blue-900/30 dark:!text-blue-400 !shadow-sm dark:!shadow-none'
: '!bg-transparent !text-slate-600 dark:!bg-[hsl(222.34deg_10.43%_12.27%/50%)] dark:!text-[hsl(240deg_5%_64.9%)] hover:!bg-[hsl(240deg_3.7%_22%)]'
"
@click="switchTimeRange('yesterday')"
>
昨日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === '7days'
? '!bg-white !text-blue-600 dark:!bg-blue-900/30 dark:!text-blue-400 !shadow-sm dark:!shadow-none'
: '!bg-transparent !text-slate-600 dark:!bg-[hsl(222.34deg_10.43%_12.27%/50%)] dark:!text-[hsl(240deg_5%_64.9%)] hover:!bg-[hsl(240deg_3.7%_22%)]'
"
@click="switchTimeRange('7days')"
>
近7日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === '30days'
? '!bg-white !text-blue-600 dark:!bg-blue-900/30 dark:!text-blue-400 !shadow-sm dark:!shadow-none'
: '!bg-transparent !text-slate-600 dark:!bg-[hsl(222.34deg_10.43%_12.27%/50%)] dark:!text-[hsl(240deg_5%_64.9%)] hover:!bg-[hsl(240deg_3.7%_22%)]'
"
@click="switchTimeRange('30days')"
>
近30日
</Button>
</div>
<!-- 日期选择器 -->
<div class="flex items-center gap-2">
<span class="hidden text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)] sm:inline">
自定义日期
</span>
<DatePicker.RangePicker
v-model:value="customDateRange"
size="small"
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始', '结束']"
class="!h-8 !border-none !bg-transparent !text-sm !font-bold dark:!text-[hsl(240deg_5%_64.9%)]"
@change="handleCustomDateRangeChange"
/>
</div>
</div>
</div>
</template>
<Spin :spinning="loading">
<div class="mx-auto w-full space-y-6">
<!-- 第一层:核心汇总指标 -->
<KpiCards :overview-data="overviewData" :tax-rate="taxRate" />
<!-- 第二层:深度分析图表 -->
<ShopCharts
ref="shopChartsRef"
:shop-sales-ratios="overviewData?.shopSalesRatios"
:shop-comparisons="overviewData?.shopComparisons"
:shop-efficiency-quadrants="overviewData?.shopEfficiencyQuadrants"
/>
<!-- 第三层:平台/店铺/品类明细切换 -->
<ComparisonSwitcher
:tax-rate="taxRate"
:platform-summary="overviewData?.platformSummary"
:platform-export-mode="platformExportMode"
:selected-export-platform-ids="selectedExportPlatformIds"
:shop-comparisons="overviewData?.shopComparisons"
:shop-export-mode="shopExportMode"
:selected-export-shop-ids="selectedExportShopIds"
:category-comparisons="overviewData?.categoryComparisons"
:category-export-mode="categoryExportMode"
:selected-export-category-ids="selectedExportCategoryIds"
@update:selected-export-platform-ids="(ids) => (selectedExportPlatformIds = ids)"
@toggle-platform-export-mode="togglePlatformExportMode"
@platform-export="handlePlatformExport"
@update:selected-export-shop-ids="(ids) => (selectedExportShopIds = ids)"
@toggle-shop-export-mode="toggleShopExportMode"
@shop-export="handleExportCompanyOverview"
@navigate="navigateToShopOverview"
@toggle-category-export-mode="handleCategoryExportToggle"
@update:selected-export-category-ids="selectedExportCategoryIds = $event"
@category-export="handleCategoryExport"
/>
</div>
</Spin>
</Page>
</template>
<style scoped>
:deep(.tax-rate-input .ant-input-number-input) {
height: 32px;
line-height: 32px;
padding-top: 0;
padding-bottom: 0;
}
</style>