feat(ecom-dmb): 概览页时间范围新增'本月'快捷选项,默认改为本月至今

This commit is contained in:
小蟑螂
2026-04-28 09:34:03 +08:00
parent 81391d20aa
commit fa9a165e9f
5 changed files with 103 additions and 17 deletions
@@ -46,9 +46,9 @@ const selectedExportShopIds = ref<number[]>([]);
const platformExportMode = ref(false); const platformExportMode = ref(false);
const selectedExportPlatformIds = ref<number[]>([]); const selectedExportPlatformIds = ref<number[]>([]);
// 日期范围 // 日期范围(默认:本月至今日)
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([ const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().subtract(30, 'day'), dayjs().startOf('month'),
dayjs(), dayjs(),
]); ]);
@@ -96,8 +96,8 @@ const parseTaxRate = (value: string | undefined) => {
// 当前选中的时间范围类型 // 当前选中的时间范围类型
const activeTimeRange = ref< const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday' '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
>('30days'); >('thisMonth');
// 自定义日期范围 // 自定义日期范围
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([ const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
@@ -112,7 +112,7 @@ const shopChartsRef = ref<{ renderShopBarChart: () => void; renderShopScatterCha
// 切换时间范围 // 切换时间范围
const switchTimeRange = async ( const switchTimeRange = async (
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday', type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
) => { ) => {
activeTimeRange.value = type; activeTimeRange.value = type;
let startDate: dayjs.Dayjs; let startDate: dayjs.Dayjs;
@@ -127,6 +127,11 @@ const switchTimeRange = async (
startDate = dayjs().subtract(30, 'day'); startDate = dayjs().subtract(30, 'day');
break; break;
} }
case 'thisMonth': {
startDate = dayjs().startOf('month');
endDate = dayjs();
break;
}
case 'custom': { case 'custom': {
if (customDateRange.value) { if (customDateRange.value) {
dateRange.value = customDateRange.value; dateRange.value = customDateRange.value;
@@ -188,6 +193,15 @@ const setTimeRangeTypeByDates = (
'day', 'day',
); );
if (
isEndDateToday &&
startDate.isSame(today.startOf('month'), 'day')
) {
activeTimeRange.value = 'thisMonth';
customDateRange.value = [startDate, endDate];
return;
}
if (daysDiff === 0 && startDate.isSame(today, 'day')) { if (daysDiff === 0 && startDate.isSame(today, 'day')) {
activeTimeRange.value = 'today'; activeTimeRange.value = 'today';
customDateRange.value = [startDate, endDate]; customDateRange.value = [startDate, endDate];
@@ -534,6 +548,19 @@ const navigateToShopOverview = (shopId: number) => {
> >
近30日 近30日
</Button> </Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === 'thisMonth'
? '!bg-white !text-blue-600 dark:!bg-blue-900/30 dark:!text-blue-400 !shadow-sm dark:!shadow-none'
: '!bg-transparent !text-slate-600 dark:!bg-[hsl(222.34deg_10.43%_12.27%/50%)] dark:!text-[hsl(240deg_5%_64.9%)] hover:!bg-[hsl(240deg_3.7%_22%)]'
"
@click="switchTimeRange('thisMonth')"
>
本月
</Button>
</div> </div>
<!-- 日期选择器 --> <!-- 日期选择器 -->
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
@@ -6,7 +6,13 @@ import type { Dayjs } from 'dayjs';
interface Props { interface Props {
modelValue: { modelValue: {
taxRate: number; taxRate: number;
activeTimeRange: '7days' | '30days' | 'custom' | 'today' | 'yesterday'; activeTimeRange:
| '7days'
| '30days'
| 'thisMonth'
| 'custom'
| 'today'
| 'yesterday';
customDateRange: [Dayjs, Dayjs] | undefined; customDateRange: [Dayjs, Dayjs] | undefined;
dateRange: [Dayjs, Dayjs]; dateRange: [Dayjs, Dayjs];
}; };
@@ -34,7 +40,9 @@ const parseTaxRate = (value: string | undefined) => {
return Number.isFinite(num) ? num / 100 : 0; return Number.isFinite(num) ? num / 100 : 0;
}; };
const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yesterday') => { const switchTimeRange = (
type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
) => {
let startDate: Dayjs; let startDate: Dayjs;
let endDate: Dayjs = dayjs(); let endDate: Dayjs = dayjs();
@@ -45,6 +53,10 @@ const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yester
case '30days': case '30days':
startDate = dayjs().subtract(30, 'day'); startDate = dayjs().subtract(30, 'day');
break; break;
case 'thisMonth':
startDate = dayjs().startOf('month');
endDate = dayjs();
break;
case 'custom': case 'custom':
if (props.modelValue.customDateRange) { if (props.modelValue.customDateRange) {
emit('update:modelValue', { emit('update:modelValue', {
@@ -178,6 +190,19 @@ const handleTaxRateChange = (val: number | string | undefined) => {
> >
近30日 近30日
</Button> </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 === 'thisMonth'
? '!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('thisMonth')"
>
本月
</Button>
</div> </div>
<!-- 日期选择器 --> <!-- 日期选择器 -->
@@ -56,16 +56,16 @@ const normalizeOverview = (raw: any) => {
}; };
}; };
// 日期范围 // 日期范围(默认:本月至今日)
const dateRange = ref<[Dayjs, Dayjs]>([ const dateRange = ref<[Dayjs, Dayjs]>([
dayjs().subtract(30, 'day'), dayjs().startOf('month'),
dayjs(), dayjs(),
]); ]);
// 当前选中的时间范围类型 // 当前选中的时间范围类型
const activeTimeRange = ref< const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday' '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
>('30days'); >('thisMonth');
// 自定义日期范围 // 自定义日期范围
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([ const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
@@ -6,7 +6,13 @@ import type { Dayjs } from 'dayjs';
interface Props { interface Props {
modelValue: { modelValue: {
taxRate: number; taxRate: number;
activeTimeRange: '7days' | '30days' | 'custom' | 'today' | 'yesterday'; activeTimeRange:
| '7days'
| '30days'
| 'thisMonth'
| 'custom'
| 'today'
| 'yesterday';
customDateRange: [Dayjs, Dayjs] | undefined; customDateRange: [Dayjs, Dayjs] | undefined;
dateRange: [Dayjs, Dayjs]; dateRange: [Dayjs, Dayjs];
}; };
@@ -34,7 +40,9 @@ const parseTaxRate = (value: string | undefined) => {
return Number.isFinite(num) ? num / 100 : 0; return Number.isFinite(num) ? num / 100 : 0;
}; };
const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yesterday') => { const switchTimeRange = (
type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
) => {
let startDate: Dayjs; let startDate: Dayjs;
let endDate: Dayjs = dayjs(); let endDate: Dayjs = dayjs();
@@ -45,6 +53,10 @@ const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yester
case '30days': case '30days':
startDate = dayjs().subtract(30, 'day'); startDate = dayjs().subtract(30, 'day');
break; break;
case 'thisMonth':
startDate = dayjs().startOf('month');
endDate = dayjs();
break;
case 'custom': case 'custom':
if (props.modelValue.customDateRange) { if (props.modelValue.customDateRange) {
emit('update:modelValue', { emit('update:modelValue', {
@@ -178,6 +190,19 @@ const handleTaxRateChange = (val: number | string | undefined) => {
> >
近30日 近30日
</Button> </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 === 'thisMonth'
? '!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('thisMonth')"
>
本月
</Button>
</div> </div>
<!-- 日期选择器 --> <!-- 日期选择器 -->
@@ -58,16 +58,16 @@ const categoryExportMode = ref(false);
const selectedExportCategoryIds = ref<number[]>([]); const selectedExportCategoryIds = ref<number[]>([]);
const categoryExportLoading = ref(false); const categoryExportLoading = ref(false);
// 日期范围 // 日期范围(默认:本月至今日)
const dateRange = ref<[Dayjs, Dayjs]>([ const dateRange = ref<[Dayjs, Dayjs]>([
dayjs().subtract(7, 'day'), dayjs().startOf('month'),
dayjs(), dayjs(),
]); ]);
// 当前选中的时间范围类型 // 当前选中的时间范围类型
const activeTimeRange = ref< const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday' '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
>('7days'); >('thisMonth');
// 自定义日期范围 // 自定义日期范围
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([ const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
@@ -122,6 +122,15 @@ const setTimeRangeTypeByDates = (
'day', 'day',
); );
if (
isEndDateToday &&
startDate.isSame(today.startOf('month'), 'day')
) {
activeTimeRange.value = 'thisMonth';
customDateRange.value = [startDate, endDate];
return;
}
if (daysDiff === 0 && startDate.isSame(today, 'day')) { if (daysDiff === 0 && startDate.isSame(today, 'day')) {
activeTimeRange.value = 'today'; activeTimeRange.value = 'today';
customDateRange.value = [startDate, endDate]; customDateRange.value = [startDate, endDate];