fix(ecom-dmb): 公司概览页切换日期从6次→1次,消除重复tab创建问题

This commit is contained in:
小蟑螂
2026-04-24 13:28:48 +08:00
parent 4c5239237d
commit 7e53ebcd25
@@ -106,13 +106,13 @@ const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
dateRange.value[1],
]);
const lastRequestKey = ref('');
const isSyncingRouteQuery = ref(false);
const isRequesting = ref(false);
// 图表引用
const shopChartsRef = ref<{ renderShopBarChart: () => void; renderShopScatterChart: () => void }>();
// 切换时间范围
const switchTimeRange = (
const switchTimeRange = async (
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
) => {
activeTimeRange.value = type;
@@ -148,10 +148,12 @@ const switchTimeRange = (
dateRange.value = [startDate, endDate];
customDateRange.value = [startDate, endDate];
syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
};
// 自定义日期范围变化
const handleCustomDateRangeChange = (
const handleCustomDateRangeChange = async (
value: [dayjs.Dayjs, dayjs.Dayjs] | [string, string] | null,
_dateString?: [string, string],
) => {
@@ -163,6 +165,8 @@ const handleCustomDateRangeChange = (
customDateRange.value = dates;
activeTimeRange.value = 'custom';
dateRange.value = dates;
syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
}
};
@@ -237,19 +241,11 @@ const syncDateRangeToRouteQuery = async () => {
return;
}
isSyncingRouteQuery.value = true;
try {
await router.replace({
path: route.path,
query: {
...route.query,
endDate,
startDate,
},
});
} finally {
isSyncingRouteQuery.value = false;
}
// 用 history.replaceState 直接改 URL,避免触发 Vue Router 导航和 Vben tab 重复创建
const url = new URL(window.location.href);
url.searchParams.set('startDate', startDate);
url.searchParams.set('endDate', endDate);
window.history.replaceState({}, '', url.toString());
};
// 加载店铺数量
@@ -268,6 +264,8 @@ const loadShopCount = async () => {
// 加载概览数据
const loadOverviewData = async () => {
if (isRequesting.value) return;
isRequesting.value = true;
try {
loading.value = true;
const params: CompanyOverviewDTO.Query = {
@@ -283,6 +281,7 @@ const loadOverviewData = async () => {
console.error('获取全店概览数据失败:', error);
} finally {
loading.value = false;
isRequesting.value = false;
}
};
@@ -312,23 +311,6 @@ watch(
{ deep: true },
);
// 监听日期范围变化
watch(
() => dateRange.value,
async () => {
await syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
},
);
watch(
() => [route.query.startDate, route.query.endDate],
async () => {
if (isSyncingRouteQuery.value) return;
await refreshOverviewByCurrentParams();
},
);
// 深色模式 class 变化时重绘图表
let darkThemeObserver: MutationObserver | null = null;