mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
feat: 店铺与平台独立概览页并对齐经营 KPI 口径
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import type { PlatformOverviewDTO, PlatformOverviewVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** 获取平台概览统计数据 */
|
||||
export async function getPlatformOverviewApi(
|
||||
params: PlatformOverviewDTO.Query,
|
||||
) {
|
||||
return requestClient.post<PlatformOverviewVO.Overview>(
|
||||
'/bi/platform/overview',
|
||||
params,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export type { PlatformOverviewDTO } from './types.dto';
|
||||
export type { PlatformOverviewVO } from './types.vo';
|
||||
@@ -0,0 +1,7 @@
|
||||
export namespace PlatformOverviewDTO {
|
||||
export interface Query {
|
||||
platformCode: string;
|
||||
dateRange: string[];
|
||||
taxRate?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/** 平台概览 VO(与后端 PlatformOverviewVO 对齐) */
|
||||
export namespace PlatformOverviewVO {
|
||||
/** 与工作台经营 KPI 同形 */
|
||||
export interface KpiItem {
|
||||
label: string;
|
||||
value: number;
|
||||
unit: string;
|
||||
changePct?: number;
|
||||
up?: boolean;
|
||||
yoyChangePct?: number | null;
|
||||
yoyUp?: boolean | null;
|
||||
sub?: string;
|
||||
amountYuan?: number | null;
|
||||
preferWanDisplay?: boolean | null;
|
||||
}
|
||||
|
||||
export interface TrendPoint {
|
||||
date: string;
|
||||
dealYuan?: number;
|
||||
dealOrderCount?: number;
|
||||
salesYuan?: number;
|
||||
salesOrderCount?: number;
|
||||
profitYuan?: number;
|
||||
netProfitYuan?: number;
|
||||
refundYuan?: number;
|
||||
}
|
||||
|
||||
export interface PieSlice {
|
||||
name: string;
|
||||
value?: number;
|
||||
pct?: number;
|
||||
}
|
||||
|
||||
export interface ProductSalesRankItem {
|
||||
productId?: number;
|
||||
productName?: string;
|
||||
productCode?: string;
|
||||
orderCount?: number;
|
||||
salesAmount?: number;
|
||||
}
|
||||
|
||||
export interface ProductSummary {
|
||||
productId: number;
|
||||
productName: string;
|
||||
productCode?: string;
|
||||
salesAmount: number;
|
||||
dealAmount?: number;
|
||||
salesOrderCount?: number;
|
||||
dealOrderCount?: number;
|
||||
salesAverageOrderValue?: number;
|
||||
dealAverageOrderValue?: number;
|
||||
productCost?: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
orderCost?: number;
|
||||
refundAmount?: number;
|
||||
totalPromotionFee?: number;
|
||||
brushFee?: number;
|
||||
feeRatio?: number;
|
||||
totalProfitBeforeTax?: number;
|
||||
salesTaxAmount?: number;
|
||||
profitAfterTax?: number;
|
||||
roi?: number;
|
||||
}
|
||||
|
||||
export interface CategorySummary {
|
||||
categoryId: number;
|
||||
categoryName: string;
|
||||
salesAmount: number;
|
||||
dealAmount?: number;
|
||||
salesOrderCount?: number;
|
||||
dealOrderCount?: number;
|
||||
salesAverageOrderValue?: number;
|
||||
dealAverageOrderValue?: number;
|
||||
productCost?: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
orderCost?: number;
|
||||
refundAmount?: number;
|
||||
totalPromotionFee?: number;
|
||||
brushFee?: number;
|
||||
feeRatio?: number;
|
||||
totalProfitBeforeTax?: number;
|
||||
salesTaxAmount?: number;
|
||||
profitAfterTax?: number;
|
||||
roi?: number;
|
||||
}
|
||||
|
||||
export interface ProductOverview {
|
||||
total: ProductSummary;
|
||||
products: ProductSummary[];
|
||||
}
|
||||
|
||||
export interface CategoryOverview {
|
||||
total: CategorySummary;
|
||||
categories: CategorySummary[];
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export interface TrendDataItem {
|
||||
date: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export interface TrendData {
|
||||
total: number;
|
||||
dailyDataList: TrendDataItem[];
|
||||
}
|
||||
|
||||
export interface Overview {
|
||||
platformCode: string;
|
||||
platformName: string;
|
||||
|
||||
kpis?: KpiItem[];
|
||||
dealTrend?: TrendPoint[];
|
||||
productSalesShare?: PieSlice[];
|
||||
momCompareDateStart?: string | null;
|
||||
momCompareDateEnd?: string | null;
|
||||
yoyCompareDateStart?: string | null;
|
||||
yoyCompareDateEnd?: string | null;
|
||||
|
||||
totalSalesAmount?: number;
|
||||
monthOverMonthGrowth?: number;
|
||||
totalOrderCount?: number;
|
||||
totalPromotionFee?: number;
|
||||
averageFeeRatio?: number;
|
||||
totalNetProfitAfterTax?: number;
|
||||
totalTaxAmount?: number;
|
||||
totalTargetOrderCount?: number;
|
||||
totalTargetAmount?: number;
|
||||
orderCountAchievementRate?: number;
|
||||
salesAmountAchievementRate?: number;
|
||||
totalROI?: number;
|
||||
averageOrderValue?: number;
|
||||
refundAmount?: number;
|
||||
totalProfitBeforeTax?: number;
|
||||
|
||||
productSalesTop10?: ProductSalesRankItem[];
|
||||
/** @deprecated */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** @deprecated */
|
||||
orderCountTrend?: TrendData;
|
||||
productOverview?: ProductOverview;
|
||||
categoryOverview?: CategoryOverview;
|
||||
}
|
||||
}
|
||||
@@ -119,13 +119,57 @@ export namespace ShopVO {
|
||||
averageOrderValue: number;
|
||||
}
|
||||
|
||||
/** 与工作台经营 KPI 同形 */
|
||||
export interface KpiItem {
|
||||
label: string;
|
||||
value: number;
|
||||
unit: string;
|
||||
changePct?: number;
|
||||
up?: boolean;
|
||||
yoyChangePct?: number | null;
|
||||
yoyUp?: boolean | null;
|
||||
sub?: string;
|
||||
amountYuan?: number | null;
|
||||
preferWanDisplay?: boolean | null;
|
||||
}
|
||||
|
||||
export interface TrendPoint {
|
||||
date: string;
|
||||
dealYuan?: number;
|
||||
dealOrderCount?: number;
|
||||
salesYuan?: number;
|
||||
salesOrderCount?: number;
|
||||
profitYuan?: number;
|
||||
netProfitYuan?: number;
|
||||
refundYuan?: number;
|
||||
}
|
||||
|
||||
export interface PieSlice {
|
||||
name: string;
|
||||
value?: number;
|
||||
pct?: number;
|
||||
}
|
||||
|
||||
/** 店铺概览统计信息 */
|
||||
export interface OverviewStatistics {
|
||||
/** 店铺ID */
|
||||
shopId?: number;
|
||||
/** 店铺名称 */
|
||||
shopName: string;
|
||||
/** 店铺总销售额 */
|
||||
/** 平台代码 */
|
||||
platformCode?: string;
|
||||
|
||||
/** 经营 KPI(与工作台同口径) */
|
||||
kpis?: KpiItem[];
|
||||
dealTrend?: TrendPoint[];
|
||||
/** 店内商品净销售额占比 */
|
||||
productSalesShare?: PieSlice[];
|
||||
momCompareDateStart?: string | null;
|
||||
momCompareDateEnd?: string | null;
|
||||
yoyCompareDateStart?: string | null;
|
||||
yoyCompareDateEnd?: string | null;
|
||||
|
||||
/** 店铺总销售额(兼容旧扁平字段) */
|
||||
totalSalesAmount: number;
|
||||
/** 较上月同期增长百分比 */
|
||||
monthOverMonthGrowth?: number;
|
||||
@@ -157,9 +201,9 @@ export namespace ShopVO {
|
||||
totalProfitBeforeTax?: number;
|
||||
/** 各商品按单量排序的销量 Top10 */
|
||||
productSalesTop10?: ProductSalesRankItem[];
|
||||
/** 销售额趋势分析 */
|
||||
/** @deprecated 使用 dealTrend */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** 单量趋势分析 */
|
||||
/** @deprecated 使用 dealTrend */
|
||||
orderCountTrend?: TrendData;
|
||||
/** 多商品数据横向汇总(含合计行) */
|
||||
productOverview?: ProductOverview;
|
||||
|
||||
@@ -687,6 +687,23 @@ function handleProductNavigate(productId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleShopNavigate(shopId: number) {
|
||||
if (!shopId || shopId <= 0) return;
|
||||
router.push({
|
||||
path: `/ec/shop/overview/${shopId}`,
|
||||
query: buildOverviewRouteQuery(dateRange.value),
|
||||
});
|
||||
}
|
||||
|
||||
function handlePlatformNavigate(platformCode: string) {
|
||||
const code = String(platformCode ?? '').trim();
|
||||
if (!code) return;
|
||||
router.push({
|
||||
path: `/ec/platform/overview/${encodeURIComponent(code)}`,
|
||||
query: buildOverviewRouteQuery(dateRange.value),
|
||||
});
|
||||
}
|
||||
|
||||
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
|
||||
null,
|
||||
);
|
||||
@@ -1017,6 +1034,8 @@ onUnmounted(() => {
|
||||
:multi-analysis="EMPTY_MULTI"
|
||||
:summary-tables="summaryTablesPanel"
|
||||
@navigate-product="handleProductNavigate"
|
||||
@navigate-shop="handleShopNavigate"
|
||||
@navigate-platform="handlePlatformNavigate"
|
||||
/>
|
||||
</Spin>
|
||||
</Tabs.TabPane>
|
||||
|
||||
+4
@@ -31,6 +31,8 @@ const props = withDefaults(
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
(e: 'navigate-product', productId: number): void;
|
||||
(e: 'navigate-shop', shopId: number): void;
|
||||
(e: 'navigate-platform', platformCode: string): void;
|
||||
}>();
|
||||
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
|
||||
|
||||
@@ -193,6 +195,7 @@ async function handleProductExport() {
|
||||
@update:selected-export-shop-ids="selectedExportShopIds = $event"
|
||||
@toggle-shop-export-mode="shopExportMode = $event"
|
||||
@export="handleShopExport"
|
||||
@navigate-shop="(id: number) => emit('navigate-shop', id)"
|
||||
/>
|
||||
|
||||
<PlatformSummaryCard
|
||||
@@ -206,6 +209,7 @@ async function handleProductExport() {
|
||||
@update:selected-export-platform-codes="selectedExportPlatformCodes = $event"
|
||||
@toggle-platform-export-mode="platformExportMode = $event"
|
||||
@export="handlePlatformExport"
|
||||
@navigate-platform="(code: string) => emit('navigate-platform', code)"
|
||||
/>
|
||||
|
||||
<CategorySummaryTable
|
||||
|
||||
+28
-5
@@ -2,6 +2,8 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import type { CompanyOverviewVO } from '#/api/bi/overview';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
||||
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
|
||||
|
||||
@@ -20,6 +22,8 @@ import OverviewTableColumnSettings from './OverviewTableColumnSettings.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchPlatformSummaryCard' });
|
||||
|
||||
const JumpIcon = createIconifyIcon('tdesign:jump');
|
||||
|
||||
interface Props {
|
||||
taxRate?: number;
|
||||
platformSummary?: CompanyOverviewVO.PlatformOverview;
|
||||
@@ -33,6 +37,7 @@ interface Emits {
|
||||
(e: 'update:selectedExportPlatformCodes', codes: string[]): void;
|
||||
(e: 'togglePlatformExportMode', enabled: boolean): void;
|
||||
(e: 'export'): void;
|
||||
(e: 'navigate-platform', platformCode: string): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -208,7 +213,9 @@ const sortedData = computed(() => {
|
||||
if ((e.target as HTMLInputElement).checked) {
|
||||
emit(
|
||||
'update:selectedExportPlatformCodes',
|
||||
platformData.map((p) => p.platformCode) || [],
|
||||
platformData
|
||||
.map((p) => p.platformCode)
|
||||
.filter((c): c is string => Boolean(c)),
|
||||
);
|
||||
} else {
|
||||
emit('update:selectedExportPlatformCodes', []);
|
||||
@@ -453,13 +460,18 @@ const sortedData = computed(() => {
|
||||
<input
|
||||
type="checkbox"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
:checked="selectedExportPlatformCodes.includes(p.platformCode)"
|
||||
:checked="
|
||||
!!p.platformCode &&
|
||||
selectedExportPlatformCodes.includes(p.platformCode)
|
||||
"
|
||||
@change="
|
||||
(e) => {
|
||||
if (!p.platformCode) return;
|
||||
const code = p.platformCode;
|
||||
const checked = (e.target as HTMLInputElement).checked;
|
||||
const newIds = checked
|
||||
? [...selectedExportPlatformCodes, p.platformCode]
|
||||
: selectedExportPlatformCodes.filter((id) => id !== p.platformCode);
|
||||
? [...selectedExportPlatformCodes, code]
|
||||
: selectedExportPlatformCodes.filter((id) => id !== code);
|
||||
emit('update:selectedExportPlatformCodes', newIds);
|
||||
}
|
||||
"
|
||||
@@ -469,7 +481,18 @@ const sortedData = computed(() => {
|
||||
<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">
|
||||
<span
|
||||
v-if="p.platformCode"
|
||||
class="inline-flex cursor-pointer items-center gap-1 rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 transition-colors hover:text-blue-300 hover:underline dark:bg-blue-900/30 dark:text-blue-400"
|
||||
@click="emit('navigate-platform', p.platformCode)"
|
||||
>
|
||||
{{ p.platformName }}
|
||||
<JumpIcon class="text-xs" />
|
||||
</span>
|
||||
<span
|
||||
v-else
|
||||
class="inline-block 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"
|
||||
>
|
||||
{{ p.platformName }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
+14
@@ -3,6 +3,8 @@ import type { CompanyOverviewVO } from '#/api/bi/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
|
||||
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
|
||||
|
||||
@@ -21,6 +23,8 @@ import OverviewTableColumnSettings from './OverviewTableColumnSettings.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchShopSummaryTable' });
|
||||
|
||||
const JumpIcon = createIconifyIcon('tdesign:jump');
|
||||
|
||||
interface Props {
|
||||
shopSummary?: CompanyOverviewVO.ShopOverview;
|
||||
taxRate: number;
|
||||
@@ -36,6 +40,7 @@ interface Emits {
|
||||
(e: 'update:selectedExportShopIds', ids: number[]): void;
|
||||
(e: 'toggleShopExportMode', enabled: boolean): void;
|
||||
(e: 'export'): void;
|
||||
(e: 'navigate-shop', shopId: number): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -371,6 +376,15 @@ const cellRoi = (v: number | null | undefined) =>
|
||||
:class="shopExportMode ? 'border-l-0' : ''"
|
||||
>
|
||||
<span
|
||||
v-if="shop.shopId != null"
|
||||
class="inline-flex cursor-pointer items-center gap-1 rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 transition-colors hover:text-blue-300 hover:underline dark:bg-blue-900/30 dark:text-blue-400"
|
||||
@click="emit('navigate-shop', shop.shopId!)"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
<JumpIcon class="text-xs" />
|
||||
</span>
|
||||
<span
|
||||
v-else
|
||||
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 }}
|
||||
|
||||
@@ -26,6 +26,8 @@ defineOptions({ name: 'WorkbenchFinanceTab' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'navigate-product', productId: number): void;
|
||||
(e: 'navigate-shop', shopId: number): void;
|
||||
(e: 'navigate-platform', platformCode: string): void;
|
||||
}>();
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -167,6 +169,8 @@ defineExpose({ redraw });
|
||||
:category-summary="categoryOverview"
|
||||
:product-summary="productOverview"
|
||||
@navigate-product="(id: number) => emit('navigate-product', id)"
|
||||
@navigate-shop="(id: number) => emit('navigate-shop', id)"
|
||||
@navigate-platform="(code: string) => emit('navigate-platform', code)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PlatformOverviewVO } from '#/api/ec/platform/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
PLATFORM_HERO_SHELL,
|
||||
PLATFORM_SPOT_CARD,
|
||||
} from '../constants/platform-ui';
|
||||
|
||||
defineOptions({ name: 'PlatformOverviewHero' });
|
||||
|
||||
const props = defineProps<{
|
||||
data: PlatformOverviewVO.Overview;
|
||||
dateLabel?: string;
|
||||
}>();
|
||||
|
||||
const IconLayers = createIconifyIcon('lucide:layers');
|
||||
const IconWallet = createIconifyIcon('lucide:wallet');
|
||||
const IconBag = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
|
||||
function pickKpi(label: string) {
|
||||
return props.data.kpis?.find((k) => k.label === label);
|
||||
}
|
||||
|
||||
function formatYuan(v: number | undefined | null) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return `¥${Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function formatNum(v: number | undefined | null, digits = 0) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
});
|
||||
}
|
||||
|
||||
const spots = computed(() => {
|
||||
const sales = pickKpi('净销售额');
|
||||
const orders = pickKpi('净销售单量');
|
||||
const profit = pickKpi('净利润');
|
||||
const roi = pickKpi('广告ROI');
|
||||
return [
|
||||
{
|
||||
key: 'sales',
|
||||
label: '净销售额',
|
||||
value:
|
||||
sales?.amountYuan != null
|
||||
? formatYuan(sales.amountYuan)
|
||||
: formatYuan(props.data.totalSalesAmount),
|
||||
delta: sales?.changePct,
|
||||
icon: IconWallet,
|
||||
},
|
||||
{
|
||||
key: 'orders',
|
||||
label: '净销售单量',
|
||||
value:
|
||||
orders != null
|
||||
? `${formatNum(orders.value)} 单`
|
||||
: `${formatNum(props.data.totalOrderCount)} 单`,
|
||||
delta: orders?.changePct,
|
||||
icon: IconBag,
|
||||
},
|
||||
{
|
||||
key: 'profit',
|
||||
label: '净利润',
|
||||
value:
|
||||
profit?.amountYuan != null
|
||||
? formatYuan(profit.amountYuan)
|
||||
: formatYuan(props.data.totalNetProfitAfterTax),
|
||||
delta: profit?.changePct,
|
||||
icon: IconNet,
|
||||
},
|
||||
{
|
||||
key: 'roi',
|
||||
label: '广告 ROI',
|
||||
value:
|
||||
roi != null
|
||||
? formatNum(Number(roi.value), 2)
|
||||
: formatNum(props.data.totalROI, 2),
|
||||
delta: roi?.changePct,
|
||||
icon: IconRoi,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
function deltaClass(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return 'text-slate-400';
|
||||
return Number(pct) >= 0
|
||||
? 'text-emerald-600 dark:text-emerald-400'
|
||||
: 'text-rose-500 dark:text-rose-400';
|
||||
}
|
||||
|
||||
function formatDelta(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return '';
|
||||
const n = Number(pct);
|
||||
return `环比 ${n > 0 ? '+' : ''}${n}%`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="PLATFORM_HERO_SHELL">
|
||||
<div
|
||||
class="pointer-events-none absolute -right-8 -top-10 size-40 rounded-full bg-violet-200/35 blur-2xl dark:bg-violet-500/10"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute -bottom-12 left-1/3 size-48 rounded-full bg-fuchsia-200/25 blur-3xl dark:bg-fuchsia-500/10"
|
||||
/>
|
||||
|
||||
<div class="relative flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="grid size-9 shrink-0 place-items-center rounded-[12px] bg-violet-600 text-white shadow-sm shadow-violet-600/25 dark:bg-violet-500"
|
||||
>
|
||||
<component :is="IconLayers" class="size-4" />
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full bg-violet-600/10 px-2 py-0.5 text-[11px] font-semibold text-violet-800 dark:bg-violet-400/10 dark:text-violet-300"
|
||||
>
|
||||
平台诊断
|
||||
</span>
|
||||
</div>
|
||||
<h2
|
||||
class="mt-3 max-w-3xl text-xl font-bold tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_96%)] sm:text-2xl"
|
||||
:title="data.platformName"
|
||||
>
|
||||
{{ data.platformName || data.platformCode || '未命名平台' }}
|
||||
</h2>
|
||||
<p
|
||||
class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<span v-if="dateLabel">统计区间 {{ dateLabel }}</span>
|
||||
<span v-if="data.platformCode">代码:{{ data.platformCode }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="relative mt-5 grid grid-cols-2 gap-2.5 lg:grid-cols-4">
|
||||
<div v-for="spot in spots" :key="spot.key" :class="PLATFORM_SPOT_CARD">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span
|
||||
class="truncate text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ spot.label }}
|
||||
</span>
|
||||
<component
|
||||
:is="spot.icon"
|
||||
class="size-3.5 shrink-0 text-violet-600/80 dark:text-violet-400/80"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 truncate text-lg font-bold tabular-nums tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ spot.value }}
|
||||
</div>
|
||||
<div
|
||||
v-if="spot.delta != null"
|
||||
class="mt-1 text-[11px] font-medium tabular-nums"
|
||||
:class="deltaClass(spot.delta)"
|
||||
>
|
||||
{{ formatDelta(spot.delta) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PlatformOverviewVO } from '#/api/ec/platform/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import { buildOverviewRouteQuery } from '#/utils/overview-date-range';
|
||||
|
||||
import {
|
||||
PLATFORM_PANEL_SHELL,
|
||||
PLATFORM_SECTION_LABEL,
|
||||
} from '../constants/platform-ui';
|
||||
|
||||
defineOptions({ name: 'PlatformProductRankStrip' });
|
||||
|
||||
const props = defineProps<{
|
||||
items?: PlatformOverviewVO.ProductSalesRankItem[] | null;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const rows = computed(() => (props.items ?? []).slice(0, 8));
|
||||
|
||||
const maxOrders = computed(() =>
|
||||
Math.max(1, ...rows.value.map((r) => Number(r.orderCount ?? 0))),
|
||||
);
|
||||
|
||||
function formatAmount(amount: number | undefined) {
|
||||
if (amount == null) return '—';
|
||||
return `¥${amount.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function barWidth(orderCount: number | undefined) {
|
||||
const n = Number(orderCount ?? 0);
|
||||
return `${Math.max(8, Math.round((n / maxOrders.value) * 100))}%`;
|
||||
}
|
||||
|
||||
function rankTone(idx: number) {
|
||||
if (idx === 0) return 'bg-violet-600 text-white';
|
||||
if (idx === 1) return 'bg-violet-500/90 text-white';
|
||||
if (idx === 2) return 'bg-fuchsia-600 text-white';
|
||||
return 'bg-slate-100 text-slate-600 dark:bg-[hsl(265deg_10%_18%)] dark:text-slate-300';
|
||||
}
|
||||
|
||||
function goProduct(productId: number | undefined) {
|
||||
if (productId == null || productId <= 0) return;
|
||||
router.push({
|
||||
path: `/ec/product/overview/${productId}`,
|
||||
query: buildOverviewRouteQuery(props.dateRange),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="rows.length" :class="PLATFORM_PANEL_SHELL">
|
||||
<div
|
||||
class="flex flex-wrap items-end justify-between gap-2 border-b border-violet-100/80 px-5 pb-3.5 pt-5 md:px-6 dark:border-violet-900/35"
|
||||
>
|
||||
<div>
|
||||
<span :class="PLATFORM_SECTION_LABEL">商品结构</span>
|
||||
<h3
|
||||
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
热销商品速览
|
||||
</h3>
|
||||
<p class="mt-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
按净销售单量排序,点击可下钻商品概览
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-2.5 px-5 py-4 md:px-6 md:py-5">
|
||||
<button
|
||||
v-for="(row, idx) in rows"
|
||||
:key="row.productId ?? `product-${idx}`"
|
||||
type="button"
|
||||
class="grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg text-left transition-colors hover:bg-violet-50/60 dark:hover:bg-violet-950/20"
|
||||
@click="goProduct(row.productId)"
|
||||
>
|
||||
<span
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-[11px] font-bold tabular-nums"
|
||||
:class="rankTone(idx)"
|
||||
>
|
||||
{{ idx + 1 }}
|
||||
</span>
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-baseline justify-between gap-2">
|
||||
<span
|
||||
class="truncate text-sm font-semibold text-slate-800 hover:text-violet-700 dark:text-[hsl(0deg_0%_95%)] dark:hover:text-violet-300"
|
||||
:title="row.productName"
|
||||
>
|
||||
{{ row.productName || '—' }}
|
||||
</span>
|
||||
<span class="shrink-0 text-xs tabular-nums text-slate-500">
|
||||
{{ row.orderCount?.toLocaleString('zh-CN') ?? 0 }} 单 ·
|
||||
{{ formatAmount(row.salesAmount) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-violet-50 dark:bg-violet-950/50"
|
||||
>
|
||||
<div
|
||||
class="h-full rounded-full bg-gradient-to-r from-violet-500 to-fuchsia-400 transition-all duration-500"
|
||||
:style="{ width: barWidth(row.orderCount) }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+385
@@ -0,0 +1,385 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { DatePicker, InputNumber, Popover, 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';
|
||||
|
||||
interface PlatformSelectOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
modelValue: {
|
||||
taxRate: number;
|
||||
activeTimeRange:
|
||||
| '7days'
|
||||
| '30days'
|
||||
| 'thisMonth'
|
||||
| 'custom'
|
||||
| 'today'
|
||||
| 'yesterday';
|
||||
customDateRange: [Dayjs, Dayjs] | undefined;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
};
|
||||
/** 当前平台 code(与路由 params.code 一致) */
|
||||
platformCode?: string;
|
||||
platformOptions?: PlatformSelectOption[];
|
||||
platformListLoading?: boolean;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', val: Props['modelValue']): void;
|
||||
(e: 'platform-change', platformCode: string): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
platformOptions: () => [],
|
||||
platformListLoading: false,
|
||||
});
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const openPopover = ref<string | null>(null);
|
||||
|
||||
function handlePopoverOpen(name: string, open: boolean) {
|
||||
if (open) {
|
||||
openPopover.value = name;
|
||||
} else if (openPopover.value === name) {
|
||||
openPopover.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
const ReceiptIcon = createIconifyIcon('lucide:receipt');
|
||||
const PlatformIcon = createIconifyIcon('lucide:layers');
|
||||
const CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||
|
||||
const selectedPlatformName = computed(() => {
|
||||
const code = props.platformCode;
|
||||
if (!code) return '选择平台';
|
||||
const opt = props.platformOptions?.find((o) => o.value === code);
|
||||
return opt?.label ?? code;
|
||||
});
|
||||
|
||||
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 '本月';
|
||||
if (props.modelValue.customDateRange) {
|
||||
return `${props.modelValue.customDateRange[0].format('M/D')}-${props.modelValue.customDateRange[1].format('M/D')}`;
|
||||
}
|
||||
return '日期';
|
||||
});
|
||||
|
||||
const handlePlatformSelectChange = (value: unknown) => {
|
||||
const code = String(value ?? '').trim();
|
||||
if (!code) return;
|
||||
emit('platform-change', code);
|
||||
};
|
||||
|
||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||
|
||||
const formatTaxRate = (value: null | number | string | undefined) => {
|
||||
if (value === null || value === undefined || value === '') return '';
|
||||
const num = Number(value);
|
||||
if (!Number.isFinite(num)) return '';
|
||||
return `${Math.round(num * 100 * 1e10) / 1e10}%`;
|
||||
};
|
||||
|
||||
const parseTaxRate = (value: string | undefined) => {
|
||||
if (!value) return 0;
|
||||
const num = Number(value.replace('%', '').trim());
|
||||
return Number.isFinite(num) ? num / 100 : 0;
|
||||
};
|
||||
|
||||
const switchTimeRange = (
|
||||
type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
|
||||
) => {
|
||||
let startDate: Dayjs;
|
||||
let endDate: 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 (props.modelValue.customDateRange) {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: type,
|
||||
dateRange: props.modelValue.customDateRange,
|
||||
});
|
||||
}
|
||||
return;
|
||||
case 'today':
|
||||
startDate = dayjs();
|
||||
endDate = dayjs();
|
||||
break;
|
||||
case 'yesterday':
|
||||
startDate = dayjs().subtract(1, 'day');
|
||||
endDate = dayjs().subtract(1, 'day');
|
||||
break;
|
||||
}
|
||||
|
||||
const newRange: [Dayjs, Dayjs] = [startDate, endDate];
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: type,
|
||||
dateRange: newRange,
|
||||
customDateRange: newRange,
|
||||
});
|
||||
};
|
||||
|
||||
const handleCustomDateRangeChange = (
|
||||
value: [Dayjs, Dayjs] | [string, string] | null,
|
||||
dateStrings?: [string, string],
|
||||
) => {
|
||||
const dates = normalizeOverviewRangePickerChange(value, dateStrings);
|
||||
if (!dates) return;
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: 'custom',
|
||||
dateRange: dates,
|
||||
customDateRange: dates,
|
||||
});
|
||||
};
|
||||
|
||||
const handleTaxRateChange = (val: number | string | undefined) => {
|
||||
const num = typeof val === 'string' ? parseTaxRate(val) : (val ?? 0.04);
|
||||
localStorage.setItem(TAX_RATE_KEY, String(num));
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
taxRate: num,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<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"
|
||||
>
|
||||
<Popover
|
||||
trigger="click"
|
||||
:open="openPopover === 'taxRate'"
|
||||
placement="bottom"
|
||||
overlay-class-name="workbench-toolbar-popover"
|
||||
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
|
||||
>
|
||||
<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>
|
||||
<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"
|
||||
:formatter="formatTaxRate"
|
||||
:parser="parseTaxRate"
|
||||
@change="handleTaxRateChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||
<div
|
||||
: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>
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
<Popover
|
||||
trigger="click"
|
||||
:open="openPopover === 'platform'"
|
||||
placement="bottom"
|
||||
overlay-class-name="workbench-toolbar-popover"
|
||||
@update:open="(val: boolean) => handlePopoverOpen('platform', val)"
|
||||
>
|
||||
<template #content>
|
||||
<div
|
||||
class="flex items-center gap-2 px-2 py-0.5"
|
||||
style="min-width: 200px"
|
||||
>
|
||||
<span
|
||||
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||
>
|
||||
平台
|
||||
</span>
|
||||
<Select
|
||||
:value="props.platformCode || undefined"
|
||||
size="small"
|
||||
show-search
|
||||
option-filter-prop="label"
|
||||
:loading="props.platformListLoading"
|
||||
:options="props.platformOptions"
|
||||
placeholder="选择平台"
|
||||
:dropdown-match-select-width="false"
|
||||
class="overview-header-select min-w-0 flex-1"
|
||||
@change="handlePlatformSelectChange"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="props.platformListLoading" class="py-3 text-center">
|
||||
<Spin size="small" />
|
||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||
</div>
|
||||
<div v-else class="py-3 text-center text-xs text-slate-600">
|
||||
暂无平台
|
||||
</div>
|
||||
</template>
|
||||
</Select>
|
||||
</div>
|
||||
</template>
|
||||
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||
<div
|
||||
:class="[overviewToolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||
>
|
||||
<PlatformIcon class="h-4 w-4 shrink-0" />
|
||||
<span
|
||||
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||
>
|
||||
{{ selectedPlatformName }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
|
||||
<Popover
|
||||
trigger="click"
|
||||
:open="openPopover === 'timeRange'"
|
||||
placement="bottom"
|
||||
overlay-class-name="workbench-toolbar-popover"
|
||||
@update:open="(val: boolean) => handlePopoverOpen('timeRange', val)"
|
||||
>
|
||||
<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 items-center gap-2">
|
||||
<span
|
||||
class="whitespace-nowrap text-xs font-bold text-slate-700 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"
|
||||
@change="handleCustomDateRangeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div :class="[overviewToolbarShellClass, 'cursor-pointer']">
|
||||
<div
|
||||
: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>
|
||||
</div>
|
||||
</div>
|
||||
</Popover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style src="../../../styles/overview-toolbar.css"></style>
|
||||
<style src="../../../styles/overview-header-select.css"></style>
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/** 平台概览:紫罗兰强调,与商品青绿、店铺琥珀、工作台蓝灰区分 */
|
||||
|
||||
export const PLATFORM_PAGE_BG =
|
||||
'bg-[#f7f5fb] dark:bg-[hsl(265deg_18%_8%)]';
|
||||
|
||||
export const PLATFORM_PANEL_SHELL =
|
||||
'overflow-hidden rounded-[16px] border border-violet-200/70 bg-white shadow-[0_1px_2px_rgba(109,40,217,0.04),0_10px_28px_rgba(109,40,217,0.05)] dark:border-violet-900/40 dark:bg-[hsl(265deg_14%_11%)] dark:shadow-none';
|
||||
|
||||
export const PLATFORM_HERO_SHELL =
|
||||
'relative overflow-hidden rounded-[18px] border border-violet-200/80 bg-gradient-to-br from-violet-50 via-white to-fuchsia-50/70 p-5 shadow-[0_1px_2px_rgba(109,40,217,0.05),0_12px_32px_rgba(109,40,217,0.07)] md:p-6 dark:border-violet-900/45 dark:from-violet-950/40 dark:via-[hsl(265deg_14%_11%)] dark:to-fuchsia-950/25 dark:shadow-none';
|
||||
|
||||
export const PLATFORM_SPOT_CARD =
|
||||
'min-w-0 rounded-[14px] border border-violet-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-violet-900/35 dark:bg-[hsl(265deg_14%_12%/80%)]';
|
||||
|
||||
export const PLATFORM_SECTION_LABEL =
|
||||
'inline-flex items-center gap-1.5 rounded-full border border-violet-200/80 bg-violet-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-violet-800 dark:border-violet-800/50 dark:bg-violet-950/40 dark:text-violet-300';
|
||||
@@ -0,0 +1,502 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PlatformOverviewVO } from '#/api/ec/platform/overview';
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
import type { WorkbenchVO } from '#/api/bi/workbench/types';
|
||||
import type { FinanceKpiCardId } from '#/views/bi/workbench/tabs/finance/constants/kpi-catalog';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
onActivated,
|
||||
onMounted,
|
||||
ref,
|
||||
watch,
|
||||
} from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getPlatformListApi } from '#/api/ec/platform/apis';
|
||||
import { getPlatformOverviewApi } from '#/api/ec/platform/overview';
|
||||
import {
|
||||
applyOverviewDateRangeFromUrl,
|
||||
buildOverviewRouteQuery,
|
||||
syncOverviewDateRangeToUrl,
|
||||
} from '#/utils/overview-date-range';
|
||||
|
||||
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
|
||||
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
|
||||
import FinanceKpiSettingsModal from '#/views/bi/workbench/tabs/finance/components/FinanceKpiSettingsModal.vue';
|
||||
import FinanceTrendChart from '#/views/bi/workbench/tabs/finance/components/FinanceTrendChart.vue';
|
||||
import { useFinanceKpiPreferences } from '#/views/bi/workbench/tabs/finance/composables/useFinanceKpiPreferences';
|
||||
|
||||
import ProductCategorySwitcher from '#/views/ec/shop/overview/components/ProductCategorySwitcher.vue';
|
||||
|
||||
import TimeRangeBar from './components/TimeRangeBar.vue';
|
||||
import PlatformHeroBanner from './components/PlatformHeroBanner.vue';
|
||||
import PlatformProductRankStrip from './components/PlatformProductRankStrip.vue';
|
||||
import {
|
||||
PLATFORM_PAGE_BG,
|
||||
PLATFORM_PANEL_SHELL,
|
||||
PLATFORM_SECTION_LABEL,
|
||||
} from './constants/platform-ui';
|
||||
|
||||
defineOptions({ name: 'PlatformOverview' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
/** 当前是否为平台概览路由 */
|
||||
const isPlatformOverviewRoute = () =>
|
||||
/\/ec\/platform\/overview\/[^/]+\/?$/.test(route.path);
|
||||
|
||||
const platformCode = computed(() => {
|
||||
if (!isPlatformOverviewRoute()) return '';
|
||||
const code = route.params.code;
|
||||
return typeof code === 'string' ? code.trim() : '';
|
||||
});
|
||||
|
||||
const platformsLoading = ref(false);
|
||||
const platformOptions = ref<{ label: string; value: string }[]>([]);
|
||||
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<null | PlatformOverviewVO.Overview>(null);
|
||||
|
||||
/** 复用店铺商品/品类表(结构同形) */
|
||||
const tableData = computed(
|
||||
() => overviewData.value as unknown as ShopVO.OverviewStatistics | null,
|
||||
);
|
||||
|
||||
const financeKpis = computed<WorkbenchVO.KpiItem[]>(
|
||||
() => (overviewData.value?.kpis as WorkbenchVO.KpiItem[] | undefined) ?? [],
|
||||
);
|
||||
const dealTrend = computed<WorkbenchVO.TrendPoint[]>(
|
||||
() =>
|
||||
(overviewData.value?.dealTrend as WorkbenchVO.TrendPoint[] | undefined) ??
|
||||
[],
|
||||
);
|
||||
const productSalesShare = computed<WorkbenchVO.PieSlice[]>(
|
||||
() =>
|
||||
(overviewData.value?.productSalesShare as
|
||||
| WorkbenchVO.PieSlice[]
|
||||
| undefined) ?? [],
|
||||
);
|
||||
|
||||
const periodDateLabel = computed(() => {
|
||||
const [start, end] = dateRange.value;
|
||||
return `${start.format('YYYY-MM-DD')} ~ ${end.format('YYYY-MM-DD')}`;
|
||||
});
|
||||
|
||||
const {
|
||||
visibleCardIds,
|
||||
primaryByCardId,
|
||||
colsPerRow,
|
||||
applySettings,
|
||||
setCardPrimary,
|
||||
} = useFinanceKpiPreferences();
|
||||
const kpiSettingsOpen = ref(false);
|
||||
const visibleKpiCount = computed(() => visibleCardIds.value.length);
|
||||
|
||||
const trendChartRef = ref<InstanceType<typeof FinanceTrendChart> | null>(null);
|
||||
const costPieRef = ref<InstanceType<typeof FinanceCostPieChart> | null>(null);
|
||||
|
||||
async function redrawCharts() {
|
||||
await nextTick();
|
||||
await trendChartRef.value?.redraw();
|
||||
await costPieRef.value?.redraw();
|
||||
}
|
||||
|
||||
function onKpiSettingsSave(payload: {
|
||||
visibleCardIds: string[];
|
||||
primaryByCardId: Record<string, string>;
|
||||
colsPerRow: number;
|
||||
}) {
|
||||
if (payload.visibleCardIds.length === 0) {
|
||||
message.warning('请至少选择一张 KPI 卡片');
|
||||
return;
|
||||
}
|
||||
applySettings(payload);
|
||||
message.success('KPI 显示已更新');
|
||||
}
|
||||
|
||||
function onSetPrimary(payload: {
|
||||
cardId: FinanceKpiCardId;
|
||||
metricLabel: string;
|
||||
}) {
|
||||
setCardPrimary(payload.cardId, payload.metricLabel);
|
||||
}
|
||||
|
||||
const categoryExportMode = ref(false);
|
||||
const selectedExportCategoryIds = ref<number[]>([]);
|
||||
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([dayjs().startOf('month'), dayjs()]);
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
dateRange.value[0],
|
||||
dateRange.value[1],
|
||||
]);
|
||||
const lastRequestKey = ref('');
|
||||
const isRequesting = ref(false);
|
||||
|
||||
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, () => {
|
||||
void loadOverviewData();
|
||||
});
|
||||
|
||||
const timeRangeState = computed(() => ({
|
||||
taxRate: taxRate.value,
|
||||
activeTimeRange: activeTimeRange.value,
|
||||
customDateRange: customDateRange.value,
|
||||
dateRange: dateRange.value,
|
||||
}));
|
||||
|
||||
const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
|
||||
taxRate.value = val.taxRate;
|
||||
activeTimeRange.value = val.activeTimeRange;
|
||||
customDateRange.value = val.customDateRange;
|
||||
dateRange.value = val.dateRange;
|
||||
lastRequestKey.value = '';
|
||||
syncDateRangeToRouteQuery();
|
||||
await refreshOverviewByCurrentParams();
|
||||
};
|
||||
|
||||
const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: 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);
|
||||
};
|
||||
|
||||
async function fetchPlatformList() {
|
||||
if (platformsLoading.value) return;
|
||||
platformsLoading.value = true;
|
||||
try {
|
||||
const list = await getPlatformListApi();
|
||||
platformOptions.value = (list ?? []).map((p) => ({
|
||||
label: p.label,
|
||||
value: p.code,
|
||||
}));
|
||||
const code = platformCode.value;
|
||||
if (
|
||||
code &&
|
||||
!platformOptions.value.some((o) => o.value === code) &&
|
||||
overviewData.value?.platformName
|
||||
) {
|
||||
platformOptions.value.unshift({
|
||||
label: overviewData.value.platformName,
|
||||
value: code,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
message.error('平台列表加载失败');
|
||||
} finally {
|
||||
platformsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handlePlatformChange(nextCode: string) {
|
||||
if (!nextCode || nextCode === platformCode.value) return;
|
||||
lastRequestKey.value = '';
|
||||
router.push({
|
||||
path: `/ec/platform/overview/${encodeURIComponent(nextCode)}`,
|
||||
query: buildOverviewRouteQuery(dateRange.value),
|
||||
});
|
||||
}
|
||||
|
||||
const loadOverviewData = async () => {
|
||||
if (!isPlatformOverviewRoute() || !platformCode.value) return;
|
||||
if (isRequesting.value) return;
|
||||
isRequesting.value = true;
|
||||
try {
|
||||
loading.value = true;
|
||||
const [startDate, endDate] = dateRange.value;
|
||||
overviewData.value = await getPlatformOverviewApi({
|
||||
platformCode: platformCode.value,
|
||||
dateRange: [
|
||||
startDate.format('YYYY-MM-DD'),
|
||||
endDate.format('YYYY-MM-DD'),
|
||||
],
|
||||
taxRate: taxRate.value,
|
||||
});
|
||||
await redrawCharts();
|
||||
} catch (err: any) {
|
||||
overviewData.value = null;
|
||||
message.error(err?.message || '加载平台概览失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
isRequesting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
function handleExportUnavailable() {
|
||||
message.info('平台概览暂不支持导出,请使用工作台汇总导出');
|
||||
}
|
||||
|
||||
const handleCategoryExportToggle = (enabled: boolean) => {
|
||||
categoryExportMode.value = enabled;
|
||||
if (enabled) selectedExportCategoryIds.value = [];
|
||||
};
|
||||
|
||||
const handleCategorySelectAllChange = (event: Event) => {
|
||||
const target = event.target as HTMLInputElement | null;
|
||||
if (!target) return;
|
||||
selectedExportCategoryIds.value = target.checked
|
||||
? (overviewData.value?.categoryOverview?.categories?.map(
|
||||
(c) => c.categoryId,
|
||||
) ?? [])
|
||||
: [];
|
||||
};
|
||||
|
||||
const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
if (!isPlatformOverviewRoute()) return;
|
||||
applyDateRangeFromRouteQuery();
|
||||
if (!platformCode.value) return;
|
||||
|
||||
const requestKey = `${platformCode.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${taxRate.value}`;
|
||||
if (!force && lastRequestKey.value === requestKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastRequestKey.value = requestKey;
|
||||
await loadOverviewData();
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [
|
||||
route.path,
|
||||
route.params.code,
|
||||
route.query.startDate,
|
||||
route.query.endDate,
|
||||
],
|
||||
async () => {
|
||||
if (!isPlatformOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams();
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isPlatformOverviewRoute()) return;
|
||||
void fetchPlatformList();
|
||||
await refreshOverviewByCurrentParams(true);
|
||||
});
|
||||
|
||||
onActivated(async () => {
|
||||
if (!isPlatformOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams(true);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page
|
||||
auto-content-height
|
||||
:class="PLATFORM_PAGE_BG"
|
||||
content-padding-class="px-4 pb-4"
|
||||
header-class="platform-overview-page-header"
|
||||
>
|
||||
<template #title>
|
||||
<div
|
||||
class="text-xl font-black tracking-tight text-violet-950 dark:text-violet-50 sm:text-2xl md:text-3xl"
|
||||
>
|
||||
平台概览
|
||||
</div>
|
||||
<p
|
||||
class="mt-0.5 text-xs font-normal text-violet-800/70 dark:text-violet-300/70"
|
||||
>
|
||||
全渠道平台 · 商品结构优先
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<div class="w-full max-w-full sm:w-auto">
|
||||
<TimeRangeBar
|
||||
:model-value="timeRangeState"
|
||||
:platform-code="platformCode"
|
||||
:platform-options="platformOptions"
|
||||
:platform-list-loading="platformsLoading"
|
||||
@update:model-value="handleTimeRangeChange"
|
||||
@platform-change="handlePlatformChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div
|
||||
v-if="overviewData"
|
||||
class="platform-overview-body mx-auto w-full min-w-0 space-y-4 pt-4"
|
||||
>
|
||||
<PlatformHeroBanner
|
||||
:data="overviewData"
|
||||
:date-label="periodDateLabel"
|
||||
/>
|
||||
|
||||
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-5">
|
||||
<FinanceTrendChart
|
||||
ref="trendChartRef"
|
||||
:trend="dealTrend"
|
||||
:panel-class="PLATFORM_PANEL_SHELL"
|
||||
class="xl:col-span-3"
|
||||
/>
|
||||
<FinanceCostPieChart
|
||||
ref="costPieRef"
|
||||
class="xl:col-span-2"
|
||||
:platform-sales-share="productSalesShare"
|
||||
:panel-class="PLATFORM_PANEL_SHELL"
|
||||
title="商品销售额占比"
|
||||
subtitle="本平台各商品占净销售额的比例"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<PlatformProductRankStrip
|
||||
:items="overviewData.productSalesTop10"
|
||||
:date-range="dateRange"
|
||||
/>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 pt-1">
|
||||
<div>
|
||||
<span :class="PLATFORM_SECTION_LABEL">指标明细</span>
|
||||
<h2
|
||||
class="mt-2 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%)]"
|
||||
>
|
||||
口径与工作台一致,卡片布局可自定义
|
||||
<span v-if="visibleKpiCount > 0">
|
||||
· 已选 {{ visibleKpiCount }} 张 · 最多 {{ colsPerRow }} 列
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="default"
|
||||
class="shrink-0 whitespace-nowrap !rounded-[10px] !border-violet-200 !bg-white !text-violet-900 shadow-[0_1px_2px_rgba(109,40,217,0.05)] hover:!border-violet-400 hover:!text-violet-800 dark:!border-violet-800/50 dark:!bg-[hsl(265deg_14%_12%)] dark:!text-violet-200 dark:hover:!border-violet-500/50 dark:hover:!text-violet-100"
|
||||
@click="kpiSettingsOpen = true"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="IconSliders" class="size-4 shrink-0" />
|
||||
</template>
|
||||
KPI 显示设置
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<FinanceKpiSettingsModal
|
||||
v-model:open="kpiSettingsOpen"
|
||||
:cols-per-row="colsPerRow"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
@save="onKpiSettingsSave"
|
||||
/>
|
||||
<FinanceKpiGrid
|
||||
:kpis="financeKpis"
|
||||
:cols-per-row="colsPerRow"
|
||||
:tax-rate="taxRate"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
:mom-compare-date-start="overviewData.momCompareDateStart"
|
||||
:mom-compare-date-end="overviewData.momCompareDateEnd"
|
||||
:yoy-compare-date-start="overviewData.yoyCompareDateStart"
|
||||
:yoy-compare-date-end="overviewData.yoyCompareDateEnd"
|
||||
@set-primary="onSetPrimary"
|
||||
/>
|
||||
|
||||
<ProductCategorySwitcher
|
||||
:data="tableData"
|
||||
:tax-rate="taxRate"
|
||||
:category-export-mode="categoryExportMode"
|
||||
:selected-export-category-ids="selectedExportCategoryIds"
|
||||
@export="handleExportUnavailable"
|
||||
@export-all="handleExportUnavailable"
|
||||
@export-toggle="handleCategoryExportToggle"
|
||||
@category-select-all="handleCategorySelectAllChange"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="!loading"
|
||||
class="flex items-center justify-center p-8 text-slate-400"
|
||||
>
|
||||
暂无数据
|
||||
</div>
|
||||
</Spin>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.platform-overview-page-header) {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:deep(.platform-overview-page-header) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.platform-overview-page-header > div:first-child),
|
||||
:deep(.platform-overview-page-header > div:last-child) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:deep(.platform-overview-page-header > div:first-child),
|
||||
:deep(.platform-overview-page-header > div:last-child) {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { SHOP_HERO_SHELL, SHOP_SPOT_CARD } from '../constants/shop-ui';
|
||||
|
||||
defineOptions({ name: 'ShopOverviewHero' });
|
||||
|
||||
const props = defineProps<{
|
||||
data: ShopVO.OverviewStatistics;
|
||||
dateLabel?: string;
|
||||
}>();
|
||||
|
||||
const IconStore = createIconifyIcon('lucide:store');
|
||||
const IconWallet = createIconifyIcon('lucide:wallet');
|
||||
const IconBag = createIconifyIcon('lucide:shopping-bag');
|
||||
const IconNet = createIconifyIcon('lucide:badge-dollar-sign');
|
||||
const IconRoi = createIconifyIcon('lucide:target');
|
||||
|
||||
function pickKpi(label: string) {
|
||||
return props.data.kpis?.find((k) => k.label === label);
|
||||
}
|
||||
|
||||
function formatYuan(v: number | undefined | null) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return `¥${Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function formatNum(v: number | undefined | null, digits = 0) {
|
||||
if (v == null || !Number.isFinite(Number(v))) return '—';
|
||||
return Number(v).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
});
|
||||
}
|
||||
|
||||
const spots = computed(() => {
|
||||
const sales = pickKpi('净销售额');
|
||||
const orders = pickKpi('净销售单量');
|
||||
const profit = pickKpi('净利润');
|
||||
const roi = pickKpi('广告ROI');
|
||||
return [
|
||||
{
|
||||
key: 'sales',
|
||||
label: '净销售额',
|
||||
value:
|
||||
sales?.amountYuan != null
|
||||
? formatYuan(sales.amountYuan)
|
||||
: formatYuan(props.data.totalSalesAmount),
|
||||
delta: sales?.changePct,
|
||||
icon: IconWallet,
|
||||
},
|
||||
{
|
||||
key: 'orders',
|
||||
label: '净销售单量',
|
||||
value:
|
||||
orders != null
|
||||
? `${formatNum(orders.value)} 单`
|
||||
: `${formatNum(props.data.totalOrderCount)} 单`,
|
||||
delta: orders?.changePct,
|
||||
icon: IconBag,
|
||||
},
|
||||
{
|
||||
key: 'profit',
|
||||
label: '净利润',
|
||||
value:
|
||||
profit?.amountYuan != null
|
||||
? formatYuan(profit.amountYuan)
|
||||
: formatYuan(props.data.totalNetProfitAfterTax),
|
||||
delta: profit?.changePct,
|
||||
icon: IconNet,
|
||||
},
|
||||
{
|
||||
key: 'roi',
|
||||
label: '广告 ROI',
|
||||
value:
|
||||
roi != null
|
||||
? formatNum(Number(roi.value), 2)
|
||||
: formatNum(props.data.totalROI, 2),
|
||||
delta: roi?.changePct,
|
||||
icon: IconRoi,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
function deltaClass(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return 'text-slate-400';
|
||||
return Number(pct) >= 0
|
||||
? 'text-emerald-600 dark:text-emerald-400'
|
||||
: 'text-rose-500 dark:text-rose-400';
|
||||
}
|
||||
|
||||
function formatDelta(pct: number | undefined | null) {
|
||||
if (pct == null || !Number.isFinite(Number(pct))) return '';
|
||||
const n = Number(pct);
|
||||
return `环比 ${n > 0 ? '+' : ''}${n}%`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="SHOP_HERO_SHELL">
|
||||
<div
|
||||
class="pointer-events-none absolute -right-8 -top-10 size-40 rounded-full bg-amber-200/35 blur-2xl dark:bg-amber-500/10"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute -bottom-12 left-1/3 size-48 rounded-full bg-orange-200/30 blur-3xl dark:bg-orange-500/10"
|
||||
/>
|
||||
|
||||
<div class="relative flex flex-wrap items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="grid size-9 shrink-0 place-items-center rounded-[12px] bg-amber-600 text-white shadow-sm shadow-amber-600/25 dark:bg-amber-500"
|
||||
>
|
||||
<component :is="IconStore" class="size-4" />
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full bg-amber-600/10 px-2 py-0.5 text-[11px] font-semibold text-amber-800 dark:bg-amber-400/10 dark:text-amber-300"
|
||||
>
|
||||
店铺诊断
|
||||
</span>
|
||||
</div>
|
||||
<h2
|
||||
class="mt-3 max-w-3xl text-xl font-bold tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_96%)] sm:text-2xl"
|
||||
:title="data.shopName"
|
||||
>
|
||||
{{ data.shopName || '未命名店铺' }}
|
||||
</h2>
|
||||
<p
|
||||
class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<span v-if="dateLabel">统计区间 {{ dateLabel }}</span>
|
||||
<span v-if="data.platformCode">平台:{{ data.platformCode }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="relative mt-5 grid grid-cols-2 gap-2.5 lg:grid-cols-4">
|
||||
<div v-for="spot in spots" :key="spot.key" :class="SHOP_SPOT_CARD">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span
|
||||
class="truncate text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
{{ spot.label }}
|
||||
</span>
|
||||
<component
|
||||
:is="spot.icon"
|
||||
class="size-3.5 shrink-0 text-amber-600/80 dark:text-amber-400/80"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 truncate text-lg font-bold tabular-nums tracking-tight text-slate-900 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ spot.value }}
|
||||
</div>
|
||||
<div
|
||||
v-if="spot.delta != null"
|
||||
class="mt-1 text-[11px] font-medium tabular-nums"
|
||||
:class="deltaClass(spot.delta)"
|
||||
>
|
||||
{{ formatDelta(spot.delta) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import { buildOverviewRouteQuery } from '#/utils/overview-date-range';
|
||||
|
||||
import { SHOP_PANEL_SHELL, SHOP_SECTION_LABEL } from '../constants/shop-ui';
|
||||
|
||||
defineOptions({ name: 'ShopProductRankStrip' });
|
||||
|
||||
const props = defineProps<{
|
||||
items?: ShopVO.ProductSalesRankItem[] | null;
|
||||
shopId?: number;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const rows = computed(() => (props.items ?? []).slice(0, 8));
|
||||
|
||||
const maxOrders = computed(() =>
|
||||
Math.max(1, ...rows.value.map((r) => Number(r.orderCount ?? 0))),
|
||||
);
|
||||
|
||||
function formatAmount(amount: number | undefined) {
|
||||
if (amount == null) return '—';
|
||||
return `¥${amount.toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 0,
|
||||
})}`;
|
||||
}
|
||||
|
||||
function barWidth(orderCount: number | undefined) {
|
||||
const n = Number(orderCount ?? 0);
|
||||
return `${Math.max(8, Math.round((n / maxOrders.value) * 100))}%`;
|
||||
}
|
||||
|
||||
function rankTone(idx: number) {
|
||||
if (idx === 0) return 'bg-amber-600 text-white';
|
||||
if (idx === 1) return 'bg-amber-500/90 text-white';
|
||||
if (idx === 2) return 'bg-orange-600 text-white';
|
||||
return 'bg-slate-100 text-slate-600 dark:bg-[hsl(28deg_10%_18%)] dark:text-slate-300';
|
||||
}
|
||||
|
||||
function goProduct(productId: number | undefined) {
|
||||
if (productId == null || productId <= 0) return;
|
||||
router.push({
|
||||
path: `/ec/product/overview/${productId}`,
|
||||
query: buildOverviewRouteQuery(
|
||||
props.dateRange,
|
||||
props.shopId != null && props.shopId > 0
|
||||
? { shopId: props.shopId }
|
||||
: undefined,
|
||||
),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="rows.length" :class="SHOP_PANEL_SHELL">
|
||||
<div
|
||||
class="flex flex-wrap items-end justify-between gap-2 border-b border-amber-100/80 px-5 pb-3.5 pt-5 md:px-6 dark:border-amber-900/35"
|
||||
>
|
||||
<div>
|
||||
<span :class="SHOP_SECTION_LABEL">商品结构</span>
|
||||
<h3
|
||||
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
热销商品速览
|
||||
</h3>
|
||||
<p class="mt-1 text-xs text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
按净销售单量排序,点击可下钻商品概览
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-2.5 px-5 py-4 md:px-6 md:py-5">
|
||||
<button
|
||||
v-for="(row, idx) in rows"
|
||||
:key="row.productId ?? `product-${idx}`"
|
||||
type="button"
|
||||
class="grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-lg text-left transition-colors hover:bg-amber-50/60 dark:hover:bg-amber-950/20"
|
||||
@click="goProduct(row.productId)"
|
||||
>
|
||||
<span
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-[11px] font-bold tabular-nums"
|
||||
:class="rankTone(idx)"
|
||||
>
|
||||
{{ idx + 1 }}
|
||||
</span>
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-baseline justify-between gap-2">
|
||||
<span
|
||||
class="truncate text-sm font-semibold text-slate-800 hover:text-amber-700 dark:text-[hsl(0deg_0%_95%)] dark:hover:text-amber-300"
|
||||
:title="row.productName"
|
||||
>
|
||||
{{ row.productName || '—' }}
|
||||
</span>
|
||||
<span class="shrink-0 text-xs tabular-nums text-slate-500">
|
||||
{{ row.orderCount?.toLocaleString('zh-CN') ?? 0 }} 单 ·
|
||||
{{ formatAmount(row.salesAmount) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-amber-50 dark:bg-amber-950/50"
|
||||
>
|
||||
<div
|
||||
class="h-full rounded-full bg-gradient-to-r from-amber-500 to-orange-400 transition-all duration-500"
|
||||
:style="{ width: barWidth(row.orderCount) }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,16 @@
|
||||
/** 店铺概览:琥珀/橙强调,与商品青绿、工作台蓝灰区分 */
|
||||
|
||||
export const SHOP_PAGE_BG =
|
||||
'bg-[#fbf7f2] dark:bg-[hsl(28deg_18%_8%)]';
|
||||
|
||||
export const SHOP_PANEL_SHELL =
|
||||
'overflow-hidden rounded-[16px] border border-amber-200/70 bg-white shadow-[0_1px_2px_rgba(180,83,9,0.04),0_10px_28px_rgba(180,83,9,0.05)] dark:border-amber-900/40 dark:bg-[hsl(28deg_14%_11%)] dark:shadow-none';
|
||||
|
||||
export const SHOP_HERO_SHELL =
|
||||
'relative overflow-hidden rounded-[18px] border border-amber-200/80 bg-gradient-to-br from-amber-50 via-white to-orange-50/80 p-5 shadow-[0_1px_2px_rgba(180,83,9,0.05),0_12px_32px_rgba(180,83,9,0.07)] md:p-6 dark:border-amber-900/45 dark:from-amber-950/40 dark:via-[hsl(28deg_14%_11%)] dark:to-orange-950/30 dark:shadow-none';
|
||||
|
||||
export const SHOP_SPOT_CARD =
|
||||
'min-w-0 rounded-[14px] border border-amber-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-amber-900/35 dark:bg-[hsl(28deg_14%_12%/80%)]';
|
||||
|
||||
export const SHOP_SECTION_LABEL =
|
||||
'inline-flex items-center gap-1.5 rounded-full border border-amber-200/80 bg-amber-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-amber-800 dark:border-amber-800/50 dark:bg-amber-950/40 dark:text-amber-300';
|
||||
@@ -1,9 +1,12 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ec/shop/types';
|
||||
import type { WorkbenchVO } from '#/api/bi/workbench/types';
|
||||
import type { FinanceKpiCardId } from '#/views/bi/workbench/tabs/finance/constants/kpi-catalog';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import {
|
||||
computed,
|
||||
nextTick,
|
||||
onActivated,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
@@ -13,7 +16,9 @@ import {
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { message, Spin } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getShopOverviewApi, getShopPageApi } from '#/api/ec/shop/apis';
|
||||
@@ -24,16 +29,27 @@ import {
|
||||
syncOverviewDateRangeToUrl,
|
||||
} from '#/utils/overview-date-range';
|
||||
|
||||
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
|
||||
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
|
||||
import FinanceKpiSettingsModal from '#/views/bi/workbench/tabs/finance/components/FinanceKpiSettingsModal.vue';
|
||||
import FinanceTrendChart from '#/views/bi/workbench/tabs/finance/components/FinanceTrendChart.vue';
|
||||
import { useFinanceKpiPreferences } from '#/views/bi/workbench/tabs/finance/composables/useFinanceKpiPreferences';
|
||||
|
||||
import TimeRangeBar from './components/TimeRangeBar.vue';
|
||||
import StatCards from './components/StatCards.vue';
|
||||
import SalesTrendChart from './components/SalesTrendChart.vue';
|
||||
import ProductSalesTop10Panel from './components/ProductSalesTop10Panel.vue';
|
||||
import ShopHeroBanner from './components/ShopHeroBanner.vue';
|
||||
import ShopProductRankStrip from './components/ShopProductRankStrip.vue';
|
||||
import ProductCategorySwitcher from './components/ProductCategorySwitcher.vue';
|
||||
import {
|
||||
SHOP_PAGE_BG,
|
||||
SHOP_PANEL_SHELL,
|
||||
SHOP_SECTION_LABEL,
|
||||
} from './constants/shop-ui';
|
||||
|
||||
defineOptions({ name: 'ShopOverview' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
const SHOP_PAGE_SIZE = 20;
|
||||
|
||||
@@ -45,18 +61,16 @@ const shopSearchKeyword = ref('');
|
||||
|
||||
let shopSearchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
/** 当前是否为店铺概览路由(keep-alive 下 route.params.id 会随其它标签变化,不可仅凭 id 请求) */
|
||||
/** 当前是否为店铺概览路由(keep-alive 下 route.params.id 会随其它标签变化) */
|
||||
const isShopOverviewRoute = () =>
|
||||
/\/ec\/shop\/overview\/[^/]+\/?$/.test(route.path);
|
||||
|
||||
// 店铺ID(从路由参数获取)
|
||||
const shopId = computed(() => {
|
||||
if (!isShopOverviewRoute()) return 0;
|
||||
const id = route.params.id;
|
||||
return id ? Number(id) : 0;
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const exportLoading = ref(false);
|
||||
const overviewData = ref<null | ShopVO.OverviewStatistics>(null);
|
||||
@@ -74,23 +88,73 @@ const shopSelectOptions = computed(() => {
|
||||
return opts;
|
||||
});
|
||||
|
||||
// 品类导出相关
|
||||
const financeKpis = computed<WorkbenchVO.KpiItem[]>(
|
||||
() => (overviewData.value?.kpis as WorkbenchVO.KpiItem[] | undefined) ?? [],
|
||||
);
|
||||
const dealTrend = computed<WorkbenchVO.TrendPoint[]>(
|
||||
() =>
|
||||
(overviewData.value?.dealTrend as WorkbenchVO.TrendPoint[] | undefined) ??
|
||||
[],
|
||||
);
|
||||
const productSalesShare = computed<WorkbenchVO.PieSlice[]>(
|
||||
() =>
|
||||
(overviewData.value?.productSalesShare as
|
||||
| WorkbenchVO.PieSlice[]
|
||||
| undefined) ?? [],
|
||||
);
|
||||
|
||||
const periodDateLabel = computed(() => {
|
||||
const [start, end] = dateRange.value;
|
||||
return `${start.format('YYYY-MM-DD')} ~ ${end.format('YYYY-MM-DD')}`;
|
||||
});
|
||||
|
||||
const {
|
||||
visibleCardIds,
|
||||
primaryByCardId,
|
||||
colsPerRow,
|
||||
applySettings,
|
||||
setCardPrimary,
|
||||
} = useFinanceKpiPreferences();
|
||||
const kpiSettingsOpen = ref(false);
|
||||
const visibleKpiCount = computed(() => visibleCardIds.value.length);
|
||||
|
||||
const trendChartRef = ref<InstanceType<typeof FinanceTrendChart> | null>(null);
|
||||
const costPieRef = ref<InstanceType<typeof FinanceCostPieChart> | null>(null);
|
||||
|
||||
async function redrawCharts() {
|
||||
await nextTick();
|
||||
await trendChartRef.value?.redraw();
|
||||
await costPieRef.value?.redraw();
|
||||
}
|
||||
|
||||
function onKpiSettingsSave(payload: {
|
||||
visibleCardIds: string[];
|
||||
primaryByCardId: Record<string, string>;
|
||||
colsPerRow: number;
|
||||
}) {
|
||||
if (payload.visibleCardIds.length === 0) {
|
||||
message.warning('请至少选择一张 KPI 卡片');
|
||||
return;
|
||||
}
|
||||
applySettings(payload);
|
||||
message.success('KPI 显示已更新');
|
||||
}
|
||||
|
||||
function onSetPrimary(payload: {
|
||||
cardId: FinanceKpiCardId;
|
||||
metricLabel: string;
|
||||
}) {
|
||||
setCardPrimary(payload.cardId, payload.metricLabel);
|
||||
}
|
||||
|
||||
const categoryExportMode = ref(false);
|
||||
const selectedExportCategoryIds = ref<number[]>([]);
|
||||
const categoryExportLoading = ref(false);
|
||||
|
||||
// 日期范围(默认:本月至今日)
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([dayjs().startOf('month'), dayjs()]);
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
dateRange.value[0],
|
||||
dateRange.value[1],
|
||||
@@ -98,16 +162,14 @@ const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
const lastRequestKey = ref('');
|
||||
const isRequesting = ref(false);
|
||||
|
||||
// 税率(持久化)
|
||||
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, () => {
|
||||
loadOverviewData();
|
||||
void loadOverviewData();
|
||||
});
|
||||
|
||||
// 时间范围状态(传递给子组件)
|
||||
const timeRangeState = computed(() => ({
|
||||
taxRate: taxRate.value,
|
||||
activeTimeRange: activeTimeRange.value,
|
||||
@@ -115,22 +177,17 @@ const timeRangeState = computed(() => ({
|
||||
dateRange: dateRange.value,
|
||||
}));
|
||||
|
||||
// 监听子组件的时间范围变化
|
||||
const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
|
||||
taxRate.value = val.taxRate;
|
||||
activeTimeRange.value = val.activeTimeRange;
|
||||
customDateRange.value = val.customDateRange;
|
||||
dateRange.value = val.dateRange;
|
||||
// 手动切换时间时清除请求缓存,确保强制刷新
|
||||
lastRequestKey.value = '';
|
||||
syncDateRangeToRouteQuery();
|
||||
await refreshOverviewByCurrentParams();
|
||||
};
|
||||
|
||||
const setTimeRangeTypeByDates = (
|
||||
startDate: Dayjs,
|
||||
endDate: Dayjs,
|
||||
) => {
|
||||
const setTimeRangeTypeByDates = (startDate: Dayjs, endDate: Dayjs) => {
|
||||
const today = dayjs();
|
||||
const daysDiff = endDate.diff(startDate, 'day');
|
||||
const isEndDateToday = endDate.isSame(today, 'day');
|
||||
@@ -143,39 +200,31 @@ const setTimeRangeTypeByDates = (
|
||||
'day',
|
||||
);
|
||||
|
||||
if (
|
||||
isEndDateToday &&
|
||||
startDate.isSame(today.startOf('month'), '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];
|
||||
};
|
||||
@@ -242,7 +291,6 @@ function handleShopChange(nextShopId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
// 加载概览数据
|
||||
const loadOverviewData = async () => {
|
||||
if (!isShopOverviewRoute() || !shopId.value) return;
|
||||
if (isRequesting.value) return;
|
||||
@@ -258,6 +306,7 @@ const loadOverviewData = async () => {
|
||||
],
|
||||
taxRate: taxRate.value,
|
||||
});
|
||||
await redrawCharts();
|
||||
} catch (err: any) {
|
||||
overviewData.value = null;
|
||||
message.error(err?.message || '加载店铺概览失败');
|
||||
@@ -267,7 +316,6 @@ const loadOverviewData = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 导出汇总数据
|
||||
const handleExportShopOverview = async () => {
|
||||
if (!shopId.value) return;
|
||||
try {
|
||||
@@ -293,7 +341,6 @@ const handleExportShopOverview = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 品类导出相关
|
||||
const handleCategoryExportToggle = (enabled: boolean) => {
|
||||
categoryExportMode.value = enabled;
|
||||
if (enabled) selectedExportCategoryIds.value = [];
|
||||
@@ -332,7 +379,9 @@ const handleCategorySelectAllChange = (event: Event) => {
|
||||
const target = event.target as HTMLInputElement | null;
|
||||
if (!target) return;
|
||||
selectedExportCategoryIds.value = target.checked
|
||||
? (overviewData.value?.categoryOverview?.categories?.map((c: ShopVO.CategorySummary) => c.categoryId) ?? [])
|
||||
? (overviewData.value?.categoryOverview?.categories?.map(
|
||||
(c: ShopVO.CategorySummary) => c.categoryId,
|
||||
) ?? [])
|
||||
: [];
|
||||
};
|
||||
|
||||
@@ -341,7 +390,7 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
applyDateRangeFromRouteQuery();
|
||||
if (!shopId.value) return;
|
||||
|
||||
const requestKey = `${shopId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}`;
|
||||
const requestKey = `${shopId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${taxRate.value}`;
|
||||
if (!force && lastRequestKey.value === requestKey) {
|
||||
return;
|
||||
}
|
||||
@@ -350,7 +399,6 @@ const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
await loadOverviewData();
|
||||
};
|
||||
|
||||
// 监听路由变化(仅在本页路径下响应,避免切到商品概览等仍用当前 id 请求店铺接口)
|
||||
watch(
|
||||
() => [
|
||||
route.path,
|
||||
@@ -364,7 +412,6 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
// 初始化
|
||||
onMounted(async () => {
|
||||
if (!isShopOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams(true);
|
||||
@@ -383,15 +430,21 @@ onActivated(async () => {
|
||||
<template>
|
||||
<Page
|
||||
auto-content-height
|
||||
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
:class="SHOP_PAGE_BG"
|
||||
content-padding-class="px-4 pb-4"
|
||||
header-class="shop-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"
|
||||
class="text-xl font-black tracking-tight text-amber-950 dark:text-amber-50 sm:text-2xl md:text-3xl"
|
||||
>
|
||||
店铺经营概览
|
||||
店铺概览
|
||||
</div>
|
||||
<p
|
||||
class="mt-0.5 text-xs font-normal text-amber-800/70 dark:text-amber-300/70"
|
||||
>
|
||||
单店诊断 · 商品结构优先
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
@@ -411,17 +464,84 @@ onActivated(async () => {
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div class="mx-auto w-full space-y-6">
|
||||
<!-- 第一层:核心统计卡片 -->
|
||||
<StatCards :data="overviewData" :loading="loading" />
|
||||
<div
|
||||
v-if="overviewData"
|
||||
class="shop-overview-body mx-auto w-full min-w-0 space-y-4 pt-4"
|
||||
>
|
||||
<ShopHeroBanner :data="overviewData" :date-label="periodDateLabel" />
|
||||
|
||||
<!-- 第二层:趋势与销量榜 -->
|
||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-3">
|
||||
<SalesTrendChart :data="overviewData" />
|
||||
<ProductSalesTop10Panel :data="overviewData" />
|
||||
<div class="grid grid-cols-1 gap-3.5 xl:grid-cols-5">
|
||||
<FinanceTrendChart
|
||||
ref="trendChartRef"
|
||||
:trend="dealTrend"
|
||||
:panel-class="SHOP_PANEL_SHELL"
|
||||
class="xl:col-span-3"
|
||||
/>
|
||||
<FinanceCostPieChart
|
||||
ref="costPieRef"
|
||||
class="xl:col-span-2"
|
||||
:platform-sales-share="productSalesShare"
|
||||
:panel-class="SHOP_PANEL_SHELL"
|
||||
title="商品销售额占比"
|
||||
subtitle="本店各商品占净销售额的比例"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 第三层:商品/品类多维度损益汇总表 -->
|
||||
<ShopProductRankStrip
|
||||
:items="overviewData.productSalesTop10"
|
||||
:shop-id="shopId"
|
||||
:date-range="dateRange"
|
||||
/>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 pt-1">
|
||||
<div>
|
||||
<span :class="SHOP_SECTION_LABEL">指标明细</span>
|
||||
<h2
|
||||
class="mt-2 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%)]"
|
||||
>
|
||||
口径与工作台一致,卡片布局可自定义
|
||||
<span v-if="visibleKpiCount > 0">
|
||||
· 已选 {{ visibleKpiCount }} 张 · 最多 {{ colsPerRow }} 列
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="default"
|
||||
class="shrink-0 whitespace-nowrap !rounded-[10px] !border-amber-200 !bg-white !text-amber-900 shadow-[0_1px_2px_rgba(180,83,9,0.05)] hover:!border-amber-400 hover:!text-amber-800 dark:!border-amber-800/50 dark:!bg-[hsl(28deg_14%_12%)] dark:!text-amber-200 dark:hover:!border-amber-500/50 dark:hover:!text-amber-100"
|
||||
@click="kpiSettingsOpen = true"
|
||||
>
|
||||
<template #icon>
|
||||
<component :is="IconSliders" class="size-4 shrink-0" />
|
||||
</template>
|
||||
KPI 显示设置
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<FinanceKpiSettingsModal
|
||||
v-model:open="kpiSettingsOpen"
|
||||
:cols-per-row="colsPerRow"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
@save="onKpiSettingsSave"
|
||||
/>
|
||||
<FinanceKpiGrid
|
||||
:kpis="financeKpis"
|
||||
:cols-per-row="colsPerRow"
|
||||
:tax-rate="taxRate"
|
||||
:visible-card-ids="visibleCardIds"
|
||||
:primary-by-card-id="primaryByCardId"
|
||||
:mom-compare-date-start="overviewData.momCompareDateStart"
|
||||
:mom-compare-date-end="overviewData.momCompareDateEnd"
|
||||
:yoy-compare-date-start="overviewData.yoyCompareDateStart"
|
||||
:yoy-compare-date-end="overviewData.yoyCompareDateEnd"
|
||||
@set-primary="onSetPrimary"
|
||||
/>
|
||||
|
||||
<ProductCategorySwitcher
|
||||
:data="overviewData"
|
||||
:tax-rate="taxRate"
|
||||
@@ -435,6 +555,12 @@ onActivated(async () => {
|
||||
@category-select-all="handleCategorySelectAllChange"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="!loading"
|
||||
class="flex items-center justify-center p-8 text-slate-400"
|
||||
>
|
||||
暂无数据
|
||||
</div>
|
||||
</Spin>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -468,10 +594,7 @@ onActivated(async () => {
|
||||
|
||||
<style>
|
||||
html.dark .shop-overview-thead table thead th {
|
||||
background-color: hsl(240deg 3.7% 15.9% / 80%) !important;
|
||||
}
|
||||
|
||||
html.dark .shop-overview-thead table thead th {
|
||||
border-color: hsl(240deg 3.7% 22%) !important;
|
||||
background-color: hsl(28deg 10% 16% / 80%) !important;
|
||||
border-color: hsl(28deg 10% 22%) !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user