mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 09:09:20 +08:00
fix(workbench): 工具栏改为缩略+点击展开 Popover,优化窄屏布局
This commit is contained in:
@@ -5,7 +5,7 @@ import { useRouter } from 'vue-router';
|
|||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
import { DatePicker, InputNumber, message, Select, Spin, Tabs } from 'ant-design-vue';
|
import { DatePicker, InputNumber, message, Popover, Select, Spin, Tabs } from 'ant-design-vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { getPlatformPageApi } from '#/api/ecommerce/platform/apis';
|
import { getPlatformPageApi } from '#/api/ecommerce/platform/apis';
|
||||||
@@ -31,6 +31,16 @@ import WorkbenchSalesRankTab from './tabs/sales-rank/index.vue';
|
|||||||
|
|
||||||
defineOptions({ name: 'PddWorkbench' });
|
defineOptions({ name: 'PddWorkbench' });
|
||||||
|
|
||||||
|
const openPopover = ref<string | null>(null);
|
||||||
|
|
||||||
|
function handlePopoverOpen(name: string, open: boolean) {
|
||||||
|
if (open) {
|
||||||
|
openPopover.value = name;
|
||||||
|
} else if (openPopover.value === name) {
|
||||||
|
openPopover.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const EMPTY_MULTI: WorkbenchVO.MultiPanel = {
|
const EMPTY_MULTI: WorkbenchVO.MultiPanel = {
|
||||||
platform: [],
|
platform: [],
|
||||||
shop: [],
|
shop: [],
|
||||||
@@ -79,6 +89,9 @@ const router = useRouter();
|
|||||||
|
|
||||||
const ImportOrderIcon = createIconifyIcon('lucide:upload');
|
const ImportOrderIcon = createIconifyIcon('lucide:upload');
|
||||||
const PromotionFeeIcon = createIconifyIcon('lucide:dollar-sign');
|
const PromotionFeeIcon = createIconifyIcon('lucide:dollar-sign');
|
||||||
|
const ToolbarToggleIcon = createIconifyIcon('lucide:sliders-horizontal');
|
||||||
|
const ReceiptIcon = createIconifyIcon('lucide:receipt');
|
||||||
|
const CalendarIcon = createIconifyIcon('lucide:calendar');
|
||||||
|
|
||||||
function goToImportOrder() {
|
function goToImportOrder() {
|
||||||
void router.push('/import/order');
|
void router.push('/import/order');
|
||||||
@@ -112,7 +125,7 @@ const toolbarActionClass =
|
|||||||
'inline-flex min-w-0 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-xl border-0 bg-transparent px-3 py-2 text-sm font-bold text-slate-800 transition-colors hover:bg-slate-100 dark:text-slate-200 dark:hover:bg-[hsl(240deg_3.7%_22%)]';
|
'inline-flex min-w-0 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-xl border-0 bg-transparent px-3 py-2 text-sm font-bold text-slate-800 transition-colors hover:bg-slate-100 dark:text-slate-200 dark:hover:bg-[hsl(240deg_3.7%_22%)]';
|
||||||
|
|
||||||
const timeRangeBtnClass =
|
const timeRangeBtnClass =
|
||||||
'inline-flex min-w-0 cursor-pointer items-center justify-center rounded-xl border-0 px-3 py-2 text-sm font-bold transition-colors sm:px-5';
|
'inline-flex min-w-0 shrink-0 cursor-pointer items-center justify-center rounded-xl border-0 px-3 py-2 text-sm font-bold whitespace-nowrap transition-colors sm:px-5';
|
||||||
|
|
||||||
function timeRangeBtnState(active: boolean) {
|
function timeRangeBtnState(active: boolean) {
|
||||||
return active
|
return active
|
||||||
@@ -621,10 +634,16 @@ onUnmounted(() => {
|
|||||||
<div
|
<div
|
||||||
class="workbench-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
class="workbench-header-extra flex w-full max-w-full flex-col gap-2 sm:w-auto sm:flex-row sm:items-center sm:gap-2"
|
||||||
>
|
>
|
||||||
<div :class="toolbarShellClass">
|
<!-- 导入 -->
|
||||||
<div
|
<Popover
|
||||||
:class="[toolbarPanelClass, 'flex items-center gap-0.5 overflow-x-auto p-1']"
|
trigger="click"
|
||||||
|
:open="openPopover === 'import'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('import', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
>
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex items-center gap-0.5 whitespace-nowrap">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
:class="toolbarActionClass"
|
:class="toolbarActionClass"
|
||||||
@@ -642,11 +661,27 @@ onUnmounted(() => {
|
|||||||
导入推广费
|
导入推广费
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
<div :class="toolbarShellClass">
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
<div
|
<div
|
||||||
:class="[toolbarPanelClass, 'flex items-center gap-2 px-2 py-1']"
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
|
<ImportOrderIcon class="h-4 w-4 shrink-0" />
|
||||||
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">导入</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
<!-- 税率 -->
|
||||||
|
<Popover
|
||||||
|
trigger="click"
|
||||||
|
:open="openPopover === 'taxRate'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex items-center gap-2 whitespace-nowrap">
|
||||||
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
税率
|
税率
|
||||||
</span>
|
</span>
|
||||||
@@ -661,18 +696,28 @@ onUnmounted(() => {
|
|||||||
:parser="parseTaxRate"
|
:parser="parseTaxRate"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
<div
|
<div
|
||||||
:class="[
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
toolbarShellClass,
|
|
||||||
'workbench-filter-platform-shop min-w-0 sm:max-w-[min(calc(100vw-2.5rem),56rem)]',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
|
<ReceiptIcon class="h-4 w-4 shrink-0" />
|
||||||
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">税率{{ formatTaxRate(taxRate) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
<!-- 平台/店铺 -->
|
||||||
|
<Popover
|
||||||
|
trigger="click"
|
||||||
|
:open="openPopover === 'filter'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('filter', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
<div
|
<div
|
||||||
:class="[
|
class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-0"
|
||||||
toolbarPanelClass,
|
|
||||||
'flex min-w-0 flex-col gap-2 p-1 sm:flex-row sm:items-center sm:gap-0 sm:divide-x sm:divide-slate-200 dark:sm:divide-[hsl(240deg_3.7%_28%)]',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="flex min-w-0 items-center gap-2 px-2 py-0.5 sm:w-[11.5rem] sm:flex-none sm:shrink-0 sm:py-0"
|
class="flex min-w-0 items-center gap-2 px-2 py-0.5 sm:w-[11.5rem] sm:flex-none sm:shrink-0 sm:py-0"
|
||||||
@@ -742,11 +787,28 @@ onUnmounted(() => {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
<div :class="toolbarShellClass">
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
<div
|
<div
|
||||||
:class="[toolbarPanelClass, 'flex w-full items-center gap-1 overflow-x-auto p-1']"
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
|
<ToolbarToggleIcon class="h-4 w-4 shrink-0" />
|
||||||
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ selectedPlatformLabelCache || selectedShopLabelCache ? `${selectedPlatformLabelCache || '全部'}/${selectedShopLabelCache || '全部'}` : '平台/店铺' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
<!-- 时间范围 -->
|
||||||
|
<Popover
|
||||||
|
trigger="click"
|
||||||
|
:open="openPopover === 'timeRange'"
|
||||||
|
placement="bottom"
|
||||||
|
@update:open="(val: boolean) => handlePopoverOpen('timeRange', val)"
|
||||||
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex flex-col gap-2 px-1 py-0.5">
|
||||||
|
<div class="flex items-center gap-1 overflow-x-auto whitespace-nowrap">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'today')]"
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'today')]"
|
||||||
@@ -783,11 +845,9 @@ onUnmounted(() => {
|
|||||||
本月
|
本月
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div class="flex items-center gap-2">
|
||||||
class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-start"
|
|
||||||
>
|
|
||||||
<span
|
<span
|
||||||
class="hidden whitespace-nowrap text-xs font-bold text-slate-700 sm:inline dark:text-slate-300"
|
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
>
|
>
|
||||||
自定义日期
|
自定义日期
|
||||||
</span>
|
</span>
|
||||||
@@ -797,11 +857,23 @@ onUnmounted(() => {
|
|||||||
format="YYYY-MM-DD"
|
format="YYYY-MM-DD"
|
||||||
:allow-clear="false"
|
:allow-clear="false"
|
||||||
:placeholder="['开始', '结束']"
|
:placeholder="['开始', '结束']"
|
||||||
class="workbench-header-range-picker !h-8 !w-full !border-none !bg-transparent !text-sm !font-bold !text-slate-800 sm:!w-[220px] dark:!text-slate-200"
|
class="workbench-header-range-picker !h-8 !flex-1 !border-none !bg-transparent !text-sm !font-bold !text-slate-800 dark:!text-slate-200"
|
||||||
@change="handleCustomDateRangeChange"
|
@change="handleCustomDateRangeChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
|
>
|
||||||
|
<CalendarIcon class="h-4 w-4 shrink-0" />
|
||||||
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
|
{{ activeTimeRange === 'today' ? '今日' : activeTimeRange === 'yesterday' ? '昨日' : activeTimeRange === '7days' ? '近7日' : activeTimeRange === '30days' ? '近30日' : activeTimeRange === 'thisMonth' ? '本月' : customDateRange ? `${customDateRange[0].format('M/D')}-${customDateRange[1].format('M/D')}` : '日期' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -1015,6 +1087,7 @@ onUnmounted(() => {
|
|||||||
:deep(.workbench-header-extra .tax-rate-input .ant-input-number-input) {
|
:deep(.workbench-header-extra .tax-rate-input .ant-input-number-input) {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
line-height: 32px;
|
line-height: 32px;
|
||||||
|
text-align: center;
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
color: rgb(15 23 42);
|
color: rgb(15 23 42);
|
||||||
@@ -1065,4 +1138,40 @@ html.dark .workbench-header-extra .workbench-header-range-picker .ant-picker-sep
|
|||||||
html.dark .workbench-header-extra .workbench-header-range-picker .ant-picker-suffix {
|
html.dark .workbench-header-extra .workbench-header-range-picker .ant-picker-suffix {
|
||||||
color: hsl(240deg 5% 75%);
|
color: hsl(240deg 5% 75%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.workbench-toolbar-popover .ant-popover-inner {
|
||||||
|
padding: 4px !important;
|
||||||
|
border-radius: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark .workbench-toolbar-popover .ant-popover-inner {
|
||||||
|
background-color: hsl(222.34deg 10.43% 14%) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark .workbench-toolbar-popover .ant-popover-arrow {
|
||||||
|
--antd-arrow-background-color: hsl(222.34deg 10.43% 14%) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workbench-toolbar-popover .tax-rate-input.ant-input-number {
|
||||||
|
background: transparent !important;
|
||||||
|
border: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workbench-toolbar-popover .tax-rate-input .ant-input-number-input {
|
||||||
|
height: 32px !important;
|
||||||
|
line-height: 32px !important;
|
||||||
|
text-align: center !important;
|
||||||
|
padding-top: 0 !important;
|
||||||
|
padding-bottom: 0 !important;
|
||||||
|
background: transparent !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workbench-toolbar-popover .tax-rate-input:hover .ant-input-number-input {
|
||||||
|
background-color: rgb(241 245 249) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark .workbench-toolbar-popover .tax-rate-input .ant-input-number-input {
|
||||||
|
color: hsl(0deg 0% 95%) !important;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+50
-9
@@ -2,7 +2,7 @@
|
|||||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||||
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
import type { WorkbenchVO } from '#/api/ecommerce/workbench/types';
|
||||||
|
|
||||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||||
|
|
||||||
@@ -33,12 +33,23 @@ const chartOverviewShell =
|
|||||||
const pieChartRef = ref<EchartsUIType>();
|
const pieChartRef = ref<EchartsUIType>();
|
||||||
const { renderEcharts: renderPieChart } = useEcharts(pieChartRef);
|
const { renderEcharts: renderPieChart } = useEcharts(pieChartRef);
|
||||||
|
|
||||||
|
let renderTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
let isUnmounted = false;
|
||||||
|
|
||||||
|
/** 与趋势图一致:有切片且存在非零销售额才绘制,避免空态卸载图表 DOM */
|
||||||
|
const hasData = computed(
|
||||||
|
() =>
|
||||||
|
props.platformSalesShare.length > 0 &&
|
||||||
|
props.platformSalesShare.some((row) => Number(row.value ?? 0) !== 0),
|
||||||
|
);
|
||||||
|
|
||||||
function colorForIndex(index: number): string {
|
function colorForIndex(index: number): string {
|
||||||
return PLATFORM_PIE_COLORS[index % PLATFORM_PIE_COLORS.length] ?? '#6366f1';
|
return PLATFORM_PIE_COLORS[index % PLATFORM_PIE_COLORS.length] ?? '#6366f1';
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawPie() {
|
function drawPie() {
|
||||||
if (!pieChartRef.value) return;
|
if (!pieChartRef.value || !hasData.value) return;
|
||||||
|
try {
|
||||||
const isDark = document.documentElement.classList.contains('dark');
|
const isDark = document.documentElement.classList.contains('dark');
|
||||||
const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155';
|
const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155';
|
||||||
const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b';
|
const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b';
|
||||||
@@ -99,25 +110,54 @@ function drawPie() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[WorkbenchFinancePlatformSalesPieChart] render failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 延迟一帧再绘制,确保 v-show 切换后 ref 与容器尺寸已就绪 */
|
||||||
|
async function scheduleRender() {
|
||||||
|
if (renderTimer) {
|
||||||
|
clearTimeout(renderTimer);
|
||||||
|
renderTimer = null;
|
||||||
|
}
|
||||||
|
await nextTick();
|
||||||
|
if (isUnmounted || !hasData.value) return;
|
||||||
|
renderTimer = setTimeout(() => {
|
||||||
|
if (isUnmounted) return;
|
||||||
|
drawPie();
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function redraw() {
|
async function redraw() {
|
||||||
await nextTick();
|
await scheduleRender();
|
||||||
drawPie();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
void redraw();
|
isUnmounted = false;
|
||||||
|
void scheduleRender();
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
isUnmounted = true;
|
||||||
|
if (renderTimer) {
|
||||||
|
clearTimeout(renderTimer);
|
||||||
|
renderTimer = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.platformSalesShare,
|
() => props.platformSalesShare,
|
||||||
() => {
|
() => {
|
||||||
void redraw();
|
void scheduleRender();
|
||||||
},
|
},
|
||||||
{ deep: true },
|
{ deep: true, immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watch(hasData, (ok) => {
|
||||||
|
if (ok) void scheduleRender();
|
||||||
|
});
|
||||||
|
|
||||||
defineExpose({ redraw });
|
defineExpose({ redraw });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -137,12 +177,13 @@ defineExpose({ redraw });
|
|||||||
</div>
|
</div>
|
||||||
<div class="px-6 py-5 md:px-8 md:py-6">
|
<div class="px-6 py-5 md:px-8 md:py-6">
|
||||||
<div
|
<div
|
||||||
v-if="!platformSalesShare.length"
|
v-show="!hasData"
|
||||||
class="flex h-[280px] items-center justify-center text-sm font-bold text-slate-400"
|
class="flex h-[280px] items-center justify-center text-sm font-bold text-slate-400"
|
||||||
>
|
>
|
||||||
暂无销售额数据
|
暂无销售额数据
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="h-[280px] w-full">
|
<!-- 用 v-show 保持 Echarts 实例挂载,避免切换日期时 v-if 销毁导致图表无法重绘 -->
|
||||||
|
<div v-show="hasData" class="h-[280px] w-full">
|
||||||
<EchartsUI ref="pieChartRef" />
|
<EchartsUI ref="pieChartRef" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user