feat: 优化工作台动画交互

This commit is contained in:
2026-08-25 20:38:02 +08:00
parent ea86cab0a9
commit 093d23d3b1
15 changed files with 545 additions and 221 deletions
@@ -5,12 +5,12 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
/** 工作台 KPI 瘦项。 */ /** 工作台 KPI 瘦项(value 为原始数值,展示格式化由调用方负责)。 */
@Data @Data
@Builder @Builder
public class BiKpiSlimVO { public class BiKpiSlimVO {
private String label; private String label;
private String value; private BigDecimal value;
private String unit; private String unit;
private BigDecimal changePct; private BigDecimal changePct;
private BigDecimal yoyChangePct; private BigDecimal yoyChangePct;
@@ -7,6 +7,9 @@ import lombok.NoArgsConstructor;
import java.math.BigDecimal; import java.math.BigDecimal;
/**
* 工作台 KPI 项:value 为原始数值,千分位等展示由前端负责。
*/
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@@ -15,7 +18,11 @@ public class WorkbenchKpiItemVO {
private String label; private String label;
private String value; /**
* 主指标原始值(金额为元、单量为笔、销量为件、比率为百分数、ROI 为倍数)。
* 不含千分位格式化。
*/
private BigDecimal value;
private String unit; private String unit;
@@ -32,8 +32,6 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@@ -42,7 +40,6 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@@ -657,77 +654,76 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
List<WorkbenchKpiItemVO> list = new ArrayList<>(); List<WorkbenchKpiItemVO> list = new ArrayList<>();
// —— 成交口径(不含已取消/未知)—— // —— 成交口径(不含已取消/未知)——
list.add(kpi("成交金额", formatYuanComma(cur.totalDealAmount()), "元", cur.totalDealAmount(), prev.totalDealAmount(), yoy.totalDealAmount(), list.add(kpi("成交金额", yuan2(cur.totalDealAmount()), "元", cur.totalDealAmount(), prev.totalDealAmount(), yoy.totalDealAmount(),
"成交状态实收", cur.totalDealAmount(), true)); "成交状态实收", cur.totalDealAmount(), true));
list.add(kpiCount("成交单量", cur.dealOrderCount(), prev.dealOrderCount(), yoy.dealOrderCount(), "单", list.add(kpiCount("成交单量", cur.dealOrderCount(), prev.dealOrderCount(), yoy.dealOrderCount(), "单",
"日均 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单")); "日均 " + avgDailyDealOrders.stripTrailingZeros().toPlainString() + " 单"));
list.add(kpiCount("成交销量", cur.dealQuantitySum(), prev.dealQuantitySum(), yoy.dealQuantitySum(), "件", "成交状态件数")); list.add(kpiCount("成交销量", cur.dealQuantitySum(), prev.dealQuantitySum(), yoy.dealQuantitySum(), "件", "成交状态件数"));
list.add(kpi("成交客单价", formatYuanComma(cur.dealAverageOrderValue()), "元", list.add(kpi("成交客单价", yuan2(cur.dealAverageOrderValue()), "元",
cur.dealAverageOrderValue(), prev.dealAverageOrderValue(), yoy.dealAverageOrderValue(), cur.dealAverageOrderValue(), prev.dealAverageOrderValue(), yoy.dealAverageOrderValue(),
"成交金额/成交单量", cur.dealAverageOrderValue(), false)); "成交金额/成交单量", cur.dealAverageOrderValue(), false));
// —— 净销售口径(成交 − 退款)—— // —— 净销售口径(成交 − 退款)——
list.add(kpi("净销售额", formatYuanComma(cur.totalSales()), "元", cur.totalSales(), prev.totalSales(), yoy.totalSales(), list.add(kpi("净销售额", yuan2(cur.totalSales()), "元", cur.totalSales(), prev.totalSales(), yoy.totalSales(),
"成交−退款", cur.totalSales(), true)); "成交−退款", cur.totalSales(), true));
list.add(kpiCount("净销售单量", cur.orderCount(), prev.orderCount(), yoy.orderCount(), "单", list.add(kpiCount("净销售单量", cur.orderCount(), prev.orderCount(), yoy.orderCount(), "单",
"日均 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单")); "日均 " + avgDailySalesOrders.stripTrailingZeros().toPlainString() + " 单"));
list.add(kpiCount("净销量", cur.salesQuantitySum(), prev.salesQuantitySum(), yoy.salesQuantitySum(), "件", list.add(kpiCount("净销量", cur.salesQuantitySum(), prev.salesQuantitySum(), yoy.salesQuantitySum(), "件",
"成交件数−退款件数")); "成交件数−退款件数"));
list.add(kpi("净销售客单价", formatYuanComma(cur.averageOrderValue()), "元", list.add(kpi("净销售客单价", yuan2(cur.averageOrderValue()), "元",
cur.averageOrderValue(), prev.averageOrderValue(), yoy.averageOrderValue(), cur.averageOrderValue(), prev.averageOrderValue(), yoy.averageOrderValue(),
"净销售额/净销售单量", cur.averageOrderValue(), false)); "净销售额/净销售单量", cur.averageOrderValue(), false));
// —— 退款 —— // —— 退款 ——
list.add(kpi("退款额", formatYuanComma(cur.totalRefund()), "元", cur.totalRefund(), prev.totalRefund(), yoy.totalRefund(), list.add(kpi("退款额", yuan2(cur.totalRefund()), "元", cur.totalRefund(), prev.totalRefund(), yoy.totalRefund(),
"计入退款状态", cur.totalRefund(), true)); "计入退款状态", cur.totalRefund(), true));
list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP).toPlainString(), "%", list.add(kpi("退款率", refundRate.setScale(2, RoundingMode.HALF_UP), "%",
refundRate, safePct(prev.totalRefund(), prev.totalSales()), safePct(yoy.totalRefund(), yoy.totalSales()), refundRate, safePct(prev.totalRefund(), prev.totalSales()), safePct(yoy.totalRefund(), yoy.totalSales()),
"退款/净销售额", null, null)); "退款/净销售额", null, null));
// —— 成本 —— // —— 成本 ——
list.add(kpi("订单成本", formatYuanComma(cur.totalCost()), "元", cur.totalCost(), prev.totalCost(), yoy.totalCost(), list.add(kpi("订单成本", yuan2(cur.totalCost()), "元", cur.totalCost(), prev.totalCost(), yoy.totalCost(),
"成本率 " + costRate.stripTrailingZeros().toPlainString() + "%", cur.totalCost(), true)); "成本率 " + costRate.stripTrailingZeros().toPlainString() + "%", cur.totalCost(), true));
list.add(kpi("商品成本", formatYuanComma(cur.productCost()), "元", cur.productCost(), prev.productCost(), yoy.productCost(), list.add(kpi("商品成本", yuan2(cur.productCost()), "元", cur.productCost(), prev.productCost(), yoy.productCost(),
null, cur.productCost(), true)); null, cur.productCost(), true));
list.add(kpi("运费成本", formatYuanComma(cur.freightCost()), "元", cur.freightCost(), prev.freightCost(), yoy.freightCost(), list.add(kpi("运费成本", yuan2(cur.freightCost()), "元", cur.freightCost(), prev.freightCost(), yoy.freightCost(),
null, cur.freightCost(), true)); null, cur.freightCost(), true));
list.add(kpi("其他成本", formatYuanComma(cur.otherCost()), "元", cur.otherCost(), prev.otherCost(), yoy.otherCost(), list.add(kpi("其他成本", yuan2(cur.otherCost()), "元", cur.otherCost(), prev.otherCost(), yoy.otherCost(),
null, cur.otherCost(), true)); null, cur.otherCost(), true));
// —— 利润与费用 —— // —— 利润与费用 ——
list.add(kpi("毛利润", formatYuanComma(cur.grossOrder()), "元", cur.grossOrder(), prev.grossOrder(), yoy.grossOrder(), list.add(kpi("毛利润", yuan2(cur.grossOrder()), "元", cur.grossOrder(), prev.grossOrder(), yoy.grossOrder(),
"毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%", cur.grossOrder(), true)); "毛利率 " + grossMarginPct.stripTrailingZeros().toPlainString() + "%", cur.grossOrder(), true));
list.add(kpi("推广费", formatYuanComma(cur.promotion()), "元", cur.promotion(), prev.promotion(), yoy.promotion(), list.add(kpi("推广费", yuan2(cur.promotion()), "元", cur.promotion(), prev.promotion(), yoy.promotion(),
null, cur.promotion(), true)); null, cur.promotion(), true));
list.add(kpi("刷单费", formatYuanComma(cur.brush()), "元", cur.brush(), prev.brush(), yoy.brush(), list.add(kpi("刷单费", yuan2(cur.brush()), "元", cur.brush(), prev.brush(), yoy.brush(),
null, cur.brush(), true)); null, cur.brush(), true));
list.add(kpi("税额", formatYuanComma(cur.tax()), "元", cur.tax(), prev.tax(), yoy.tax(), list.add(kpi("税额", yuan2(cur.tax()), "元", cur.tax(), prev.tax(), yoy.tax(),
"税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%", "税率 " + taxRate.multiply(new BigDecimal("100")).stripTrailingZeros().toPlainString() + "%",
cur.tax(), true)); cur.tax(), true));
list.add(kpi("净利润", formatYuanComma(cur.netProfit()), "元", cur.netProfit(), prev.netProfit(), yoy.netProfit(), list.add(kpi("净利润", yuan2(cur.netProfit()), "元", cur.netProfit(), prev.netProfit(), yoy.netProfit(),
"净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%", "净利率 " + netMarginPct.stripTrailingZeros().toPlainString() + "%",
cur.netProfit(), true)); cur.netProfit(), true));
// —— 运营效率 —— // —— 运营效率 ——
list.add(kpi("广告ROI", roi.stripTrailingZeros().toPlainString(), ":1", roi, prevRoi, yoyRoi, list.add(kpi("广告ROI", roi.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros(), ":1", roi, prevRoi, yoyRoi,
"净销售额/推广费", null, null)); "净销售额/推广费", null, null));
return list; return list;
} }
/** 非金额类 KPI(单量、件数等) */ /** 非金额类 KPI(单量、件数等):value 为原始整数 */
private WorkbenchKpiItemVO kpiCount(String label, int cur, int prev, int yoy, String unit, String sub) { private WorkbenchKpiItemVO kpiCount(String label, int cur, int prev, int yoy, String unit, String sub) {
DecimalFormat df = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CHINA)); return kpi(label, BigDecimal.valueOf(cur), unit,
return kpi(label, df.format(cur), unit,
BigDecimal.valueOf(cur), BigDecimal.valueOf(prev), BigDecimal.valueOf(yoy), BigDecimal.valueOf(cur), BigDecimal.valueOf(prev), BigDecimal.valueOf(yoy),
sub, null, null); sub, null, null);
} }
/** /**
* 单张 KPI:展示格式化主值 + 环比/同比变化率;{@code amountYuan} 供前端换算「万」; * 单张 KPI:原始数值 + 环比/同比变化率;{@code amountYuan} 供前端换算「万」;
* {@code preferWanDisplay} 为 true 时建议主数字用万展示。 * {@code preferWanDisplay} 为 true 时建议主数字用万展示。千分位由前端格式化。
*/ */
private WorkbenchKpiItemVO kpi(String label, String value, String unit, private WorkbenchKpiItemVO kpi(String label, BigDecimal value, String unit,
BigDecimal curAmt, BigDecimal prevAmt, BigDecimal yoyAmt, String sub, BigDecimal curAmt, BigDecimal prevAmt, BigDecimal yoyAmt, String sub,
BigDecimal amountYuan, Boolean preferWanDisplay) { BigDecimal amountYuan, Boolean preferWanDisplay) {
BigDecimal change = pctChange(curAmt, prevAmt); BigDecimal change = pctChange(curAmt, prevAmt);
@@ -799,7 +795,7 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
return new DateRange(range.startDate().minusMonths(1), range.endDate().minusMonths(1)); return new DateRange(range.startDate().minusMonths(1), range.endDate().minusMonths(1));
} }
/** 金额统一保留两位小数(输出 VO 与前端展示) */ /** 金额统一保留两位小数(输出 VO) */
private static BigDecimal yuan2(BigDecimal yuan) { private static BigDecimal yuan2(BigDecimal yuan) {
if (yuan == null) { if (yuan == null) {
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
@@ -807,15 +803,6 @@ public class BiWorkbenchServiceImpl implements BiWorkbenchService {
return yuan.setScale(2, RoundingMode.HALF_UP); return yuan.setScale(2, RoundingMode.HALF_UP);
} }
/** KPI 主数字:千分位 + 两位小数的字符串 */
private static String formatYuanComma(BigDecimal yuan) {
if (yuan == null) {
return "0.00";
}
BigDecimal v = yuan.setScale(2, RoundingMode.HALF_UP);
return new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.CHINA)).format(v);
}
/** 计算 num/den*100,分母无效时返回 0 */ /** 计算 num/den*100,分母无效时返回 0 */
private static BigDecimal safePct(BigDecimal num, BigDecimal den) { private static BigDecimal safePct(BigDecimal num, BigDecimal den) {
if (den == null || den.compareTo(BigDecimal.ZERO) <= 0) { if (den == null || den.compareTo(BigDecimal.ZERO) <= 0) {
@@ -18,7 +18,8 @@ export namespace WorkbenchVO {
export interface KpiItem { export interface KpiItem {
label: string; label: string;
value: string; /** 主指标原始数值(金额为元;不含千分位) */
value: number;
unit: string; unit: string;
changePct?: number; changePct?: number;
up?: boolean; up?: boolean;
@@ -0,0 +1,23 @@
<script lang="ts" setup>
/**
* 汇总表金额单元格:¥ 格式 + 数值滚动。
*/
import AnimatedNumberText from './AnimatedNumberText.vue';
defineOptions({ name: 'WorkbenchAnimatedMoneyCell' });
defineProps<{
value: number | null | undefined;
}>();
function formatAmount(amount: number) {
return `¥${amount.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}
</script>
<template>
<AnimatedNumberText :value="value" :format="formatAmount" />
</template>
@@ -0,0 +1,64 @@
<script lang="ts" setup>
/**
* 数值滚动展示:刷新时从旧值过渡到新值,空值显示占位。
*/
import { computed, ref, watch } from 'vue';
import { TransitionPresets, useTransition } from '@vueuse/core';
defineOptions({ name: 'WorkbenchAnimatedNumberText' });
const props = withDefaults(
defineProps<{
value: number | null | undefined;
/** 对过渡中的数值做展示格式化 */
format?: (n: number) => string;
decimals?: number;
duration?: number;
empty?: string;
}>(),
{
decimals: 2,
duration: 650,
empty: '-',
},
);
const source = ref(0);
const ready = ref(false);
const hasValue = computed(() => {
if (props.value === null || props.value === undefined) return false;
return Number.isFinite(Number(props.value));
});
watch(
() => props.value,
(v) => {
if (v === null || v === undefined || !Number.isFinite(Number(v))) {
ready.value = false;
return;
}
source.value = Number(v);
ready.value = true;
},
{ immediate: true },
);
const output = useTransition(source, {
duration: computed(() => props.duration),
transition: TransitionPresets.easeOutCubic,
disabled: computed(() => !ready.value),
});
const display = computed(() => {
if (!ready.value || !hasValue.value) return props.empty;
const n = output.value;
if (props.format) return props.format(n);
return n.toFixed(props.decimals);
});
</script>
<template>
<span class="tabular-nums">{{ display }}</span>
</template>
@@ -1,5 +1,14 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'; import {
computed,
nextTick,
onActivated,
onDeactivated,
onMounted,
onUnmounted,
ref,
watch,
} from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
@@ -100,6 +109,7 @@ const ToolbarToggleIcon = createIconifyIcon('lucide:sliders-horizontal');
const ReceiptIcon = createIconifyIcon('lucide:receipt'); const ReceiptIcon = createIconifyIcon('lucide:receipt');
const CalendarIcon = createIconifyIcon('lucide:calendar'); const CalendarIcon = createIconifyIcon('lucide:calendar');
const RefreshIcon = createIconifyIcon('lucide:refresh-cw'); const RefreshIcon = createIconifyIcon('lucide:refresh-cw');
const CheckIcon = createIconifyIcon('lucide:check');
/** 快捷区间 + 自定义 RangePicker */ /** 快捷区间 + 自定义 RangePicker */
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([ const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
@@ -447,38 +457,60 @@ function buildWorkbenchQuery(): WorkbenchDTO.Query {
return query; return query;
} }
/** 筛选变更后清空已加载 Tab,避免展示过期数据 */ const DATA_TAB_KEYS: DataTabKey[] = ['finance', 'multi', 'salesRank'];
function invalidateDataTabs() {
tabLoaded.finance = false; /** 离开页面超过该时长再自动刷新(visibility) */
tabLoaded.multi = false; const AUTO_REFRESH_AWAY_MS = 30_000;
tabLoaded.salesRank = false;
financeSlice.value = null; /** 标脏但不清空已有数据,切回该 Tab 时再静默重拉 */
multiAnalysisData.value = null; function softInvalidateDataTabs(except?: DataTabKey) {
salesRankData.value = null; for (const key of DATA_TAB_KEYS) {
if (key !== except) {
tabLoaded[key] = false;
}
}
} }
/** 按 Tab 首次激活懒加载,已加载则跳过 */ function hasTabData(tab: DataTabKey): boolean {
async function loadTabData(tab: DataTabKey) { switch (tab) {
if (!metaLoaded.value || tabLoaded[tab]) { case 'finance': {
return financeSlice.value != null;
}
case 'multi': {
return multiAnalysisData.value != null;
}
case 'salesRank': {
return salesRankData.value != null;
}
}
}
/** 按 Tab 懒加载;force 时重拉。已有数据时不打全屏 Spin */
async function loadTabData(tab: DataTabKey, opts?: { force?: boolean }) {
if (!metaLoaded.value) {
return;
}
if (!opts?.force && tabLoaded[tab]) {
return; return;
} }
const query = buildWorkbenchQuery(); const query = buildWorkbenchQuery();
const blocking = !hasTabData(tab);
try { try {
switch (tab) { switch (tab) {
case 'finance': { case 'finance': {
financeLoading.value = true; if (blocking) financeLoading.value = true;
financeSlice.value = await getWorkbenchFinanceApi(query); financeSlice.value = await getWorkbenchFinanceApi(query);
tabLoaded.finance = true; tabLoaded.finance = true;
break; break;
} }
case 'multi': { case 'multi': {
multiLoading.value = true; if (blocking) multiLoading.value = true;
multiAnalysisData.value = await getWorkbenchMultiAnalysisApi(query); multiAnalysisData.value = await getWorkbenchMultiAnalysisApi(query);
tabLoaded.multi = true; tabLoaded.multi = true;
break; break;
} }
case 'salesRank': { case 'salesRank': {
salesRankLoading.value = true; if (blocking) salesRankLoading.value = true;
salesRankData.value = await getWorkbenchSalesRankApi(query); salesRankData.value = await getWorkbenchSalesRankApi(query);
tabLoaded.salesRank = true; tabLoaded.salesRank = true;
break; break;
@@ -487,19 +519,26 @@ async function loadTabData(tab: DataTabKey) {
} catch (e: unknown) { } catch (e: unknown) {
const msg = e instanceof Error ? e.message : '工作台数据加载失败'; const msg = e instanceof Error ? e.message : '工作台数据加载失败';
message.error(msg); message.error(msg);
// 已有数据则保留;仅首屏失败时落空壳,避免空白死循环
switch (tab) { switch (tab) {
case 'finance': { case 'finance': {
if (!financeSlice.value) {
financeSlice.value = { finance: EMPTY_FINANCE, summaryTables: null }; financeSlice.value = { finance: EMPTY_FINANCE, summaryTables: null };
}
tabLoaded.finance = true; tabLoaded.finance = true;
break; break;
} }
case 'multi': { case 'multi': {
if (!multiAnalysisData.value) {
multiAnalysisData.value = EMPTY_MULTI; multiAnalysisData.value = EMPTY_MULTI;
}
tabLoaded.multi = true; tabLoaded.multi = true;
break; break;
} }
case 'salesRank': { case 'salesRank': {
if (!salesRankData.value) {
salesRankData.value = EMPTY_MULTI; salesRankData.value = EMPTY_MULTI;
}
tabLoaded.salesRank = true; tabLoaded.salesRank = true;
break; break;
} }
@@ -519,35 +558,106 @@ async function loadTabData(tab: DataTabKey) {
} }
} }
async function refreshActiveDataTab() { /** 强制刷新当前 Tab,并将其余数据 Tab 标脏 */
const tab = activeTab.value; async function softRefreshActiveTab() {
if (tab === 'periodCompare') { if (activeTab.value === 'periodCompare') {
await periodCompareTabRef.value?.refresh?.({ silent: true });
softInvalidateDataTabs();
return; return;
} }
await loadTabData(tab as DataTabKey); const tab = activeTab.value as DataTabKey;
await loadTabData(tab, { force: true });
softInvalidateDataTabs(tab);
}
async function refreshActiveDataTab(opts?: { force?: boolean }) {
if (activeTab.value === 'periodCompare') {
// 筛选变更等带 force:静默重拉,保留旧图
await periodCompareTabRef.value?.refresh?.({ silent: !!opts?.force });
return;
}
await loadTabData(activeTab.value as DataTabKey, opts);
} }
const refreshing = ref(false); const refreshing = ref(false);
/** 手动刷新成功后按钮短暂「已刷新」 */
const refreshDone = ref(false);
const REFRESH_DONE_MS = 1200;
let refreshDoneTimer: ReturnType<typeof setTimeout> | null = null;
/** 手动刷新:强制重拉当前 Tab(含区间对比) */ function clearRefreshDoneTimer() {
if (refreshDoneTimer) {
clearTimeout(refreshDoneTimer);
refreshDoneTimer = null;
}
}
function flashRefreshDone() {
clearRefreshDoneTimer();
refreshDone.value = true;
refreshDoneTimer = setTimeout(() => {
refreshDone.value = false;
refreshDoneTimer = null;
}, REFRESH_DONE_MS);
}
/** 手动刷新:强制重拉当前 Tab(含区间对比),其它 Tab 标脏;成功后按钮闪「已刷新」 */
async function handleManualRefresh() { async function handleManualRefresh() {
if (refreshing.value) {
return;
}
clearRefreshDoneTimer();
refreshDone.value = false;
refreshing.value = true;
try {
await softRefreshActiveTab();
flashRefreshDone();
} finally {
refreshing.value = false;
}
}
let leftPageAt: number | null = null;
let skipNextActivatedRefresh = true;
function markPageLeft() {
leftPageAt = Date.now();
}
/** 路由返回:总是静默刷新;切回浏览器标签:离开 ≥30s 才刷 */
async function maybeAutoRefreshOnReturn(reason: 'activated' | 'visible') {
if (reason === 'visible') {
// 未记录离开时刻则忽略(避免无 hidden 的 visible 误刷)
if (leftPageAt == null) {
return;
}
const awayMs = Date.now() - leftPageAt;
leftPageAt = null;
if (awayMs < AUTO_REFRESH_AWAY_MS) {
return;
}
} else {
leftPageAt = null;
}
if (refreshing.value) { if (refreshing.value) {
return; return;
} }
refreshing.value = true; refreshing.value = true;
try { try {
if (activeTab.value === 'periodCompare') { await softRefreshActiveTab();
await periodCompareTabRef.value?.refresh?.();
return;
}
const tab = activeTab.value as DataTabKey;
tabLoaded[tab] = false;
await loadTabData(tab);
} finally { } finally {
refreshing.value = false; refreshing.value = false;
} }
} }
function onDocumentVisibilityChange() {
if (document.hidden) {
markPageLeft();
return;
}
void maybeAutoRefreshOnReturn('visible');
}
const activeTab = ref('finance'); const activeTab = ref('finance');
function handleProductNavigate(productId: number) { function handleProductNavigate(productId: number) {
@@ -573,7 +683,7 @@ const salesRankTabRef = ref<InstanceType<typeof WorkbenchSalesRankTab> | null>(
const periodCompareTabRef = ref< const periodCompareTabRef = ref<
| (InstanceType<typeof WorkbenchPeriodCompareTab> & { | (InstanceType<typeof WorkbenchPeriodCompareTab> & {
redraw: () => Promise<void>; redraw: () => Promise<void>;
refresh: () => Promise<void>; refresh: (opts?: { silent?: boolean }) => Promise<void>;
}) })
| null | null
>(null); >(null);
@@ -613,8 +723,8 @@ watch(activeTab, (tab) => {
watch( watch(
[() => dateRange.value, taxRate, selectedPlatformSlug, selectedShopSlug], [() => dateRange.value, taxRate, selectedPlatformSlug, selectedShopSlug],
() => { () => {
invalidateDataTabs(); softInvalidateDataTabs();
void refreshActiveDataTab(); void refreshActiveDataTab({ force: true });
}, },
{ deep: true }, { deep: true },
); );
@@ -622,6 +732,7 @@ watch(
let darkObserver: MutationObserver | null = null; let darkObserver: MutationObserver | null = null;
onMounted(async () => { onMounted(async () => {
document.addEventListener('visibilitychange', onDocumentVisibilityChange);
await loadTabData('finance'); await loadTabData('finance');
setTimeout(() => { setTimeout(() => {
void redrawActiveTabCharts(); void redrawActiveTabCharts();
@@ -635,7 +746,21 @@ onMounted(async () => {
}); });
}); });
onActivated(() => {
if (skipNextActivatedRefresh) {
skipNextActivatedRefresh = false;
return;
}
void maybeAutoRefreshOnReturn('activated');
});
onDeactivated(() => {
markPageLeft();
});
onUnmounted(() => { onUnmounted(() => {
document.removeEventListener('visibilitychange', onDocumentVisibilityChange);
clearRefreshDoneTimer();
if (platformSearchTimer) clearTimeout(platformSearchTimer); if (platformSearchTimer) clearTimeout(platformSearchTimer);
if (shopSearchTimer) clearTimeout(shopSearchTimer); if (shopSearchTimer) clearTimeout(shopSearchTimer);
darkObserver?.disconnect(); darkObserver?.disconnect();
@@ -826,20 +951,30 @@ onUnmounted(() => {
refreshing ? 'cursor-wait opacity-70' : 'cursor-pointer', refreshing ? 'cursor-wait opacity-70' : 'cursor-pointer',
]" ]"
role="button" role="button"
title="刷新当前页数据" :title="refreshDone ? '已刷新' : '刷新当前页数据'"
@click="handleManualRefresh" @click="handleManualRefresh"
> >
<div <div
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']" :class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
> >
<CheckIcon
v-if="refreshDone && !refreshing"
class="h-4 w-4 shrink-0 text-emerald-600 dark:text-emerald-400"
/>
<RefreshIcon <RefreshIcon
v-else
class="h-4 w-4 shrink-0" class="h-4 w-4 shrink-0"
:class="{ 'animate-spin': refreshing }" :class="{ 'animate-spin': refreshing }"
/> />
<span <span
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300" class="whitespace-nowrap text-xs font-bold"
:class="
refreshDone && !refreshing
? 'text-emerald-600 dark:text-emerald-400'
: 'text-slate-700 dark:text-slate-300'
"
> >
刷新 {{ refreshing ? '刷新' : refreshDone ? '已刷新' : '刷新' }}
</span> </span>
</div> </div>
</div> </div>
@@ -849,7 +984,7 @@ onUnmounted(() => {
<div class="workbench-page-body min-w-0"> <div class="workbench-page-body min-w-0">
<Tabs v-model:active-key="activeTab" class="workbench-tabs"> <Tabs v-model:active-key="activeTab" class="workbench-tabs">
<Tabs.TabPane key="finance" tab="经营概览"> <Tabs.TabPane key="finance" tab="经营概览">
<Spin :spinning="financeLoading"> <Spin :spinning="financeLoading && !financeSlice">
<WorkbenchFinanceTab <WorkbenchFinanceTab
ref="financeTabRef" ref="financeTabRef"
:tax-rate="taxRate" :tax-rate="taxRate"
@@ -862,7 +997,7 @@ onUnmounted(() => {
</Spin> </Spin>
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane key="multi" tab="多维分析"> <Tabs.TabPane key="multi" tab="多维分析">
<Spin :spinning="multiLoading"> <Spin :spinning="multiLoading && !multiAnalysisData">
<WorkbenchMultiTab <WorkbenchMultiTab
ref="multiTabRef" ref="multiTabRef"
:multi-analysis="multiPanel" :multi-analysis="multiPanel"
@@ -870,7 +1005,7 @@ onUnmounted(() => {
</Spin> </Spin>
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane key="salesRank" tab="销售额排行榜"> <Tabs.TabPane key="salesRank" tab="销售额排行榜">
<Spin :spinning="salesRankLoading"> <Spin :spinning="salesRankLoading && !salesRankData">
<WorkbenchSalesRankTab <WorkbenchSalesRankTab
ref="salesRankTabRef" ref="salesRankTabRef"
:sales-rank="salesRankPanel" :sales-rank="salesRankPanel"
@@ -19,6 +19,7 @@ import {
salesTaxColumnHint, salesTaxColumnHint,
} from '#/utils/overview-table-hints'; } from '#/utils/overview-table-hints';
import AnimatedNumberText from '../../components/AnimatedNumberText.vue';
import { formatYuanDetail, yuanToWanNum } from '../../utils/money'; import { formatYuanDetail, yuanToWanNum } from '../../utils/money';
defineOptions({ name: 'WorkbenchPeriodCompareTab' }); defineOptions({ name: 'WorkbenchPeriodCompareTab' });
@@ -300,11 +301,15 @@ function buildWorkbenchQuery(range: [dayjs.Dayjs, dayjs.Dayjs]): WorkbenchDTO.Qu
return q; return q;
} }
async function fetchSlices() { async function fetchSlices(_opts?: { silent?: boolean }) {
if (props.activeTab !== 'periodCompare') { if (props.activeTab !== 'periodCompare') {
return; return;
} }
const hasExisting = sliceA.value != null || sliceB.value != null;
// 已有数据时静默刷新,避免 Spin 盖住图表
if (!hasExisting) {
loading.value = true; loading.value = true;
}
try { try {
const [a, b] = await Promise.all([ const [a, b] = await Promise.all([
getWorkbenchPeriodCompareSliceApi(buildWorkbenchQuery(periodA.value)), getWorkbenchPeriodCompareSliceApi(buildWorkbenchQuery(periodA.value)),
@@ -315,8 +320,10 @@ async function fetchSlices() {
} catch (e: unknown) { } catch (e: unknown) {
const msg = e instanceof Error ? e.message : '区间对比数据加载失败'; const msg = e instanceof Error ? e.message : '区间对比数据加载失败';
message.error(msg); message.error(msg);
if (!hasExisting) {
sliceA.value = null; sliceA.value = null;
sliceB.value = null; sliceB.value = null;
}
} finally { } finally {
loading.value = false; loading.value = false;
} }
@@ -345,11 +352,10 @@ function formatMoney(n: number) {
return `¥${n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; return `¥${n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
} }
function formatCell(m: CompareMetric, side: 'a' | 'b') { function formatMetricValue(m: CompareMetric, v: number) {
const v = side === 'a' ? m.valueA : m.valueB;
switch (m.format) { switch (m.format) {
case 'int': { case 'int': {
return v.toLocaleString('zh-CN'); return Math.round(v).toLocaleString('zh-CN');
} }
case 'money': { case 'money': {
return formatMoney(v); return formatMoney(v);
@@ -366,6 +372,15 @@ function formatCell(m: CompareMetric, side: 'a' | 'b') {
} }
} }
function formatCell(m: CompareMetric, side: 'a' | 'b') {
const v = side === 'a' ? m.valueA : m.valueB;
return formatMetricValue(m, v);
}
function metricValueFormatter(m: CompareMetric) {
return (n: number) => formatMetricValue(m, n);
}
function delta(m: CompareMetric) { function delta(m: CompareMetric) {
return m.valueB - m.valueA; return m.valueB - m.valueA;
} }
@@ -487,6 +502,10 @@ function drawMoneyCompareChart() {
const legendB = `区间 B`; const legendB = `区间 B`;
void renderMoneyBar({ void renderMoneyBar({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
title: { title: {
text: '金额类指标对比(万元)', text: '金额类指标对比(万元)',
left: 0, left: 0,
@@ -554,7 +573,7 @@ function drawMoneyCompareChart() {
itemStyle: { color: t.barB, borderRadius: [0, 4, 4, 0] }, itemStyle: { color: t.barB, borderRadius: [0, 4, 4, 0] },
}, },
], ],
}); }, false);
} }
function drawGrowthCompareChart() { function drawGrowthCompareChart() {
@@ -579,6 +598,10 @@ function drawGrowthCompareChart() {
maxV = maxV <= 0 ? Math.max(0, maxV + pad) : maxV + pad; maxV = maxV <= 0 ? Math.max(0, maxV + pad) : maxV + pad;
void renderGrowthBar({ void renderGrowthBar({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
title: { title: {
text: '相对区间 A 的增幅(%)', text: '相对区间 A 的增幅(%)',
left: 0, left: 0,
@@ -661,7 +684,7 @@ function drawGrowthCompareChart() {
}, },
}, },
], ],
} as never); } as never, false);
} }
async function redraw() { async function redraw() {
@@ -735,7 +758,7 @@ defineExpose({ redraw, refresh: fetchSlices });
</div> </div>
</div> </div>
<Spin :spinning="loading"> <Spin :spinning="loading && !sliceA && !sliceB">
<div <div
class="border-t border-slate-100 px-3 py-4 dark:border-[hsl(240deg_3.7%_22%)] md:px-6" class="border-t border-slate-100 px-3 py-4 dark:border-[hsl(240deg_3.7%_22%)] md:px-6"
> >
@@ -808,10 +831,16 @@ defineExpose({ redraw, refresh: fetchSlices });
</OverviewColumnHint> </OverviewColumnHint>
</td> </td>
<td class="px-4 py-3 font-mono text-xs font-bold tabular-nums text-slate-800 dark:text-slate-100"> <td class="px-4 py-3 font-mono text-xs font-bold tabular-nums text-slate-800 dark:text-slate-100">
{{ formatCell(m, 'a') }} <AnimatedNumberText
:value="m.valueA"
:format="metricValueFormatter(m)"
/>
</td> </td>
<td class="px-4 py-3 font-mono text-xs font-bold tabular-nums text-slate-800 dark:text-slate-100"> <td class="px-4 py-3 font-mono text-xs font-bold tabular-nums text-slate-800 dark:text-slate-100">
{{ formatCell(m, 'b') }} <AnimatedNumberText
:value="m.valueB"
:format="metricValueFormatter(m)"
/>
</td> </td>
<td <td
class="border-l border-slate-100 px-4 py-3 font-mono text-xs tabular-nums dark:border-[hsl(240deg_3.7%_22%)]" class="border-l border-slate-100 px-4 py-3 font-mono text-xs tabular-nums dark:border-[hsl(240deg_3.7%_22%)]"
@@ -8,6 +8,8 @@ import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells'; import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue'; import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import AnimatedMoneyCell from '../../../components/AnimatedMoneyCell.vue';
import { import {
salesTaxColumnHint, salesTaxColumnHint,
storeOverviewHints, storeOverviewHints,
@@ -59,11 +61,6 @@ const someCategoriesSelected = computed(() => {
return props.selectedExportCategoryIds.length > 0; return props.selectedExportCategoryIds.length > 0;
}); });
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) => const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2)); formatNumberCell(v, (n) => n.toFixed(2));
@@ -271,33 +268,33 @@ const cellRoi = (v: number | null | undefined) =>
{{ cat.categoryName }} {{ cat.categoryName }}
</span> </span>
</td> </td>
<td class="p-6 font-black">{{ formatAmount(cat.salesAmount) }}</td> <td class="p-6 font-black"><AnimatedMoneyCell :value="cat.salesAmount" /></td>
<td class="p-6 font-black text-amber-700 dark:text-amber-400">{{ formatAmount(cat.dealAmount) }}</td> <td class="p-6 font-black text-amber-700 dark:text-amber-400"><AnimatedMoneyCell :value="cat.dealAmount" /></td>
<td class="p-6 font-medium">{{ formatIntCell(cat.orderCount) }}</td> <td class="p-6 font-medium">{{ formatIntCell(cat.orderCount) }}</td>
<td class="p-6 font-medium"> <td class="p-6 font-medium">
{{ cellMoney(cat.averageOrderValue) }} <AnimatedMoneyCell :value="cat.averageOrderValue" />
</td> </td>
<td class="p-6">{{ cellMoney(cat.productCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="cat.productCost" /></td>
<td class="p-6">{{ cellMoney(cat.shippingCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="cat.shippingCost" /></td>
<td class="p-6">{{ cellMoney(cat.otherCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="cat.otherCost" /></td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300"> <td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{ cellMoney(cat.orderCost) }} <AnimatedMoneyCell :value="cat.orderCost" />
</td> </td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400"> <td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cellMoney(cat.refundAmount) }} <AnimatedMoneyCell :value="cat.refundAmount" />
</td> </td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(cat.salesTaxAmount) }} <AnimatedMoneyCell :value="cat.salesTaxAmount" />
</td> </td>
<td class="p-6">{{ cellMoney(cat.totalPromotionFee) }}</td> <td class="p-6"><AnimatedMoneyCell :value="cat.totalPromotionFee" /></td>
<td class="p-6 text-orange-600 dark:text-orange-400"> <td class="p-6 text-orange-600 dark:text-orange-400">
{{ cellMoney(cat.brushFee) }} <AnimatedMoneyCell :value="cat.brushFee" />
</td> </td>
<td class="p-6 font-bold text-emerald-700 dark:text-emerald-400"> <td class="p-6 font-bold text-emerald-700 dark:text-emerald-400">
{{ cellMoney(cat.grossProfit) }} <AnimatedMoneyCell :value="cat.grossProfit" />
</td> </td>
<td class="p-6 font-bold"> <td class="p-6 font-bold">
{{ cellMoney(cat.totalProfitBeforeTax) }} <AnimatedMoneyCell :value="cat.totalProfitBeforeTax" />
</td> </td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cat.feeRatio !== undefined ? formatFeeRatioPercent(cat.feeRatio) : '-' }} {{ cat.feeRatio !== undefined ? formatFeeRatioPercent(cat.feeRatio) : '-' }}
@@ -306,7 +303,7 @@ const cellRoi = (v: number | null | undefined) =>
{{ cellRoi(cat.roi) }} {{ cellRoi(cat.roi) }}
</td> </td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black text-emerald-600 dark:text-emerald-300"> <td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black text-emerald-600 dark:text-emerald-300">
{{ cellMoney(cat.profitAfterTax) }} <AnimatedMoneyCell :value="cat.profitAfterTax" />
</td> </td>
</tr> </tr>
<tr v-if="!categorySummary?.categories?.length"> <tr v-if="!categorySummary?.categories?.length">
@@ -320,30 +317,30 @@ const cellRoi = (v: number | null | undefined) =>
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]"> <tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="sticky-col bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] p-6 text-base">合计</td> <td class="sticky-col bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] p-6 text-base">合计</td>
<!-- 规模 --> <!-- 规模 -->
<td class="p-6">{{ cellMoney(categorySummary?.total?.salesAmount) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.salesAmount" /></td>
<td class="p-6 text-amber-700 dark:text-amber-400">{{ cellMoney(categorySummary?.total?.dealAmount) }}</td> <td class="p-6 text-amber-700 dark:text-amber-400"><AnimatedMoneyCell :value="categorySummary?.total?.dealAmount" /></td>
<td class="p-6">{{ formatIntCell(categorySummary?.total?.orderCount) }}</td> <td class="p-6">{{ formatIntCell(categorySummary?.total?.orderCount) }}</td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(categorySummary?.total?.averageOrderValue) }} <AnimatedMoneyCell :value="categorySummary?.total?.averageOrderValue" />
</td> </td>
<!-- 成本 --> <!-- 成本 -->
<td class="p-6">{{ cellMoney(categorySummary?.total?.productCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.productCost" /></td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.shippingCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.shippingCost" /></td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.otherCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.otherCost" /></td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(categorySummary?.total?.orderCost) }}</td> <td class="p-6 font-bold text-orange-800 dark:text-orange-300"><AnimatedMoneyCell :value="categorySummary?.total?.orderCost" /></td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(categorySummary?.total?.refundAmount) }}</td> <td class="p-6 text-rose-600 dark:text-rose-400"><AnimatedMoneyCell :value="categorySummary?.total?.refundAmount" /></td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ cellMoney(categorySummary?.total?.salesTaxAmount) }}</td> <td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"><AnimatedMoneyCell :value="categorySummary?.total?.salesTaxAmount" /></td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.totalPromotionFee) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.totalPromotionFee" /></td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(categorySummary?.total?.brushFee) }}</td> <td class="p-6 text-orange-600 dark:text-orange-400"><AnimatedMoneyCell :value="categorySummary?.total?.brushFee" /></td>
<!-- 盈利 --> <!-- 盈利 -->
<td class="p-6 text-emerald-700 dark:text-emerald-400">{{ cellMoney(categorySummary?.total?.grossProfit) }}</td> <td class="p-6 text-emerald-700 dark:text-emerald-400"><AnimatedMoneyCell :value="categorySummary?.total?.grossProfit" /></td>
<td class="p-6">{{ cellMoney(categorySummary?.total?.totalProfitBeforeTax) }}</td> <td class="p-6"><AnimatedMoneyCell :value="categorySummary?.total?.totalProfitBeforeTax" /></td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categorySummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(categorySummary?.total?.feeRatio) : '-' }}</td> <td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categorySummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(categorySummary?.total?.feeRatio) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(categorySummary?.total?.roi) }}</td> <td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(categorySummary?.total?.roi) }}</td>
<td <td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950" class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(categorySummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'" :class="(categorySummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'"
>{{ cellMoney(categorySummary?.total?.profitAfterTax) }}</td> ><AnimatedMoneyCell :value="categorySummary?.total?.profitAfterTax" /></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@@ -54,6 +54,10 @@ function drawPie() {
const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff'; const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff';
renderPieChart({ renderPieChart({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
tooltip: { tooltip: {
trigger: 'item', trigger: 'item',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
@@ -107,7 +111,7 @@ function drawPie() {
})), })),
}, },
], ],
}); }, false);
} catch (error) { } catch (error) {
console.error('[WorkbenchFinancePlatformSalesPieChart] render failed:', error); console.error('[WorkbenchFinancePlatformSalesPieChart] render failed:', error);
} }
@@ -8,6 +8,7 @@ import { Popover, Tooltip } from 'ant-design-vue';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue'; import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import AnimatedNumberText from '../../../components/AnimatedNumberText.vue';
import { formatYuanDetail, yuanToWanNum } from '../../../utils/money'; import { formatYuanDetail, yuanToWanNum } from '../../../utils/money';
import { getFinanceKpiHint } from '../constants/finance-kpi-hints'; import { getFinanceKpiHint } from '../constants/finance-kpi-hints';
import { import {
@@ -135,31 +136,83 @@ function compareRangeHint(start?: string | null, end?: string | null): string {
return '对比区间未返回'; return '对比区间未返回';
} }
/** 主数字:可滚动的数值源 + 单位/悬停文案 */
function primaryAnim(kpi: WorkbenchVO.KpiItem): {
value: number | null;
format: (n: number) => string;
unitText: string;
hover: string;
fallback: string;
} {
const ay = kpi.amountYuan;
if (ay != null && Number.isFinite(ay)) {
const hover = formatYuanDetail(ay);
if (kpi.preferWanDisplay === true) {
return {
value: yuanToWanNum(ay),
format: (n) => n.toFixed(2),
unitText: '万',
hover,
fallback: '',
};
}
// 有 amountYuan 但不按万展示(如客单价)
return {
value: ay,
format: (n) =>
n.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
unitText: kpi.unit?.trim() ?? '',
hover,
fallback: '',
};
}
const num = typeof kpi.value === 'number' ? kpi.value : Number(kpi.value);
if (Number.isFinite(num)) {
const decimals =
Number.isInteger(num) || Math.abs(num - Math.round(num)) < 1e-9 ? 0 : 2;
return {
value: num,
format: (n) =>
decimals === 0
? Math.round(n).toLocaleString('zh-CN')
: n.toLocaleString('zh-CN', {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}),
unitText: kpi.unit?.trim() ?? '',
hover: '',
fallback: '',
};
}
return {
value: null,
format: () => '',
unitText: kpi.unit?.trim() ?? '',
hover: '',
fallback: '-',
};
}
function primaryLine(kpi: WorkbenchVO.KpiItem): { function primaryLine(kpi: WorkbenchVO.KpiItem): {
display: string; display: string;
unitText: string; unitText: string;
hover: string; hover: string;
} { } {
const ay = kpi.amountYuan; const anim = primaryAnim(kpi);
if (ay == null || !Number.isFinite(ay)) { if (anim.value == null) {
return { return {
display: String(kpi.value ?? ''), display: anim.fallback,
unitText: kpi.unit?.trim() ?? '', unitText: anim.unitText,
hover: '', hover: anim.hover,
};
}
const hover = formatYuanDetail(ay);
if (kpi.preferWanDisplay === true) {
return {
display: yuanToWanNum(ay).toFixed(2),
unitText: '万',
hover,
}; };
} }
return { return {
display: String(kpi.value ?? ''), display: anim.format(anim.value),
unitText: kpi.unit?.trim() ?? '', unitText: anim.unitText,
hover, hover: anim.hover,
}; };
} }
@@ -192,7 +245,7 @@ function onPickPrimary(cardId: FinanceKpiCardId, metricLabel: string) {
} }
function toneIconClass(tone: string): string { function toneIconClass(tone: string): string {
return FINANCE_TONE_ICON[tone] ?? FINANCE_TONE_ICON.blue; return FINANCE_TONE_ICON[tone] ?? FINANCE_TONE_ICON.blue ?? '';
} }
const emptyShellClass = const emptyShellClass =
@@ -307,26 +360,40 @@ const emptyShellClass =
<template v-if="row.primaryKpi"> <template v-if="row.primaryKpi">
<div class="mt-3 inline-flex max-w-full items-baseline gap-0.5 whitespace-nowrap"> <div class="mt-3 inline-flex max-w-full items-baseline gap-0.5 whitespace-nowrap">
<Tooltip <Tooltip
v-if="primaryLine(row.primaryKpi).hover" v-if="primaryAnim(row.primaryKpi).hover"
:title="primaryLine(row.primaryKpi).hover" :title="primaryAnim(row.primaryKpi).hover"
> >
<span <span
class="cursor-default tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]" class="cursor-default tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
> >
{{ primaryLine(row.primaryKpi).display }} <AnimatedNumberText
v-if="primaryAnim(row.primaryKpi).value != null"
:value="primaryAnim(row.primaryKpi).value"
:format="primaryAnim(row.primaryKpi).format"
/>
<template v-else>
{{ primaryAnim(row.primaryKpi).fallback }}
</template>
</span> </span>
</Tooltip> </Tooltip>
<span <span
v-else v-else
class="tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]" class="tabular-nums text-[26px] font-bold leading-none tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
> >
{{ primaryLine(row.primaryKpi).display }} <AnimatedNumberText
v-if="primaryAnim(row.primaryKpi).value != null"
:value="primaryAnim(row.primaryKpi).value"
:format="primaryAnim(row.primaryKpi).format"
/>
<template v-else>
{{ primaryAnim(row.primaryKpi).fallback }}
</template>
</span> </span>
<span <span
v-if="primaryLine(row.primaryKpi).unitText" v-if="primaryAnim(row.primaryKpi).unitText"
class="text-sm font-semibold leading-none text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]" class="text-sm font-semibold leading-none text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
> >
{{ primaryLine(row.primaryKpi).unitText }} {{ primaryAnim(row.primaryKpi).unitText }}
</span> </span>
</div> </div>
@@ -100,6 +100,10 @@ function drawFinanceTrend() {
const showDataZoom = props.trend.length > 14; const showDataZoom = props.trend.length > 14;
renderFinanceTrend({ renderFinanceTrend({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { type: 'cross', crossStyle: { color: isDark ? '#475569' : '#94a3b8' } }, axisPointer: { type: 'cross', crossStyle: { color: isDark ? '#475569' : '#94a3b8' } },
@@ -360,7 +364,7 @@ function drawFinanceTrend() {
z: 6, z: 6,
}, },
], ],
}); }, false);
} catch (error) { } catch (error) {
console.error('[WorkbenchFinanceTrendChart] render failed:', error); console.error('[WorkbenchFinanceTrendChart] render failed:', error);
} }
@@ -6,6 +6,8 @@ import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells'; import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue'; import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import AnimatedMoneyCell from '../../../components/AnimatedMoneyCell.vue';
import { import {
salesTaxColumnHint, salesTaxColumnHint,
storeOverviewHints, storeOverviewHints,
@@ -46,11 +48,6 @@ const somePlatformsSelected = computed(() => {
return props.selectedExportPlatformCodes.length > 0; return props.selectedExportPlatformCodes.length > 0;
}); });
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) => const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2)); formatNumberCell(v, (n) => n.toFixed(2));
@@ -344,28 +341,28 @@ const sortedData = computed(() => {
<!-- 目标 --> <!-- 目标 -->
<td class="p-6 font-medium">{{ p.targetOrderCount.toLocaleString('zh-CN') }}</td> <td class="p-6 font-medium">{{ p.targetOrderCount.toLocaleString('zh-CN') }}</td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.orderCountAchievementRate) }}</td> <td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.orderCountAchievementRate) }}</td>
<td class="p-6 font-medium">{{ formatAmount(p.targetAmount) }}</td> <td class="p-6 font-medium"><AnimatedMoneyCell :value="p.targetAmount" /></td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.salesAmountAchievementRate) }}</td> <td class="p-6 font-black text-blue-600 dark:text-blue-400">{{ formatPercentPlain(p.salesAmountAchievementRate) }}</td>
<!-- 规模 --> <!-- 规模 -->
<td class="p-6 font-black">{{ formatAmount(p.salesAmount) }}</td> <td class="p-6 font-black"><AnimatedMoneyCell :value="p.salesAmount" /></td>
<td class="p-6 font-black text-amber-700 dark:text-amber-400">{{ formatAmount(p.dealAmount) }}</td> <td class="p-6 font-black text-amber-700 dark:text-amber-400"><AnimatedMoneyCell :value="p.dealAmount" /></td>
<td class="p-6 font-medium">{{ p.orderCount.toLocaleString('zh-CN') }}</td> <td class="p-6 font-medium">{{ p.orderCount.toLocaleString('zh-CN') }}</td>
<td class="p-6 font-medium">{{ formatAmount(p.averageOrderValue) }}</td> <td class="p-6 font-medium"><AnimatedMoneyCell :value="p.averageOrderValue" /></td>
<!-- 成本 --> <!-- 成本 -->
<td class="p-6">{{ formatAmount(p.productCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="p.productCost" /></td>
<td class="p-6">{{ formatAmount(p.shippingCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="p.shippingCost" /></td>
<td class="p-6">{{ formatAmount(p.otherCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="p.otherCost" /></td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ formatAmount(p.orderCost) }}</td> <td class="p-6 font-bold text-orange-800 dark:text-orange-300"><AnimatedMoneyCell :value="p.orderCost" /></td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400">{{ formatAmount(p.refundAmount) }}</td> <td class="p-6 font-bold text-rose-600 dark:text-rose-400"><AnimatedMoneyCell :value="p.refundAmount" /></td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(p.salesTaxAmount) }}</td> <td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"><AnimatedMoneyCell :value="p.salesTaxAmount" /></td>
<td class="p-6">{{ formatAmount(p.totalPromotionFee) }}</td> <td class="p-6"><AnimatedMoneyCell :value="p.totalPromotionFee" /></td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(p.brushFee) }}</td> <td class="p-6 text-orange-600 dark:text-orange-400"><AnimatedMoneyCell :value="p.brushFee" /></td>
<!-- 盈利 --> <!-- 盈利 -->
<td class="p-6 font-bold text-emerald-700 dark:text-emerald-400"> <td class="p-6 font-bold text-emerald-700 dark:text-emerald-400">
{{ formatAmount(p.grossProfit) }} <AnimatedMoneyCell :value="p.grossProfit" />
</td> </td>
<td class="p-6 font-bold" :class="p.totalProfitBeforeTax >= 0 ? 'text-slate-800 dark:text-[hsl(0deg_0%_95%)]' : 'text-rose-600 dark:text-rose-400'"> <td class="p-6 font-bold" :class="p.totalProfitBeforeTax >= 0 ? 'text-slate-800 dark:text-[hsl(0deg_0%_95%)]' : 'text-rose-600 dark:text-rose-400'">
{{ formatAmount(p.totalProfitBeforeTax) }} <AnimatedMoneyCell :value="p.totalProfitBeforeTax" />
</td> </td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatFeeRatioPercent(p.feeRatio) }}</td> <td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatFeeRatioPercent(p.feeRatio) }}</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ p.roi.toFixed(2) }}</td> <td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ p.roi.toFixed(2) }}</td>
@@ -373,7 +370,7 @@ const sortedData = computed(() => {
class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black" class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black"
:class="p.profitAfterTax >= 0 ? 'text-emerald-600 dark:text-emerald-300' : 'text-rose-600 dark:text-rose-400'" :class="p.profitAfterTax >= 0 ? 'text-emerald-600 dark:text-emerald-300' : 'text-rose-600 dark:text-rose-400'"
> >
{{ formatAmount(p.profitAfterTax) }} <AnimatedMoneyCell :value="p.profitAfterTax" />
</td> </td>
</tr> </tr>
</tbody> </tbody>
@@ -386,34 +383,34 @@ const sortedData = computed(() => {
<td class="p-6 text-blue-600 dark:text-blue-400"> <td class="p-6 text-blue-600 dark:text-blue-400">
{{ totalData.orderCountAchievementRate !== undefined ? formatPercentPlain(totalData.orderCountAchievementRate) : '-' }} {{ totalData.orderCountAchievementRate !== undefined ? formatPercentPlain(totalData.orderCountAchievementRate) : '-' }}
</td> </td>
<td class="p-6">{{ cellMoney(totalData.targetAmount) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.targetAmount" /></td>
<td class="p-6 text-blue-600 dark:text-blue-400"> <td class="p-6 text-blue-600 dark:text-blue-400">
{{ totalData.salesAmountAchievementRate !== undefined ? formatPercentPlain(totalData.salesAmountAchievementRate) : '-' }} {{ totalData.salesAmountAchievementRate !== undefined ? formatPercentPlain(totalData.salesAmountAchievementRate) : '-' }}
</td> </td>
<!-- 规模 --> <!-- 规模 -->
<td class="p-6">{{ cellMoney(totalData.salesAmount) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.salesAmount" /></td>
<td class="p-6 text-amber-700 dark:text-amber-400">{{ cellMoney(totalData.dealAmount) }}</td> <td class="p-6 text-amber-700 dark:text-amber-400"><AnimatedMoneyCell :value="totalData.dealAmount" /></td>
<td class="p-6">{{ formatIntCell(totalData.orderCount) }}</td> <td class="p-6">{{ formatIntCell(totalData.orderCount) }}</td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(totalData.averageOrderValue) }} <AnimatedMoneyCell :value="totalData.averageOrderValue" />
</td> </td>
<!-- 成本 --> <!-- 成本 -->
<td class="p-6">{{ cellMoney(totalData.productCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.productCost" /></td>
<td class="p-6">{{ cellMoney(totalData.shippingCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.shippingCost" /></td>
<td class="p-6">{{ cellMoney(totalData.otherCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.otherCost" /></td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(totalData.orderCost) }}</td> <td class="p-6 font-bold text-orange-800 dark:text-orange-300"><AnimatedMoneyCell :value="totalData.orderCost" /></td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(totalData.refundAmount) }}</td> <td class="p-6 text-rose-600 dark:text-rose-400"><AnimatedMoneyCell :value="totalData.refundAmount" /></td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(totalData.salesTaxAmount) }} <AnimatedMoneyCell :value="totalData.salesTaxAmount" />
</td> </td>
<td class="p-6">{{ cellMoney(totalData.totalPromotionFee) }}</td> <td class="p-6"><AnimatedMoneyCell :value="totalData.totalPromotionFee" /></td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(totalData.brushFee) }}</td> <td class="p-6 text-orange-600 dark:text-orange-400"><AnimatedMoneyCell :value="totalData.brushFee" /></td>
<!-- 盈利 --> <!-- 盈利 -->
<td class="p-6 text-emerald-700 dark:text-emerald-400"> <td class="p-6 text-emerald-700 dark:text-emerald-400">
{{ cellMoney(totalData.grossProfit) }} <AnimatedMoneyCell :value="totalData.grossProfit" />
</td> </td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(totalData.totalProfitBeforeTax) }} <AnimatedMoneyCell :value="totalData.totalProfitBeforeTax" />
</td> </td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ totalData.feeRatio !== undefined ? formatFeeRatioPercent(totalData.feeRatio) : '-' }} {{ totalData.feeRatio !== undefined ? formatFeeRatioPercent(totalData.feeRatio) : '-' }}
@@ -425,7 +422,7 @@ const sortedData = computed(() => {
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950" class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(totalData.profitAfterTax ?? 0) >= 0 ? 'text-emerald-700 dark:text-emerald-300' : 'text-rose-600 dark:text-rose-400'" :class="(totalData.profitAfterTax ?? 0) >= 0 ? 'text-emerald-700 dark:text-emerald-300' : 'text-rose-600 dark:text-rose-400'"
> >
{{ cellMoney(totalData.profitAfterTax) }} <AnimatedMoneyCell :value="totalData.profitAfterTax" />
</td> </td>
</tr> </tr>
</tfoot> </tfoot>
@@ -7,6 +7,8 @@ import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells'; import { formatIntCell, formatNumberCell } from '#/utils/overview-table-cells';
import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue'; import OverviewColumnHint from '#/components/overview/OverviewColumnHint.vue';
import AnimatedMoneyCell from '../../../components/AnimatedMoneyCell.vue';
import { import {
salesTaxColumnHint, salesTaxColumnHint,
storeOverviewHints, storeOverviewHints,
@@ -47,16 +49,11 @@ const someShopsSelected = computed(() => {
return props.selectedExportShopIds.length > 0; return props.selectedExportShopIds.length > 0;
}); });
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
};
const formatPercentPlain = (value: number | undefined) => { const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-'; if (value === undefined) return '-';
return `${value.toFixed(1)}%`; return `${value.toFixed(1)}%`;
}; };
const cellMoney = (v: number | null | undefined) => formatNumberCell(v, formatAmount);
const cellRoi = (v: number | null | undefined) => const cellRoi = (v: number | null | undefined) =>
formatNumberCell(v, (n) => n.toFixed(2)); formatNumberCell(v, (n) => n.toFixed(2));
</script> </script>
@@ -301,7 +298,7 @@ const cellRoi = (v: number | null | undefined) =>
}} }}
</td> </td>
<td class="p-6 font-medium"> <td class="p-6 font-medium">
{{ cellMoney(shop.targetAmount) }} <AnimatedMoneyCell :value="shop.targetAmount" />
</td> </td>
<td class="p-6 font-black text-blue-600 dark:text-blue-400"> <td class="p-6 font-black text-blue-600 dark:text-blue-400">
{{ {{
@@ -312,48 +309,48 @@ const cellRoi = (v: number | null | undefined) =>
</td> </td>
<!-- 规模 --> <!-- 规模 -->
<td class="p-6 font-black"> <td class="p-6 font-black">
{{ formatAmount(shop.salesAmount as number) }} <AnimatedMoneyCell :value="shop.salesAmount" />
</td> </td>
<td class="p-6 font-black text-amber-700 dark:text-amber-400"> <td class="p-6 font-black text-amber-700 dark:text-amber-400">
{{ formatAmount(shop.dealAmount as number ) }} <AnimatedMoneyCell :value="shop.dealAmount" />
</td> </td>
<td class="p-6 font-medium"> <td class="p-6 font-medium">
{{ formatIntCell(shop.orderCount) }} {{ formatIntCell(shop.orderCount) }}
</td> </td>
<td class="p-6 font-medium"> <td class="p-6 font-medium">
{{ cellMoney(shop.averageOrderValue) }} <AnimatedMoneyCell :value="shop.averageOrderValue" />
</td> </td>
<!-- 成本 --> <!-- 成本 -->
<td class="p-6"> <td class="p-6">
{{ cellMoney(shop.productCost) }} <AnimatedMoneyCell :value="shop.productCost" />
</td> </td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(shop.shippingCost) }} <AnimatedMoneyCell :value="shop.shippingCost" />
</td> </td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(shop.otherCost) }} <AnimatedMoneyCell :value="shop.otherCost" />
</td> </td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300"> <td class="p-6 font-bold text-orange-800 dark:text-orange-300">
{{ cellMoney(shop.orderCost) }} <AnimatedMoneyCell :value="shop.orderCost" />
</td> </td>
<td class="p-6 font-bold text-rose-600 dark:text-rose-400"> <td class="p-6 font-bold text-rose-600 dark:text-rose-400">
{{ cellMoney(shop.refundAmount) }} <AnimatedMoneyCell :value="shop.refundAmount" />
</td> </td>
<td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ cellMoney(shop.salesTaxAmount) }} <AnimatedMoneyCell :value="shop.salesTaxAmount" />
</td> </td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(shop.totalPromotionFee) }} <AnimatedMoneyCell :value="shop.totalPromotionFee" />
</td> </td>
<td class="p-6 text-orange-600 dark:text-orange-400"> <td class="p-6 text-orange-600 dark:text-orange-400">
{{ cellMoney(shop.brushFee) }} <AnimatedMoneyCell :value="shop.brushFee" />
</td> </td>
<!-- 盈利 --> <!-- 盈利 -->
<td class="p-6 font-bold text-emerald-700 dark:text-emerald-400"> <td class="p-6 font-bold text-emerald-700 dark:text-emerald-400">
{{ cellMoney(shop.grossProfit) }} <AnimatedMoneyCell :value="shop.grossProfit" />
</td> </td>
<td class="p-6 font-bold"> <td class="p-6 font-bold">
{{ cellMoney(shop.totalProfitBeforeTax) }} <AnimatedMoneyCell :value="shop.totalProfitBeforeTax" />
</td> </td>
<td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"> <td class="p-6 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{ {{
@@ -366,7 +363,7 @@ const cellRoi = (v: number | null | undefined) =>
{{ cellRoi(shop.roi) }} {{ cellRoi(shop.roi) }}
</td> </td>
<td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black text-emerald-600 dark:text-emerald-300"> <td class="bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%)] p-6 text-base font-black text-emerald-600 dark:text-emerald-300">
{{ cellMoney(shop.profitAfterTax) }} <AnimatedMoneyCell :value="shop.profitAfterTax" />
</td> </td>
</tr> </tr>
<tr v-if="!shopSummary?.shops?.length"> <tr v-if="!shopSummary?.shops?.length">
@@ -393,7 +390,7 @@ const cellRoi = (v: number | null | undefined) =>
: '-' : '-'
}} }}
</td> </td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.targetAmount) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.targetAmount" /></td>
<td class="p-6 text-blue-600 dark:text-blue-400"> <td class="p-6 text-blue-600 dark:text-blue-400">
{{ {{
shopSummary?.total?.salesAmountAchievementRate !== undefined shopSummary?.total?.salesAmountAchievementRate !== undefined
@@ -402,30 +399,30 @@ const cellRoi = (v: number | null | undefined) =>
}} }}
</td> </td>
<!-- 规模 --> <!-- 规模 -->
<td class="p-6">{{ cellMoney(shopSummary?.total?.salesAmount) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.salesAmount" /></td>
<td class="p-6 text-amber-700 dark:text-amber-400">{{ cellMoney(shopSummary?.total?.dealAmount) }}</td> <td class="p-6 text-amber-700 dark:text-amber-400"><AnimatedMoneyCell :value="shopSummary?.total?.dealAmount" /></td>
<td class="p-6">{{ formatIntCell(shopSummary?.total?.orderCount) }}</td> <td class="p-6">{{ formatIntCell(shopSummary?.total?.orderCount) }}</td>
<td class="p-6"> <td class="p-6">
{{ cellMoney(shopSummary?.total?.averageOrderValue) }} <AnimatedMoneyCell :value="shopSummary?.total?.averageOrderValue" />
</td> </td>
<!-- 成本 --> <!-- 成本 -->
<td class="p-6">{{ cellMoney(shopSummary?.total?.productCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.productCost" /></td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.shippingCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.shippingCost" /></td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.otherCost) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.otherCost" /></td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cellMoney(shopSummary?.total?.orderCost) }}</td> <td class="p-6 font-bold text-orange-800 dark:text-orange-300"><AnimatedMoneyCell :value="shopSummary?.total?.orderCost" /></td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ cellMoney(shopSummary?.total?.refundAmount) }}</td> <td class="p-6 text-rose-600 dark:text-rose-400"><AnimatedMoneyCell :value="shopSummary?.total?.refundAmount" /></td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ cellMoney(shopSummary?.total?.salesTaxAmount) }}</td> <td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"><AnimatedMoneyCell :value="shopSummary?.total?.salesTaxAmount" /></td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.totalPromotionFee) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.totalPromotionFee" /></td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cellMoney(shopSummary?.total?.brushFee) }}</td> <td class="p-6 text-orange-600 dark:text-orange-400"><AnimatedMoneyCell :value="shopSummary?.total?.brushFee" /></td>
<!-- 盈利 --> <!-- 盈利 -->
<td class="p-6 text-emerald-700 dark:text-emerald-400">{{ cellMoney(shopSummary?.total?.grossProfit) }}</td> <td class="p-6 text-emerald-700 dark:text-emerald-400"><AnimatedMoneyCell :value="shopSummary?.total?.grossProfit" /></td>
<td class="p-6">{{ cellMoney(shopSummary?.total?.totalProfitBeforeTax) }}</td> <td class="p-6"><AnimatedMoneyCell :value="shopSummary?.total?.totalProfitBeforeTax" /></td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopSummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(shopSummary?.total?.feeRatio) : '-' }}</td> <td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopSummary?.total?.feeRatio !== undefined ? formatFeeRatioPercent(shopSummary?.total?.feeRatio) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(shopSummary?.total?.roi) }}</td> <td class="p-6 text-indigo-700 dark:text-indigo-400">{{ cellRoi(shopSummary?.total?.roi) }}</td>
<td <td
class="bg-emerald-100 p-6 text-base dark:bg-emerald-950" class="bg-emerald-100 p-6 text-base dark:bg-emerald-950"
:class="(shopSummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'" :class="(shopSummary?.total?.profitAfterTax ?? 0) < 0 ? 'text-rose-600 dark:text-rose-400' : 'text-emerald-700 dark:text-emerald-300'"
>{{ cellMoney(shopSummary?.total?.profitAfterTax) }}</td> ><AnimatedMoneyCell :value="shopSummary?.total?.profitAfterTax" /></td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@@ -95,6 +95,10 @@ const drawMultiBarChart = () => {
const bottomPad = multiChartGridBottomPx(r.length, rotateLabels); const bottomPad = multiChartGridBottomPx(r.length, rotateLabels);
renderMultiBar({ renderMultiBar({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
@@ -176,7 +180,7 @@ const drawMultiBarChart = () => {
itemStyle: { color: isDark ? '#fb7185' : '#e11d48' }, itemStyle: { color: isDark ? '#fb7185' : '#e11d48' },
}, },
], ],
}); }, false);
}; };
const drawMultiLineChart = () => { const drawMultiLineChart = () => {
@@ -191,6 +195,10 @@ const drawMultiLineChart = () => {
const bottomPad = multiChartGridBottomPx(r.length, rotateLabels); const bottomPad = multiChartGridBottomPx(r.length, rotateLabels);
renderMultiLine({ renderMultiLine({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff', backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
@@ -250,7 +258,7 @@ const drawMultiLineChart = () => {
itemStyle: { color: isDark ? '#fbbf24' : '#d97706' }, itemStyle: { color: isDark ? '#fbbf24' : '#d97706' },
}, },
], ],
}); }, false);
}; };
const drawRankBarChart = () => { const drawRankBarChart = () => {
@@ -265,6 +273,10 @@ const drawRankBarChart = () => {
); );
renderRankBar({ renderRankBar({
animation: true,
animationDuration: 500,
animationDurationUpdate: 650,
animationEasingUpdate: 'cubicOut',
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
axisPointer: { type: 'shadow' }, axisPointer: { type: 'shadow' },
@@ -332,7 +344,7 @@ const drawRankBarChart = () => {
}, },
}, },
], ],
}); }, false);
}; };
const redraw = async () => { const redraw = async () => {