refactor: 完全迁移店铺概览和商品概览到bi层

This commit is contained in:
2026-08-13 09:31:07 +08:00
parent 44fb58b878
commit 9af2efaf31
76 changed files with 2020 additions and 7419 deletions
@@ -11,7 +11,7 @@ import { requestClient } from '#/api/request';
*/
export async function getProductOverviewApi(params: ProductOverviewDTO.Query) {
return requestClient.post<ProductOverviewVO.Overview>(
'/ec/product/overview',
'/bi/product/overview',
params,
);
}
@@ -62,6 +62,20 @@ export async function getShopProductPageApi(
);
}
/**
* 店铺概览统计(BI:Mongo 订单日汇聚)
*/
export async function getShopOverviewApi(params: {
shopId: number;
dateRange: string[];
taxRate?: number;
}) {
return requestClient.post<ShopVO.OverviewStatistics>(
'/bi/shop/overview',
params,
);
}
/**
* 店铺数据统计-按商品汇总(Excel)
*/
@@ -70,20 +84,7 @@ export async function exportShopSummaryByProductApi(params: {
dateRange: string[];
exportType?: string;
}) {
return requestClient.post('/ec/shop/export/summary-by-product', params, {
responseType: 'blob',
});
}
/**
* 全店概览-按店铺汇总(Excel)
*/
export async function exportCompanyOverviewApi(params: {
dateRange: string[];
shopIds?: number[];
exportType?: string;
}) {
return requestClient.post('/ec/store-overview/export/by-shop', params, {
return requestClient.post('/bi/shop/export/summary-by-product', params, {
responseType: 'blob',
});
}
@@ -1,43 +0,0 @@
import type { CompanyOverviewDTO, CompanyOverviewVO } from './types';
import { requestClient } from '#/api/request';
/**
* 全店概览 API(统计与导出)
*/
/**
* 获取全店概览统计数据
*/
export async function getCompanyOverviewApi(data: CompanyOverviewDTO.Query) {
return requestClient.post<CompanyOverviewVO.Info>(
'/ec/store/overview',
data,
);
}
/**
* 全店概览-按品类汇总(Excel)
*/
export async function exportCategoryOverviewApi(params: {
dateRange: string[];
categoryIds?: number[];
taxRate: number;
}) {
return requestClient.post('/ec/store-overview/export/by-category', params, {
responseType: 'blob',
});
}
/**
* 全店概览-按店铺汇总(Excel)
*/
export async function exportCompanyOverviewApi(params: {
dateRange: string[];
shopIds?: number[];
exportType?: string;
}) {
return requestClient.post('/ec/store-overview/export/by-shop', params, {
responseType: 'blob',
});
}
@@ -1,6 +1,4 @@
/**
* 全店铺概览管理模块API导出
* 工作台底表等复用的汇总表类型(原全店概览 VO,页面已下线)。
*/
export * from './apis';
export * from './types';
@@ -1,6 +1,4 @@
/**
* 全店铺概览管理模块类型定义导出
* 工作台汇总表类型(原全店概览 VO 字段,页面已下线)。
*/
export * from './types.dto';
export * from './types.vo';
@@ -1,13 +0,0 @@
/**
* 全店铺概览相关DTO类型定义
*/
export namespace CompanyOverviewDTO {
/** 全店铺概览查询参数 */
export interface Query {
/** 日期范围数组(第一个是开始日期,第二个是结束日期,只有一个日期则返回当天数据) */
dateRange: string[];
/** 税率(默认0.04,即4%) */
taxRate?: number;
}
}
@@ -257,7 +257,7 @@ export namespace CompanyOverviewVO {
categories: CategorySummary[];
}
/** 工作台底部四张汇总表(与全店概览同源字段) */
/** 工作台底部四张汇总表 */
export interface WorkbenchTableBundle {
shopTable?: ShopOverview | null;
platformTable?: PlatformOverview | null;
@@ -20,7 +20,6 @@
"title": "Dashboard",
"analytics": "Analytics",
"workspace": "Workspace",
"storeOverview": "Store overview",
"workbench": "E-commerce operations workbench"
}
}
@@ -20,7 +20,6 @@
"title": "概览",
"analytics": "分析页",
"workspace": "工作台",
"storeOverview": "全店概览",
"workbench": "电商运营工作台"
}
}
@@ -12,34 +12,16 @@ const routes: RouteRecordRaw[] = [
name: 'Dashboard',
path: '/dashboard',
children: [
{
name: 'Analytics',
path: '/store-overview',
component: () => import('#/views/dashboard/store-overview/index.vue'),
meta: {
affixTab: true,
icon: 'lucide:area-chart',
title: $t('page.dashboard.storeOverview'),
},
},
{
name: 'PddWorkbench',
path: '/workbench',
component: () => import('#/views/dashboard/workbench/index.vue'),
meta: {
affixTab: true,
icon: 'lucide:gauge',
title: $t('page.dashboard.workbench'),
},
},
// {
// name: 'Workspace',
// path: '/workspace',
// component: () => import('#/views/dashboard/workspace/index.vue'),
// meta: {
// icon: 'carbon:workspace',
// title: $t('page.dashboard.workspace'),
// },
// },
],
},
];
@@ -53,7 +53,7 @@ export type OverviewRouteQuery = {
shopId?: string;
};
/** 概览页跳转(店铺/商品)时附带的 query,与全店概览一致 */
/** 概览页跳转(店铺/商品)时附带的 query,与工作台筛选一致 */
export function buildOverviewRouteQuery(
dateRange: [Dayjs, Dayjs],
options?: { shopId?: number },
@@ -1,5 +1,5 @@
/**
* 店铺/全店概览接口:费比 feeRatio / averageFeeRatio 为小数(推广费÷销售额,如 0.05 = 5%)。
* 店铺/工作台接口:费比 feeRatio / averageFeeRatio 为小数(推广费÷销售额,如 0.05 = 5%)。
* 达成率等字段后端已为 0–100 的数值,勿用本函数。
*/
export function formatFeeRatioPercent(value: number | undefined | null): string {
@@ -1,322 +0,0 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { computed } from 'vue';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import {
salesTaxColumnHint,
storeOverviewHints,
} from '#/utils/overview-table-hints';
defineOptions({ name: 'CategoryComparisonTable' });
interface Props {
categorySummary?: CompanyOverviewVO.CategoryOverview;
taxRate: number;
categoryExportMode?: boolean;
selectedExportCategoryIds?: number[];
headingTitle?: string;
headingSubtitle?: string;
/** 首列维度名称,如「品类」「商品」 */
firstColumnLabel?: string;
}
interface Emits {
(e: 'update:selectedExportCategoryIds', ids: number[]): void;
(e: 'toggleCategoryExportMode', enabled: boolean): void;
(e: 'export'): void;
}
const props = withDefaults(defineProps<Props>(), {
categoryExportMode: false,
selectedExportCategoryIds: () => [],
headingTitle: '各品类多维度经营明细汇总',
headingSubtitle: '包含:规模、成本及最终损益所有维度',
firstColumnLabel: '品类',
});
const emit = defineEmits<Emits>();
const allCategoriesSelected = computed(() => {
const total = props.categorySummary?.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', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2));
</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%)]">
{{ props.headingTitle }}
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ props.headingSubtitle }}
</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
? []
: (categorySummary?.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"
>
{{ props.firstColumnLabel }}
</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="8"
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%)]">
<OverviewColumnHint :title="storeOverviewHints.salesAmount">
实际销售额
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.orderCount">单量</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.averageOrderValue">客单价</OverviewColumnHint>
</th>
<th class="border-b border-l px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.productCost">商品成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.shippingCost">运费</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.otherCost">其他成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-bold text-orange-800 dark:text-orange-300">
<OverviewColumnHint :title="storeOverviewHints.orderCost">订单成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:text-rose-400">
<OverviewColumnHint :title="storeOverviewHints.refundAmount">退款金额</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.totalPromotionFee">推广费</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-orange-600 dark:text-orange-400">
<OverviewColumnHint :title="storeOverviewHints.brushFee">刷单费用</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
<OverviewColumnHint :title="storeOverviewHints.feeRatioCategoryRow">费比%</OverviewColumnHint>
</th>
<th class="border-b border-l px-6 py-4 font-bold">
<OverviewColumnHint :title="storeOverviewHints.totalProfitBeforeTax">
税前盈亏
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:text-rose-400">
<OverviewColumnHint :title="salesTaxColumnHint(taxRate)">
{{ (taxRate * 100).toFixed(0) }}%税额
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">
<OverviewColumnHint :title="storeOverviewHints.roi">ROI</OverviewColumnHint>
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">
<OverviewColumnHint light :title="storeOverviewHints.profitAfterTax">
税后盈亏
</OverviewColumnHint>
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="cat in (categorySummary?.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="inline-block 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 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">{{ formatIntCell(cat.orderCount) }}</td>
<td class="p-6 font-medium">
{{ cellMoney(cat.averageOrderValue) }}
</td>
<td class="p-6">{{ cellMoney(cat.productCost) }}</td>
<td class="p-6">{{ cellMoney(cat.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(cat.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{ cellMoney(cat.orderCost) }}
</td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cellMoney(cat.refundAmount) }}
</td>
<td class="p-6">{{ cellMoney(cat.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">
{{ cellMoney(cat.brushFee) }}
</td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cat.feeRatio !== undefined ? formatFeeRatioPercent(cat.feeRatio) : '-' }}
</td>
<td class="p-6 font-bold">
{{ cellMoney(cat.totalProfitBeforeTax) }}
</td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(cat.salesTaxAmount) }}
</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">
{{ cellRoi(cat.roi) }}
</td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black text-emerald-600">
{{ cellMoney(cat.profitAfterTax) }}
</td>
</tr>
<tr v-if="!categorySummary?.categories?.length">
<td :colspan="categoryExportMode ? 18 : 17" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="categorySummary?.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">{{ cellMoney(categorySummary?.total?.salesAmount) }}</td>
<td class="p-6">{{ formatIntCell(categorySummary?.total?.orderCount) }}</td>
<td class="p-6">
{{ cellMoney(categorySummary?.total?.averageOrderValue) }}
</td>
<!-- 成本 -->
<td class="p-6">{{ cellMoney(categorySummary?.total?.productCost) }}</td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(categorySummary?.total?.orderCost) }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(categorySummary?.total?.refundAmount) }}</td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(categorySummary?.total?.brushFee) }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categorySummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(categorySummary?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ cellMoney(categorySummary?.total?.totalProfitBeforeTax) }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ cellMoney(categorySummary?.total?.salesTaxAmount) }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(categorySummary?.total?.roi) }}</td>
<td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(categorySummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'"
>{{ cellMoney(categorySummary?.total?.profitAfterTax) }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -1,159 +0,0 @@
<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;
selectedExportPlatformCodes: string[];
shopSummary?: CompanyOverviewVO.ShopOverview;
shopExportMode: boolean;
selectedExportShopIds: number[];
categorySummary?: CompanyOverviewVO.CategoryOverview;
categoryExportMode: boolean;
selectedExportCategoryIds: number[];
}
interface Emits {
(e: 'update:selectedExportPlatformCodes', codes: string[]): 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 'shop';
};
const activeMode = ref<'platform' | 'shop' | 'category'>(getDefaultMode());
watch(activeMode, (val) => localStorage.setItem(STORAGE_KEY, val));
const modeOptions = [
{ label: '店铺汇总', value: 'shop' },
{ label: '平台汇总', value: 'platform' },
{ label: '品类汇总', value: 'category' },
];
</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-codes="props.selectedExportPlatformCodes"
@update:selected-export-platform-codes="
(codes) => emit('update:selectedExportPlatformCodes', codes)
"
@toggle-platform-export-mode="
(enabled) => emit('togglePlatformExportMode', enabled)
"
@export="emit('platformExport')"
/>
<ShopComparisonTable
v-if="activeMode === 'shop'"
:shop-summary="props.shopSummary"
: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-summary="props.categorySummary"
: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>
@@ -1,142 +0,0 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
defineOptions({ name: 'KpiCards' });
interface Props {
overviewData: CompanyOverviewVO.Info | null;
taxRate: number;
}
const props = defineProps<Props>();
void props; // kept for template compatibility
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
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%)]">
{{ formatFeeRatioPercent(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>
@@ -1,424 +0,0 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import {
salesTaxColumnHint,
storeOverviewHints,
} from '#/utils/overview-table-hints';
defineOptions({ name: 'PlatformSummaryCard' });
interface Props {
taxRate?: number;
platformSummary?: CompanyOverviewVO.PlatformOverview;
platformExportMode?: boolean;
selectedExportPlatformCodes?: string[];
headingTitle?: string;
headingSubtitle?: string;
}
interface Emits {
(e: 'update:selectedExportPlatformCodes', codes: string[]): void;
(e: 'togglePlatformExportMode', enabled: boolean): void;
(e: 'export'): void;
}
const props = withDefaults(defineProps<Props>(), {
platformExportMode: false,
selectedExportPlatformCodes: () => [],
headingTitle: '各平台多维度经营明细汇总',
headingSubtitle: '目标达成 · 规模 · 成本费用 · 盈利分析,四大维度完整汇总',
});
const emit = defineEmits<Emits>();
const allPlatformsSelected = computed(() => {
const total = platformData.value.length;
return total > 0 && props.selectedExportPlatformCodes.length === total;
});
const somePlatformsSelected = computed(() => {
return props.selectedExportPlatformCodes.length > 0;
});
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2));
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 => ({
platformCode: p.platformCode,
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,
orderCost: p.orderCost ?? 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;
});
});
</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%)]">
{{ props.headingTitle }}
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ props.headingSubtitle }}
</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="selectedExportPlatformCodes.length === 0"
@click="emit('export')"
>
导出已选平台 ({{ selectedExportPlatformCodes.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:selectedExportPlatformCodes',
platformData.map((p) => p.platformCode) || [],
);
} else {
emit('update:selectedExportPlatformCodes', []);
}
}
"
/>
</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="8"
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-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.targetOrderCount">
目标单量
</OverviewColumnHint>
</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">
<OverviewColumnHint :title="storeOverviewHints.orderCountAchievementRate">
单量达成率
</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.targetAmount">目标额</OverviewColumnHint>
</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">
<OverviewColumnHint :title="storeOverviewHints.salesAmountAchievementRate">
销售达成率
</OverviewColumnHint>
</th>
<!-- 规模子列 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<OverviewColumnHint :title="storeOverviewHints.salesAmount">
实际销售额
</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.orderCount">单量</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.averageOrderValue">客单价</OverviewColumnHint>
</th>
<!-- 成本子列 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.productCost">商品成本</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.shippingCost">运费</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.otherCost">其他成本</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold text-orange-800 dark:text-orange-300">
<OverviewColumnHint :title="storeOverviewHints.orderCost">订单成本</OverviewColumnHint>
</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">
<OverviewColumnHint :title="storeOverviewHints.refundAmount">退款金额</OverviewColumnHint>
</th>
<th class="border-b border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.totalPromotionFee">推广费</OverviewColumnHint>
</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">
<OverviewColumnHint :title="storeOverviewHints.brushFee">刷单费用</OverviewColumnHint>
</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%)]">
<OverviewColumnHint :title="storeOverviewHints.feeRatioPlatform">费比%</OverviewColumnHint>
</th>
<!-- 盈利子列 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold">
<OverviewColumnHint :title="storeOverviewHints.totalProfitBeforeTax">
税前盈亏
</OverviewColumnHint>
</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%)]">
<OverviewColumnHint :title="salesTaxColumnHint(taxRate ?? 0.04)">
{{ taxRateNum.toFixed(0) }}%税额
</OverviewColumnHint>
</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">
<OverviewColumnHint :title="storeOverviewHints.roi">ROI</OverviewColumnHint>
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">
<OverviewColumnHint light :title="storeOverviewHints.profitAfterTax">
税后盈亏
</OverviewColumnHint>
</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.platformCode"
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="selectedExportPlatformCodes.includes(p.platformCode)"
@change="
(e) => {
const checked = (e.target as HTMLInputElement).checked;
const newIds = checked
? [...selectedExportPlatformCodes, p.platformCode]
: selectedExportPlatformCodes.filter((id) => id !== p.platformCode);
emit('update:selectedExportPlatformCodes', newIds);
}
"
/>
</td>
<!-- 平台名 -->
<td
class="sticky-col border-r-2 border-slate-100 dark:border-r-[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="inline-block 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-orange-800 dark:text-orange-300">{{ formatAmount(p.orderCost) }}</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%)]">{{ formatFeeRatioPercent(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">{{ formatIntCell(totalData.targetOrderCount) }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">
{{ totalData.orderCountAchievementRate !== undefined ? formatPercentPlain(totalData.orderCountAchievementRate) : '-' }}
</td>
<td class="p-6">{{ cellMoney(totalData.targetAmount) }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">
{{ totalData.salesAmountAchievementRate !== undefined ? formatPercentPlain(totalData.salesAmountAchievementRate) : '-' }}
</td>
<!-- 规模 -->
<td class="p-6">{{ cellMoney(totalData.salesAmount) }}</td>
<td class="p-6">{{ formatIntCell(totalData.orderCount) }}</td>
<td class="p-6">
{{ cellMoney(totalData.averageOrderValue) }}
</td>
<!-- 成本 -->
<td class="p-6">{{ cellMoney(totalData.productCost) }}</td>
<td class="p-6">{{ cellMoney(totalData.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(totalData.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(totalData.orderCost) }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(totalData.refundAmount) }}</td>
<td class="p-6">{{ cellMoney(totalData.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(totalData.brushFee) }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ totalData.feeRatio !== undefined ? formatFeeRatioPercent(totalData.feeRatio) : '-' }}
</td>
<!-- 盈利 -->
<td class="p-6">
{{ cellMoney(totalData.totalProfitBeforeTax) }}
</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(totalData.salesTaxAmount) }}
</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">
{{ cellRoi(totalData.roi) }}
</td>
<td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(totalData.profitAfterTax ?? 0) >= 0 ? 'text-emerald-700 dark:text-emerald-300' : 'text-rose-600 dark:text-rose-400'"
>
{{ cellMoney(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 ? 22 : 21" class="p-6">暂无数据</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -1,275 +0,0 @@
<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';
import dayjs from 'dayjs';
defineOptions({ name: 'ShopCharts' });
interface Props {
shopSalesRatios?: CompanyOverviewVO.ShopSalesRatio[];
shopSummary?: CompanyOverviewVO.ShopOverview;
salesAmountTrend?: CompanyOverviewVO.TrendData;
orderCountTrend?: CompanyOverviewVO.TrendData;
}
const props = defineProps<Props>();
const barChartRef = ref<EchartsUIType>();
const trendChartRef = ref<EchartsUIType>();
const { renderEcharts: renderBarChart } = useEcharts(barChartRef);
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
// 渲染店铺销售占比排行图表
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();
const isDark = document.documentElement.classList.contains('dark');
renderBarChart({
grid: {
left: '3%',
right: '12%',
bottom: '3%',
top: '3%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#000' },
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: isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b',
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', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`,
fontWeight: 900,
color: isDark ? 'hsl(0deg 0% 95%)' : '#334155',
},
},
],
});
};
// 渲染销售额与单量趋势平滑曲线
const renderTrendLineChart = () => {
if (!trendChartRef.value) return;
const salesTrend = props.salesAmountTrend;
const orderTrend = props.orderCountTrend;
if (!salesTrend?.dailyDataList?.length && !orderTrend?.dailyDataList?.length) {
const isDark = document.documentElement.classList.contains('dark');
renderTrendChart({
title: {
text: '暂无趋势数据',
left: 'center',
top: 'middle',
textStyle: {
color: isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b',
fontSize: 14,
fontWeight: 'bold',
},
},
xAxis: { show: false },
yAxis: { show: false },
series: [],
});
return;
}
const dates = (salesTrend?.dailyDataList || orderTrend?.dailyDataList || []).map(
(item) => dayjs(item.date).format('MM-DD'),
);
const salesData = (salesTrend?.dailyDataList || []).map((item) => item.value);
const orderData = (orderTrend?.dailyDataList || []).map((item) => item.value);
const isDark = document.documentElement.classList.contains('dark');
renderTrendChart({
grid: {
left: '3%',
right: '3%',
bottom: '3%',
top: '5%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#000' },
},
xAxis: {
type: 'category',
boundaryGap: false,
data: dates,
axisLine: {
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 22%)' : '#e2e8f0' },
},
axisLabel: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
},
yAxis: [
{
type: 'value',
name: '销售额',
nameTextStyle: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
axisLabel: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
splitLine: {
lineStyle: {
type: 'dashed',
color: isDark ? 'hsl(240deg 3.7% 22%)' : undefined,
},
},
},
{
type: 'value',
name: '单量',
position: 'right',
nameTextStyle: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
axisLabel: { color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined },
splitLine: { show: false },
},
],
series: [
{
name: '销售额',
type: 'line',
smooth: true,
symbol: 'none',
lineStyle: { width: 3, color: '#3b82f6' },
areaStyle: {
color: {
type: 'linear',
x: 0, y: 0, x2: 0, y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(59, 130, 246, 0.4)' },
{ offset: 1, color: 'rgba(59, 130, 246, 0)' },
],
},
},
data: salesData,
},
{
name: '日单量',
type: 'line',
yAxisIndex: 1,
smooth: true,
symbol: 'none',
lineStyle: { width: 3, color: '#10b981' },
areaStyle: {
color: {
type: 'linear',
x: 0, y: 0, x2: 0, y2: 1,
colorStops: [
{ offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
{ offset: 1, color: 'rgba(16, 185, 129, 0)' },
],
},
},
data: orderData,
},
],
});
};
const rerenderCharts = async () => {
await nextTick();
renderShopBarChart();
renderTrendLineChart();
};
watch(
() => [props.shopSalesRatios, props.salesAmountTrend, props.orderCountTrend],
() => {
rerenderCharts();
},
{ deep: true, immediate: true },
);
onMounted(() => {
rerenderCharts();
});
defineExpose({ renderShopBarChart, renderShopScatterChart: renderTrendLineChart });
</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] xl:col-span-1"
>
<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="trendChartRef" />
</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%)]">
各店铺销售贡献排行
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="barChartRef" />
</div>
</div>
</div>
</template>
@@ -1,424 +0,0 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { createIconifyIcon } from '@vben/icons';
import { computed } from 'vue';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import {
salesTaxColumnHint,
storeOverviewHints,
} from '#/utils/overview-table-hints';
const JumpIcon = createIconifyIcon('tdesign:jump');
defineOptions({ name: 'ShopComparisonTable' });
interface Props {
shopSummary?: CompanyOverviewVO.ShopOverview;
taxRate: number;
shopExportMode: boolean;
selectedExportShopIds: number[];
/** 覆盖默认表头主标题(如工作台演示) */
headingTitle?: string;
/** 覆盖默认表头副标题 */
headingSubtitle?: string;
}
interface Emits {
(e: 'update:selectedExportShopIds', ids: number[]): void;
(e: 'toggleShopExportMode', enabled: boolean): void;
(e: 'export'): void;
(e: 'navigate', shopId: number): void;
}
const props = withDefaults(defineProps<Props>(), {
headingTitle: '各店铺多维度经营明细汇总',
headingSubtitle: '包含:目标达成、规模、成本及最终损益所有维度',
});
const emit = defineEmits<Emits>();
const allShopsSelected = computed(() => {
const total = props.shopSummary?.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', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2));
</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%)]">
{{ props.headingTitle }}
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ props.headingSubtitle }}
</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',
shopSummary?.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="8"
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 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.targetOrderCount">
目标单量
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-blue-600 dark:text-blue-400">
<OverviewColumnHint :title="storeOverviewHints.orderCountAchievementRate">
单量达成率
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.targetAmount">目标额</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-blue-600 dark:text-blue-400">
<OverviewColumnHint :title="storeOverviewHints.salesAmountAchievementRate">
销售达成率
</OverviewColumnHint>
</th>
<!-- 规模 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<OverviewColumnHint :title="storeOverviewHints.salesAmount">
实际销售额
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.orderCount">单量</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.averageOrderValue">客单价</OverviewColumnHint>
</th>
<!-- 成本 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.productCost">商品成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.shippingCost">运费</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.otherCost">其他成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-bold text-orange-800 dark:text-orange-300">
<OverviewColumnHint :title="storeOverviewHints.orderCost">订单成本</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:text-rose-400">
<OverviewColumnHint :title="storeOverviewHints.refundAmount">退款金额</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.totalPromotionFee">推广费</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-orange-600 dark:text-orange-400">
<OverviewColumnHint :title="storeOverviewHints.brushFee">刷单费用</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
<OverviewColumnHint :title="storeOverviewHints.feeRatioShopRow">费比%</OverviewColumnHint>
</th>
<!-- 盈利 -->
<th class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold">
<OverviewColumnHint :title="storeOverviewHints.totalProfitBeforeTax">
税前盈亏
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:text-rose-400">
<OverviewColumnHint :title="salesTaxColumnHint(taxRate)">
{{ (taxRate * 100).toFixed(0) }}%税额
</OverviewColumnHint>
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">
<OverviewColumnHint :title="storeOverviewHints.roi">ROI</OverviewColumnHint>
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">
<OverviewColumnHint light :title="storeOverviewHints.profitAfterTax">
税后盈亏
</OverviewColumnHint>
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="shop in (shopSummary?.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 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"
: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 dark:border-r-[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"
:class="shopExportMode ? 'border-l-0' : ''"
>
<span
class="inline-flex cursor-pointer items-center gap-1 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 transition-colors hover:text-blue-300 hover:underline"
@click="emit('navigate', shop.shopId)"
>
{{ shop.shopName }}
<JumpIcon class="text-xs" />
</span>
</td>
<!-- 目标 -->
<td class="p-6 font-medium">
{{ formatIntCell(shop.targetOrderCount) }}
</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">
{{ cellMoney(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">
{{ formatIntCell(shop.orderCount) }}
</td>
<td class="p-6 font-medium">
{{ cellMoney(shop.averageOrderValue) }}
</td>
<!-- 成本 -->
<td class="p-6">
{{ cellMoney(shop.productCost) }}
</td>
<td class="p-6">
{{ cellMoney(shop.shippingCost) }}
</td>
<td class="p-6">
{{ cellMoney(shop.otherCost) }}
</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{ cellMoney(shop.orderCost) }}
</td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cellMoney(shop.refundAmount) }}
</td>
<td class="p-6">
{{ cellMoney(shop.totalPromotionFee) }}
</td>
<td class="p-6 text-orange-600 dark:text-orange-400">
{{ cellMoney(shop.brushFee) }}
</td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
shop.feeRatio !== undefined
? formatFeeRatioPercent(shop.feeRatio)
: '-'
}}
</td>
<!-- 盈利 -->
<td class="p-6 font-bold">
{{ cellMoney(shop.totalProfitBeforeTax) }}
</td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(shop.salesTaxAmount) }}
</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">
{{ cellRoi(shop.roi) }}
</td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base font-black text-emerald-600">
{{ cellMoney(shop.profitAfterTax) }}
</td>
</tr>
<tr v-if="!shopSummary?.shops?.length">
<td :colspan="shopExportMode ? 22 : 21" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="shopSummary?.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">{{ formatIntCell(shopSummary?.total?.targetOrderCount) }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">
{{
shopSummary?.total?.orderCountAchievementRate !== undefined
? formatPercentPlain(shopSummary?.total?.orderCountAchievementRate)
: '-'
}}
</td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.targetAmount) }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">
{{
shopSummary?.total?.salesAmountAchievementRate !== undefined
? formatPercentPlain(shopSummary?.total?.salesAmountAchievementRate)
: '-'
}}
</td>
<!-- 规模 -->
<td class="p-6">{{ cellMoney(shopSummary?.total?.salesAmount) }}</td>
<td class="p-6">{{ formatIntCell(shopSummary?.total?.orderCount) }}</td>
<td class="p-6">
{{ cellMoney(shopSummary?.total?.averageOrderValue) }}
</td>
<!-- 成本 -->
<td class="p-6">{{ cellMoney(shopSummary?.total?.productCost) }}</td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(shopSummary?.total?.orderCost) }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(shopSummary?.total?.refundAmount) }}</td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(shopSummary?.total?.brushFee) }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopSummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(shopSummary?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ cellMoney(shopSummary?.total?.totalProfitBeforeTax) }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ cellMoney(shopSummary?.total?.salesTaxAmount) }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(shopSummary?.total?.roi) }}</td>
<td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(shopSummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'"
>{{ cellMoney(shopSummary?.total?.profitAfterTax) }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</template>
@@ -1,615 +0,0 @@
<script lang="ts" setup>
import type {
CompanyOverviewDTO,
CompanyOverviewVO,
} from '#/api/ecommerce/store-overview';
import {
onActivated,
onMounted,
onUnmounted,
ref,
watch,
} from 'vue';
import { 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 { exportByPost } from '#/utils/export';
import {
applyOverviewDateRangeFromUrl,
buildOverviewRouteQuery,
normalizeOverviewRangePickerChange,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
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 loading = ref(false);
const exportLoading = ref(false);
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
// 指定店铺导出模式
const shopExportMode = ref(false);
const selectedExportShopIds = ref<number[]>([]);
// 指定平台导出模式
const platformExportMode = ref(false);
const selectedExportPlatformCodes = ref<string[]>([]);
// 日期范围(默认:本月至今日)
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().startOf('month'),
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 });
}
const [cStart, cEnd] = dateRange.value;
await exportByPost(
'/ec/store-overview/export/by-category',
params,
`全店概览_按品类汇总_${cStart.format('YYYYMMDD')}-${cEnd.format('YYYYMMDD')}.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' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
>('thisMonth');
// 自定义日期范围
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' | 'thisMonth' | '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 'thisMonth': {
startDate = dayjs().startOf('month');
endDate = dayjs();
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();
};
// 自定义日期范围变化(同一天点两次时,antd 可能只给出开始日、结束为 null,dayjs(undefined) 会变成「今天」)
const handleCustomDateRangeChange = async (
value: [dayjs.Dayjs, dayjs.Dayjs] | [string, string] | null,
dateStrings?: [string, string],
) => {
const dates = normalizeOverviewRangePickerChange(value, dateStrings);
if (!dates) {
return;
}
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 (
isEndDateToday &&
startDate.isSame(today.startOf('month'), 'day')
) {
activeTimeRange.value = 'thisMonth';
customDateRange.value = [startDate, endDate];
return;
}
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 = () =>
applyOverviewDateRangeFromUrl(dateRange, setTimeRangeTypeByDates);
const syncDateRangeToRouteQuery = () => {
syncOverviewDateRangeToUrl(dateRange.value);
};
// 加载概览数据
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 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.ShopSummary[] = [];
if (overviewData.value?.shopSummary) {
const shops = overviewData.value.shopSummary.shops;
dataToExport =
selectedExportShopIds.value.length > 0
? shops.filter((s) =>
selectedExportShopIds.value.includes(s.shopId),
)
: shops;
}
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/by-shop',
{
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) {
selectedExportPlatformCodes.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/store-overview/export/by-platform',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
platformCodes: selectedExportPlatformCodes.value.length > 0
? selectedExportPlatformCodes.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: buildOverviewRouteQuery(dateRange.value),
});
};
</script>
<template>
<Page
auto-content-height
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
header-class="store-overview-page-header"
>
<template #title>
<div
class="text-xl font-black tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_98%)] sm:text-2xl md:text-3xl"
>
全店铺经营概览大盘
</div>
</template>
<template #extra>
<!-- 税率 + 时间选择器 -->
<div class="flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2">
<!-- 税率输入 -->
<div
class="flex min-h-[44px] w-full items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 px-3 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)] sm:w-auto"
>
<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 w-full flex-col gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 p-1.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)] sm:w-auto sm:flex-row sm:items-center sm:gap-2"
>
<!-- 快速选择按钮组 -->
<div
class="flex w-full items-center gap-1 overflow-x-auto rounded-xl bg-white/30 p-1 dark:bg-[hsl(240deg_3.7%_22%/30%)]"
>
<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>
<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 === 'thisMonth'
? '!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('thisMonth')"
>
本月
</Button>
</div>
<!-- 日期选择器 -->
<div class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-start">
<span class="hidden whitespace-nowrap 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 !w-full !border-none !bg-transparent !text-sm !font-bold dark:!text-[hsl(240deg_5%_64.9%)] sm:!w-[220px]"
@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-summary="overviewData?.shopSummary"
:sales-amount-trend="overviewData?.salesAmountTrend"
:order-count-trend="overviewData?.orderCountTrend"
/>
<!-- 第三层:平台/店铺/品类明细切换 -->
<ComparisonSwitcher
:tax-rate="taxRate"
:platform-summary="overviewData?.platformSummary"
:platform-export-mode="platformExportMode"
:selected-export-platform-codes="selectedExportPlatformCodes"
:shop-summary="overviewData?.shopSummary"
:shop-export-mode="shopExportMode"
:selected-export-shop-ids="selectedExportShopIds"
:category-summary="overviewData?.categorySummary"
:category-export-mode="categoryExportMode"
:selected-export-category-ids="selectedExportCategoryIds"
@update:selected-export-platform-codes="(codes) => (selectedExportPlatformCodes = codes)"
@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;
}
:deep(.store-overview-page-header) {
align-items: center;
}
@media (max-width: 640px) {
:deep(.store-overview-page-header) {
flex-direction: column;
align-items: stretch;
gap: 10px;
}
:deep(.store-overview-page-header > div:first-child) {
width: 100%;
}
:deep(.store-overview-page-header > div:last-child) {
width: 100%;
}
}
</style>
@@ -101,7 +101,7 @@ function goToImportPromotionFee() {
void router.push('/import/promotion-fee');
}
/** 与全店概览一致:快捷区间 + 自定义 RangePicker */
/** 与工作台一致:快捷区间 + 自定义 RangePicker */
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().startOf('month'),
dayjs(),
@@ -200,7 +200,7 @@ async function handleProductExport() {
<PlatformSummaryCard
v-if="activeMode === 'platform'"
heading-title="各平台多维度经营明细汇总"
heading-subtitle="与全店概览同款表格"
heading-subtitle="与工作台经营概览同源表格"
:platform-summary="platformSummary ?? undefined"
:tax-rate="taxRate"
:platform-export-mode="platformExportMode"
@@ -213,7 +213,7 @@ async function handleProductExport() {
<CategorySummaryTable
v-if="activeMode === 'category'"
heading-title="各品类多维度经营明细汇总"
heading-subtitle="与全店概览同款表格"
heading-subtitle="与工作台经营概览同源表格"
:category-summary="categorySummary ?? undefined"
:tax-rate="taxRate"
:category-export-mode="categoryExportMode"
@@ -226,7 +226,7 @@ async function handleProductExport() {
<CategorySummaryTable
v-if="activeMode === 'product'"
heading-title="各商品多维度经营明细汇总"
heading-subtitle="列结构与品类表一致;数据与全店概览商品维度同源;点击商品名可跳转商品概览"
heading-subtitle="列结构与品类表一致;数据与工作台商品维度同源;点击商品名可跳转商品概览"
first-column-label="商品"
:product-navigate="true"
:category-summary="productSummary ?? undefined"
@@ -374,7 +374,7 @@ defineExpose({ redraw });
class="mt-0.5 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
销售/毛利/净利/退款(柱)与毛利率、净利率(线)·
{{ liveData ? '接口数据(与全店概览订单口径一致)' : '演示数据' }}
{{ liveData ? '接口数据(与工作台订单口径一致)' : '演示数据' }}
</p>
</div>
<div
@@ -28,7 +28,7 @@ defineExpose({ redraw });
<p
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
按平台、店铺、品类、商品各一张卡;数据与全店概览订单统计口径一致
按平台、店铺、品类、商品各一张卡;数据与工作台订单统计口径一致
</p>
<WorkbenchMultiDimCardsGrid
ref="gridRef"
@@ -16,7 +16,7 @@ import { Page } from '@vben/common-ui';
import { message, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import { getShopOverviewApi, getShopPageApi } from '#/api/ecommerce/shop/apis';
import { exportByPost } from '#/utils/export';
import {
applyOverviewDateRangeFromUrl,
@@ -249,8 +249,18 @@ const loadOverviewData = async () => {
isRequesting.value = true;
try {
loading.value = true;
// 原 /ec/shop/overview 已下线,待接入 Mongo BI 读模型
const [startDate, endDate] = dateRange.value;
overviewData.value = await getShopOverviewApi({
shopId: shopId.value,
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
});
} catch (err: any) {
overviewData.value = null;
message.error(err?.message || '加载店铺概览失败');
} finally {
loading.value = false;
isRequesting.value = false;
@@ -267,7 +277,7 @@ const handleExportShopOverview = async () => {
const safeName = String(shopName).replace(/[/\\:*?"<>|]/g, '_');
const filename = `${safeName}_按商品汇总统计_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/shop/export/summary-by-product',
'/bi/shop/export/summary-by-product',
{
shopId: shopId.value,
dateRange: [
@@ -309,7 +319,7 @@ const handleCategoryExport = async () => {
const catShopName = overviewData.value?.shopName || `店铺${shopId.value}`;
const catSafeName = String(catShopName).replace(/[/\\:*?"<>|]/g, '_');
await exportByPost(
'/ec/shop/export/summary-by-category',
'/bi/shop/export/summary-by-category',
params,
`${catSafeName}_按品类汇总统计_${catStart.format('YYYYMMDD')}-${catEnd.format('YYYYMMDD')}.xlsx`,
);
@@ -17,7 +17,7 @@ exports[`defaultPreferences immutability test > should not modify the config obj
"contentPaddingRight": 0,
"contentPaddingTop": 0,
"defaultAvatar": "https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp",
"defaultHomePath": "/store-overview",
"defaultHomePath": "/workbench",
"dynamicTitle": true,
"enableCheckUpdates": true,
"enablePreferences": true,
@@ -17,7 +17,7 @@ const defaultPreferences: Preferences = {
contentPaddingTop: 0,
defaultAvatar:
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/avatar-v1.webp',
defaultHomePath: '/store-overview',
defaultHomePath: '/workbench',
dynamicTitle: true,
enableCheckUpdates: true,
enablePreferences: true,