refactor(ecom-dmb): 店铺概览商品/品类损益对比表合并为ProductCategorySwitcher组件

This commit is contained in:
小蟑螂
2026-04-24 22:07:24 +08:00
parent 30728ee711
commit 0de9d4cdd2
2 changed files with 121 additions and 10 deletions
@@ -0,0 +1,116 @@
<script lang="ts" setup>
import type { ShopVO } from '#/api/ecommerce/shop/types';
import { ref } from 'vue';
import { Segmented } from 'ant-design-vue';
import CategoryComparisonTable from './CategoryComparisonTable.vue';
import ProductComparisonTable from './ProductComparisonTable.vue';
defineOptions({ name: 'ProductCategorySwitcher' });
interface Props {
data: ShopVO.OverviewStatistics | null;
taxRate: number;
categoryExportMode: boolean;
selectedExportCategoryIds: number[];
categoryExportLoading?: boolean;
exportLoading?: boolean;
}
interface Emits {
(e: 'export'): void;
(e: 'exportAll'): void;
(e: 'exportToggle'): void;
(e: 'categorySelectAll'): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const activeMode = ref<'product' | 'category'>('product');
const modeOptions = [
{ label: '商品汇总', value: 'product' },
{ 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>
<ProductComparisonTable
v-if="activeMode === 'product'"
:data="props.data"
:tax-rate="props.taxRate"
:export-loading="props.exportLoading"
@export="emit('export')"
/>
<CategoryComparisonTable
v-if="activeMode === 'category'"
:data="props.data"
:tax-rate="props.taxRate"
:category-export-mode="props.categoryExportMode"
:selected-export-category-ids="props.selectedExportCategoryIds"
:category-export-loading="props.categoryExportLoading"
@export-all="emit('exportAll')"
@export-toggle="emit('exportToggle')"
@category-select-all="emit('categorySelectAll')"
/>
</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>
@@ -31,6 +31,7 @@ import SalesTrendChart from './components/SalesTrendChart.vue';
import FinancialPanel from './components/FinancialPanel.vue';
import ProductComparisonTable from './components/ProductComparisonTable.vue';
import CategoryComparisonTable from './components/CategoryComparisonTable.vue';
import ProductCategorySwitcher from './components/ProductCategorySwitcher.vue';
defineOptions({ name: 'ShopOverview' });
@@ -611,21 +612,15 @@ onActivated(async () => {
<FinancialPanel :data="overviewData" :tax-rate="taxRate" />
</div>
<!-- 第三层:商品16维度横向对比表 -->
<ProductComparisonTable
:data="overviewData"
:tax-rate="taxRate"
:export-loading="exportLoading"
@export="handleExportShopOverview"
/>
<!-- 第四层:品类多维度损益对比表 -->
<CategoryComparisonTable
<!-- 第三层:商品/品类多维度损益对比表 -->
<ProductCategorySwitcher
:data="overviewData"
:tax-rate="taxRate"
:category-export-mode="categoryExportMode"
:selected-export-category-ids="selectedExportCategoryIds"
:category-export-loading="categoryExportLoading"
:export-loading="exportLoading"
@export="handleExportShopOverview"
@export-all="handleCategoryExport"
@export-toggle="handleCategoryExportToggle"
@category-select-all="handleCategorySelectAllChange"