feat: 概览页标签优先显示实体名称

This commit is contained in:
2026-09-05 14:55:28 +08:00
parent f122176369
commit f3b0384334
5 changed files with 85 additions and 7 deletions
@@ -0,0 +1,12 @@
/**
* 概览页标签标题:有实体名则优先覆盖菜单默认标题(如「商品概览」)。
*/
export function formatOverviewTabTitle(
name: null | string | undefined,
fallback: string,
maxLen = 18,
): string {
const raw = (name ?? '').trim() || fallback;
if (raw.length <= maxLen) return raw;
return `${raw.slice(0, Math.max(1, maxLen - 1))}…`;
}
@@ -16,6 +16,7 @@ import {
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Spin } from 'ant-design-vue';
@@ -28,6 +29,7 @@ import {
buildOverviewRouteQuery,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
@@ -50,6 +52,7 @@ defineOptions({ name: 'CategoryOverview' });
const route = useRoute();
const router = useRouter();
const { setTabTitle } = useTabs();
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
/** 当前是否为品类概览路由 */
@@ -62,6 +65,16 @@ const categoryId = computed(() => {
return Number.isFinite(id) && id > 0 ? id : 0;
});
/** 数据加载后用品类名覆盖菜单默认标签「品类概览」 */
async function syncCategoryTabTitle(name?: null | string) {
if (!isCategoryOverviewRoute()) return;
await setTabTitle(
formatOverviewTabTitle(
name,
categoryId.value ? `品类 #${categoryId.value}` : '品类概览',
),
);
}
const categoriesLoading = ref(false);
const categoryOptions = ref<{ label: string; value: number }[]>([]);
@@ -259,18 +272,23 @@ function handleCategoryChange(nextId: number) {
const loadOverviewData = async () => {
if (!isCategoryOverviewRoute() || !categoryId.value) return;
if (isRequesting.value) return;
const requestCategoryId = categoryId.value;
isRequesting.value = true;
try {
loading.value = true;
const [startDate, endDate] = dateRange.value;
overviewData.value = await getCategoryOverviewApi({
categoryId: categoryId.value,
const res = await getCategoryOverviewApi({
categoryId: requestCategoryId,
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
});
overviewData.value = res;
if (isCategoryOverviewRoute() && categoryId.value === requestCategoryId) {
await syncCategoryTabTitle(res?.categoryName);
}
await redrawCharts();
} catch (err: any) {
overviewData.value = null;
@@ -16,6 +16,7 @@ import {
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Spin } from 'ant-design-vue';
@@ -28,6 +29,7 @@ import {
buildOverviewRouteQuery,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
@@ -50,6 +52,7 @@ defineOptions({ name: 'PlatformOverview' });
const route = useRoute();
const router = useRouter();
const { setTabTitle } = useTabs();
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
/** 当前是否为平台概览路由 */
@@ -62,6 +65,16 @@ const platformCode = computed(() => {
return typeof code === 'string' ? code.trim() : '';
});
/** 数据加载后用平台名覆盖菜单默认标签「平台概览」 */
async function syncPlatformTabTitle(name?: null | string) {
if (!isPlatformOverviewRoute()) return;
await setTabTitle(
formatOverviewTabTitle(
name,
platformCode.value ? platformCode.value : '平台概览',
),
);
}
const platformsLoading = ref(false);
const platformOptions = ref<{ label: string; value: string }[]>([]);
@@ -259,18 +272,23 @@ function handlePlatformChange(nextCode: string) {
const loadOverviewData = async () => {
if (!isPlatformOverviewRoute() || !platformCode.value) return;
if (isRequesting.value) return;
const requestCode = platformCode.value;
isRequesting.value = true;
try {
loading.value = true;
const [startDate, endDate] = dateRange.value;
overviewData.value = await getPlatformOverviewApi({
platformCode: platformCode.value,
const res = await getPlatformOverviewApi({
platformCode: requestCode,
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
});
overviewData.value = res;
if (isPlatformOverviewRoute() && platformCode.value === requestCode) {
await syncPlatformTabTitle(res?.platformName);
}
await redrawCharts();
} catch (err: any) {
overviewData.value = null;
@@ -8,6 +8,7 @@ import { computed, nextTick, onActivated, onMounted, onUnmounted, ref, watch } f
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { createIconifyIcon } from '@vben/icons';
import { Button, Spin, message } from 'ant-design-vue';
@@ -28,6 +29,7 @@ import {
parseOverviewShopIdFromQuery,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
@@ -45,6 +47,7 @@ defineOptions({ name: 'ProductOverview' });
const route = useRoute();
const router = useRouter();
const { setTabTitle } = useTabs();
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
const PRODUCT_PAGE_SIZE = 20;
@@ -60,6 +63,14 @@ const productId = computed(() => {
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
});
/** 数据加载后用商品名覆盖菜单默认标签「商品概览」 */
async function syncProductTabTitle(name?: null | string) {
if (!isProductOverviewRoute()) return;
await setTabTitle(
formatOverviewTabTitle(name, productId.value ? `商品 #${productId.value}` : '商品概览'),
);
}
const contextShopId = computed(() => {
if (!isProductOverviewRoute()) return undefined;
return parseOverviewShopIdFromQuery(
@@ -393,11 +404,12 @@ const handleTimeRangeChange = async (val: typeof timeRangeState.value) => {
async function loadOverviewData() {
if (!isProductOverviewRoute() || !productId.value) return;
if (isRequesting.value) return;
const requestProductId = productId.value;
isRequesting.value = true;
try {
loading.value = true;
const res = await getProductOverviewApi({
productId: productId.value,
productId: requestProductId,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
taxRate: taxRate.value,
@@ -406,6 +418,9 @@ async function loadOverviewData() {
: {}),
});
overviewData.value = res ?? null;
if (isProductOverviewRoute() && productId.value === requestProductId) {
await syncProductTabTitle(res?.productName);
}
await redrawCharts();
} catch (err: any) {
message.error(err?.message || '加载失败');
@@ -16,6 +16,7 @@ import {
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useTabs } from '@vben/hooks';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Spin } from 'ant-design-vue';
@@ -28,6 +29,7 @@ import {
buildOverviewRouteQuery,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
import { formatOverviewTabTitle } from '#/utils/overview-tab-title';
import FinanceCostPieChart from '#/views/bi/workbench/tabs/finance/components/FinanceCostPieChart.vue';
import FinanceKpiGrid from '#/views/bi/workbench/tabs/finance/components/FinanceKpiGrid.vue';
@@ -49,6 +51,7 @@ defineOptions({ name: 'ShopOverview' });
const route = useRoute();
const router = useRouter();
const { setTabTitle } = useTabs();
const IconSliders = createIconifyIcon('lucide:sliders-horizontal');
const SHOP_PAGE_SIZE = 20;
@@ -71,6 +74,13 @@ const shopId = computed(() => {
return id ? Number(id) : 0;
});
/** 数据加载后用店铺名覆盖菜单默认标签「店铺概览」 */
async function syncShopTabTitle(name?: null | string) {
if (!isShopOverviewRoute()) return;
await setTabTitle(
formatOverviewTabTitle(name, shopId.value ? `店铺 #${shopId.value}` : '店铺概览'),
);
}
const loading = ref(false);
const exportLoading = ref(false);
const overviewData = ref<null | ShopVO.OverviewStatistics>(null);
@@ -294,18 +304,23 @@ function handleShopChange(nextShopId: number) {
const loadOverviewData = async () => {
if (!isShopOverviewRoute() || !shopId.value) return;
if (isRequesting.value) return;
const requestShopId = shopId.value;
isRequesting.value = true;
try {
loading.value = true;
const [startDate, endDate] = dateRange.value;
overviewData.value = await getShopOverviewApi({
shopId: shopId.value,
const res = await getShopOverviewApi({
shopId: requestShopId,
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
});
overviewData.value = res;
if (isShopOverviewRoute() && shopId.value === requestShopId) {
await syncShopTabTitle(res?.shopName);
}
await redrawCharts();
} catch (err: any) {
overviewData.value = null;