feat: 工作台跳转店铺和商品页带上日期范围参数

This commit is contained in:
小蟑螂
2026-05-22 21:11:19 +08:00
parent 0b653cf56e
commit 6531523c57
6 changed files with 53 additions and 9 deletions
@@ -46,6 +46,17 @@ export function normalizeOverviewRangePickerChange(
const START_Q = 'startDate';
const END_Q = 'endDate';
/** 概览页跳转(店铺/商品)时附带的 query,与全店概览一致 */
export function buildOverviewRouteQuery(dateRange: [Dayjs, Dayjs]): {
startDate: string;
endDate: string;
} {
return {
startDate: dateRange[0].format('YYYY-MM-DD'),
endDate: dateRange[1].format('YYYY-MM-DD'),
};
}
/** 从当前地址栏读取概览日期 query(含 replaceState 写入、未反映到 Vue Router 的情况) */
export function getOverviewDateQueryFromLocation(): {
startDate: string;
@@ -23,6 +23,7 @@ import { getCompanyOverviewApi } from '#/api/ecommerce/store-overview/apis';
import { exportByPost } from '#/utils/export';
import {
applyOverviewDateRangeFromUrl,
buildOverviewRouteQuery,
normalizeOverviewRangePickerChange,
syncOverviewDateRangeToUrl,
} from '#/utils/overview-date-range';
@@ -410,10 +411,7 @@ const handlePlatformExport = async () => {
const navigateToShopOverview = (shopId: number) => {
router.push({
path: `/ecom/shop/overview/${shopId}`,
query: {
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
},
query: buildOverviewRouteQuery(dateRange.value),
});
};
</script>
@@ -15,7 +15,10 @@ import type { ShopVO } from '#/api/ecommerce/shop/types';
import { getWorkbenchSummaryApi } from '#/api/ecommerce/workbench/apis';
import type { WorkbenchDTO, WorkbenchVO } from '#/api/ecommerce/workbench/types';
import { $t } from '#/locales';
import { normalizeOverviewRangePickerChange } from '#/utils/overview-date-range';
import {
buildOverviewRouteQuery,
normalizeOverviewRangePickerChange,
} from '#/utils/overview-date-range';
import WorkbenchFinanceTab from './tabs/finance/index.vue';
import WorkbenchMultiTab from './tabs/multi/index.vue';
@@ -253,7 +256,17 @@ async function loadShopAndPlatformMeta() {
const activeTab = ref('finance');
function handleShopNavigate(shopId: number) {
router.push(`/ecom/shop/overview/${shopId}`);
router.push({
path: `/ecom/shop/overview/${shopId}`,
query: buildOverviewRouteQuery(dateRange.value),
});
}
function handleProductNavigate(productId: number) {
router.push({
path: `/ecom/product/overview/${productId}`,
query: buildOverviewRouteQuery(dateRange.value),
});
}
const financeTabRef = ref<InstanceType<typeof WorkbenchFinanceTab> | null>(
@@ -533,6 +546,7 @@ onUnmounted(() => {
:multi-analysis="multiPanel"
:summary-tables="summaryTablesPanel"
@navigate="handleShopNavigate"
@navigate-product="handleProductNavigate"
/>
</Tabs.TabPane>
<Tabs.TabPane key="multi" tab="多维分析">
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import type { CompanyOverviewVO } from '#/api/ecommerce/store-overview';
import { createIconifyIcon } from '@vben/icons';
import { computed } from 'vue';
import { formatFeeRatioPercent } from '#/utils/overview-fee-ratio';
@@ -14,6 +15,8 @@ import {
defineOptions({ name: 'WorkbenchCategoryComparisonTable' });
const JumpIcon = createIconifyIcon('tdesign:jump');
interface Props {
categorySummary?: CompanyOverviewVO.CategoryOverview;
taxRate: number;
@@ -23,12 +26,15 @@ interface Props {
headingSubtitle?: string;
/** 首列维度名称,如「品类」「商品」 */
firstColumnLabel?: string;
/** 为 true 时首列名称可点击跳转商品概览(categoryId 即商品 ID) */
productNavigate?: boolean;
}
interface Emits {
(e: 'update:selectedExportCategoryIds', ids: number[]): void;
(e: 'toggleCategoryExportMode', enabled: boolean): void;
(e: 'export'): void;
(e: 'navigate-product', productId: number): void;
}
const props = withDefaults(defineProps<Props>(), {
@@ -37,6 +43,7 @@ const props = withDefaults(defineProps<Props>(), {
headingTitle: '各品类多维度经营明细汇总',
headingSubtitle: '包含:规模、成本及最终损益所有维度',
firstColumnLabel: '品类',
productNavigate: false,
});
const emit = defineEmits<Emits>();
@@ -243,7 +250,18 @@ const cellRoi = (v: number | null | undefined) =>
/>
</td>
<td class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none">
<span class="inline-block rounded-full bg-blue-50 dark:bg-blue-900/30 px-3 py-1 text-sm font-bold text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline">
<span
v-if="productNavigate && cat.categoryId != null"
class="inline-flex cursor-pointer items-center gap-1 rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 transition-colors hover:text-blue-300 hover:underline dark:bg-blue-900/30 dark:text-blue-400"
@click="emit('navigate-product', cat.categoryId!)"
>
{{ cat.categoryName }}
<JumpIcon class="text-xs" />
</span>
<span
v-else
class="inline-block rounded-full bg-blue-50 px-3 py-1 text-sm font-bold text-blue-600 dark:bg-blue-900/30 dark:text-blue-400"
>
{{ cat.categoryName }}
</span>
</td>
@@ -31,6 +31,7 @@ const props = withDefaults(
);
const emit = defineEmits<{
(e: 'navigate', shopId: number): void;
(e: 'navigate-product', productId: number): void;
}>();
const activeMode = ref<'category' | 'platform' | 'product' | 'shop'>('shop');
@@ -188,7 +189,6 @@ async function handleProductExport() {
heading-title="各店铺多维度经营明细汇总"
:shop-summary="shopSummary ?? undefined"
:tax-rate="taxRate"
:navigable="false"
:shop-export-mode="shopExportMode"
:selected-export-shop-ids="selectedExportShopIds"
@update:selected-export-shop-ids="selectedExportShopIds = $event"
@@ -228,7 +228,7 @@ async function handleProductExport() {
heading-title="各商品多维度经营明细汇总"
heading-subtitle="列结构与品类表一致;数据与全店概览商品维度同源;点击商品名可跳转商品概览"
first-column-label="商品"
product-navigate
:product-navigate="true"
:category-summary="productSummary ?? undefined"
:tax-rate="taxRate"
:category-export-mode="productExportMode"
@@ -236,6 +236,7 @@ async function handleProductExport() {
@update:selected-export-category-ids="selectedExportProductIds = $event"
@toggle-category-export-mode="productExportMode = $event"
@export="handleProductExport"
@navigate-product="(id: number) => emit('navigate-product', id)"
/>
</div>
</template>
@@ -19,6 +19,7 @@ defineOptions({ name: 'WorkbenchFinanceTab' });
const emit = defineEmits<{
(e: 'navigate', shopId: number): void;
(e: 'navigate-product', productId: number): void;
}>();
const props = defineProps<{
@@ -95,6 +96,7 @@ defineExpose({ redraw });
:category-summary="categoryOverview"
:product-summary="productOverview"
@navigate="(id: number) => emit('navigate', id)"
@navigate-product="(id: number) => emit('navigate-product', id)"
/>
</div>
</template>