mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:49:19 +08:00
feat(ecom-dmb): 概览页时间范围新增'本月'快捷选项,默认改为本月至今
This commit is contained in:
@@ -46,9 +46,9 @@ const selectedExportShopIds = ref<number[]>([]);
|
||||
const platformExportMode = ref(false);
|
||||
const selectedExportPlatformIds = ref<number[]>([]);
|
||||
|
||||
// 日期范围
|
||||
// 日期范围(默认:本月至今日)
|
||||
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
@@ -96,8 +96,8 @@ const parseTaxRate = (value: string | undefined) => {
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
|
||||
>('30days');
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
|
||||
@@ -112,7 +112,7 @@ const shopChartsRef = ref<{ renderShopBarChart: () => void; renderShopScatterCha
|
||||
|
||||
// 切换时间范围
|
||||
const switchTimeRange = async (
|
||||
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
|
||||
type: '7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday',
|
||||
) => {
|
||||
activeTimeRange.value = type;
|
||||
let startDate: dayjs.Dayjs;
|
||||
@@ -127,6 +127,11 @@ const switchTimeRange = async (
|
||||
startDate = dayjs().subtract(30, 'day');
|
||||
break;
|
||||
}
|
||||
case 'thisMonth': {
|
||||
startDate = dayjs().startOf('month');
|
||||
endDate = dayjs();
|
||||
break;
|
||||
}
|
||||
case 'custom': {
|
||||
if (customDateRange.value) {
|
||||
dateRange.value = customDateRange.value;
|
||||
@@ -188,6 +193,15 @@ const setTimeRangeTypeByDates = (
|
||||
'day',
|
||||
);
|
||||
|
||||
if (
|
||||
isEndDateToday &&
|
||||
startDate.isSame(today.startOf('month'), 'day')
|
||||
) {
|
||||
activeTimeRange.value = 'thisMonth';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
|
||||
activeTimeRange.value = 'today';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
@@ -534,6 +548,19 @@ const navigateToShopOverview = (shopId: number) => {
|
||||
>
|
||||
近30日
|
||||
</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 class="flex items-center gap-2">
|
||||
|
||||
+27
-2
@@ -6,7 +6,13 @@ import type { Dayjs } from 'dayjs';
|
||||
interface Props {
|
||||
modelValue: {
|
||||
taxRate: number;
|
||||
activeTimeRange: '7days' | '30days' | 'custom' | 'today' | 'yesterday';
|
||||
activeTimeRange:
|
||||
| '7days'
|
||||
| '30days'
|
||||
| 'thisMonth'
|
||||
| 'custom'
|
||||
| 'today'
|
||||
| 'yesterday';
|
||||
customDateRange: [Dayjs, Dayjs] | undefined;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
};
|
||||
@@ -34,7 +40,9 @@ const parseTaxRate = (value: string | undefined) => {
|
||||
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 endDate: Dayjs = dayjs();
|
||||
|
||||
@@ -45,6 +53,10 @@ const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yester
|
||||
case '30days':
|
||||
startDate = dayjs().subtract(30, 'day');
|
||||
break;
|
||||
case 'thisMonth':
|
||||
startDate = dayjs().startOf('month');
|
||||
endDate = dayjs();
|
||||
break;
|
||||
case 'custom':
|
||||
if (props.modelValue.customDateRange) {
|
||||
emit('update:modelValue', {
|
||||
@@ -178,6 +190,19 @@ const handleTaxRateChange = (val: number | string | undefined) => {
|
||||
>
|
||||
近30日
|
||||
</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>
|
||||
|
||||
<!-- 日期选择器 -->
|
||||
|
||||
@@ -56,16 +56,16 @@ const normalizeOverview = (raw: any) => {
|
||||
};
|
||||
};
|
||||
|
||||
// 日期范围
|
||||
// 日期范围(默认:本月至今日)
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([
|
||||
dayjs().subtract(30, 'day'),
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
|
||||
>('30days');
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
|
||||
+27
-2
@@ -6,7 +6,13 @@ import type { Dayjs } from 'dayjs';
|
||||
interface Props {
|
||||
modelValue: {
|
||||
taxRate: number;
|
||||
activeTimeRange: '7days' | '30days' | 'custom' | 'today' | 'yesterday';
|
||||
activeTimeRange:
|
||||
| '7days'
|
||||
| '30days'
|
||||
| 'thisMonth'
|
||||
| 'custom'
|
||||
| 'today'
|
||||
| 'yesterday';
|
||||
customDateRange: [Dayjs, Dayjs] | undefined;
|
||||
dateRange: [Dayjs, Dayjs];
|
||||
};
|
||||
@@ -34,7 +40,9 @@ const parseTaxRate = (value: string | undefined) => {
|
||||
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 endDate: Dayjs = dayjs();
|
||||
|
||||
@@ -45,6 +53,10 @@ const switchTimeRange = (type: '7days' | '30days' | 'custom' | 'today' | 'yester
|
||||
case '30days':
|
||||
startDate = dayjs().subtract(30, 'day');
|
||||
break;
|
||||
case 'thisMonth':
|
||||
startDate = dayjs().startOf('month');
|
||||
endDate = dayjs();
|
||||
break;
|
||||
case 'custom':
|
||||
if (props.modelValue.customDateRange) {
|
||||
emit('update:modelValue', {
|
||||
@@ -178,6 +190,19 @@ const handleTaxRateChange = (val: number | string | undefined) => {
|
||||
>
|
||||
近30日
|
||||
</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>
|
||||
|
||||
<!-- 日期选择器 -->
|
||||
|
||||
@@ -58,16 +58,16 @@ const categoryExportMode = ref(false);
|
||||
const selectedExportCategoryIds = ref<number[]>([]);
|
||||
const categoryExportLoading = ref(false);
|
||||
|
||||
// 日期范围
|
||||
// 日期范围(默认:本月至今日)
|
||||
const dateRange = ref<[Dayjs, Dayjs]>([
|
||||
dayjs().subtract(7, 'day'),
|
||||
dayjs().startOf('month'),
|
||||
dayjs(),
|
||||
]);
|
||||
|
||||
// 当前选中的时间范围类型
|
||||
const activeTimeRange = ref<
|
||||
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
|
||||
>('7days');
|
||||
'7days' | '30days' | 'thisMonth' | 'custom' | 'today' | 'yesterday'
|
||||
>('thisMonth');
|
||||
|
||||
// 自定义日期范围
|
||||
const customDateRange = ref<[Dayjs, Dayjs] | undefined>([
|
||||
@@ -122,6 +122,15 @@ const setTimeRangeTypeByDates = (
|
||||
'day',
|
||||
);
|
||||
|
||||
if (
|
||||
isEndDateToday &&
|
||||
startDate.isSame(today.startOf('month'), 'day')
|
||||
) {
|
||||
activeTimeRange.value = 'thisMonth';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
return;
|
||||
}
|
||||
|
||||
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
|
||||
activeTimeRange.value = 'today';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
|
||||
Reference in New Issue
Block a user