mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:49:19 +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,187 +634,246 @@ 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'"
|
||||||
<button
|
placement="bottom"
|
||||||
type="button"
|
@update:open="(val: boolean) => handlePopoverOpen('import', val)"
|
||||||
:class="toolbarActionClass"
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
@click="goToImportOrder"
|
>
|
||||||
|
<template #content>
|
||||||
|
<div class="flex items-center gap-0.5 whitespace-nowrap">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="toolbarActionClass"
|
||||||
|
@click="goToImportOrder"
|
||||||
|
>
|
||||||
|
<ImportOrderIcon class="h-4 w-4 shrink-0" />
|
||||||
|
导入订单
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="toolbarActionClass"
|
||||||
|
@click="goToImportPromotionFee"
|
||||||
|
>
|
||||||
|
<PromotionFeeIcon class="h-4 w-4 shrink-0" />
|
||||||
|
导入推广费
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
<ImportOrderIcon class="h-4 w-4 shrink-0" />
|
<ImportOrderIcon class="h-4 w-4 shrink-0" />
|
||||||
导入订单
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">导入</span>
|
||||||
</button>
|
</div>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="toolbarActionClass"
|
|
||||||
@click="goToImportPromotionFee"
|
|
||||||
>
|
|
||||||
<PromotionFeeIcon class="h-4 w-4 shrink-0" />
|
|
||||||
导入推广费
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
<div :class="toolbarShellClass">
|
|
||||||
<div
|
<!-- 税率 -->
|
||||||
:class="[toolbarPanelClass, 'flex items-center gap-2 px-2 py-1']"
|
<Popover
|
||||||
>
|
trigger="click"
|
||||||
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
:open="openPopover === 'taxRate'"
|
||||||
税率
|
placement="bottom"
|
||||||
</span>
|
@update:open="(val: boolean) => handlePopoverOpen('taxRate', val)"
|
||||||
<InputNumber
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
v-model:value="taxRate"
|
|
||||||
:min="0"
|
|
||||||
:max="1"
|
|
||||||
:step="0.01"
|
|
||||||
size="small"
|
|
||||||
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
|
||||||
:formatter="formatTaxRate"
|
|
||||||
:parser="parseTaxRate"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
:class="[
|
|
||||||
toolbarShellClass,
|
|
||||||
'workbench-filter-platform-shop min-w-0 sm:max-w-[min(calc(100vw-2.5rem),56rem)]',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<div
|
<template #content>
|
||||||
:class="[
|
<div class="flex items-center gap-2 whitespace-nowrap">
|
||||||
toolbarPanelClass,
|
<span class="shrink-0 text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
'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
|
|
||||||
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"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
|
||||||
>
|
|
||||||
平台
|
|
||||||
</span>
|
</span>
|
||||||
<Select
|
<InputNumber
|
||||||
v-model:value="selectedPlatformSlug"
|
v-model:value="taxRate"
|
||||||
|
:min="0"
|
||||||
|
:max="1"
|
||||||
|
:step="0.01"
|
||||||
size="small"
|
size="small"
|
||||||
show-search
|
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-transparent !text-center !text-sm !font-bold !text-slate-800 !shadow-none dark:!text-slate-100"
|
||||||
allow-clear
|
:formatter="formatTaxRate"
|
||||||
:filter-option="false"
|
:parser="parseTaxRate"
|
||||||
:loading="platformLoading"
|
/>
|
||||||
:options="platformSelectOptions"
|
|
||||||
placeholder="全部平台"
|
|
||||||
class="workbench-header-select min-w-0 flex-1"
|
|
||||||
@search="handlePlatformSearch"
|
|
||||||
@popup-scroll="handlePlatformPopupScroll"
|
|
||||||
@dropdown-visible-change="handlePlatformDropdownVisibleChange"
|
|
||||||
>
|
|
||||||
<template #notFoundContent>
|
|
||||||
<div v-if="platformLoading" class="py-3 text-center">
|
|
||||||
<Spin size="small" />
|
|
||||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="py-3 text-center text-xs text-slate-600">
|
|
||||||
暂无平台
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
<div
|
<div
|
||||||
class="flex min-w-0 flex-1 items-center gap-2 border-t border-slate-200/80 px-2 pt-2 sm:min-w-[16rem] sm:border-t-0 sm:py-0 sm:pt-0 dark:border-[hsl(240deg_3.7%_22%)]"
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
<span
|
<ReceiptIcon class="h-4 w-4 shrink-0" />
|
||||||
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">税率{{ formatTaxRate(taxRate) }}</span>
|
||||||
>
|
|
||||||
店铺
|
|
||||||
</span>
|
|
||||||
<Select
|
|
||||||
v-model:value="selectedShopSlug"
|
|
||||||
size="small"
|
|
||||||
show-search
|
|
||||||
allow-clear
|
|
||||||
:filter-option="false"
|
|
||||||
:loading="shopLoading"
|
|
||||||
:options="shopSelectOptions"
|
|
||||||
placeholder="全部店铺"
|
|
||||||
:dropdown-match-select-width="false"
|
|
||||||
class="workbench-header-select workbench-shop-select min-w-0 flex-1"
|
|
||||||
@search="handleShopSearch"
|
|
||||||
@popup-scroll="handleShopPopupScroll"
|
|
||||||
@dropdown-visible-change="handleShopDropdownVisibleChange"
|
|
||||||
>
|
|
||||||
<template #notFoundContent>
|
|
||||||
<div v-if="shopLoading" class="py-3 text-center">
|
|
||||||
<Spin size="small" />
|
|
||||||
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
|
||||||
</div>
|
|
||||||
<div v-else class="py-3 text-center text-xs text-slate-600">
|
|
||||||
暂无店铺
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Popover>
|
||||||
<div :class="toolbarShellClass">
|
|
||||||
<div
|
<!-- 平台/店铺 -->
|
||||||
:class="[toolbarPanelClass, 'flex w-full items-center gap-1 overflow-x-auto p-1']"
|
<Popover
|
||||||
>
|
trigger="click"
|
||||||
<button
|
:open="openPopover === 'filter'"
|
||||||
type="button"
|
placement="bottom"
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'today')]"
|
@update:open="(val: boolean) => handlePopoverOpen('filter', val)"
|
||||||
@click="switchTimeRange('today')"
|
overlay-class-name="workbench-toolbar-popover"
|
||||||
|
>
|
||||||
|
<template #content>
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-0"
|
||||||
>
|
>
|
||||||
今日
|
<div
|
||||||
</button>
|
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"
|
||||||
<button
|
>
|
||||||
type="button"
|
<span
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'yesterday')]"
|
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
@click="switchTimeRange('yesterday')"
|
>
|
||||||
|
平台
|
||||||
|
</span>
|
||||||
|
<Select
|
||||||
|
v-model:value="selectedPlatformSlug"
|
||||||
|
size="small"
|
||||||
|
show-search
|
||||||
|
allow-clear
|
||||||
|
:filter-option="false"
|
||||||
|
:loading="platformLoading"
|
||||||
|
:options="platformSelectOptions"
|
||||||
|
placeholder="全部平台"
|
||||||
|
class="workbench-header-select min-w-0 flex-1"
|
||||||
|
@search="handlePlatformSearch"
|
||||||
|
@popup-scroll="handlePlatformPopupScroll"
|
||||||
|
@dropdown-visible-change="handlePlatformDropdownVisibleChange"
|
||||||
|
>
|
||||||
|
<template #notFoundContent>
|
||||||
|
<div v-if="platformLoading" class="py-3 text-center">
|
||||||
|
<Spin size="small" />
|
||||||
|
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="py-3 text-center text-xs text-slate-600">
|
||||||
|
暂无平台
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="flex min-w-0 flex-1 items-center gap-2 border-t border-slate-200/80 px-2 pt-2 sm:min-w-[16rem] sm:border-t-0 sm:py-0 sm:pt-0 dark:border-[hsl(240deg_3.7%_22%)]"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="w-9 shrink-0 text-right text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
店铺
|
||||||
|
</span>
|
||||||
|
<Select
|
||||||
|
v-model:value="selectedShopSlug"
|
||||||
|
size="small"
|
||||||
|
show-search
|
||||||
|
allow-clear
|
||||||
|
:filter-option="false"
|
||||||
|
:loading="shopLoading"
|
||||||
|
:options="shopSelectOptions"
|
||||||
|
placeholder="全部店铺"
|
||||||
|
:dropdown-match-select-width="false"
|
||||||
|
class="workbench-header-select workbench-shop-select min-w-0 flex-1"
|
||||||
|
@search="handleShopSearch"
|
||||||
|
@popup-scroll="handleShopPopupScroll"
|
||||||
|
@dropdown-visible-change="handleShopDropdownVisibleChange"
|
||||||
|
>
|
||||||
|
<template #notFoundContent>
|
||||||
|
<div v-if="shopLoading" class="py-3 text-center">
|
||||||
|
<Spin size="small" />
|
||||||
|
<div class="mt-1 text-xs text-slate-600">加载中...</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="py-3 text-center text-xs text-slate-600">
|
||||||
|
暂无店铺
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<div :class="[toolbarShellClass, 'cursor-pointer']">
|
||||||
|
<div
|
||||||
|
:class="[toolbarPanelClass, 'flex items-center gap-1 px-2 py-1']"
|
||||||
>
|
>
|
||||||
昨日
|
<ToolbarToggleIcon class="h-4 w-4 shrink-0" />
|
||||||
</button>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">{{ selectedPlatformLabelCache || selectedShopLabelCache ? `${selectedPlatformLabelCache || '全部'}/${selectedShopLabelCache || '全部'}` : '平台/店铺' }}</span>
|
||||||
<button
|
</div>
|
||||||
type="button"
|
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === '7days')]"
|
|
||||||
@click="switchTimeRange('7days')"
|
|
||||||
>
|
|
||||||
近7日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === '30days')]"
|
|
||||||
@click="switchTimeRange('30days')"
|
|
||||||
>
|
|
||||||
近30日
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'thisMonth')]"
|
|
||||||
@click="switchTimeRange('thisMonth')"
|
|
||||||
>
|
|
||||||
本月
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
</Popover>
|
||||||
class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-start"
|
|
||||||
>
|
<!-- 时间范围 -->
|
||||||
<span
|
<Popover
|
||||||
class="hidden whitespace-nowrap text-xs font-bold text-slate-700 sm:inline dark:text-slate-300"
|
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
|
||||||
|
type="button"
|
||||||
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'today')]"
|
||||||
|
@click="switchTimeRange('today')"
|
||||||
|
>
|
||||||
|
今日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'yesterday')]"
|
||||||
|
@click="switchTimeRange('yesterday')"
|
||||||
|
>
|
||||||
|
昨日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === '7days')]"
|
||||||
|
@click="switchTimeRange('7days')"
|
||||||
|
>
|
||||||
|
近7日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === '30days')]"
|
||||||
|
@click="switchTimeRange('30days')"
|
||||||
|
>
|
||||||
|
近30日
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="[timeRangeBtnClass, timeRangeBtnState(activeTimeRange === 'thisMonth')]"
|
||||||
|
@click="switchTimeRange('thisMonth')"
|
||||||
|
>
|
||||||
|
本月
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
自定义日期
|
||||||
|
</span>
|
||||||
|
<DatePicker.RangePicker
|
||||||
|
v-model:value="customDateRange"
|
||||||
|
size="small"
|
||||||
|
format="YYYY-MM-DD"
|
||||||
|
:allow-clear="false"
|
||||||
|
:placeholder="['开始', '结束']"
|
||||||
|
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"
|
||||||
|
/>
|
||||||
|
</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>
|
<span class="whitespace-nowrap text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
<DatePicker.RangePicker
|
{{ activeTimeRange === 'today' ? '今日' : activeTimeRange === 'yesterday' ? '昨日' : activeTimeRange === '7days' ? '近7日' : activeTimeRange === '30days' ? '近30日' : activeTimeRange === 'thisMonth' ? '本月' : customDateRange ? `${customDateRange[0].format('M/D')}-${customDateRange[1].format('M/D')}` : '日期' }}
|
||||||
v-model:value="customDateRange"
|
</span>
|
||||||
size="small"
|
</div>
|
||||||
format="YYYY-MM-DD"
|
|
||||||
:allow-clear="false"
|
|
||||||
: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"
|
|
||||||
@change="handleCustomDateRangeChange"
|
|
||||||
/>
|
|
||||||
</div>
|
</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>
|
||||||
|
|||||||
+106
-65
@@ -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,91 +33,131 @@ 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;
|
||||||
const isDark = document.documentElement.classList.contains('dark');
|
try {
|
||||||
const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155';
|
const isDark = document.documentElement.classList.contains('dark');
|
||||||
const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b';
|
const labelColor = isDark ? 'hsl(0deg 0% 95%)' : '#334155';
|
||||||
const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff';
|
const legendColor = isDark ? 'hsl(240deg 5% 64.9%)' : '#64748b';
|
||||||
|
const border = isDark ? 'hsl(222.34deg 10.43% 12.27%)' : '#fff';
|
||||||
|
|
||||||
renderPieChart({
|
renderPieChart({
|
||||||
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',
|
||||||
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' },
|
textStyle: { color: isDark ? 'hsl(0deg 0% 95%)' : '#0f172a' },
|
||||||
formatter: (params: any) => {
|
formatter: (params: any) => {
|
||||||
const name = String(params.name ?? '');
|
const name = String(params.name ?? '');
|
||||||
const val = Number(params.value ?? 0);
|
const val = Number(params.value ?? 0);
|
||||||
const row = props.platformSalesShare.find((r) => r.name === name);
|
const row = props.platformSalesShare.find((r) => r.name === name);
|
||||||
const pctText =
|
const pctText =
|
||||||
row?.pct != null ? `${row.pct}%(占实际销售额)` : '';
|
row?.pct != null ? `${row.pct}%(占实际销售额)` : '';
|
||||||
return `${name}<br/>约 ${formatWanShort(val)}<br/>${formatYuanDetail(val)}<br/>${pctText}`;
|
return `${name}<br/>约 ${formatWanShort(val)}<br/>${formatYuanDetail(val)}<br/>${pctText}`;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
legend: {
|
||||||
legend: {
|
orient: 'vertical',
|
||||||
orient: 'vertical',
|
right: '0',
|
||||||
right: '0',
|
top: 'center',
|
||||||
top: 'center',
|
itemWidth: 10,
|
||||||
itemWidth: 10,
|
itemHeight: 10,
|
||||||
itemHeight: 10,
|
textStyle: { color: legendColor, fontSize: 11, fontWeight: 700 },
|
||||||
textStyle: { color: legendColor, fontSize: 11, fontWeight: 700 },
|
},
|
||||||
},
|
series: [
|
||||||
series: [
|
{
|
||||||
{
|
type: 'pie',
|
||||||
type: 'pie',
|
radius: ['40%', '68%'],
|
||||||
radius: ['40%', '68%'],
|
center: ['36%', '50%'],
|
||||||
center: ['36%', '50%'],
|
avoidLabelOverlap: true,
|
||||||
avoidLabelOverlap: true,
|
|
||||||
itemStyle: {
|
|
||||||
borderRadius: 6,
|
|
||||||
borderColor: border,
|
|
||||||
borderWidth: 2,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
show: true,
|
|
||||||
formatter: '{b}\n{d}%',
|
|
||||||
color: labelColor,
|
|
||||||
fontSize: 11,
|
|
||||||
fontWeight: 700,
|
|
||||||
},
|
|
||||||
labelLine: {
|
|
||||||
length: 12,
|
|
||||||
length2: 8,
|
|
||||||
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' },
|
|
||||||
},
|
|
||||||
data: props.platformSalesShare.map((row, index) => ({
|
|
||||||
name: row.name,
|
|
||||||
value: row.value ?? 0,
|
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
color: colorForIndex(index),
|
borderRadius: 6,
|
||||||
|
borderColor: border,
|
||||||
|
borderWidth: 2,
|
||||||
},
|
},
|
||||||
})),
|
label: {
|
||||||
},
|
show: true,
|
||||||
],
|
formatter: '{b}\n{d}%',
|
||||||
});
|
color: labelColor,
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: 700,
|
||||||
|
},
|
||||||
|
labelLine: {
|
||||||
|
length: 12,
|
||||||
|
length2: 8,
|
||||||
|
lineStyle: { color: isDark ? 'hsl(240deg 3.7% 35%)' : '#cbd5e1' },
|
||||||
|
},
|
||||||
|
data: props.platformSalesShare.map((row, index) => ({
|
||||||
|
name: row.name,
|
||||||
|
value: row.value ?? 0,
|
||||||
|
itemStyle: {
|
||||||
|
color: colorForIndex(index),
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} 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