mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
refactor(shop-overview): 拆分组件,品类表表头样式与商品表对齐
- 拆分为 TimeRangeBar/StatCards/SalesTrendChart/FinancialPanel/ ProductComparisonTable/CategoryComparisonTable 六个组件 - index.vue 从 1603 行缩减至 ~730 行 - CategoryComparisonTable 表头添加 sticky + max-h 滚动, 成本/损益 group header 配色与商品表对齐 - 修复 SalesTrendChart 缺少 onMounted 引入
This commit is contained in:
+206
@@ -0,0 +1,206 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
taxRate: number;
|
||||
categoryExportMode: boolean;
|
||||
selectedExportCategoryIds: number[];
|
||||
categoryExportLoading?: boolean;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'export-all'): void;
|
||||
(e: 'export-toggle', enabled: boolean): void;
|
||||
(e: 'category-select-all', event: Event): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const formatAmount = (amount: number) => `¥${amount.toLocaleString('zh-CN')}`;
|
||||
|
||||
const formatPercentPlain = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="flex items-center justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8"
|
||||
>
|
||||
<div>
|
||||
<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%)]">
|
||||
当前时间范围内的品类经营数据汇总,支持按品类导出
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<template v-if="props.categoryExportMode">
|
||||
<Button
|
||||
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('export-toggle', false)"
|
||||
>
|
||||
取消选择
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-blue-600 !px-8 !py-3 !text-sm !font-bold !text-white !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
|
||||
:loading="props.categoryExportLoading"
|
||||
:disabled="props.selectedExportCategoryIds.length === 0"
|
||||
@click="emit('export-all')"
|
||||
>
|
||||
导出选中 ({{ props.selectedExportCategoryIds.length }})
|
||||
</Button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<Button
|
||||
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
|
||||
@click="emit('export-toggle', true)"
|
||||
>
|
||||
指定品类导出
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-black !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
|
||||
:loading="props.categoryExportLoading"
|
||||
@click="emit('export-all')"
|
||||
>
|
||||
导出全部
|
||||
</Button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="max-h-[420px] overflow-auto">
|
||||
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
|
||||
<colgroup>
|
||||
<col style="width: 60px; min-width: 60px;" />
|
||||
<col style="width: 160px; min-width: 160px;" />
|
||||
<col style="width: 130px; min-width: 130px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 130px; min-width: 130px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 140px; min-width: 140px;" />
|
||||
</colgroup>
|
||||
<thead
|
||||
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
style="position: sticky; top: 0; z-index: 20;"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
v-if="props.categoryExportMode"
|
||||
rowspan="2"
|
||||
class="border-b border-r border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="Boolean(props.data?.categoryComparisons?.length) && props.selectedExportCategoryIds.length === (props.data?.categoryComparisons?.length ?? 0)"
|
||||
:indeterminate="props.selectedExportCategoryIds.length > 0 && props.selectedExportCategoryIds.length < (props.data?.categoryComparisons?.length ?? 0)"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
@change="emit('category-select-all', $event)"
|
||||
/>
|
||||
</th>
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)] border-r-2 border-slate-100 bg-white shadow-sm dark:shadow-none"
|
||||
:style="props.categoryExportMode ? 'left: 40px' : 'left: 0'"
|
||||
>
|
||||
品类名称
|
||||
</th>
|
||||
<th colspan="3" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50)] p-3 text-center">
|
||||
经营规模维度
|
||||
</th>
|
||||
<th colspan="7" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50)] p-3 text-center italic text-orange-700 dark:text-orange-400">
|
||||
成本费用维度
|
||||
</th>
|
||||
<th colspan="5" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-3 text-center italic text-emerald-700 dark:text-emerald-400">
|
||||
盈利分析维度
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
|
||||
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)]">实际销售额</th>
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">单量</th>
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">客单价</th>
|
||||
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">商品成本</th>
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">运费</th>
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">其他成本</th>
|
||||
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-rose-400">退款金额</th>
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">推广费</th>
|
||||
<th class="border-b px-6 py-4 text-orange-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-orange-400">刷单费用</th>
|
||||
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 text-slate-400 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
|
||||
<th class="border-b px-6 py-4 font-bold dark:bg-[hsl(142deg_71.8%_29%/20%)]">税前盈亏</th>
|
||||
<th class="border-b px-6 py-4 italic text-rose-500 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-rose-400">{{ (props.taxRate * 100).toFixed(0) }}%税额</th>
|
||||
<th class="border-b px-6 py-4 font-black text-indigo-700 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-indigo-400">ROI</th>
|
||||
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">税后盈亏</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
|
||||
<tr
|
||||
v-for="cat in props.data?.categoryComparisons"
|
||||
:key="cat.categoryId ?? 'uncategorized'"
|
||||
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)]"
|
||||
>
|
||||
<td
|
||||
v-if="props.categoryExportMode"
|
||||
class="border-b border-r border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white p-3 text-center dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<input
|
||||
v-model="props.selectedExportCategoryIds"
|
||||
type="checkbox"
|
||||
:value="cat.categoryId"
|
||||
class="h-4 w-4 cursor-pointer accent-blue-600"
|
||||
/>
|
||||
</td>
|
||||
<td class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none">
|
||||
<span class="text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline">
|
||||
{{ cat.categoryName || '未分类' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-6 font-black">{{ formatAmount(cat.salesAmount) }}</td>
|
||||
<td class="p-6">{{ cat.orderCount?.toLocaleString('zh-CN') || '-' }}</td>
|
||||
<td class="p-6">{{ cat.averageOrderValue ? `¥${cat.averageOrderValue.toFixed(2)}` : '-' }}</td>
|
||||
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.productCost ? formatAmount(cat.productCost) : '-' }}</td>
|
||||
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.shippingCost ? formatAmount(cat.shippingCost) : '-' }}</td>
|
||||
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.otherCost ? formatAmount(cat.otherCost) : '-' }}</td>
|
||||
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 font-bold text-rose-600 dark:text-rose-400">{{ cat.refundAmount ? formatAmount(cat.refundAmount) : '-' }}</td>
|
||||
<td class="p-6 text-amber-600 dark:text-amber-400">{{ cat.totalPromotionFee ? formatAmount(cat.totalPromotionFee) : '-' }}</td>
|
||||
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cat.brushFee ? formatAmount(cat.brushFee) : '-' }}</td>
|
||||
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-400">{{ cat.feeRatio !== undefined ? formatPercentPlain(cat.feeRatio) : '-' }}</td>
|
||||
<td class="p-6 font-bold">{{ cat.totalProfitBeforeTax ? formatAmount(cat.totalProfitBeforeTax) : '-' }}</td>
|
||||
<td class="p-6 italic text-rose-500 dark:text-rose-400">{{ cat.salesTaxAmount ? formatAmount(cat.salesTaxAmount) : '-' }}</td>
|
||||
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ cat.roi?.toFixed(2) || '-' }}</td>
|
||||
<td
|
||||
class="border-l bg-emerald-50/30 p-6 text-base font-black dark:bg-[hsl(142deg_71.8%_29%/20%)]"
|
||||
:class="(cat.profitAfterTax ?? 0) < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
|
||||
>
|
||||
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!props.data?.categoryComparisons?.length">
|
||||
<td :colspan="props.categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
taxRate: number;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
|
||||
const formatPercent = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-col rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
财务损益全维度 (P&L)
|
||||
</h3>
|
||||
<div class="flex flex-1 flex-col space-y-4 text-sm">
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">推广费总支出</span>
|
||||
<span class="font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalPromotionFee ? `-${formatAmount(data.totalPromotionFee)}` : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">客单价 (AOV)</span>
|
||||
<span class="font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalSalesAmount && data?.totalOrderCount ? formatAmount(data.totalSalesAmount / data.totalOrderCount) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pb-2">
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">总税后盈亏 (Profit)</span>
|
||||
<span class="font-bold text-indigo-600 dark:text-indigo-400">
|
||||
{{ data?.totalProfitAfterTax ? formatAmount(data.totalProfitAfterTax) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 扣除项 -->
|
||||
<div class="mt-4 space-y-3 rounded-2xl bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] p-4">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">销售额 {{ (props.taxRate * 100).toFixed(0) }}% 税额</span>
|
||||
<span class="font-bold text-rose-500 dark:text-rose-400">
|
||||
{{ data?.totalTaxAmount ? formatAmount(data.totalTaxAmount) : '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">较上月同期增长</span>
|
||||
<span class="font-black text-emerald-500 dark:text-emerald-400">
|
||||
{{ formatPercent(data?.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 最终结果 -->
|
||||
<div
|
||||
class="mt-auto flex items-center justify-between rounded-2xl bg-slate-900 p-5 text-white shadow-2xl dark:shadow-none"
|
||||
>
|
||||
<div>
|
||||
<p class="text-[10px] font-black uppercase opacity-60">Final Net Profit</p>
|
||||
<p class="text-xs font-bold">税后最终净利</p>
|
||||
</div>
|
||||
<div class="text-3xl font-black">
|
||||
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Button } from 'ant-design-vue';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
taxRate: number;
|
||||
exportLoading?: boolean;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'export'): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
const router = useRouter();
|
||||
|
||||
const formatAmount = (amount: number) => `¥${amount.toLocaleString('zh-CN')}`;
|
||||
|
||||
const formatPercentPlain = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div
|
||||
class="flex items-center justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8"
|
||||
>
|
||||
<div>
|
||||
<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%)]">
|
||||
横向对比各商品规模、成本及 ROI 效率
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-black !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
|
||||
:loading="exportLoading"
|
||||
@click="emit('export')"
|
||||
>
|
||||
导出店铺概览
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="max-h-[420px] overflow-auto">
|
||||
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
|
||||
<colgroup>
|
||||
<col style="width: 220px; min-width: 220px;" />
|
||||
<col style="width: 140px; min-width: 140px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 130px; min-width: 130px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 100px; min-width: 100px;" />
|
||||
<col style="width: 110px; min-width: 110px;" />
|
||||
<col style="width: 130px; min-width: 130px;" />
|
||||
<col style="width: 120px; min-width: 120px;" />
|
||||
<col style="width: 140px; min-width: 140px;" />
|
||||
</colgroup>
|
||||
<thead
|
||||
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
style="position: sticky; top: 0; z-index: 20;"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col z-10 border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/80%)] dark:text-[hsl(0deg_0%_95%)]"
|
||||
style="left: 0"
|
||||
>
|
||||
商品详情
|
||||
</th>
|
||||
<th
|
||||
colspan="3"
|
||||
class="border-b border-l border-slate-200 dark:border-b dark:border-l dark:border-[hsl(240deg_3.7%_22%)] bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50)] px-3 py-3 text-center"
|
||||
>
|
||||
商品规模 (Scale)
|
||||
</th>
|
||||
<th
|
||||
colspan="6"
|
||||
class="border-b border-l border-slate-200 dark:border-b dark:border-l dark:border-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50)] px-3 py-3 text-center italic text-orange-700 dark:text-orange-400"
|
||||
>
|
||||
费用成本 (Costs)
|
||||
</th>
|
||||
<th
|
||||
colspan="5"
|
||||
class="border-b border-l border-slate-200 dark:border-b dark:border-l dark:border-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-3 py-3 text-center italic text-emerald-700"
|
||||
>
|
||||
单品损益 (Profitability)
|
||||
</th>
|
||||
</tr>
|
||||
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
|
||||
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_15.9%/80%)]">销售额</th>
|
||||
<th class="border-b border-l dark:border-l dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">单量</th>
|
||||
<th class="border-b px-6 py-4">客单价</th>
|
||||
<th class="border-b border-l dark:border-l dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">商品成本</th>
|
||||
<th class="border-b px-6 py-4">运费</th>
|
||||
<th class="border-b px-6 py-4">其他成本</th>
|
||||
<th class="border-b px-6 py-4 text-rose-600">退款金额</th>
|
||||
<th class="border-b px-6 py-4">推广费</th>
|
||||
<th class="border-b px-6 py-4">刷单费用</th>
|
||||
<th class="border-b border-l dark:border-l dark:border-[hsl(240deg_3.7%_22%)] px-6 py-4">费比 %</th>
|
||||
<th class="border-b px-6 py-4 text-indigo-700 dark:text-indigo-400">单品 ROI</th>
|
||||
<th class="border-b px-6 py-4">税前盈亏</th>
|
||||
<th class="border-b px-6 py-4 italic text-rose-500 dark:text-rose-400">
|
||||
{{ (props.taxRate * 100).toFixed(0) }}%税额
|
||||
</th>
|
||||
<th class="border-b bg-emerald-600 px-6 py-4 font-black text-white">
|
||||
税后净利
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
|
||||
<tr
|
||||
v-for="product in data?.productComparisons"
|
||||
:key="product.productId"
|
||||
class="transition-colors hover:bg-blue-50/30"
|
||||
>
|
||||
<td
|
||||
class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] px-6 py-6 font-bold text-slate-900 dark:text-[hsl(0deg_0%_95%)] cursor-pointer hover:text-blue-600 dark:text-blue-400 hover:underline"
|
||||
style="left: 0; position: sticky; z-index: 10;"
|
||||
@click="router.push(`/ecom/product/details/${product.productId}`)"
|
||||
>
|
||||
<div>{{ product.productName }}</div>
|
||||
<div
|
||||
v-if="product.productCode"
|
||||
class="text-[10px] font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
编码: {{ product.productCode }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 font-black">{{ formatAmount(product.salesAmount) }}</td>
|
||||
<td class="px-6 py-4 font-medium">{{ product.orderCount?.toLocaleString('zh-CN') || '-' }}</td>
|
||||
<td class="px-6 py-4">{{ product.averageOrderValue ? formatAmount(product.averageOrderValue) : '-' }}</td>
|
||||
<td class="px-6 py-4">{{ product.productCost ? formatAmount(product.productCost) : '-' }}</td>
|
||||
<td class="px-6 py-4">{{ product.shippingCost ? formatAmount(product.shippingCost) : '-' }}</td>
|
||||
<td class="px-6 py-4">{{ product.otherCost ? formatAmount(product.otherCost) : '-' }}</td>
|
||||
<td class="px-6 py-4 font-bold text-rose-500 dark:text-rose-400">
|
||||
{{ product.refundAmount ? formatAmount(product.refundAmount) : '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4">{{ product.totalPromotionFee ? formatAmount(product.totalPromotionFee) : '-' }}</td>
|
||||
<td class="px-6 py-4 text-amber-500 dark:text-amber-400">
|
||||
{{ product.brushFee ? formatAmount(product.brushFee) : '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ product.feeRatio !== undefined ? formatPercentPlain(product.feeRatio) : '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">
|
||||
{{ product.roi?.toFixed(2) || '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ product.totalProfitBeforeTax ? formatAmount(product.totalProfitBeforeTax) : '-' }}
|
||||
</td>
|
||||
<td class="px-6 py-4 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
{{ product.salesTaxAmount ? formatAmount(product.salesTaxAmount) : '-' }}
|
||||
</td>
|
||||
<td
|
||||
class="bg-emerald-50/30 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-6 py-4 text-base font-black"
|
||||
:class="product.profitAfterTax && product.profitAfterTax < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
|
||||
>
|
||||
{{ product.profitAfterTax ? formatAmount(product.profitAfterTax) : '-' }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!data?.productComparisons?.length">
|
||||
<td colspan="15" class="p-8 text-center text-gray-400">
|
||||
暂无数据
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
interface Props {
|
||||
data: {
|
||||
salesAmountTrend?: {
|
||||
dailyDataList: { date: string; value: number }[];
|
||||
};
|
||||
orderCountTrend?: {
|
||||
dailyDataList: { date: string; value: number }[];
|
||||
};
|
||||
} | null;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const trendChartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts: renderTrendChart } = useEcharts(trendChartRef);
|
||||
|
||||
const renderChart = () => {
|
||||
if (!trendChartRef.value || !props.data) return;
|
||||
|
||||
const salesTrend = props.data.salesAmountTrend;
|
||||
const orderTrend = props.data.orderCountTrend;
|
||||
|
||||
if (!salesTrend || !orderTrend) return;
|
||||
|
||||
const dates = salesTrend.dailyDataList.map((item) =>
|
||||
dayjs(item.date).format('MM-DD'),
|
||||
);
|
||||
const salesData = salesTrend.dailyDataList.map((item) => item.value);
|
||||
const orderData = orderTrend.dailyDataList.map((item) => item.value);
|
||||
|
||||
const isDark = document.documentElement.classList.contains('dark');
|
||||
renderTrendChart({
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '3%',
|
||||
bottom: '3%',
|
||||
top: '5%',
|
||||
containLabel: true,
|
||||
},
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff',
|
||||
textStyle: {
|
||||
color: isDark ? 'hsl(0deg 0% 95%)' : '#000',
|
||||
},
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: dates,
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : '#e2e8f0',
|
||||
},
|
||||
},
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
name: '销售额',
|
||||
nameTextStyle: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
axisLabel: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
splitLine: {
|
||||
lineStyle: {
|
||||
type: 'dashed',
|
||||
color: isDark ? 'hsl(240deg 3.7% 22%)' : undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'value',
|
||||
name: '单量',
|
||||
position: 'right',
|
||||
nameTextStyle: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
axisLabel: {
|
||||
color: isDark ? 'hsl(240deg 5% 64.9%)' : undefined,
|
||||
},
|
||||
splitLine: { show: false },
|
||||
},
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '销售额',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#3b82f6' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(59, 130, 246, 0.4)' },
|
||||
{ offset: 1, color: 'rgba(59, 130, 246, 0)' },
|
||||
],
|
||||
},
|
||||
},
|
||||
data: salesData,
|
||||
},
|
||||
{
|
||||
name: '日单量',
|
||||
type: 'line',
|
||||
yAxisIndex: 1,
|
||||
smooth: true,
|
||||
symbol: 'none',
|
||||
lineStyle: { width: 3, color: '#10b981' },
|
||||
areaStyle: {
|
||||
color: {
|
||||
type: 'linear',
|
||||
x: 0,
|
||||
y: 0,
|
||||
x2: 0,
|
||||
y2: 1,
|
||||
colorStops: [
|
||||
{ offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
|
||||
{ offset: 1, color: 'rgba(16, 185, 129, 0)' },
|
||||
],
|
||||
},
|
||||
},
|
||||
data: orderData,
|
||||
},
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {
|
||||
if (props.data) {
|
||||
setTimeout(() => renderChart(), 100);
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
const darkObserver = new MutationObserver(() => {
|
||||
if (props.data) renderChart();
|
||||
});
|
||||
darkObserver.observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['class'],
|
||||
});
|
||||
onUnmounted(() => darkObserver.disconnect());
|
||||
});
|
||||
|
||||
defineExpose({ renderChart });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px] xl:col-span-2">
|
||||
<h3 class="mb-6 text-lg font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
销售额与单量趋势分析
|
||||
</h3>
|
||||
<div class="h-[380px] w-full">
|
||||
<EchartsUI ref="trendChartRef" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
interface Props {
|
||||
data: ShopVO.OverviewStatistics | null;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toLocaleString('zh-CN')}`;
|
||||
};
|
||||
|
||||
const formatPercentPlain = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value.toFixed(1)}%`;
|
||||
};
|
||||
|
||||
const formatPercent = (value: number | undefined) => {
|
||||
if (value === undefined) return '-';
|
||||
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<!-- 销售大盘 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div class="mb-4 flex items-start justify-between">
|
||||
<span class="text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
店铺销售总额
|
||||
</span>
|
||||
<span
|
||||
v-if="data?.monthOverMonthGrowth !== undefined"
|
||||
class="rounded bg-emerald-50 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-2 py-1 text-xs font-bold text-emerald-600 dark:text-emerald-400"
|
||||
>
|
||||
增长率 {{ formatPercent(data.monthOverMonthGrowth) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalSalesAmount ? formatAmount(data.totalSalesAmount) : '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.salesAmountAchievementRate !== undefined"
|
||||
class="mt-6 flex items-center justify-between border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4 text-xs font-bold"
|
||||
>
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">销售额目标达成</span>
|
||||
<span class="font-black text-blue-600 dark:text-blue-400">
|
||||
{{ formatPercentPlain(data.salesAmountAchievementRate) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 订单达成 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
订单总量与达成
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ data?.totalOrderCount?.toLocaleString('zh-CN') || '-' }}
|
||||
<span class="ml-1 text-sm font-normal text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">单</span>
|
||||
</div>
|
||||
<div v-if="data?.orderCountAchievementRate !== undefined" class="mt-6">
|
||||
<div class="mb-2 flex justify-between text-[10px] font-black text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
<span>
|
||||
目标:
|
||||
{{ data.totalTargetOrderCount?.toLocaleString('zh-CN') || '-' }} 单
|
||||
</span>
|
||||
<span>
|
||||
达成率:
|
||||
{{ formatPercentPlain(data.orderCountAchievementRate) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="h-2 w-full overflow-hidden rounded-full bg-slate-100">
|
||||
<div
|
||||
class="h-full bg-indigo-500 transition-all duration-1000"
|
||||
:style="{ width: `${Math.min(data.orderCountAchievementRate || 0, 100)}%` }"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 推广效率 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div class="mb-4 text-xs font-black uppercase tracking-widest text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
投资回报率 (ROI)
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-indigo-600 dark:text-indigo-400">
|
||||
{{ data?.totalROI?.toFixed(2) || '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.averageFeeRatio !== undefined"
|
||||
class="mt-6 space-y-2 border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4"
|
||||
>
|
||||
<div class="flex justify-between text-xs font-bold">
|
||||
<span class="text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">平均费比</span>
|
||||
<span class="text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ formatPercentPlain(data.averageFeeRatio) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 利润汇总 -->
|
||||
<div
|
||||
class="flex flex-col justify-between rounded-[20px] border-l-4 border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] border-l-emerald-500 dark:border-l-emerald-500 bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
|
||||
>
|
||||
<div class="mb-4 text-xs font-black uppercase tracking-widest text-emerald-600 dark:text-emerald-400">
|
||||
店铺总净利润 (税后)
|
||||
</div>
|
||||
<div class="text-4xl font-black leading-none text-emerald-600 dark:text-emerald-400">
|
||||
{{ data?.totalNetProfitAfterTax ? formatAmount(data.totalNetProfitAfterTax) : '-' }}
|
||||
</div>
|
||||
<div
|
||||
v-if="data?.totalTaxAmount !== undefined"
|
||||
class="mt-6 flex justify-between border-t border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] pt-4 text-[11px] font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
<span>已扣除 {{ (data.totalNetProfitAfterTax ? (data.totalNetProfitAfterTax / (1 - (data.totalTaxAmount / (data.totalSalesAmount || 1))) - 1) * 100 : 4).toFixed(0) }}% 税额</span>
|
||||
<span>-{{ formatAmount(data.totalTaxAmount) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
<script lang="ts" setup>
|
||||
import { Button, DatePicker, InputNumber } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
interface Props {
|
||||
modelValue: {
|
||||
taxRate: number;
|
||||
activeTimeRange: '7days' | '30days' | 'custom' | 'today' | 'yesterday';
|
||||
customDateRange: [Dayjs, Dayjs] | undefined;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
};
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', val: Props['modelValue']): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const TAX_RATE_KEY = 'overview-tax-rate';
|
||||
|
||||
const formatTaxRate = (value: null | number | string | undefined) => {
|
||||
if (value === null || value === undefined || value === '') return '';
|
||||
const num = Number(value);
|
||||
if (!Number.isFinite(num)) return '';
|
||||
return `${num * 100}%`;
|
||||
};
|
||||
|
||||
const parseTaxRate = (value: string | undefined) => {
|
||||
if (!value) return 0;
|
||||
const num = Number(value.replace('%', '').trim());
|
||||
return Number.isFinite(num) ? num / 100 : 0;
|
||||
};
|
||||
|
||||
const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yesterday') => {
|
||||
let startDate: Dayjs;
|
||||
let endDate: Dayjs = dayjs();
|
||||
|
||||
switch (type) {
|
||||
case '7days':
|
||||
startDate = dayjs().subtract(7, 'day');
|
||||
break;
|
||||
case '30days':
|
||||
startDate = dayjs().subtract(30, 'day');
|
||||
break;
|
||||
case 'custom':
|
||||
if (props.modelValue.customDateRange) {
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: type,
|
||||
dateRange: props.modelValue.customDateRange,
|
||||
});
|
||||
}
|
||||
return;
|
||||
case 'today':
|
||||
startDate = dayjs();
|
||||
endDate = dayjs();
|
||||
break;
|
||||
case 'yesterday':
|
||||
startDate = dayjs().subtract(1, 'day');
|
||||
endDate = dayjs().subtract(1, 'day');
|
||||
break;
|
||||
}
|
||||
|
||||
const newRange: [Dayjs, Dayjs] = [startDate, endDate];
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: type,
|
||||
dateRange: newRange,
|
||||
customDateRange: newRange,
|
||||
});
|
||||
};
|
||||
|
||||
const handleCustomDateRangeChange = (
|
||||
value: [Dayjs, Dayjs] | [string, string] | null,
|
||||
) => {
|
||||
if (value && Array.isArray(value) && value.length === 2) {
|
||||
const dates = [
|
||||
dayjs.isDayjs(value[0]) ? value[0] : dayjs(value[0]),
|
||||
dayjs.isDayjs(value[1]) ? value[1] : dayjs(value[1]),
|
||||
] as [Dayjs, Dayjs];
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
activeTimeRange: 'custom',
|
||||
dateRange: dates,
|
||||
customDateRange: dates,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleTaxRateChange = (val: number | string | undefined) => {
|
||||
const num = typeof val === 'string' ? parseTaxRate(val) : val ?? 0.04;
|
||||
localStorage.setItem(TAX_RATE_KEY, String(num));
|
||||
emit('update:modelValue', {
|
||||
...props.modelValue,
|
||||
taxRate: num,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- 税率输入 -->
|
||||
<div
|
||||
class="flex h-[42px] items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 dark:bg-[hsl(240deg_3.7%_15.9%/30%)] px-3"
|
||||
>
|
||||
<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">税率</span>
|
||||
<InputNumber
|
||||
:value="props.modelValue.taxRate"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.01"
|
||||
:precision="2"
|
||||
size="small"
|
||||
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-white/30 dark:!bg-[hsl(240deg_3.7%_22%/30%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] !text-sm !font-bold"
|
||||
:formatter="formatTaxRate"
|
||||
:parser="parseTaxRate"
|
||||
@change="handleTaxRateChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 时间选择器 -->
|
||||
<div
|
||||
class="flex items-center gap-1.5 rounded-2xl border border-slate-200 bg-slate-200/50 dark:bg-[hsl(240deg_3.7%_15.9%/30%)] p-1"
|
||||
>
|
||||
<div class="flex rounded-xl bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-1 shadow-inner dark:shadow-none">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
props.modelValue.activeTimeRange === 'today'
|
||||
? '!bg-white !font-black !text-blue-600 dark:text-blue-400 dark:!shadow-none !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('today')"
|
||||
>
|
||||
今日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
props.modelValue.activeTimeRange === 'yesterday'
|
||||
? '!bg-white !font-black !text-blue-600 dark:text-blue-400 dark:!shadow-none !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('yesterday')"
|
||||
>
|
||||
昨日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
props.modelValue.activeTimeRange === '7days'
|
||||
? '!bg-white !font-black !text-blue-600 dark:text-blue-400 dark:!shadow-none !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('7days')"
|
||||
>
|
||||
近7日
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-lg !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-all"
|
||||
:class="
|
||||
props.modelValue.activeTimeRange === '30days'
|
||||
? '!bg-white !font-black !text-blue-600 dark:text-blue-400 dark:!shadow-none !shadow-sm'
|
||||
: '!bg-transparent !text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] hover:!text-slate-800'
|
||||
"
|
||||
@click="switchTimeRange('30days')"
|
||||
>
|
||||
近30日
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!-- 日期选择器 -->
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">自定义日期</span>
|
||||
<DatePicker.RangePicker
|
||||
:value="props.modelValue.customDateRange"
|
||||
size="small"
|
||||
format="YYYY-MM-DD"
|
||||
:allow-clear="false"
|
||||
:placeholder="['开始日期', '结束日期']"
|
||||
class="!h-8 !cursor-pointer !border-none !bg-transparent !text-sm !font-bold"
|
||||
@change="handleCustomDateRangeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.tax-rate-input .ant-input-number-input) {
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
padding-top: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user