mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:49:20 +08:00
feat: 完成工作台页的后端接口实现和前端对接
This commit is contained in:
@@ -5,19 +5,36 @@ import { useRouter } from 'vue-router';
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, DatePicker, InputNumber, Select, Tabs } from 'ant-design-vue';
|
||||
import { Button, DatePicker, InputNumber, message, Select, Spin, Tabs } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform/apis';
|
||||
import type { PlatformVO } from '#/api/ecommerce/platform/types';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import { getWorkbenchSummaryApi } from '#/api/ecommerce/workbench/apis';
|
||||
import type { WorkbenchDTO, WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
import { $t } from '#/locales';
|
||||
import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range';
|
||||
|
||||
import { PLATFORM_OPTIONS, STORES } from './data';
|
||||
import WorkbenchFinanceTab from './tabs/finance/WorkbenchFinanceTab.vue';
|
||||
import WorkbenchMultiTab from './tabs/multi/WorkbenchMultiTab.vue';
|
||||
import WorkbenchSalesRankTab from './tabs/sales-rank/WorkbenchSalesRankTab.vue';
|
||||
|
||||
defineOptions({ name: 'PddWorkbench' });
|
||||
|
||||
const EMPTY_WORKBENCH: WorkbenchVO.Info = {
|
||||
finance: { kpis: [], gmvTrend: [], costStructure: [] },
|
||||
multiAnalysis: {
|
||||
platform: [],
|
||||
shop: [],
|
||||
category: [],
|
||||
product: [],
|
||||
},
|
||||
salesRank: { platform: [], shop: [], category: [], product: [] },
|
||||
summaryTables: null,
|
||||
};
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const ImportOrderIcon = createIconifyIcon('lucide:upload');
|
||||
@@ -26,7 +43,7 @@ function goToImportOrder() {
|
||||
void router.push('/import');
|
||||
}
|
||||
|
||||
/** 与全店概览右上角一致:快捷区间 + 自定义 RangePicker(演示页仅本地状态) */
|
||||
/** 与全店概览一致:快捷区间 + 自定义 RangePicker */
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
@@ -95,7 +112,7 @@ const handleCustomDateRangeChange = (
|
||||
dateRange.value = dates;
|
||||
};
|
||||
|
||||
/** 税率(与全店/店铺概览共用 localStorage,便于切换页面时值一致) */
|
||||
/** 税率(与全店/店铺概览共用 localStorage) */
|
||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||
const taxRate = ref<number>(0.04);
|
||||
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
|
||||
@@ -116,20 +133,103 @@ const parseTaxRate = (value: string | undefined) => {
|
||||
return Number.isFinite(num) ? num / 100 : 0;
|
||||
};
|
||||
|
||||
const activeTab = ref('finance');
|
||||
const selectedStoreIndex = ref(0);
|
||||
const selectedPlatform = ref<string>('pdd');
|
||||
const platforms = ref<PlatformVO.Info[]>([]);
|
||||
const shops = ref<ShopVO.Info[]>([]);
|
||||
const metaLoaded = ref(false);
|
||||
|
||||
const storeSelectOptions = computed(() =>
|
||||
STORES.map((s, i) => ({
|
||||
label: `${s.name}(${s.star})`,
|
||||
value: i,
|
||||
const selectedPlatformSlug = ref<string>('all');
|
||||
const selectedShopSlug = ref<string>('all');
|
||||
|
||||
const filteredShops = computed(() => {
|
||||
if (selectedPlatformSlug.value === 'all') {
|
||||
return shops.value;
|
||||
}
|
||||
const pid = Number(selectedPlatformSlug.value);
|
||||
return shops.value.filter((s) => s.platformId === pid);
|
||||
});
|
||||
|
||||
watch(filteredShops, (list) => {
|
||||
if (selectedShopSlug.value === 'all') return;
|
||||
const ok = list.some((s) => String(s.id) === selectedShopSlug.value);
|
||||
if (!ok) selectedShopSlug.value = 'all';
|
||||
});
|
||||
|
||||
const platformSelectOptions = computed(() => [
|
||||
{ label: '全平台', value: 'all' },
|
||||
...platforms.value.map((p) => ({
|
||||
label: p.platformName,
|
||||
value: String(p.id),
|
||||
})),
|
||||
]);
|
||||
|
||||
const shopSelectOptions = computed(() => [
|
||||
{ label: '全部门店', value: 'all' },
|
||||
...filteredShops.value.map((s) => ({
|
||||
label: s.name,
|
||||
value: String(s.id),
|
||||
})),
|
||||
]);
|
||||
|
||||
const workbenchData = ref<WorkbenchVO.Info | null>(null);
|
||||
const workbenchLoading = ref(false);
|
||||
|
||||
const financePanel = computed(
|
||||
() => workbenchData.value?.finance ?? EMPTY_WORKBENCH.finance,
|
||||
);
|
||||
const multiPanel = computed(
|
||||
() => workbenchData.value?.multiAnalysis ?? EMPTY_WORKBENCH.multiAnalysis,
|
||||
);
|
||||
const salesRankPanel = computed(
|
||||
() => workbenchData.value?.salesRank ?? EMPTY_WORKBENCH.salesRank,
|
||||
);
|
||||
const summaryTablesPanel = computed(
|
||||
() => workbenchData.value?.summaryTables ?? null,
|
||||
);
|
||||
|
||||
const platformSelectOptions = computed(() =>
|
||||
PLATFORM_OPTIONS.map((o) => ({ label: o.label, value: o.value })),
|
||||
);
|
||||
async function fetchWorkbenchSummary() {
|
||||
if (!metaLoaded.value) return;
|
||||
workbenchLoading.value = true;
|
||||
try {
|
||||
const query: WorkbenchDTO.Query = {
|
||||
dateRange: [
|
||||
dateRange.value[0].format('YYYY-MM-DD'),
|
||||
dateRange.value[1].format('YYYY-MM-DD'),
|
||||
],
|
||||
taxRate: taxRate.value,
|
||||
};
|
||||
if (selectedPlatformSlug.value !== 'all') {
|
||||
query.platformId = Number(selectedPlatformSlug.value);
|
||||
}
|
||||
if (selectedShopSlug.value !== 'all') {
|
||||
query.shopId = Number(selectedShopSlug.value);
|
||||
}
|
||||
workbenchData.value = await getWorkbenchSummaryApi(query);
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : '工作台数据加载失败';
|
||||
message.error(msg);
|
||||
workbenchData.value = EMPTY_WORKBENCH;
|
||||
} finally {
|
||||
workbenchLoading.value = false;
|
||||
await nextTick();
|
||||
void redrawActiveTabCharts();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadShopAndPlatformMeta() {
|
||||
try {
|
||||
const [platList, shopRes] = await Promise.all([
|
||||
getActivePlatformsApi(),
|
||||
getShopPageApi({ page: 1, pageSize: 500, filters: {} }),
|
||||
]);
|
||||
platforms.value = platList ?? [];
|
||||
shops.value = shopRes?.records ?? [];
|
||||
} catch {
|
||||
message.error('店铺或平台列表加载失败');
|
||||
}
|
||||
metaLoaded.value = true;
|
||||
}
|
||||
|
||||
const activeTab = ref('finance');
|
||||
|
||||
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
|
||||
null,
|
||||
@@ -164,9 +264,19 @@ watch(activeTab, () => {
|
||||
}, 80);
|
||||
});
|
||||
|
||||
watch(
|
||||
[() => dateRange.value, taxRate, selectedPlatformSlug, selectedShopSlug],
|
||||
() => {
|
||||
void fetchWorkbenchSummary();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
let darkObserver: MutationObserver | null = null;
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await loadShopAndPlatformMeta();
|
||||
await fetchWorkbenchSummary();
|
||||
setTimeout(() => {
|
||||
void redrawActiveTabCharts();
|
||||
}, 120);
|
||||
@@ -202,7 +312,7 @@ onUnmounted(() => {
|
||||
|
||||
<template #description>
|
||||
<span class="text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
多店铺 · 多维度经营数据(演示数据,接口就绪后可替换)
|
||||
数据来自接口 POST /ec/workbench/summary,统计口径与「全店概览」一致(订单列表内存聚合)
|
||||
</span>
|
||||
</template>
|
||||
|
||||
@@ -234,7 +344,7 @@ onUnmounted(() => {
|
||||
平台
|
||||
</span>
|
||||
<Select
|
||||
v-model:value="selectedPlatform"
|
||||
v-model:value="selectedPlatformSlug"
|
||||
size="small"
|
||||
:options="platformSelectOptions"
|
||||
placeholder="选择平台"
|
||||
@@ -250,9 +360,9 @@ onUnmounted(() => {
|
||||
店铺
|
||||
</span>
|
||||
<Select
|
||||
v-model:value="selectedStoreIndex"
|
||||
v-model:value="selectedShopSlug"
|
||||
size="small"
|
||||
:options="storeSelectOptions"
|
||||
:options="shopSelectOptions"
|
||||
placeholder="选择店铺"
|
||||
class="workbench-header-select min-w-0 flex-1"
|
||||
/>
|
||||
@@ -374,17 +484,31 @@ onUnmounted(() => {
|
||||
</template>
|
||||
|
||||
<div class="workbench-page-body min-w-0">
|
||||
<Tabs v-model:active-key="activeTab" class="workbench-tabs">
|
||||
<Tabs.TabPane key="finance" tab="经营概览">
|
||||
<WorkbenchFinanceTab ref="financeTabRef" :tax-rate="taxRate" />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="multi" tab="多维分析">
|
||||
<WorkbenchMultiTab ref="multiTabRef" />
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="salesRank" tab="销售额排行榜">
|
||||
<WorkbenchSalesRankTab ref="salesRankTabRef" />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
<Spin :spinning="workbenchLoading">
|
||||
<Tabs v-model:active-key="activeTab" class="workbench-tabs">
|
||||
<Tabs.TabPane key="finance" tab="经营概览">
|
||||
<WorkbenchFinanceTab
|
||||
ref="financeTabRef"
|
||||
:tax-rate="taxRate"
|
||||
:finance="financePanel"
|
||||
:multi-analysis="multiPanel"
|
||||
:summary-tables="summaryTablesPanel"
|
||||
/>
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="multi" tab="多维分析">
|
||||
<WorkbenchMultiTab
|
||||
ref="multiTabRef"
|
||||
:multi-analysis="multiPanel"
|
||||
/>
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane key="salesRank" tab="销售额排行榜">
|
||||
<WorkbenchSalesRankTab
|
||||
ref="salesRankTabRef"
|
||||
:sales-rank="salesRankPanel"
|
||||
/>
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Spin>
|
||||
</div>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
+51
-6
@@ -1,17 +1,50 @@
|
||||
<script lang="ts" setup>
|
||||
import { nextTick, ref } from 'vue';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import WorkbenchFinanceCostPieChart from './components/WorkbenchFinanceCostPieChart.vue';
|
||||
import WorkbenchFinanceKpiGrid from './components/WorkbenchFinanceKpiGrid.vue';
|
||||
import WorkbenchFinanceTrendChart from './components/WorkbenchFinanceTrendChart.vue';
|
||||
import WorkbenchOverviewTables from './components/WorkbenchOverviewTables.vue';
|
||||
|
||||
import {
|
||||
buildCategoryOverviewFromDimRows,
|
||||
buildPlatformOverviewFromDimRows,
|
||||
buildShopOverviewFromDimRows,
|
||||
} from '../../workbench-overview-bridge';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceTab' });
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
taxRate: number;
|
||||
finance: WorkbenchVO.FinancePanel;
|
||||
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||
summaryTables?: CompanyOverviewVO.WorkbenchTableBundle | null;
|
||||
}>();
|
||||
|
||||
const shopOverview = computed(
|
||||
() =>
|
||||
props.summaryTables?.shopTable ??
|
||||
buildShopOverviewFromDimRows(props.multiAnalysis.shop),
|
||||
);
|
||||
const platformOverview = computed(
|
||||
() =>
|
||||
props.summaryTables?.platformTable ??
|
||||
buildPlatformOverviewFromDimRows(props.multiAnalysis.platform),
|
||||
);
|
||||
const categoryOverview = computed(
|
||||
() =>
|
||||
props.summaryTables?.categoryTable ??
|
||||
buildCategoryOverviewFromDimRows(props.multiAnalysis.category),
|
||||
);
|
||||
const productOverview = computed(
|
||||
() =>
|
||||
props.summaryTables?.productTable ??
|
||||
buildCategoryOverviewFromDimRows(props.multiAnalysis.product),
|
||||
);
|
||||
|
||||
const trendChartRef = ref<InstanceType<
|
||||
typeof WorkbenchFinanceTrendChart
|
||||
> | null>(null);
|
||||
@@ -30,11 +63,23 @@ defineExpose({ redraw });
|
||||
|
||||
<template>
|
||||
<div class="mt-4 space-y-6">
|
||||
<WorkbenchFinanceKpiGrid />
|
||||
<WorkbenchFinanceKpiGrid :kpis="finance.kpis" />
|
||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
|
||||
<WorkbenchFinanceTrendChart ref="trendChartRef" />
|
||||
<WorkbenchFinanceCostPieChart ref="costPieRef" />
|
||||
<WorkbenchFinanceTrendChart
|
||||
ref="trendChartRef"
|
||||
:trend="finance.gmvTrend"
|
||||
/>
|
||||
<WorkbenchFinanceCostPieChart
|
||||
ref="costPieRef"
|
||||
:cost-structure="finance.costStructure"
|
||||
/>
|
||||
</div>
|
||||
<WorkbenchOverviewTables :tax-rate="taxRate" />
|
||||
<WorkbenchOverviewTables
|
||||
:tax-rate="taxRate"
|
||||
:shop-summary="shopOverview"
|
||||
:platform-summary="platformOverview"
|
||||
:category-summary="categoryOverview"
|
||||
:product-summary="productOverview"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+36
-12
@@ -1,19 +1,34 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
import { COST_STRUCTURE, COST_STRUCTURE_PIE_COLORS } from '../../../data';
|
||||
import { COST_STRUCTURE_PIE_COLORS } from '../../../data';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceCostPieChart' });
|
||||
|
||||
const props = defineProps<{
|
||||
costStructure: WorkbenchVO.CostSlice[];
|
||||
}>();
|
||||
|
||||
const SLICE_COLOR_BY_NAME: Record<string, string> = {
|
||||
商品成本: COST_STRUCTURE_PIE_COLORS[1] ?? '#f97316',
|
||||
物流费用: COST_STRUCTURE_PIE_COLORS[4] ?? '#fb923c',
|
||||
其他成本: COST_STRUCTURE_PIE_COLORS[5] ?? '#fdba74',
|
||||
推广费: COST_STRUCTURE_PIE_COLORS[2] ?? '#ea580c',
|
||||
刷单费: COST_STRUCTURE_PIE_COLORS[3] ?? '#f43f5e',
|
||||
税费: COST_STRUCTURE_PIE_COLORS[5] ?? '#94a3b8',
|
||||
净利润: COST_STRUCTURE_PIE_COLORS[0] ?? '#059669',
|
||||
};
|
||||
|
||||
const chartOverviewShell =
|
||||
'overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]';
|
||||
|
||||
const costTotal = computed(() =>
|
||||
COST_STRUCTURE.reduce((a, x) => a + x.value, 0),
|
||||
props.costStructure.reduce((a, x) => a + (Number(x.value) || 0), 0),
|
||||
);
|
||||
|
||||
const costPieChartRef = ref<EchartsUIType>();
|
||||
@@ -34,10 +49,8 @@ function drawCostPie() {
|
||||
formatter: (params: any) => {
|
||||
const name = String(params.name ?? '');
|
||||
const val = Number(params.value ?? 0);
|
||||
const row = COST_STRUCTURE.find((r) => r.name === name);
|
||||
const pctText = row
|
||||
? `${row.pct}%(占实收)`
|
||||
: `${Number(params.percent ?? 0).toFixed(1)}%`;
|
||||
const row = props.costStructure.find((r) => r.name === name);
|
||||
const pctText = row?.pct != null ? `${row.pct}%(占销售额)` : '';
|
||||
return `${name}<br/>${val} 万<br/>${pctText}`;
|
||||
},
|
||||
},
|
||||
@@ -72,11 +85,14 @@ function drawCostPie() {
|
||||
length2: 8,
|
||||
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' },
|
||||
},
|
||||
data: COST_STRUCTURE.map((row, i) => ({
|
||||
data: props.costStructure.map((row, i) => ({
|
||||
name: row.name,
|
||||
value: row.value,
|
||||
value: row.value ?? 0,
|
||||
itemStyle: {
|
||||
color: COST_STRUCTURE_PIE_COLORS[i] ?? '#6366f1',
|
||||
color:
|
||||
SLICE_COLOR_BY_NAME[row.name] ??
|
||||
COST_STRUCTURE_PIE_COLORS[i] ??
|
||||
'#6366f1',
|
||||
},
|
||||
})),
|
||||
},
|
||||
@@ -93,6 +109,14 @@ onMounted(() => {
|
||||
void redraw();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.costStructure,
|
||||
() => {
|
||||
void redraw();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
@@ -104,13 +128,13 @@ defineExpose({ redraw });
|
||||
<h3
|
||||
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
成本结构拆解(占实收比例示意)
|
||||
成本结构(占销售额 %)
|
||||
</h3>
|
||||
<p
|
||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
合计约 {{ costTotal.toFixed(1) }} 万 ·
|
||||
扇区按金额(万)占比;悬浮可见占实收比例
|
||||
扇区金额单位:万元;悬浮可见占销售额比例
|
||||
</p>
|
||||
</div>
|
||||
<div class="px-6 py-5 md:px-8 md:py-6">
|
||||
|
||||
+14
-4
@@ -1,15 +1,25 @@
|
||||
<script lang="ts" setup>
|
||||
import { FINANCE_KPIS } from '../../../data';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceKpiGrid' });
|
||||
|
||||
defineProps<{
|
||||
kpis: WorkbenchVO.KpiItem[];
|
||||
}>();
|
||||
|
||||
const kpiCardClass =
|
||||
'rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-5 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px] sm:p-6';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div v-for="(kpi, idx) in FINANCE_KPIS" :key="idx" :class="kpiCardClass">
|
||||
<div
|
||||
v-if="kpis.length === 0"
|
||||
class="rounded-2xl border border-dashed border-slate-200 bg-white/60 px-6 py-10 text-center text-sm font-bold text-slate-400 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
暂无 KPI 数据(请调整筛选或日期范围)
|
||||
</div>
|
||||
<div v-else class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div v-for="(kpi, idx) in kpis" :key="idx" :class="kpiCardClass">
|
||||
<div class="mb-3 flex items-start justify-between gap-2">
|
||||
<span
|
||||
class="text-xs font-black text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@@ -24,7 +34,7 @@ const kpiCardClass =
|
||||
: 'bg-red-50 text-red-600 dark:bg-red-900/25 dark:text-red-400'
|
||||
"
|
||||
>
|
||||
{{ kpi.up ? '▲' : '▼' }}{{ kpi.changePct
|
||||
{{ kpi.up ? '▲' : '▼' }}{{ kpi.changePct ?? 0
|
||||
}}{{ kpi.label === '广告ROI' ? '' : '%' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
+22
-11
@@ -1,14 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { nextTick, onMounted, ref } from 'vue';
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
import { GMV_TREND } from '../../../data';
|
||||
|
||||
defineOptions({ name: 'WorkbenchFinanceTrendChart' });
|
||||
|
||||
const props = defineProps<{
|
||||
trend: WorkbenchVO.TrendPoint[];
|
||||
}>();
|
||||
|
||||
const chartOverviewShell =
|
||||
'overflow-hidden rounded-2xl border border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-white/90 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:shadow-none backdrop-blur-[10px]';
|
||||
|
||||
@@ -30,7 +33,7 @@ function drawFinanceTrend() {
|
||||
legend: {
|
||||
top: 0,
|
||||
textStyle: { color: axisLabel, fontWeight: 700 },
|
||||
data: ['GMV(万)', '净利润(万)', '退款(万)'],
|
||||
data: ['GMV(万)', '毛利(万)', '退款(万)'],
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
@@ -41,7 +44,7 @@ function drawFinanceTrend() {
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: GMV_TREND.map((d) => d.date),
|
||||
data: props.trend.map((d) => d.date),
|
||||
axisLine: { lineStyle: { color: split } },
|
||||
axisLabel: { color: axisLabel, fontSize: 11 },
|
||||
},
|
||||
@@ -54,7 +57,7 @@ function drawFinanceTrend() {
|
||||
{
|
||||
name: 'GMV(万)',
|
||||
type: 'bar',
|
||||
data: GMV_TREND.map((d) => d.gmv),
|
||||
data: props.trend.map((d) => d.gmv ?? 0),
|
||||
barMaxWidth: 14,
|
||||
itemStyle: {
|
||||
color: {
|
||||
@@ -76,18 +79,18 @@ function drawFinanceTrend() {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: '净利润(万)',
|
||||
name: '毛利(万)',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbolSize: 6,
|
||||
data: GMV_TREND.map((d) => d.profit),
|
||||
data: props.trend.map((d) => d.profit ?? 0),
|
||||
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||
},
|
||||
{
|
||||
name: '退款(万)',
|
||||
type: 'bar',
|
||||
data: GMV_TREND.map((d) => d.refund),
|
||||
data: props.trend.map((d) => d.refund ?? 0),
|
||||
barMaxWidth: 8,
|
||||
itemStyle: {
|
||||
color: isDark
|
||||
@@ -108,6 +111,14 @@ onMounted(() => {
|
||||
void redraw();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.trend,
|
||||
() => {
|
||||
void redraw();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
@@ -119,12 +130,12 @@ defineExpose({ redraw });
|
||||
<h3
|
||||
class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
GMV 与净利润趋势
|
||||
GMV 与毛利趋势
|
||||
</h3>
|
||||
<p
|
||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
柱=GMV,线=净利润,浅柱=退款(示例区间)
|
||||
柱=GMV,线=日毛利(销售额−成本−退款),浅柱=退款;与全店概览订单口径一致
|
||||
</p>
|
||||
</div>
|
||||
<div class="px-6 py-5 md:px-8 md:py-6">
|
||||
|
||||
+28
-29
@@ -2,30 +2,30 @@
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||
|
||||
import { message, Segmented } from 'ant-design-vue';
|
||||
|
||||
import CategoryComparisonTable from '../../../../store-overview/components/CategoryComparisonTable.vue';
|
||||
import PlatformSummaryCard from '../../../../store-overview/components/PlatformSummaryCard.vue';
|
||||
import ShopComparisonTable from '../../../../store-overview/components/ShopComparisonTable.vue';
|
||||
import {
|
||||
getWorkbenchCategoryOverview,
|
||||
getWorkbenchPlatformOverview,
|
||||
getWorkbenchProductAsCategoryOverview,
|
||||
getWorkbenchShopOverview,
|
||||
} from '../../../overview-mock';
|
||||
|
||||
defineOptions({ name: 'WorkbenchOverviewTables' });
|
||||
|
||||
withDefaults(defineProps<{ taxRate?: number }>(), {
|
||||
taxRate: 0.04,
|
||||
});
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
taxRate?: number;
|
||||
shopSummary?: CompanyOverviewVO.ShopOverview | null;
|
||||
platformSummary?: CompanyOverviewVO.PlatformOverview | null;
|
||||
categorySummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||
productSummary?: CompanyOverviewVO.CategoryOverview | null;
|
||||
}>(),
|
||||
{
|
||||
taxRate: 0.04,
|
||||
},
|
||||
);
|
||||
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
|
||||
|
||||
const shopOverview = getWorkbenchShopOverview();
|
||||
const platformOverview = getWorkbenchPlatformOverview();
|
||||
const categoryOverview = getWorkbenchCategoryOverview();
|
||||
const productOverview = getWorkbenchProductAsCategoryOverview();
|
||||
|
||||
const shopExportMode = ref(false);
|
||||
const selectedExportShopIds = ref<number[]>([]);
|
||||
const platformExportMode = ref(false);
|
||||
@@ -45,7 +45,7 @@ const modeOptions = [
|
||||
];
|
||||
|
||||
function demoExportHint() {
|
||||
message.warning('工作台为静态演示,导出请使用「全店概览」页面');
|
||||
message.warning('工作台明细与全店概览同源;批量导出请使用「全店概览」页面');
|
||||
}
|
||||
|
||||
function navigateToShopOverview(shopId: number) {
|
||||
@@ -60,8 +60,7 @@ function navigateToShopOverview(shopId: number) {
|
||||
<p
|
||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
下列表格与「全店概览」使用相同组件与列结构(演示数据,可替换为接口返回的
|
||||
VO)。
|
||||
下列表格与「全店概览」使用相同组件;四表数据由工作台接口按订单、推广费、刷单与店铺月度目标等口径汇总(与全店概览后端计算一致)。若接口未返回汇总表字段,则回退为按维度行估算(部分列为「-」)。
|
||||
</p>
|
||||
<div class="flex justify-end">
|
||||
<Segmented
|
||||
@@ -73,9 +72,9 @@ function navigateToShopOverview(shopId: number) {
|
||||
|
||||
<ShopComparisonTable
|
||||
v-if="activeMode === 'shop'"
|
||||
heading-title="各店铺多维度经营明细汇总(演示)"
|
||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
||||
:shop-summary="shopOverview"
|
||||
heading-title="各店铺多维度经营明细汇总"
|
||||
heading-subtitle="与全店概览同款表格;金额与目标等为后端汇总口径(元)"
|
||||
:shop-summary="shopSummary ?? undefined"
|
||||
:tax-rate="taxRate"
|
||||
:shop-export-mode="shopExportMode"
|
||||
:selected-export-shop-ids="selectedExportShopIds"
|
||||
@@ -87,9 +86,9 @@ function navigateToShopOverview(shopId: number) {
|
||||
|
||||
<PlatformSummaryCard
|
||||
v-if="activeMode === 'platform'"
|
||||
heading-title="各平台多维度经营明细汇总(演示)"
|
||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
||||
:platform-summary="platformOverview"
|
||||
heading-title="各平台多维度经营明细汇总"
|
||||
heading-subtitle="与全店概览同款表格"
|
||||
:platform-summary="platformSummary ?? undefined"
|
||||
:tax-rate="taxRate"
|
||||
:platform-export-mode="platformExportMode"
|
||||
:selected-export-platform-ids="selectedExportPlatformIds"
|
||||
@@ -100,9 +99,9 @@ function navigateToShopOverview(shopId: number) {
|
||||
|
||||
<CategoryComparisonTable
|
||||
v-if="activeMode === 'category'"
|
||||
heading-title="各品类多维度经营明细汇总(演示)"
|
||||
heading-subtitle="与「全店概览」同款表格;对接接口后可替换为实时数据"
|
||||
:category-summary="categoryOverview"
|
||||
heading-title="各品类多维度经营明细汇总"
|
||||
heading-subtitle="与全店概览同款表格"
|
||||
:category-summary="categorySummary ?? undefined"
|
||||
:tax-rate="taxRate"
|
||||
:category-export-mode="categoryExportMode"
|
||||
:selected-export-category-ids="selectedExportCategoryIds"
|
||||
@@ -113,10 +112,10 @@ function navigateToShopOverview(shopId: number) {
|
||||
|
||||
<CategoryComparisonTable
|
||||
v-if="activeMode === 'product'"
|
||||
heading-title="各商品多维度经营明细汇总(演示)"
|
||||
heading-subtitle="列结构与品类表一致,首列为商品名称;对接接口后可替换为实时数据"
|
||||
heading-title="各商品多维度经营明细汇总"
|
||||
heading-subtitle="列结构与品类表一致;数据与全店概览商品维度同源"
|
||||
first-column-label="商品"
|
||||
:category-summary="productOverview"
|
||||
:category-summary="productSummary ?? undefined"
|
||||
:tax-rate="taxRate"
|
||||
:category-export-mode="productExportMode"
|
||||
:selected-export-category-ids="selectedExportProductIds"
|
||||
|
||||
+12
-2
@@ -1,10 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import WorkbenchMultiDimCardsGrid from './components/WorkbenchMultiDimCardsGrid.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchMultiTab' });
|
||||
|
||||
defineProps<{
|
||||
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||
}>();
|
||||
|
||||
const gridRef = ref<InstanceType<typeof WorkbenchMultiDimCardsGrid> | null>(
|
||||
null,
|
||||
);
|
||||
@@ -22,8 +28,12 @@ defineExpose({ redraw });
|
||||
<p
|
||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
按平台、店铺、品类、商品各一张卡,分别对比销售额、毛利额、净利额、退款及毛利率/净利率(演示数据)
|
||||
按平台、店铺、品类、商品各一张卡;数据与全店概览订单统计口径一致
|
||||
</p>
|
||||
<WorkbenchMultiDimCardsGrid ref="gridRef" />
|
||||
<WorkbenchMultiDimCardsGrid
|
||||
ref="gridRef"
|
||||
:multi-analysis="multiAnalysis"
|
||||
live-data
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+43
-17
@@ -2,8 +2,9 @@
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import type { WorkbenchDimKey } from '../../../data';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
@@ -15,6 +16,10 @@ const props = defineProps<{
|
||||
dimension: WorkbenchDimKey;
|
||||
title: string;
|
||||
variant: 'analysis' | 'rank';
|
||||
/** 接口维度行;未传时使用本地演示数据 */
|
||||
rows?: WorkbenchVO.DimRow[];
|
||||
/** 为 true 时排行图不展示演示环比 */
|
||||
liveData?: boolean;
|
||||
}>();
|
||||
|
||||
/** 多维分析:不在卡片上 overflow-hidden,避免底部 X 轴类目名被裁掉 */
|
||||
@@ -38,21 +43,29 @@ function multiChartGridBottomPx(
|
||||
return 44;
|
||||
}
|
||||
|
||||
const rows = computed(() => WORKBENCH_MULTI_BY_DIM[props.dimension]);
|
||||
const rows = computed(() =>
|
||||
props.rows !== undefined
|
||||
? props.rows
|
||||
: WORKBENCH_MULTI_BY_DIM[props.dimension],
|
||||
);
|
||||
|
||||
const rankMomDemo = [16.2, 11.4, 8.8, -2.1, 6.5, 4.2, 3.8, 2.4];
|
||||
|
||||
const rankRows = computed(() => {
|
||||
const raw = [...rows.value];
|
||||
const sorted = raw.sort((a, b) => b.gmvWan - a.gmvWan);
|
||||
const total = sorted.reduce((s, r) => s + r.gmvWan, 0) || 1;
|
||||
const sorted = raw.sort(
|
||||
(a, b) => Number(b.gmvWan ?? 0) - Number(a.gmvWan ?? 0),
|
||||
);
|
||||
const total = sorted.reduce((s, r) => s + Number(r.gmvWan ?? 0), 0) || 1;
|
||||
return sorted.map((r, i) => ({
|
||||
rank: i + 1,
|
||||
key: r.key,
|
||||
name: r.name,
|
||||
gmvWan: r.gmvWan,
|
||||
sharePct: Number(((r.gmvWan / total) * 100).toFixed(1)),
|
||||
momPct: rankMomDemo[i % rankMomDemo.length] ?? 0,
|
||||
gmvWan: Number(r.gmvWan ?? 0),
|
||||
sharePct: Number(((Number(r.gmvWan ?? 0) / total) * 100).toFixed(1)),
|
||||
momPct: props.liveData
|
||||
? 0
|
||||
: (rankMomDemo[i % rankMomDemo.length] ?? 0),
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -123,28 +136,28 @@ const drawMultiBarChart = () => {
|
||||
{
|
||||
name: '销售额(万)',
|
||||
type: 'bar',
|
||||
data: r.map((row) => row.gmvWan),
|
||||
data: r.map((row) => Number(row.gmvWan ?? 0)),
|
||||
barMaxWidth: 16,
|
||||
itemStyle: { color: isDark ? '#60a5fa' : '#2563eb' },
|
||||
},
|
||||
{
|
||||
name: '毛利额(万)',
|
||||
type: 'bar',
|
||||
data: r.map((row) => row.grossProfitWan),
|
||||
data: r.map((row) => Number(row.grossProfitWan ?? 0)),
|
||||
barMaxWidth: 16,
|
||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||
},
|
||||
{
|
||||
name: '净利额(万)',
|
||||
type: 'bar',
|
||||
data: r.map((row) => row.netProfitWan),
|
||||
data: r.map((row) => Number(row.netProfitWan ?? 0)),
|
||||
barMaxWidth: 16,
|
||||
itemStyle: { color: isDark ? '#a78bfa' : '#7c3aed' },
|
||||
},
|
||||
{
|
||||
name: '退款金额(万)',
|
||||
type: 'bar',
|
||||
data: r.map((row) => row.refundWan),
|
||||
data: r.map((row) => Number(row.refundWan ?? 0)),
|
||||
barMaxWidth: 16,
|
||||
itemStyle: { color: isDark ? '#fb7185' : '#e11d48' },
|
||||
},
|
||||
@@ -209,7 +222,7 @@ const drawMultiLineChart = () => {
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbolSize: 6,
|
||||
data: r.map((row) => row.grossMarginPct),
|
||||
data: r.map((row) => Number(row.grossMarginPct ?? 0)),
|
||||
lineStyle: { width: 2.5, color: isDark ? '#34d399' : '#059669' },
|
||||
itemStyle: { color: isDark ? '#34d399' : '#059669' },
|
||||
},
|
||||
@@ -218,7 +231,7 @@ const drawMultiLineChart = () => {
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbolSize: 6,
|
||||
data: r.map((row) => row.netMarginPct),
|
||||
data: r.map((row) => Number(row.netMarginPct ?? 0)),
|
||||
lineStyle: { width: 2.5, color: isDark ? '#fbbf24' : '#d97706' },
|
||||
itemStyle: { color: isDark ? '#fbbf24' : '#d97706' },
|
||||
},
|
||||
@@ -255,7 +268,10 @@ const drawRankBarChart = () => {
|
||||
if (!row) return '';
|
||||
const mom =
|
||||
row.momPct >= 0 ? `▲${row.momPct}` : `▼${Math.abs(row.momPct)}`;
|
||||
return `${row.name}<br/>${p?.marker ?? ''} 销售额 <b>${row.gmvWan}</b> 万<br/>占合计 <b>${row.sharePct}%</b><br/>环比 <b>${mom}%</b>`;
|
||||
const momLine = props.liveData
|
||||
? ''
|
||||
: `<br/>环比 <b>${mom}%</b>(演示)`;
|
||||
return `${row.name}<br/>${p?.marker ?? ''} 销售额 <b>${row.gmvWan}</b> 万<br/>占合计 <b>${row.sharePct}%</b>${momLine}`;
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
@@ -284,7 +300,7 @@ const drawRankBarChart = () => {
|
||||
{
|
||||
name: '销售额(万)',
|
||||
type: 'bar',
|
||||
data: r.map((row) => row.gmvWan),
|
||||
data: r.map((row) => Number(row.gmvWan ?? 0)),
|
||||
barMaxWidth: 22,
|
||||
itemStyle: {
|
||||
borderRadius: [0, 8, 8, 0],
|
||||
@@ -319,6 +335,14 @@ onMounted(() => {
|
||||
void redraw();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => [props.rows, props.dimension, props.variant, props.liveData],
|
||||
() => {
|
||||
void redraw();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
defineExpose({ redraw });
|
||||
</script>
|
||||
|
||||
@@ -335,7 +359,8 @@ defineExpose({ redraw });
|
||||
<p
|
||||
class="mt-0.5 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
销售/毛利/净利/退款(柱)与毛利率、净利率(线)· 演示数据
|
||||
销售/毛利/净利/退款(柱)与毛利率、净利率(线)·
|
||||
{{ liveData ? '接口数据(与全店概览订单口径一致)' : '演示数据' }}
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
@@ -376,7 +401,8 @@ defineExpose({ redraw });
|
||||
<p
|
||||
class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
自上而下为第 1 名;悬浮查看占合计与环比(演示数据)
|
||||
自上而下为第 1 名;悬浮查看占合计
|
||||
{{ liveData ? '(接口数据)' : '与环比(演示)' }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="mt-4 h-[320px] min-h-0 w-full overflow-hidden md:h-[360px]">
|
||||
|
||||
+15
@@ -1,10 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import WorkbenchDimChartsCard from './WorkbenchDimChartsCard.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchMultiDimCardsGrid' });
|
||||
|
||||
const props = defineProps<{
|
||||
multiAnalysis: WorkbenchVO.MultiPanel;
|
||||
liveData?: boolean;
|
||||
}>();
|
||||
|
||||
const multiPlatformCardRef = ref<InstanceType<
|
||||
typeof WorkbenchDimChartsCard
|
||||
> | null>(null);
|
||||
@@ -42,24 +49,32 @@ defineExpose({ redraw });
|
||||
dimension="platform"
|
||||
variant="analysis"
|
||||
title="平台"
|
||||
:rows="props.multiAnalysis.platform"
|
||||
:live-data="props.liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="multiShopCardRef"
|
||||
dimension="shop"
|
||||
variant="analysis"
|
||||
title="店铺"
|
||||
:rows="props.multiAnalysis.shop"
|
||||
:live-data="props.liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="multiCategoryCardRef"
|
||||
dimension="category"
|
||||
variant="analysis"
|
||||
title="品类"
|
||||
:rows="props.multiAnalysis.category"
|
||||
:live-data="props.liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="multiProductCardRef"
|
||||
dimension="product"
|
||||
variant="analysis"
|
||||
title="商品"
|
||||
:rows="props.multiAnalysis.product"
|
||||
:live-data="props.liveData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+8
-2
@@ -1,10 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import WorkbenchSalesRankCardsGrid from './components/WorkbenchSalesRankCardsGrid.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchSalesRankTab' });
|
||||
|
||||
defineProps<{
|
||||
salesRank: WorkbenchVO.MultiPanel;
|
||||
}>();
|
||||
|
||||
const gridRef = ref<InstanceType<typeof WorkbenchSalesRankCardsGrid> | null>(
|
||||
null,
|
||||
);
|
||||
@@ -22,8 +28,8 @@ defineExpose({ redraw });
|
||||
<p
|
||||
class="text-xs font-bold text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
各维度独立排行:平台、店铺、品类、商品销售额 TOP(演示数据)
|
||||
各维度按销售额排序;接口未返回环比时仅展示占比
|
||||
</p>
|
||||
<WorkbenchSalesRankCardsGrid ref="gridRef" />
|
||||
<WorkbenchSalesRankCardsGrid ref="gridRef" :sales-rank="salesRank" live-data />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+15
@@ -1,10 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
import { nextTick, ref } from 'vue';
|
||||
|
||||
import WorkbenchDimChartsCard from '../../multi/components/WorkbenchDimChartsCard.vue';
|
||||
|
||||
defineOptions({ name: 'WorkbenchSalesRankCardsGrid' });
|
||||
|
||||
defineProps<{
|
||||
salesRank: WorkbenchVO.MultiPanel;
|
||||
liveData?: boolean;
|
||||
}>();
|
||||
|
||||
const rankPlatformCardRef = ref<InstanceType<
|
||||
typeof WorkbenchDimChartsCard
|
||||
> | null>(null);
|
||||
@@ -42,24 +49,32 @@ defineExpose({ redraw });
|
||||
dimension="platform"
|
||||
variant="rank"
|
||||
title="平台"
|
||||
:rows="salesRank.platform"
|
||||
:live-data="liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="rankShopCardRef"
|
||||
dimension="shop"
|
||||
variant="rank"
|
||||
title="店铺"
|
||||
:rows="salesRank.shop"
|
||||
:live-data="liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="rankCategoryCardRef"
|
||||
dimension="category"
|
||||
variant="rank"
|
||||
title="品类"
|
||||
:rows="salesRank.category"
|
||||
:live-data="liveData"
|
||||
/>
|
||||
<WorkbenchDimChartsCard
|
||||
ref="rankProductCardRef"
|
||||
dimension="product"
|
||||
variant="rank"
|
||||
title="商品"
|
||||
:rows="salesRank.product"
|
||||
:live-data="liveData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
|
||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||
|
||||
function wanToYuan(w?: number | null): number {
|
||||
const n = Number(w);
|
||||
if (!Number.isFinite(n)) return 0;
|
||||
return Math.round(n * 10_000 * 100) / 100;
|
||||
}
|
||||
|
||||
function dimRowToShopSummary(row: WorkbenchVO.DimRow): CompanyOverviewVO.ShopSummary {
|
||||
const salesAmount = wanToYuan(row.gmvWan);
|
||||
const refundAmount = wanToYuan(row.refundWan);
|
||||
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||
const shopId = Number(row.key);
|
||||
return {
|
||||
shopId: Number.isFinite(shopId) ? shopId : 0,
|
||||
shopName: row.name,
|
||||
salesAmount,
|
||||
refundAmount,
|
||||
totalCost,
|
||||
productCost: totalCost,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
totalProfitBeforeTax: grossYuan,
|
||||
profitAfterTax,
|
||||
};
|
||||
}
|
||||
|
||||
function aggregateShopTotal(
|
||||
shops: CompanyOverviewVO.ShopSummary[],
|
||||
): CompanyOverviewVO.ShopSummary {
|
||||
const sum = (k: keyof CompanyOverviewVO.ShopSummary) =>
|
||||
shops.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||
const salesAmount = sum('salesAmount');
|
||||
const orderCount = sum('orderCount') || 1;
|
||||
const totalPromotionFee = sum('totalPromotionFee');
|
||||
const averageOrderValue = salesAmount / orderCount;
|
||||
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||
return {
|
||||
shopId: 0,
|
||||
shopName: '合计',
|
||||
targetOrderCount: sum('targetOrderCount'),
|
||||
orderCountAchievementRate: sum('orderCountAchievementRate'),
|
||||
targetAmount: sum('targetAmount'),
|
||||
salesAmountAchievementRate: sum('salesAmountAchievementRate'),
|
||||
salesAmount,
|
||||
orderCount: sum('orderCount'),
|
||||
averageOrderValue,
|
||||
productCost: sum('productCost'),
|
||||
shippingCost: sum('shippingCost'),
|
||||
otherCost: sum('otherCost'),
|
||||
totalCost: sum('totalCost'),
|
||||
refundAmount: sum('refundAmount'),
|
||||
totalPromotionFee,
|
||||
brushFee: sum('brushFee'),
|
||||
feeRatio,
|
||||
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||
salesTaxAmount: sum('salesTaxAmount'),
|
||||
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||
profitAfterTax: sum('profitAfterTax'),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildShopOverviewFromDimRows(
|
||||
rows: WorkbenchVO.DimRow[],
|
||||
): CompanyOverviewVO.ShopOverview {
|
||||
const shops = rows.map(dimRowToShopSummary);
|
||||
return { total: aggregateShopTotal(shops), shops };
|
||||
}
|
||||
|
||||
function dimRowToCategorySummary(
|
||||
row: WorkbenchVO.DimRow,
|
||||
): CompanyOverviewVO.CategorySummary {
|
||||
const salesAmount = wanToYuan(row.gmvWan);
|
||||
const refundAmount = wanToYuan(row.refundWan);
|
||||
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||
const rawId = Number(row.key);
|
||||
const categoryId =
|
||||
row.key === '0' || !Number.isFinite(rawId) ? undefined : rawId;
|
||||
return {
|
||||
categoryId,
|
||||
categoryName: row.name,
|
||||
salesAmount,
|
||||
refundAmount,
|
||||
totalCost,
|
||||
productCost: totalCost,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
totalProfitBeforeTax: grossYuan,
|
||||
profitAfterTax,
|
||||
};
|
||||
}
|
||||
|
||||
function aggregateCategoryTotal(
|
||||
rows: CompanyOverviewVO.CategorySummary[],
|
||||
): CompanyOverviewVO.CategorySummary {
|
||||
const sum = (k: keyof CompanyOverviewVO.CategorySummary) =>
|
||||
rows.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||
const salesAmount = sum('salesAmount');
|
||||
const orderCount = sum('orderCount') || 1;
|
||||
const totalPromotionFee = sum('totalPromotionFee');
|
||||
const averageOrderValue = salesAmount / orderCount;
|
||||
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||
return {
|
||||
categoryName: '合计',
|
||||
salesAmount,
|
||||
orderCount: sum('orderCount'),
|
||||
averageOrderValue,
|
||||
productCost: sum('productCost'),
|
||||
shippingCost: sum('shippingCost'),
|
||||
otherCost: sum('otherCost'),
|
||||
totalCost: sum('totalCost'),
|
||||
refundAmount: sum('refundAmount'),
|
||||
totalPromotionFee,
|
||||
brushFee: sum('brushFee'),
|
||||
feeRatio,
|
||||
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||
salesTaxAmount: sum('salesTaxAmount'),
|
||||
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||
profitAfterTax: sum('profitAfterTax'),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildCategoryOverviewFromDimRows(
|
||||
rows: WorkbenchVO.DimRow[],
|
||||
): CompanyOverviewVO.CategoryOverview {
|
||||
const categories = rows.map(dimRowToCategorySummary);
|
||||
return { total: aggregateCategoryTotal(categories), categories };
|
||||
}
|
||||
|
||||
function dimRowToPlatformSummary(
|
||||
row: WorkbenchVO.DimRow,
|
||||
): CompanyOverviewVO.PlatformSummary {
|
||||
const salesAmount = wanToYuan(row.gmvWan);
|
||||
const refundAmount = wanToYuan(row.refundWan);
|
||||
const grossYuan = wanToYuan(row.grossProfitWan);
|
||||
const profitAfterTax = wanToYuan(row.netProfitWan);
|
||||
const totalCost = Math.max(0, salesAmount - refundAmount - grossYuan);
|
||||
const platformId = Number(row.key);
|
||||
return {
|
||||
platformId: Number.isFinite(platformId) ? platformId : 0,
|
||||
platformName: row.name,
|
||||
salesAmount,
|
||||
refundAmount,
|
||||
totalCost,
|
||||
productCost: totalCost,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
totalProfitBeforeTax: grossYuan,
|
||||
profitAfterTax,
|
||||
};
|
||||
}
|
||||
|
||||
function aggregatePlatformTotal(
|
||||
rows: CompanyOverviewVO.PlatformSummary[],
|
||||
): CompanyOverviewVO.PlatformSummary {
|
||||
const sum = (k: keyof CompanyOverviewVO.PlatformSummary) =>
|
||||
rows.reduce((a, x) => a + (Number(x[k]) || 0), 0);
|
||||
const salesAmount = sum('salesAmount');
|
||||
const orderCount = sum('orderCount') || 1;
|
||||
const totalPromotionFee = sum('totalPromotionFee');
|
||||
const averageOrderValue = salesAmount / orderCount;
|
||||
const feeRatio = salesAmount ? (totalPromotionFee / salesAmount) * 100 : 0;
|
||||
return {
|
||||
platformId: 0,
|
||||
platformName: '合计',
|
||||
targetOrderCount: sum('targetOrderCount'),
|
||||
orderCountAchievementRate: sum('orderCountAchievementRate'),
|
||||
targetAmount: sum('targetAmount'),
|
||||
salesAmountAchievementRate: sum('salesAmountAchievementRate'),
|
||||
salesAmount,
|
||||
orderCount: sum('orderCount'),
|
||||
averageOrderValue,
|
||||
productCost: sum('productCost'),
|
||||
shippingCost: sum('shippingCost'),
|
||||
otherCost: sum('otherCost'),
|
||||
totalCost: sum('totalCost'),
|
||||
refundAmount: sum('refundAmount'),
|
||||
totalPromotionFee,
|
||||
brushFee: sum('brushFee'),
|
||||
feeRatio,
|
||||
totalProfitBeforeTax: sum('totalProfitBeforeTax'),
|
||||
salesTaxAmount: sum('salesTaxAmount'),
|
||||
roi: totalPromotionFee ? salesAmount / totalPromotionFee : 0,
|
||||
profitAfterTax: sum('profitAfterTax'),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPlatformOverviewFromDimRows(
|
||||
rows: WorkbenchVO.DimRow[],
|
||||
): CompanyOverviewVO.PlatformOverview {
|
||||
const platforms = rows.map(dimRowToPlatformSummary);
|
||||
return { total: aggregatePlatformTotal(platforms), platforms };
|
||||
}
|
||||
Reference in New Issue
Block a user