mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 14:29:19 +08:00
feat: 工作台增加SKU汇总表并支持跳转SKU概览
This commit is contained in:
@@ -75,12 +75,14 @@ export namespace CompanyOverviewVO {
|
||||
categories?: CategorySummary[];
|
||||
}
|
||||
|
||||
/** 工作台底部四张汇总表 */
|
||||
/** 工作台底部汇总表 */
|
||||
export interface WorkbenchTableBundle {
|
||||
shopTable?: ShopOverview;
|
||||
platformTable?: PlatformOverview;
|
||||
categoryTable?: CategoryOverview;
|
||||
productTable?: CategoryOverview;
|
||||
/** SKU 汇总;categoryId=skuId */
|
||||
skuTable?: CategoryOverview;
|
||||
}
|
||||
|
||||
/** 店铺汇总行 */
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { SkuOverviewDTO, SkuOverviewVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/** 获取 SKU 概览统计数据 */
|
||||
export async function getSkuOverviewApi(params: SkuOverviewDTO.Query) {
|
||||
return requestClient.post<SkuOverviewVO.Overview>(
|
||||
'/bi/sku/overview',
|
||||
params,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export type { SkuOverviewDTO } from './types.dto';
|
||||
export type { SkuOverviewVO } from './types.vo';
|
||||
@@ -0,0 +1,10 @@
|
||||
export namespace SkuOverviewDTO {
|
||||
/** SKU 概览查询参数 */
|
||||
export interface Query {
|
||||
skuId: number;
|
||||
shopId?: number;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
taxRate?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/** SKU 概览 VO(与后端 SkuOverviewVO 对齐) */
|
||||
export namespace SkuOverviewVO {
|
||||
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;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export interface TrendDataItem {
|
||||
date: string;
|
||||
value: number;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
export interface TrendData {
|
||||
total: number;
|
||||
dailyDataList: TrendDataItem[];
|
||||
}
|
||||
|
||||
export interface Overview {
|
||||
skuId: number;
|
||||
skuName?: string;
|
||||
skuCode?: string;
|
||||
productId?: number;
|
||||
productName?: string;
|
||||
|
||||
kpis?: KpiItem[];
|
||||
dealTrend?: TrendPoint[];
|
||||
momCompareDateStart?: string | null;
|
||||
momCompareDateEnd?: string | null;
|
||||
yoyCompareDateStart?: string | null;
|
||||
yoyCompareDateEnd?: string | null;
|
||||
|
||||
totalSalesAmount?: number;
|
||||
monthOverMonthGrowth?: number;
|
||||
totalOrderCount?: number;
|
||||
averageFeeRatio?: number;
|
||||
totalNetProfitAfterTax?: number;
|
||||
totalTaxAmount?: number;
|
||||
totalROI?: number;
|
||||
totalPromotionFee?: number;
|
||||
refundAmount?: number;
|
||||
averageOrderValue?: number;
|
||||
totalProfitBeforeTax?: number;
|
||||
|
||||
/** @deprecated */
|
||||
salesAmountTrend?: TrendData;
|
||||
/** @deprecated */
|
||||
orderCountTrend?: TrendData;
|
||||
}
|
||||
}
|
||||
@@ -712,6 +712,20 @@ function handleCategoryNavigate(categoryId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleSkuNavigate(skuId: number) {
|
||||
if (!skuId || skuId <= 0) return;
|
||||
const shopId = parseSelectedShopId();
|
||||
router.push({
|
||||
path: `/ec/sku/overview/${skuId}`,
|
||||
query: buildOverviewRouteQuery(
|
||||
dateRange.value,
|
||||
shopId != null && Number.isFinite(shopId) && shopId > 0
|
||||
? { shopId }
|
||||
: undefined,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
|
||||
null,
|
||||
);
|
||||
@@ -1045,6 +1059,7 @@ onUnmounted(() => {
|
||||
@navigate-shop="handleShopNavigate"
|
||||
@navigate-platform="handlePlatformNavigate"
|
||||
@navigate-category="handleCategoryNavigate"
|
||||
@navigate-sku="handleSkuNavigate"
|
||||
/>
|
||||
</Spin>
|
||||
</Tabs.TabPane>
|
||||
|
||||
+15
-3
@@ -33,11 +33,13 @@ interface Props {
|
||||
headingSubtitle?: string;
|
||||
/** 首列维度名称,如「品类」「商品」 */
|
||||
firstColumnLabel?: string;
|
||||
/** 为 true 时首列名称可点击跳转商品概览(categoryId 即商品 ID) */
|
||||
/** 为首列名称可点击跳转商品概览(categoryId 即商品 ID) */
|
||||
productNavigate?: boolean;
|
||||
/** 为 true 时首列名称可点击跳转品类概览 */
|
||||
categoryNavigate?: boolean;
|
||||
columnPrefsKey?: 'category' | 'product';
|
||||
/** 为 true 时首列名称可点击跳转 SKU 概览(categoryId 即 skuId) */
|
||||
skuNavigate?: boolean;
|
||||
columnPrefsKey?: 'category' | 'product' | 'sku';
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
@@ -46,6 +48,7 @@ interface Emits {
|
||||
(e: 'export'): void;
|
||||
(e: 'navigate-product', productId: number): void;
|
||||
(e: 'navigate-category', categoryId: number): void;
|
||||
(e: 'navigate-sku', skuId: number): void;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -56,6 +59,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
firstColumnLabel: '品类',
|
||||
productNavigate: false,
|
||||
categoryNavigate: false,
|
||||
skuNavigate: false,
|
||||
columnPrefsKey: 'category',
|
||||
});
|
||||
|
||||
@@ -69,7 +73,7 @@ const {
|
||||
applyVisible,
|
||||
resetToDefault,
|
||||
} = useOverviewTableColumnPrefs(
|
||||
props.columnPrefsKey as 'category' | 'product',
|
||||
props.columnPrefsKey as 'category' | 'product' | 'sku',
|
||||
);
|
||||
|
||||
const emptyColspan = computed(
|
||||
@@ -357,6 +361,14 @@ const cellRoi = (v: number | null | undefined) =>
|
||||
{{ cat.categoryName }}
|
||||
<JumpIcon class="text-xs" />
|
||||
</span>
|
||||
<span
|
||||
v-else-if="skuNavigate && cat.categoryId != 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-sku', cat.categoryId!)"
|
||||
>
|
||||
{{ cat.categoryName }}
|
||||
<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"
|
||||
|
||||
+27
-1
@@ -23,6 +23,7 @@ const props = withDefaults(
|
||||
platformSummary?: CompanyOverviewVO.PlatformOverview | null;
|
||||
categorySummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||
productSummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||
skuSummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||
}>(),
|
||||
{
|
||||
taxRate: 0.04,
|
||||
@@ -34,8 +35,9 @@ const emit = defineEmits<{
|
||||
(e: 'navigate-shop', shopId: number): void;
|
||||
(e: 'navigate-platform', platformCode: string): void;
|
||||
(e: 'navigate-category', categoryId: number): void;
|
||||
(e: 'navigate-sku', skuId: number): void;
|
||||
}>();
|
||||
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
|
||||
const activeMode = ref<'category' | 'platform' | 'product' | 'shop' | 'sku'>('shop');
|
||||
|
||||
const shopExportMode = ref(false);
|
||||
const selectedExportShopIds = ref<number[]>([]);
|
||||
@@ -45,6 +47,8 @@ const categoryExportMode = ref(false);
|
||||
const selectedExportCategoryIds = ref<number[]>([]);
|
||||
const productExportMode = ref(false);
|
||||
const selectedExportProductIds = ref<number[]>([]);
|
||||
const skuExportMode = ref(false);
|
||||
const selectedExportSkuIds = ref<number[]>([]);
|
||||
|
||||
const exportLoading = ref(false);
|
||||
|
||||
@@ -53,6 +57,7 @@ const modeOptions = [
|
||||
{ label: '平台汇总', value: 'platform' },
|
||||
{ label: '品类汇总', value: 'category' },
|
||||
{ label: '商品汇总', value: 'product' },
|
||||
{ label: 'SKU汇总', value: 'sku' },
|
||||
];
|
||||
|
||||
function dateSegmentForFilename(): string {
|
||||
@@ -173,6 +178,10 @@ async function handleProductExport() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleSkuExport() {
|
||||
message.info('SKU 汇总导出即将支持,请先使用页面查看或商品维度导出');
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -244,6 +253,23 @@ async function handleProductExport() {
|
||||
@export="handleProductExport"
|
||||
@navigate-product="(id: number) => emit('navigate-product', id)"
|
||||
/>
|
||||
|
||||
<CategorySummaryTable
|
||||
v-if="activeMode === 'sku'"
|
||||
column-prefs-key="sku"
|
||||
heading-title="各 SKU 多维度经营明细汇总"
|
||||
heading-subtitle="数据来自 Mongo SKU 日汇聚;推广按所属商品推广占比分摊;点击规格名可跳转 SKU 概览"
|
||||
first-column-label="SKU"
|
||||
:sku-navigate="true"
|
||||
:category-summary="skuSummary ?? undefined"
|
||||
:tax-rate="taxRate"
|
||||
:category-export-mode="skuExportMode"
|
||||
:selected-export-category-ids="selectedExportSkuIds"
|
||||
@update:selected-export-category-ids="selectedExportSkuIds = $event"
|
||||
@toggle-category-export-mode="skuExportMode = $event"
|
||||
@export="handleSkuExport"
|
||||
@navigate-sku="(id: number) => emit('navigate-sku', id)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
/** 经营概览底部四表:可配置列目录(首列维度名固定不可隐藏) */
|
||||
|
||||
export type OverviewTableKey = 'shop' | 'platform' | 'category' | 'product';
|
||||
export type OverviewTableKey = 'shop' | 'platform' | 'category' | 'product' | 'sku';
|
||||
|
||||
export type OverviewColGroupId = 'target' | 'scale' | 'cost' | 'profit';
|
||||
|
||||
@@ -99,7 +99,7 @@ const TARGET_IDS = new Set<OverviewColumnId>(
|
||||
|
||||
/** 某张表可用的列(品类/商品无目标列) */
|
||||
export function columnsForTable(tableKey: OverviewTableKey): OverviewColumnDef[] {
|
||||
if (tableKey === 'category' || tableKey === 'product') {
|
||||
if (tableKey === 'category' || tableKey === 'product' || tableKey === 'sku') {
|
||||
return OVERVIEW_COLUMNS.filter((c) => !TARGET_IDS.has(c.id));
|
||||
}
|
||||
return [...OVERVIEW_COLUMNS];
|
||||
@@ -110,7 +110,7 @@ export function defaultVisibleIds(tableKey: OverviewTableKey): OverviewColumnId[
|
||||
}
|
||||
|
||||
export function groupsForTable(tableKey: OverviewTableKey): OverviewColGroupDef[] {
|
||||
if (tableKey === 'category' || tableKey === 'product') {
|
||||
if (tableKey === 'category' || tableKey === 'product' || tableKey === 'sku') {
|
||||
return OVERVIEW_COL_GROUPS.filter((g) => g.id !== 'target');
|
||||
}
|
||||
return [...OVERVIEW_COL_GROUPS];
|
||||
|
||||
@@ -29,6 +29,7 @@ const emit = defineEmits<{
|
||||
(e: 'navigate-shop', shopId: number): void;
|
||||
(e: 'navigate-platform', platformCode: string): void;
|
||||
(e: 'navigate-category', categoryId: number): void;
|
||||
(e: 'navigate-sku', skuId: number): void;
|
||||
}>();
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -60,6 +61,7 @@ const productOverview = computed(
|
||||
props.summaryTables?.productTable ??
|
||||
buildCategoryOverviewFromDimRows(props.multiAnalysis.product),
|
||||
);
|
||||
const skuOverview = computed(() => props.summaryTables?.skuTable ?? null);
|
||||
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
@@ -169,10 +171,12 @@ defineExpose({ redraw });
|
||||
:platform-summary="platformOverview"
|
||||
:category-summary="categoryOverview"
|
||||
:product-summary="productOverview"
|
||||
:sku-summary="skuOverview"
|
||||
@navigate-product="(id: number) => emit('navigate-product', id)"
|
||||
@navigate-shop="(id: number) => emit('navigate-shop', id)"
|
||||
@navigate-platform="(code: string) => emit('navigate-platform', code)"
|
||||
@navigate-category="(id: number) => emit('navigate-category', id)"
|
||||
@navigate-sku="(id: number) => emit('navigate-sku', id)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+23
-1
@@ -3,6 +3,8 @@ import type { ProductOverviewVO } from '#/api/ec/product/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
|
||||
import {
|
||||
overviewTableHints,
|
||||
@@ -46,6 +48,17 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
footerTotal: null,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'navigate-sku', skuId: number): void;
|
||||
}>();
|
||||
|
||||
const JumpIcon = createIconifyIcon('tdesign:jump');
|
||||
|
||||
function onNavigateSku(skuId: number | undefined) {
|
||||
if (skuId == null || skuId <= 0) return;
|
||||
emit('navigate-sku', skuId);
|
||||
}
|
||||
|
||||
const formatAmount = (amount: number | undefined) => {
|
||||
if (amount === undefined || amount === null) return '-';
|
||||
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
||||
@@ -251,7 +264,16 @@ const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
|
||||
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"
|
||||
v-if="item.skuId > 0"
|
||||
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="onNavigateSku(item.skuId)"
|
||||
>
|
||||
{{ item.skuName }}
|
||||
<JumpIcon class="text-xs" />
|
||||
</span>
|
||||
<span
|
||||
v-else
|
||||
class="inline-flex items-center rounded-full bg-slate-50 px-3 py-1 text-sm font-bold text-slate-500 dark:bg-slate-800/50 dark:text-slate-400"
|
||||
>
|
||||
{{ item.skuName }}
|
||||
</span>
|
||||
|
||||
@@ -388,6 +388,14 @@ function handleProductChange(nextProductId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
function handleSkuNavigate(skuId: number) {
|
||||
if (!skuId || skuId <= 0) return;
|
||||
router.push({
|
||||
path: `/ec/sku/overview/${skuId}`,
|
||||
query: buildProductOverviewQuery(),
|
||||
});
|
||||
}
|
||||
|
||||
const timeRangeState = computed(() => ({
|
||||
taxRate: taxRate.value,
|
||||
activeTimeRange: activeTimeRange.value,
|
||||
@@ -613,6 +621,7 @@ onUnmounted(() => {
|
||||
:data="overviewData?.specSummaries?.list ?? []"
|
||||
:footer-total="overviewData?.specSummaries?.total"
|
||||
:tax-rate="taxRate"
|
||||
@navigate-sku="handleSkuNavigate"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SkuOverviewVO } from '#/api/ec/sku/overview';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
SKU_HERO_SHELL,
|
||||
SKU_SPOT_CARD,
|
||||
} from '../constants/sku-ui';
|
||||
|
||||
defineOptions({ name: 'SkuOverviewHero' });
|
||||
|
||||
const props = defineProps<{
|
||||
data: SkuOverviewVO.Overview;
|
||||
dateLabel?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'navigate-product'): void;
|
||||
}>();
|
||||
|
||||
const IconBarcode = createIconifyIcon('lucide:barcode');
|
||||
const IconPackage = createIconifyIcon('lucide:package');
|
||||
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,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
const canNavigateProduct = computed(
|
||||
() =>
|
||||
props.data.productId != null &&
|
||||
Number.isFinite(props.data.productId) &&
|
||||
props.data.productId > 0,
|
||||
);
|
||||
|
||||
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}%`;
|
||||
}
|
||||
|
||||
function handleProductClick() {
|
||||
if (!canNavigateProduct.value) return;
|
||||
emit('navigate-product');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section :class="SKU_HERO_SHELL">
|
||||
<div
|
||||
class="pointer-events-none absolute -right-8 -top-10 size-40 rounded-full bg-indigo-200/30 blur-2xl dark:bg-indigo-500/10"
|
||||
/>
|
||||
<div
|
||||
class="pointer-events-none absolute -bottom-12 left-1/3 size-48 rounded-full bg-slate-200/25 blur-3xl dark:bg-slate-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-indigo-600 text-white shadow-sm shadow-indigo-600/25 dark:bg-indigo-500"
|
||||
>
|
||||
<component :is="IconBarcode" class="size-4" />
|
||||
</span>
|
||||
<span
|
||||
class="rounded-full bg-indigo-600/10 px-2 py-0.5 text-[11px] font-semibold text-indigo-700 dark:bg-indigo-400/10 dark:text-indigo-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.skuName"
|
||||
>
|
||||
{{ data.skuName || '未命名 SKU' }}
|
||||
</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="data.skuCode">编码 {{ data.skuCode }}</span>
|
||||
<span v-if="canNavigateProduct" class="inline-flex items-center gap-1">
|
||||
<component :is="IconPackage" class="size-3 shrink-0" />
|
||||
所属商品
|
||||
<button
|
||||
type="button"
|
||||
class="max-w-[16rem] truncate font-medium text-indigo-700 underline-offset-2 hover:text-indigo-900 hover:underline dark:text-indigo-300 dark:hover:text-indigo-200"
|
||||
:title="data.productName"
|
||||
@click="handleProductClick"
|
||||
>
|
||||
{{ data.productName || `商品 #${data.productId}` }}
|
||||
</button>
|
||||
</span>
|
||||
<span v-else-if="data.productName">
|
||||
所属商品 {{ data.productName }}
|
||||
</span>
|
||||
<span v-if="dateLabel">统计区间 {{ dateLabel }}</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="SKU_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-indigo-600/80 dark:text-indigo-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>
|
||||
+302
@@ -0,0 +1,302 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { DatePicker, InputNumber, Popover } 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 Props {
|
||||
modelValue: {
|
||||
taxRate: number;
|
||||
activeTimeRange:
|
||||
| '7days'
|
||||
| '30days'
|
||||
| 'thisMonth'
|
||||
| 'custom'
|
||||
| 'today'
|
||||
| 'yesterday';
|
||||
customDateRange: [Dayjs, Dayjs] | undefined;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
};
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', val: Props['modelValue']): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
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 CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||
|
||||
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 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 === '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>
|
||||
@@ -0,0 +1,16 @@
|
||||
/** SKU 概览:靛蓝/slate-blue 强调,与商品青绿、品类玫红、店铺琥珀、平台紫区分 */
|
||||
|
||||
export const SKU_PAGE_BG =
|
||||
'bg-[#f4f6fb] dark:bg-[hsl(222deg_22%_8%)]';
|
||||
|
||||
export const SKU_PANEL_SHELL =
|
||||
'overflow-hidden rounded-[16px] border border-indigo-200/70 bg-white shadow-[0_1px_2px_rgba(67,56,202,0.04),0_10px_28px_rgba(67,56,202,0.05)] dark:border-indigo-900/40 dark:bg-[hsl(222deg_16%_11%)] dark:shadow-none';
|
||||
|
||||
export const SKU_HERO_SHELL =
|
||||
'relative overflow-hidden rounded-[18px] border border-indigo-200/80 bg-gradient-to-br from-indigo-50 via-white to-slate-100/80 p-5 shadow-[0_1px_2px_rgba(67,56,202,0.05),0_12px_32px_rgba(67,56,202,0.07)] md:p-6 dark:border-indigo-900/45 dark:from-indigo-950/40 dark:via-[hsl(222deg_16%_11%)] dark:to-slate-950/30 dark:shadow-none';
|
||||
|
||||
export const SKU_SPOT_CARD =
|
||||
'min-w-0 rounded-[14px] border border-indigo-100/90 bg-white/80 px-3.5 py-3 backdrop-blur-sm dark:border-indigo-900/35 dark:bg-[hsl(222deg_16%_12%/80%)]';
|
||||
|
||||
export const SKU_SECTION_LABEL =
|
||||
'inline-flex items-center gap-1.5 rounded-full border border-indigo-200/80 bg-indigo-50/80 px-2.5 py-0.5 text-[11px] font-semibold tracking-wide text-indigo-800 dark:border-indigo-800/50 dark:bg-indigo-950/40 dark:text-indigo-300';
|
||||
@@ -0,0 +1,436 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SkuOverviewVO } from '#/api/ec/sku/overview';
|
||||
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 { useTabs } from '@vben/hooks';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Spin } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getSkuOverviewApi } from '#/api/ec/sku/overview';
|
||||
import {
|
||||
applyOverviewDateRangeFromUrl,
|
||||
buildOverviewRouteQuery,
|
||||
parseOverviewShopIdFromQuery,
|
||||
syncOverviewDateRangeToUrl,
|
||||
} from '#/utils/overview-date-range';
|
||||
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
|
||||
|
||||
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 SkuHeroBanner from './components/SkuHeroBanner.vue';
|
||||
import {
|
||||
SKU_PAGE_BG,
|
||||
SKU_PANEL_SHELL,
|
||||
SKU_SECTION_LABEL,
|
||||
} from './constants/sku-ui';
|
||||
|
||||
defineOptions({ name: 'SkuOverview' });
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { setTabTitle } = useTabs();
|
||||
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
|
||||
|
||||
/** 当前是否为 SKU 概览路由 */
|
||||
const isSkuOverviewRoute = () =>
|
||||
/\/ec\/sku\/overview\/[^/]+\/?$/.test(route.path);
|
||||
|
||||
const skuId = computed(() => {
|
||||
if (!isSkuOverviewRoute()) return 0;
|
||||
const id = Number(route.params.id);
|
||||
return Number.isFinite(id) && id > 0 ? id : 0;
|
||||
});
|
||||
|
||||
const contextShopId = computed(() => {
|
||||
if (!isSkuOverviewRoute()) return undefined;
|
||||
return parseOverviewShopIdFromQuery(
|
||||
route.query as Record<string, unknown>,
|
||||
);
|
||||
});
|
||||
|
||||
/** 数据加载后用 SKU 名覆盖菜单默认标签 */
|
||||
async function syncSkuTabTitle(name?: null | string) {
|
||||
if (!isSkuOverviewRoute()) return;
|
||||
await setTabTitle(
|
||||
formatOverviewTabTitle(
|
||||
'SKU',
|
||||
name,
|
||||
skuId.value ? `#${skuId.value}` : '概览',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const loading = ref(false);
|
||||
const overviewData = ref<null | SkuOverviewVO.Overview>(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 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);
|
||||
|
||||
async function redrawCharts() {
|
||||
await nextTick();
|
||||
await trendChartRef.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 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);
|
||||
};
|
||||
|
||||
function handleNavigateProduct() {
|
||||
const productId = overviewData.value?.productId;
|
||||
if (productId == null || productId <= 0) return;
|
||||
router.push({
|
||||
path: `/ec/product/overview/${productId}`,
|
||||
query: buildOverviewRouteQuery(
|
||||
dateRange.value,
|
||||
contextShopId.value != null && contextShopId.value > 0
|
||||
? { shopId: contextShopId.value }
|
||||
: undefined,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
const loadOverviewData = async () => {
|
||||
if (!isSkuOverviewRoute() || !skuId.value) return;
|
||||
if (isRequesting.value) return;
|
||||
const requestSkuId = skuId.value;
|
||||
isRequesting.value = true;
|
||||
try {
|
||||
loading.value = true;
|
||||
const [startDate, endDate] = dateRange.value;
|
||||
const res = await getSkuOverviewApi({
|
||||
skuId: requestSkuId,
|
||||
startDate: startDate.format('YYYY-MM-DD'),
|
||||
endDate: endDate.format('YYYY-MM-DD'),
|
||||
taxRate: taxRate.value,
|
||||
...(contextShopId.value != null && contextShopId.value > 0
|
||||
? { shopId: contextShopId.value }
|
||||
: {}),
|
||||
});
|
||||
overviewData.value = res;
|
||||
if (isSkuOverviewRoute() && skuId.value === requestSkuId) {
|
||||
await syncSkuTabTitle(res?.skuName);
|
||||
}
|
||||
await redrawCharts();
|
||||
} catch (err: any) {
|
||||
overviewData.value = null;
|
||||
message.error(err?.message || '加载SKU概览失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
isRequesting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const refreshOverviewByCurrentParams = async (force = false) => {
|
||||
if (!isSkuOverviewRoute()) return;
|
||||
applyDateRangeFromRouteQuery();
|
||||
if (!skuId.value) return;
|
||||
|
||||
const shopKey = contextShopId.value ?? '';
|
||||
const requestKey = `${skuId.value}_${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}_${taxRate.value}_${shopKey}`;
|
||||
if (!force && lastRequestKey.value === requestKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastRequestKey.value = requestKey;
|
||||
await loadOverviewData();
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [
|
||||
route.path,
|
||||
route.params.id,
|
||||
route.query.startDate,
|
||||
route.query.endDate,
|
||||
route.query.shopId,
|
||||
],
|
||||
async () => {
|
||||
if (!isSkuOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams();
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isSkuOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams(true);
|
||||
});
|
||||
|
||||
onActivated(async () => {
|
||||
if (!isSkuOverviewRoute()) return;
|
||||
await refreshOverviewByCurrentParams(true);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page
|
||||
auto-content-height
|
||||
:class="SKU_PAGE_BG"
|
||||
content-padding-class="px-4 pb-4"
|
||||
header-class="sku-overview-page-header"
|
||||
>
|
||||
<template #title>
|
||||
<div
|
||||
class="text-xl font-black tracking-tight text-indigo-950 dark:text-indigo-50 sm:text-2xl md:text-3xl"
|
||||
>
|
||||
SKU 概览
|
||||
</div>
|
||||
<p
|
||||
class="mt-0.5 text-xs font-normal text-indigo-800/70 dark:text-indigo-300/70"
|
||||
>
|
||||
规格诊断 · 穿透商品
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<div class="w-full max-w-full sm:w-auto">
|
||||
<TimeRangeBar
|
||||
:model-value="timeRangeState"
|
||||
@update:model-value="handleTimeRangeChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div
|
||||
v-if="overviewData"
|
||||
class="sku-overview-body mx-auto w-full min-w-0 space-y-4 pt-4"
|
||||
>
|
||||
<SkuHeroBanner
|
||||
:data="overviewData"
|
||||
:date-label="periodDateLabel"
|
||||
@navigate-product="handleNavigateProduct"
|
||||
/>
|
||||
|
||||
<FinanceTrendChart
|
||||
ref="trendChartRef"
|
||||
:trend="dealTrend"
|
||||
:panel-class="SKU_PANEL_SHELL"
|
||||
/>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 pt-1">
|
||||
<div>
|
||||
<span :class="SKU_SECTION_LABEL">指标明细</span>
|
||||
<h2
|
||||
class="mt-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
SKU 经营指标
|
||||
</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-indigo-200 !bg-white !text-indigo-900 shadow-[0_1px_2px_rgba(67,56,202,0.05)] hover:!border-indigo-400 hover:!text-indigo-800 dark:!border-indigo-800/50 dark:!bg-[hsl(222deg_16%_12%)] dark:!text-indigo-200 dark:hover:!border-indigo-500/50 dark:hover:!text-indigo-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"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="!loading"
|
||||
class="flex items-center justify-center p-8 text-slate-400"
|
||||
>
|
||||
暂无数据
|
||||
</div>
|
||||
</Spin>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.sku-overview-page-header) {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:deep(.sku-overview-page-header) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.sku-overview-page-header > div:first-child),
|
||||
:deep(.sku-overview-page-header > div:last-child) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
:deep(.sku-overview-page-header > div:first-child),
|
||||
:deep(.sku-overview-page-header > div:last-child) {
|
||||
width: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user