feat: 调整权限点

This commit is contained in:
2026-08-24 14:16:44 +08:00
parent d57745effb
commit 25a6911600
43 changed files with 1176 additions and 769 deletions
@@ -581,13 +581,6 @@ async function handleManualRefresh() {
const activeTab = ref('finance');
function handleShopNavigate(shopId: number) {
router.push({
path: `/ec/shop/overview/${shopId}`,
query: buildOverviewRouteQuery(dateRange.value),
});
}
function handleProductNavigate(productId: number) {
const shopId = parseSelectedShopId();
router.push({
@@ -913,7 +906,6 @@ onUnmounted(() => {
:finance="financePanel"
:multi-analysis="EMPTY_MULTI"
:summary-tables="summaryTablesPanel"
@navigate="handleShopNavigate"
@navigate-product="handleProductNavigate"
/>
</Spin>
@@ -30,7 +30,6 @@ const props = withDefaults(
},
);
const emit = defineEmits<{
(e: 'navigate', shopId: number): void;
(e: 'navigate-product', productId: number): void;
}>();
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
@@ -194,7 +193,6 @@ async function handleProductExport() {
@update:selected-export-shop-ids="selectedExportShopIds = $event"
@toggle-shop-export-mode="shopExportMode = $event"
@export="handleShopExport"
@navigate="(id: number) => emit('navigate', id)"
/>
<PlatformSummaryCard
@@ -1,7 +1,6 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/bi/overview';
import { createIconifyIcon } from '@vben/icons';
import { computed } from 'vue';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
@@ -15,8 +14,6 @@ import {
import { FINANCE_PANEL_SHELL } from '../constants/finance-ui';
const JumpIcon = createIconifyIcon('tdesign:jump');
defineOptions({ name: 'WorkbenchShopSummaryTable' });
interface Props {
@@ -34,7 +31,6 @@ 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>(), {
@@ -288,11 +284,9 @@ const cellRoi = (v: number | null | undefined) =>
: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 as number)"
class="inline-flex items-center rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 dark:bg-blue-900/30 dark:text-blue-400"
>
{{ shop.shopName }}
<JumpIcon class="text-xs" />
</span>
</td>
<!-- 目标 -->
@@ -25,7 +25,6 @@ import {
defineOptions({ name: 'WorkbenchFinanceTab' });
const emit = defineEmits<{
(e: 'navigate', shopId: number): void;
(e: 'navigate-product', productId: number): void;
}>();
@@ -167,7 +166,6 @@ defineExpose({ redraw });
:platform-summary="platformOverview"
:category-summary="categoryOverview"
:product-summary="productOverview"
@navigate="(id: number) => emit('navigate', id)"
@navigate-product="(id: number) => emit('navigate-product', id)"
/>
</div>
@@ -4,6 +4,8 @@ import type { EchartsUIType } from '@vben/plugins/echarts';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import dayjs from 'dayjs';
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
interface Props {
@@ -205,12 +207,21 @@ defineExpose({ renderChart });
</script>
<template>
<div class="rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px] xl:col-span-2">
<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 :class="[FINANCE_PANEL_SHELL, 'xl:col-span-2']">
<div
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
>
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
销售额与单量趋势
</h3>
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
双轴展示销售额与订单量,与上方 KPI 同一时间范围
</p>
</div>
<div class="px-5 py-4 md:px-6 md:py-5">
<div class="h-[320px] w-full">
<EchartsUI ref="trendChartRef" />
</div>
</div>
</div>
</template>
@@ -1,4 +1,6 @@
<script lang="ts" setup>
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
interface SkuSalesRankItem {
skuId?: number;
skuName?: string;
@@ -15,72 +17,80 @@ defineProps<Props>();
const formatAmount = (amount: number | undefined) => {
if (amount === undefined || amount === null) return '-';
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
return `¥${amount.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
};
function rankBadgeClass(idx: number) {
if (idx === 0) return 'bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300';
if (idx === 1) return 'bg-slate-100 text-slate-600 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-slate-300';
if (idx === 2) return 'bg-orange-50 text-orange-700 dark:bg-orange-950/40 dark:text-orange-300';
return 'bg-slate-50 text-slate-500 dark:bg-[hsl(240deg_3.7%_15.9%)] dark:text-[hsl(240deg_5%_64.9%)]';
}
</script>
<template>
<div
class="flex flex-col rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<h3 class="mb-1 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
各 SKU 销量 Top10
</h3>
<p class="mb-5 text-xs font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
按单量排序,与上方时间范围一致
</p>
<div :class="FINANCE_PANEL_SHELL">
<div
class="border-b border-slate-100 px-5 pb-3.5 pt-5 md:px-6 md:pt-5 dark:border-b-[hsl(240deg_3.7%_22%)]"
>
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
各 SKU 销量 Top10
</h3>
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
按单量排序,与当前筛选时间范围一致
</p>
</div>
<div class="max-h-[380px] flex-1 space-y-2 overflow-y-auto pr-1">
<template v-if="data?.length">
<div
v-for="(row, idx) in data"
:key="row.skuId ?? `rank-${idx}`"
class="flex items-center gap-3 rounded-xl border border-slate-100/90 bg-slate-50/60 px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/50%)]"
>
<span
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-sm font-black tabular-nums"
:class="
idx === 0
? 'bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-200'
: idx === 1
? 'bg-slate-200 text-slate-700 dark:bg-slate-600 dark:text-slate-100'
: idx === 2
? 'bg-orange-100 text-orange-900 dark:bg-orange-900/30 dark:text-orange-200'
: 'bg-slate-100 text-slate-500 dark:bg-slate-700 dark:text-slate-300'
"
<div class="px-5 py-4 md:px-6 md:py-5">
<div class="max-h-[320px] space-y-2 overflow-y-auto pr-1">
<template v-if="data?.length">
<div
v-for="(row, idx) in data"
:key="row.skuId ?? `rank-${idx}`"
class="flex items-center gap-3 rounded-[10px] border border-slate-200/90 bg-white px-3 py-2.5 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
{{ idx + 1 }}
</span>
<div class="min-w-0 flex-1">
<div
class="truncate text-sm font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
:title="row.skuName"
<span
class="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg text-xs font-bold tabular-nums"
:class="rankBadgeClass(idx)"
>
{{ row.skuName || '-' }}
{{ idx + 1 }}
</span>
<div class="min-w-0 flex-1">
<div
class="truncate text-sm font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
:title="row.skuName"
>
{{ row.skuName || '-' }}
</div>
<div
v-if="row.skuCode"
class="truncate text-[11px] text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
{{ row.skuCode }}
</div>
</div>
<div
v-if="row.skuCode"
class="truncate text-[11px] text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
>
{{ row.skuCode }}
</div>
</div>
<div class="shrink-0 text-right">
<div class="text-sm font-black tabular-nums text-indigo-600 dark:text-indigo-400">
{{ row.orderCount != null ? row.orderCount.toLocaleString('zh-CN') : '-' }}
<span class="text-[10px] font-semibold text-slate-400 dark:text-[hsl(240deg_5%_55%)]">单</span>
</div>
<div class="text-[11px] font-semibold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ formatAmount(row.salesAmount) }}
<div class="shrink-0 text-right">
<div class="text-sm font-bold tabular-nums text-blue-600 dark:text-blue-400">
{{ row.orderCount != null ? row.orderCount.toLocaleString('zh-CN') : '-' }}
<span class="text-[10px] font-medium text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
单
</span>
</div>
<div class="text-[11px] font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ formatAmount(row.salesAmount) }}
</div>
</div>
</div>
</template>
<div
v-else
class="flex h-[280px] items-center justify-center text-sm text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
暂无 SKU 数据
</div>
</template>
<div
v-else
class="flex flex-1 items-center justify-center py-16 text-sm text-slate-400 dark:text-[hsl(240deg_5%_55%)]"
>
暂无 SKU 数据
</div>
</div>
</div>
@@ -7,8 +7,12 @@ import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import {
overviewTableHints,
salesTaxColumnHint,
storeOverviewHints,
} from '#/utils/overview-table-hints';
import { formatNumberCell } from '#/utils/overview-table-cells';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { FINANCE_PANEL_SHELL } from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
interface SkuData {
skuId: number;
@@ -33,7 +37,6 @@ interface SkuData {
interface Props {
data: SkuData[];
/** 后端合计行(含 orderCost),优先展示 */
footerTotal?: ProductOverviewVO.SkuSummaryTotal | null;
taxRate?: number;
}
@@ -49,9 +52,7 @@ const formatAmount = (amount: number | undefined) => {
};
const cellMoney = (v: number | null | undefined) =>
formatNumberCell(v, (n) =>
`¥${n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`,
);
formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2));
@@ -60,12 +61,6 @@ const formatPercent = (value: number | undefined) => {
return `${value.toFixed(1)}%`;
};
const formatCount = (value: number | undefined) => {
if (value === undefined || value === null) return '-';
return value.toLocaleString('zh-CN');
};
/** 无后端合计时由行数据汇总(兼容旧数据) */
const computedFooter = computed(() => {
if (!props.data || props.data.length === 0) return null;
const total: SkuData = {
@@ -106,8 +101,9 @@ const computedFooter = computed(() => {
});
if (total.salesAmount > 0) {
total.averageOrderValue = total.salesAmount / total.orderCount;
total.feeRatio = (total.promotionFee / total.salesAmount) * 100;
const costBase = total.orderCost ?? total.productCost + total.shippingCost + total.otherCost;
total.feeRatio = total.promotionFee / total.salesAmount;
const costBase =
total.orderCost ?? total.productCost + total.shippingCost + total.otherCost;
total.roi =
costBase + total.promotionFee > 0
? (total.profitAfterTax / (costBase + total.promotionFee)) * 100
@@ -120,16 +116,16 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
</script>
<template>
<div
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div :class="FINANCE_PANEL_SHELL">
<div
class="flex items-center justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6"
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 p-5 md:flex-row md:items-center md:px-6 dark:border-b-[hsl(240deg_3.7%_22%)]"
>
<div>
<h3 class="text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">商品 SKU 销售汇总</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
各 SKU 经营明细:规模、成本及最终损益
<h3 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
商品 SKU 销售汇总
</h3>
<p class="mt-1 text-xs font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
各 SKU 经营明细:规模、成本及最终损益(列序与工作台店铺汇总表对齐)
</p>
</div>
</div>
@@ -142,81 +138,105 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
<tr>
<th
rowspan="2"
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-5 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] shadow-sm dark:shadow-none"
class="sticky-col border-b 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 text-base font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)] shadow-sm dark:shadow-none"
>
SKU 名称
SKU
</th>
<th
colspan="3"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-blue-50/50 dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)] p-3 text-center text-blue-700 dark:text-blue-400"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
经营规模
经营规模维度
</th>
<th
colspan="7"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(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%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-3 text-center text-emerald-700 dark:text-emerald-400"
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%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%)] p-3 text-center text-emerald-700 dark:text-emerald-200"
>
盈利分析
盈利分析维度
</th>
</tr>
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
<tr class="bg-slate-50 dark:bg-[hsl(240deg_3.7%_15.9%)] text-sm">
<!-- 规模 -->
<th class="border-b border-l px-5 py-3 font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<OverviewColumnHint :title="overviewTableHints.salesAmountShort">
销售额
<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-5 py-3">
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="overviewTableHints.orderCountSku">
订单量
单量
</OverviewColumnHint>
</th>
<th class="border-b px-5 py-3">
<OverviewColumnHint :title="overviewTableHints.averageOrderValue">客单价</OverviewColumnHint>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.averageOrderValue">
客单价
</OverviewColumnHint>
</th>
<!-- 成本 -->
<th class="border-b border-l px-5 py-3">
<OverviewColumnHint :title="overviewTableHints.productCost">商品成本</OverviewColumnHint>
<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-5 py-3">
<OverviewColumnHint :title="overviewTableHints.shippingCost">运费</OverviewColumnHint>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.shippingCost">
运费
</OverviewColumnHint>
</th>
<th class="border-b px-5 py-3">
<OverviewColumnHint :title="overviewTableHints.otherCost">其他成本</OverviewColumnHint>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="storeOverviewHints.otherCost">
其他成本
</OverviewColumnHint>
</th>
<th class="border-b px-5 py-3 font-bold text-orange-800 dark:text-orange-300">
<OverviewColumnHint :title="overviewTableHints.orderCost">订单成本</OverviewColumnHint>
<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-5 py-3 font-bold text-rose-600 dark:text-rose-400">
<OverviewColumnHint :title="overviewTableHints.refundAmount">退款金额</OverviewColumnHint>
<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-5 py-3">
<OverviewColumnHint :title="overviewTableHints.promotionFeeSku">推广费</OverviewColumnHint>
</th>
<th class="border-b px-5 py-3 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
<OverviewColumnHint :title="overviewTableHints.feeRatioSku">费比 %</OverviewColumnHint>
</th>
<!-- 盈利 -->
<th class="border-b border-l px-5 py-3 font-bold">
<OverviewColumnHint :title="overviewTableHints.profitBeforeTaxSku">税前盈亏</OverviewColumnHint>
</th>
<th class="border-b px-5 py-3 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
<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-5 py-3 font-black text-indigo-700 dark:text-indigo-400">
<OverviewColumnHint :title="overviewTableHints.roi">ROI</OverviewColumnHint>
<th class="border-b px-6 py-4">
<OverviewColumnHint :title="overviewTableHints.promotionFeeSku">
推广费
</OverviewColumnHint>
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-5 py-3 font-black text-white">
<OverviewColumnHint light :title="overviewTableHints.profitAfterTax">
税后盈亏
<!-- 盈利 -->
<th
class="border-b border-l border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4 font-bold"
>
<OverviewColumnHint :title="overviewTableHints.profitBeforeTaxSku">
税前净利
</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 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>
@@ -225,69 +245,124 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
<tr
v-for="item in data"
:key="item.skuId"
class="transition-colors hover:bg-slate-50/50 dark:hover:bg-[hsl(240deg_3.7%_15.9%/30%)]"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)]"
>
<!-- SKU 名称 -->
<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-5 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">{{ item.skuName }}</span>
<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-flex items-center rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 dark:bg-blue-900/30 dark:text-blue-400"
>
{{ item.skuName }}
</span>
</td>
<!-- 规模 -->
<td class="p-5 font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ formatAmount(item.salesAmount) }}</td>
<td class="p-5 font-medium">
<span>{{ formatCount(item.orderCount) }}</span>
<span class="ml-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">单</span>
<span class="ml-2 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">({{ formatCount(item.quantity) }}件)</span>
<td class="p-6 font-black">
{{ formatAmount(item.salesAmount) }}
</td>
<td class="p-6 font-medium">
{{ formatIntCell(item.orderCount) }}
<span class="ml-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
({{ formatIntCell(item.quantity) }}件)
</span>
</td>
<td class="p-6 font-medium">
{{ cellMoney(item.averageOrderValue) }}
</td>
<td class="p-5 font-medium">{{ formatAmount(item.averageOrderValue) }}</td>
<!-- 成本 -->
<td class="p-5">{{ cellMoney(item.productCost) }}</td>
<td class="p-5">{{ cellMoney(item.shippingCost) }}</td>
<td class="p-5">{{ cellMoney(item.otherCost) }}</td>
<td class="p-5 font-bold text-orange-800 dark:text-orange-300">
<td class="p-6">{{ cellMoney(item.productCost) }}</td>
<td class="p-6">{{ cellMoney(item.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(item.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{ cellMoney(item.orderCost) }}
</td>
<td class="p-5 font-bold text-rose-600 dark:text-rose-400">
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cellMoney(item.refundAmount) }}
</td>
<td class="p-5">{{ cellMoney(item.promotionFee) }}</td>
<td class="p-5 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercent(item.feeRatio) }}</td>
<!-- 盈利 -->
<td class="p-5 font-bold" :class="item.profitBeforeTax >= 0 ? 'text-slate-800 dark:text-[hsl(0deg_0%_95%)]' : 'text-rose-600 dark:text-rose-400'">
{{ formatAmount(item.profitBeforeTax) }}
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(item.salesTaxAmount) }}
</td>
<td class="p-5 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ cellMoney(item.salesTaxAmount) }}</td>
<td class="p-5 font-black text-indigo-700 dark:text-indigo-400">{{ cellRoi(item.roi) }}</td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-5 text-base font-black" :class="item.profitAfterTax >= 0 ? 'text-emerald-600 dark:text-emerald-400' : 'text-rose-600 dark:text-rose-400'">
{{ formatAmount(item.profitAfterTax) }}
<td class="p-6">{{ cellMoney(item.promotionFee) }}</td>
<!-- 盈利 -->
<td class="p-6 font-bold">
{{ cellMoney(item.profitBeforeTax) }}
</td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ formatFeeRatioPercent(item.feeRatio) }}
</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">
{{ cellRoi(item.roi) }}
</td>
<td
class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black text-emerald-600 dark:text-emerald-300"
>
{{ cellMoney(item.profitAfterTax) }}
</td>
</tr>
<tr v-if="!data || data.length === 0">
<td colspan="16" class="p-8 text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">暂无 SKU 数据</td>
<td
colspan="15"
class="p-8 text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
>
暂无 SKU 数据
</td>
</tr>
</tbody>
<tfoot v-if="footerRow" 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="border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] p-5 text-base">合计</td>
<td class="p-5">{{ formatAmount(footerRow.salesAmount) }}</td>
<td class="p-5">
<span>{{ formatCount(footerRow.orderCount) }}</span>
<span class="ml-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">单</span>
<span class="ml-2 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">({{ formatCount(footerRow.quantity) }}件)</span>
<td class="sticky-col bg-slate-100 p-6 text-base dark:bg-[hsl(240deg_3.7%_22%)]">
合计
</td>
<td class="p-5">{{ formatAmount(footerRow.averageOrderValue) }}</td>
<td class="p-5">{{ formatAmount(footerRow.productCost) }}</td>
<td class="p-5">{{ formatAmount(footerRow.shippingCost) }}</td>
<td class="p-5">{{ formatAmount(footerRow.otherCost) }}</td>
<td class="p-5 font-bold text-orange-800 dark:text-orange-300">
{{ footerRow.orderCost != null ? formatAmount(footerRow.orderCost) : formatAmount((footerRow.productCost || 0) + (footerRow.shippingCost || 0) + (footerRow.otherCost || 0)) }}
<td class="p-6">{{ cellMoney(footerRow.salesAmount) }}</td>
<td class="p-6">
{{ formatIntCell(footerRow.orderCount) }}
<span class="ml-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
({{ formatIntCell(footerRow.quantity) }}件)
</span>
</td>
<td class="p-6">{{ cellMoney(footerRow.averageOrderValue) }}</td>
<td class="p-6">{{ cellMoney(footerRow.productCost) }}</td>
<td class="p-6">{{ cellMoney(footerRow.shippingCost) }}</td>
<td class="p-6">{{ cellMoney(footerRow.otherCost) }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{
footerRow.orderCost != null
? cellMoney(footerRow.orderCost)
: cellMoney(
(footerRow.productCost || 0) +
(footerRow.shippingCost || 0) +
(footerRow.otherCost || 0),
)
}}
</td>
<td class="p-6 text-rose-600 dark:text-rose-400">
{{ cellMoney(footerRow.refundAmount) }}
</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(footerRow.salesTaxAmount) }}
</td>
<td class="p-6">{{ cellMoney(footerRow.promotionFee) }}</td>
<td class="p-6">{{ cellMoney(footerRow.profitBeforeTax) }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{
footerRow.feeRatio !== undefined
? formatFeeRatioPercent(footerRow.feeRatio)
: '-'
}}
</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">
{{ cellRoi(footerRow.roi) }}
</td>
<td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="
(footerRow.profitAfterTax ?? 0) < 0
? 'text-rose-600 dark:text-rose-400'
: 'text-emerald-700 dark:text-emerald-300'
"
>
{{ cellMoney(footerRow.profitAfterTax) }}
</td>
<td class="p-5 text-rose-600 dark:text-rose-400">{{ formatAmount(footerRow.refundAmount) }}</td>
<td class="p-5">{{ formatAmount(footerRow.promotionFee) }}</td>
<td class="p-5 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercent(footerRow.feeRatio) }}</td>
<td class="p-5">{{ formatAmount(footerRow.profitBeforeTax) }}</td>
<td class="p-5 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(footerRow.salesTaxAmount) }}</td>
<td class="p-5 text-indigo-700 dark:text-indigo-400">{{ cellRoi(footerRow.roi) }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-5 text-base text-emerald-600 dark:text-emerald-400">{{ formatAmount(footerRow.profitAfterTax) }}</td>
</tr>
</tfoot>
</table>
@@ -303,7 +378,22 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
}
.table-container {
overflow-x: auto;
max-height: 1000px;
overflow: auto;
}
thead {
position: sticky;
top: 0;
z-index: 20;
}
thead tr:last-child th:last-child,
tbody td:last-child:not([colspan]),
tfoot td:last-child:not([colspan]) {
position: sticky;
right: 0;
z-index: 10;
}
.table-container::-webkit-scrollbar {
@@ -1,4 +1,17 @@
<script lang="ts" setup>
import { createIconifyIcon } from '@vben/icons';
import {
FINANCE_KPI_CARD_SHELL,
FINANCE_TONE_ICON,
} from '#/views/bi/workbench/tabs/finance/constants/finance-ui';
const IconSales = createIconifyIcon('lucide:wallet');
const IconOrders = createIconifyIcon('lucide:shopping-bag');
const IconRoi = createIconifyIcon('lucide:target');
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
const IconTax = createIconifyIcon('lucide:landmark');
interface Props {
data: {
productName?: string;
@@ -17,9 +30,43 @@ interface Props {
defineProps<Props>();
const cards = [
{
key: 'sales',
label: '实际销售额',
tone: 'blue' as const,
icon: IconSales,
},
{
key: 'orders',
label: '销售单量',
tone: 'blue' as const,
icon: IconOrders,
},
{
key: 'roi',
label: '广告 ROI',
tone: 'purple' as const,
icon: IconRoi,
},
{
key: 'profit',
label: '净利润',
tone: 'green' as const,
icon: IconNet,
},
];
function toneClass(tone: string) {
return FINANCE_TONE_ICON[tone] ?? FINANCE_TONE_ICON.blue;
}
const formatAmount = (amount: number | undefined) => {
if (amount === undefined) return '-';
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
return `¥${amount.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
};
const toNumber = (value: unknown): number | undefined => {
@@ -33,110 +80,120 @@ const formatPercentPlain = (value: number | undefined | null) => {
return `${value.toFixed(1)}%`;
};
const formatPercent = (value: number | undefined) => {
if (value === undefined) return '-';
const formatGrowth = (value: number | undefined) => {
if (value === undefined) return '';
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
};
</script>
<template>
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
<!-- 销售额 -->
<div
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div class="mb-4 flex items-start justify-between">
<span class="text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
商品销售总额
</span>
<span
v-if="data?.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 dark:text-emerald-400"
>
增长率 {{ formatPercent(data.monthOverMonthGrowth) }}
</span>
<div class="grid grid-cols-1 gap-3.5 sm:grid-cols-2 xl:grid-cols-4">
<div
v-for="meta in cards"
:key="meta.key"
:class="FINANCE_KPI_CARD_SHELL"
>
<div class="flex items-start justify-between gap-2">
<span
class="min-w-0 truncate text-[16px] font-semibold leading-snug text-slate-800 dark:text-[hsl(0deg_0%_90%)]"
>
{{ meta.label }}
</span>
<div
class="grid size-9 shrink-0 place-items-center rounded-[10px]"
:class="toneClass(meta.tone)"
>
<component :is="meta.icon" class="size-4" />
</div>
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
</div>
<!-- 销售额 -->
<template v-if="meta.key === 'sales'">
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
{{ data?.totalSalesAmount ? formatAmount(data.totalSalesAmount) : '-' }}
</div>
<div
v-if="data?.salesAmountAchievementRate !== undefined"
class="mt-6 flex items-center justify-between border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4 text-xs font-bold"
class="mt-2.5 flex min-h-[1.25rem] flex-wrap items-center justify-between gap-x-2 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">销售额目标达成</span>
<span class="font-black text-blue-600 dark:text-blue-400">
{{ formatPercentPlain(data.salesAmountAchievementRate) }}
<span v-if="data?.salesAmountAchievementRate !== undefined">
目标达成
<span class="ml-1 font-semibold text-blue-600 dark:text-blue-400">
{{ formatPercentPlain(data.salesAmountAchievementRate) }}
</span>
</span>
<span
v-if="data?.monthOverMonthGrowth !== undefined"
:class="
data.monthOverMonthGrowth >= 0
? 'font-semibold text-emerald-500 dark:text-emerald-400'
: 'font-semibold text-rose-500 dark:text-rose-400'
"
>
环比 {{ formatGrowth(data.monthOverMonthGrowth) }}
</span>
</div>
</div>
</template>
<!-- 订单达成 -->
<div
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
订单总量与达成
<!-- 单量 -->
<template v-else-if="meta.key === 'orders'">
<div class="mt-3 inline-flex items-baseline gap-1 tabular-nums">
<span class="text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
{{ data?.totalOrderCount?.toLocaleString('zh-CN') || '-' }}
</span>
<span class="text-sm font-semibold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
单
</span>
</div>
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
{{ data?.totalOrderCount?.toLocaleString('zh-CN') || '-' }}
<span class="ml-1 text-sm font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">单</span>
</div>
<div v-if="data?.orderCountAchievementRate !== undefined" class="mt-6">
<div class="mb-2 flex justify-between text-[10px] font-black text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
<div
v-if="data?.orderCountAchievementRate !== undefined"
class="mt-2.5 space-y-2"
>
<div class="flex justify-between text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
<span>目标达成率</span>
<span>
<span class="font-semibold text-blue-600 dark:text-blue-400">
{{ formatPercentPlain(data.orderCountAchievementRate) }}
</span>
</div>
<div class="h-2 w-full overflow-hidden rounded-full bg-slate-100">
<div class="h-1.5 w-full overflow-hidden rounded-full bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<div
class="h-full bg-indigo-500 transition-all duration-1000"
:style="{ width: `${Math.min(data.orderCountAchievementRate || 0, 100)}%` }"
></div>
class="h-full rounded-full bg-blue-500 transition-all duration-700"
:style="{
width: `${Math.min(data.orderCountAchievementRate || 0, 100)}%`,
}"
/>
</div>
</div>
</div>
</template>
<!-- 推广效率 -->
<div
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
投资回报率 (ROI)
</div>
<div class="text-4xl font-black leading-none text-indigo-600 dark:text-indigo-400">
{{ toNumber(data?.totalROI)?.toFixed(2) || '-' }}
<!-- ROI -->
<template v-else-if="meta.key === 'roi'">
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-indigo-600 dark:text-indigo-400">
{{ toNumber(data?.totalROI)?.toFixed(2) ?? '-' }}
</div>
<div
v-if="data?.averageFeeRatio !== undefined"
class="mt-6 space-y-2 border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4"
class="mt-2.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<div class="flex justify-between text-xs font-bold">
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">平均费比</span>
<span class="text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
{{ formatPercentPlain(data.averageFeeRatio) }}
</span>
</div>
平均费比
<span class="ml-1 font-semibold text-slate-700 dark:text-[hsl(0deg_0%_90%)]">
{{ formatPercentPlain(data.averageFeeRatio) }}
</span>
</div>
</div>
</template>
<!-- 利润汇总 -->
<div
class="flex flex-col justify-between rounded-[20px] border-l-4 border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] border-l-emerald-500 dark:border-l-emerald-500 bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div class="mb-4 text-xs font-black uppercase tracking-widest text-emerald-600 dark:text-emerald-400">
商品净利润 (税后)
</div>
<div class="text-4xl font-black leading-none text-emerald-600 dark:text-emerald-400">
<!-- 净利润 -->
<template v-else-if="meta.key === 'profit'">
<div class="mt-3 tabular-nums text-[26px] font-bold leading-none tracking-tight text-emerald-600 dark:text-emerald-400">
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
</div>
<div
v-if="data?.totalTaxAmount !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4 text-[11px] font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
class="mt-2.5 flex items-center gap-1.5 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<span>已扣除税额</span>
<span>{{ formatAmount(data.totalTaxAmount) }}</span>
<IconTax class="size-3.5 shrink-0 opacity-70" />
<span>已扣税额 {{ formatAmount(data.totalTaxAmount) }}</span>
</div>
</div>
</template>
</div>
</template>
</div>
</template>
@@ -3,15 +3,20 @@ import { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { DatePicker, InputNumber, Popover, Select, Spin } from 'ant-design-vue';
import {
DatePicker,
InputNumber,
Popover,
Segmented,
Select,
Spin,
} from 'ant-design-vue';
import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range';
import {
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState,
overviewToolbarPanelClass,
overviewToolbarShellClass,
} from '../../../styles/overview-toolbar-classes';
@@ -34,11 +39,9 @@ interface Props {
customDateRange: [Dayjs, Dayjs] | undefined;
dateRange: [Dayjs, Dayjs];
};
/** 路由 query.shopId,未选店铺时为 undefined */
shopId?: number;
shopOptions?: SelectOption[];
shopListLoading?: boolean;
/** 当前商品 ID(与路由 params.id 一致) */
productId?: number;
productOptions?: SelectOption[];
productListLoading?: boolean;
@@ -75,26 +78,47 @@ function handlePopoverOpen(name: string, open: boolean) {
}
const ReceiptIcon = createIconifyIcon('lucide:receipt');
const FilterIcon = createIconifyIcon('lucide:sliders-horizontal');
const ToolbarToggleIcon = createIconifyIcon('lucide:sliders-horizontal');
const CalendarIcon = createIconifyIcon('lucide:calendar');
const collapsedFilterLabel = computed(() => {
const shopName = props.shopId != null && props.shopId > 0
? (props.shopOptions?.find((o) => o.value === String(props.shopId))?.label ?? `店铺 #${props.shopId}`)
: '全部';
const productName = props.productId != null && props.productId > 0
? (props.productOptions?.find((o) => o.value === String(props.productId))?.label ?? `商品 #${props.productId}`)
: '选择商品';
type TimeRangeKey =
| '7days'
| '30days'
| 'custom'
| 'thisMonth'
| 'today'
| 'yesterday';
const timeRangeSegmentOptions: {
label: string;
value: Exclude<TimeRangeKey, 'custom'>;
}[] = [
{ label: '今日', value: 'today' },
{ label: '昨日', value: 'yesterday' },
{ label: '近7日', value: '7days' },
{ label: '近30日', value: '30days' },
{ label: '本月', value: 'thisMonth' },
];
const filterTriggerLabel = computed(() => {
const shopName =
props.shopId != null && props.shopId > 0
? (props.shopOptions?.find((o) => o.value === String(props.shopId))?.label ??
`店铺 #${props.shopId}`)
: '全部';
const productName =
props.productId != null && props.productId > 0
? (props.productOptions?.find((o) => o.value === String(props.productId))?.label ??
`商品 #${props.productId}`)
: '选择商品';
return `${shopName}/${productName}`;
});
const timeRangeLabel = computed(() => {
const t = props.modelValue.activeTimeRange;
if (t === 'today') return '今日';
if (t === 'yesterday') return '昨日';
if (t === '7days') return '近7日';
if (t === '30days') return '近30日';
if (t === 'thisMonth') return '本月';
const hit = timeRangeSegmentOptions.find(
(o) => o.value === props.modelValue.activeTimeRange,
);
if (hit) return hit.label;
if (props.modelValue.customDateRange) {
return `${props.modelValue.customDateRange[0].format('M/D')}-${props.modelValue.customDateRange[1].format('M/D')}`;
}
@@ -136,12 +160,10 @@ const formatTaxRate = (value: null | number | string | undefined) => {
const parseTaxRate = (value: string | undefined) => {
if (!value) return 0;
const num = Number(value.replace('%', '').trim());
return Number.isFinite(num) ? num / 100 : 0;
return Number.isFinite(num) ? Math.round((num / 100) * 1e12) / 1e12 : 0;
};
const switchTimeRange = (
type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
) => {
const switchTimeRange = (type: TimeRangeKey) => {
let startDate: Dayjs;
let endDate: Dayjs = dayjs();
@@ -152,10 +174,6 @@ const switchTimeRange = (
case '30days':
startDate = dayjs().subtract(30, 'day');
break;
case 'thisMonth':
startDate = dayjs().startOf('month');
endDate = dayjs();
break;
case 'custom':
if (props.modelValue.customDateRange) {
emit('update:modelValue', {
@@ -165,6 +183,10 @@ const switchTimeRange = (
});
}
return;
case 'thisMonth':
startDate = dayjs().startOf('month');
endDate = dayjs();
break;
case 'today':
startDate = dayjs();
endDate = dayjs();
@@ -184,6 +206,10 @@ const switchTimeRange = (
});
};
function onTimeRangeSegmentChange(value: string | number) {
switchTimeRange(String(value) as Exclude<TimeRangeKey, 'custom'>);
}
const handleCustomDateRangeChange = (
value: [Dayjs, Dayjs] | [string, string] | null,
dateStrings?: [string, string],
@@ -198,8 +224,9 @@ const handleCustomDateRangeChange = (
});
};
const handleTaxRateChange = (val: number | string | undefined) => {
const num = typeof val === 'string' ? parseTaxRate(val) : val ?? 0.04;
const handleTaxRateChange = (val: number | string | null | undefined) => {
const num =
typeof val === 'string' ? parseTaxRate(val) : (val ?? props.modelValue.taxRate);
localStorage.setItem(TAX_RATE_KEY, String(num));
emit('update:modelValue', {
...props.modelValue,
@@ -210,29 +237,23 @@ const handleTaxRateChange = (val: number | string | undefined) => {
<template>
<div
class="overview-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
class="workbench-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
>
<!-- 税率 -->
<Popover
trigger="click"
:open="openPopover === 'taxRate'"
placement="bottom"
placement="bottomRight"
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
overlay-class-name="workbench-toolbar-popover"
>
<template #content>
<div class="flex items-center gap-2 whitespace-nowrap">
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
税率
</span>
<div class="flex items-center gap-2 py-1">
<span class="text-sm text-slate-600 dark:text-slate-300">税率</span>
<InputNumber
:value="props.modelValue.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-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
class="w-28"
:formatter="formatTaxRate"
:parser="parseTaxRate"
@change="handleTaxRateChange"
@@ -244,32 +265,29 @@ const handleTaxRateChange = (val: number | string | undefined) => {
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
>
<ReceiptIcon class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">税率{{ formatTaxRate(props.modelValue.taxRate) }}</span>
<span
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
>
税率{{ formatTaxRate(props.modelValue.taxRate) }}
</span>
</div>
</div>
</Popover>
<!-- 店铺/商品 -->
<Popover
trigger="click"
:open="openPopover === 'filter'"
placement="bottom"
placement="bottomRight"
@update:open="(val: boolean) => handlePopoverOpen('filter', val)"
overlay-class-name="workbench-toolbar-popover"
>
<template #content>
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-0">
<div
class="flex min-w-0 items-center gap-2 px-2 py-0.5 sm:w-[11.5rem] sm:flex-none sm:shrink-0 sm:py-0"
>
<span
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
>
<div class="flex w-[17.5rem] flex-col gap-3 py-1 sm:w-[22rem]">
<div class="flex items-center gap-2">
<span class="w-9 shrink-0 text-sm text-slate-600 dark:text-slate-300">
店铺
</span>
<Select
:value="shopSelectValue"
size="small"
show-search
allow-clear
:filter-option="false"
@@ -277,7 +295,7 @@ const handleTaxRateChange = (val: number | string | undefined) => {
:options="props.shopOptions"
placeholder="全部店铺"
:dropdown-match-select-width="false"
class="overview-header-select overview-shop-select min-w-0 flex-1"
class="min-w-0 flex-1"
@change="handleShopSelectChange"
@search="(kw: string) => emit('shop-search', kw)"
@popup-scroll="(e: Event) => emit('shop-popup-scroll', e)"
@@ -288,18 +306,16 @@ const handleTaxRateChange = (val: number | string | undefined) => {
<template #notFoundContent>
<div v-if="props.shopListLoading" class="py-3 text-center">
<Spin size="small" />
<div class="mt-1 text-xs text-slate-600">加载中...</div>
<div class="mt-1 text-xs text-slate-500">加载中...</div>
</div>
<div v-else class="py-3 text-center text-xs text-slate-500">
暂无店铺
</div>
<div v-else class="py-3 text-center text-xs text-slate-600">暂无店铺</div>
</template>
</Select>
</div>
<div
class="flex min-w-0 flex-1 items-center gap-2 border-t border-slate-200/80 px-2 pt-2 sm:min-w-[16rem] sm:border-t-0 sm:py-0 sm:pt-0 dark:border-[hsl(240deg_3.7%_22%)]"
>
<span
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
>
<div class="flex items-center gap-2">
<span class="w-9 shrink-0 text-sm text-slate-600 dark:text-slate-300">
商品
</span>
<Select
@@ -308,14 +324,13 @@ const handleTaxRateChange = (val: number | string | undefined) => {
? String(props.productId)
: undefined
"
size="small"
show-search
:filter-option="false"
:loading="props.productListLoading"
:options="props.productOptions"
placeholder="选择商品"
:dropdown-match-select-width="false"
class="overview-header-select overview-product-select min-w-0 flex-1"
class="min-w-0 flex-1"
@change="handleProductSelectChange"
@search="(kw: string) => emit('product-search', kw)"
@popup-scroll="(e: Event) => emit('product-popup-scroll', e)"
@@ -326,9 +341,11 @@ const handleTaxRateChange = (val: number | string | undefined) => {
<template #notFoundContent>
<div v-if="props.productListLoading" class="py-3 text-center">
<Spin size="small" />
<div class="mt-1 text-xs text-slate-600">加载中...</div>
<div class="mt-1 text-xs text-slate-500">加载中...</div>
</div>
<div v-else class="py-3 text-center text-xs text-slate-500">
暂无商品
</div>
<div v-else class="py-3 text-center text-xs text-slate-600">暂无商品</div>
</template>
</Select>
</div>
@@ -338,87 +355,40 @@ const handleTaxRateChange = (val: number | string | undefined) => {
<div
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
>
<FilterIcon class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ collapsedFilterLabel }}</span>
<ToolbarToggleIcon class="h-4 w-4 shrink-0" />
<span
class="max-w-[10rem] truncate whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
>
{{ filterTriggerLabel }}
</span>
</div>
</div>
</Popover>
<!-- 时间范围 -->
<Popover
trigger="click"
:open="openPopover === 'timeRange'"
placement="bottom"
placement="bottomRight"
@update:open="(val: boolean) => handlePopoverOpen('timeRange', val)"
overlay-class-name="workbench-toolbar-popover"
>
<template #content>
<div class="flex flex-col gap-2 px-1 py-0.5">
<div class="flex items-center gap-1 overflow-x-auto whitespace-nowrap">
<button
type="button"
:class="[
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'today'),
]"
@click="switchTimeRange('today')"
>
今日
</button>
<button
type="button"
:class="[
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'yesterday'),
]"
@click="switchTimeRange('yesterday')"
>
昨日
</button>
<button
type="button"
:class="[
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '7days'),
]"
@click="switchTimeRange('7days')"
>
近7日
</button>
<button
type="button"
:class="[
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === '30days'),
]"
@click="switchTimeRange('30days')"
>
近30日
</button>
<button
type="button"
:class="[
overviewTimeRangeBtnClass,
overviewTimeRangeBtnState(props.modelValue.activeTimeRange === 'thisMonth'),
]"
@click="switchTimeRange('thisMonth')"
>
本月
</button>
</div>
<div class="flex w-[20rem] flex-col gap-3 py-1 sm:w-[26rem]">
<Segmented
:value="props.modelValue.activeTimeRange"
:options="timeRangeSegmentOptions"
block
@change="onTimeRangeSegmentChange"
/>
<div class="flex items-center gap-2">
<span
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
>
自定义日期
<span class="shrink-0 text-sm text-slate-600 dark:text-slate-300">
自定义
</span>
<DatePicker.RangePicker
:value="props.modelValue.customDateRange"
size="small"
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始', '结束']"
class="overview-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
class="min-w-0 flex-1"
@change="handleCustomDateRangeChange"
/>
</div>
@@ -429,12 +399,13 @@ const handleTaxRateChange = (val: number | string | undefined) => {
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
>
<CalendarIcon class="h-4 w-4 shrink-0" />
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ timeRangeLabel }}</span>
<span
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
>
{{ timeRangeLabel }}
</span>
</div>
</div>
</Popover>
</div>
</template>
<style src="../../../styles/overview-toolbar.css"></style>
<style src="../../../styles/overview-header-select.css"></style>
@@ -437,6 +437,7 @@ onUnmounted(() => {
<Page
auto-content-height
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
content-padding-class="px-4 pb-4"
header-class="product-overview-page-header"
>
<template #title>
@@ -448,7 +449,9 @@ onUnmounted(() => {
</template>
<template #extra>
<div class="w-full max-w-full sm:w-auto">
<div
class="workbench-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
>
<TimeRangeBar
:model-value="timeRangeState"
:shop-id="contextShopId"
@@ -471,12 +474,19 @@ onUnmounted(() => {
</template>
<Spin :spinning="loading">
<div v-if="overviewData" class="mx-auto w-full space-y-6">
<!-- 第一层:核心统计卡片 -->
<div v-if="overviewData" class="product-overview-body mx-auto w-full min-w-0 space-y-4 pt-4">
<div>
<h2 class="text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
经营概览
</h2>
<p class="mt-0.5 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
商品核心 KPI · 与当前筛选时间范围一致
</p>
</div>
<StatCards :data="overviewData" :loading="loading" />
<!-- 第二层:趋势与财务拆解 -->
<div class="grid grid-cols-1 gap-6 xl:grid-cols-3">
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-3">
<SalesTrendChart :data="overviewData" />
<SkuSalesTop10Panel :data="overviewData?.specSalesTop10 ?? []" />
</div>
@@ -509,46 +519,23 @@ onUnmounted(() => {
}
}
:deep(.product-overview-page-header > div:first-child),
:deep(.product-overview-page-header > div:first-child) {
width: 100%;
}
@media (min-width: 640px) {
:deep(.product-overview-page-header > div:first-child) {
width: auto;
}
}
:deep(.product-overview-page-header > div:last-child) {
width: 100%;
}
@media (min-width: 640px) {
:deep(.product-overview-page-header > div:first-child),
:deep(.product-overview-page-header > div:last-child) {
width: auto;
}
}
/* 表格滚动条优化 */
.table-container::-webkit-scrollbar {
height: 6px;
}
.table-container::-webkit-scrollbar-thumb {
background: #e2e8f0;
border-radius: 10px;
}
</style>
<style>
html.dark .product-overview-thead table thead th {
background-color: hsl(240deg 3.7% 15.9% / 80%) !important;
}
html.dark .product-overview-thead table thead th {
border-color: hsl(240deg 3.7% 22%) !important;
}
html.dark .table-container table tbody tr:hover td {
background-color: hsl(217.2deg 32.6% 17.5% / 30%) !important;
}
html.dark .table-container::-webkit-scrollbar-thumb {
background: hsl(240deg 3.7% 22%);
}
html.dark .table-container::-webkit-scrollbar-track {
background: hsl(240deg 3.7% 15.9%);
}
</style>
@@ -3,7 +3,7 @@ export const overviewToolbarShellClass =
'flex w-full flex-col gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 p-1.5 sm:w-auto sm:flex-row sm:items-center sm:gap-2 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)]';
export const overviewToolbarPanelClass =
'overview-toolbar-panel rounded-xl bg-white dark:bg-[hsl(222.34deg_10.43%_14%)]';
'rounded-xl bg-white dark:bg-[hsl(222.34deg_10.43%_14%)]';
export const overviewToolbarLabelClass =
'text-xs font-bold text-slate-700 dark:text-slate-300';