From 517f939b6672d094e5177658baf7cfd5ec5d2c79 Mon Sep 17 00:00:00 2001 From: Abeautifulsnow Date: Fri, 9 Oct 2026 17:55:15 +0800 Subject: [PATCH] feat(grid): copy selection aggregate values on click --- apps/desktop/src/components/grid/DataGrid.vue | 2 + .../components/grid/DataGridPagination.vue | 22 +++++- .../grid/__tests__/DataGridSurfaces.spec.ts | 72 +++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index e187b9fe35..62905efeb8 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -15475,6 +15475,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val :selection-summary="selectionSummary" :selection-summary-sum-text="selectionSummarySumText" :selection-summary-average-text="selectionSummaryAverageText" + :selection-summary-pending="isSelectingCells" :loading="gridPaginationBusy || infiniteScrollLoading" :infinite-scroll-enabled="infiniteScrollEnabled" :infinite-scroll-all-loaded="infiniteScrollAllLoaded" @@ -15500,6 +15501,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val @last-page="lastPage" @load-all-rows="loadAllRowsAndGoToLast" @select-export="selectExportMenuItem" + @copy-selection-summary="copyText" /> diff --git a/apps/desktop/src/components/grid/DataGridPagination.vue b/apps/desktop/src/components/grid/DataGridPagination.vue index 6a3a3ee4e4..50deab205a 100644 --- a/apps/desktop/src/components/grid/DataGridPagination.vue +++ b/apps/desktop/src/components/grid/DataGridPagination.vue @@ -17,6 +17,8 @@ const props = withDefaults( selectionSummary: { cellCount: number; rowCount: number } | null; selectionSummarySumText: string; selectionSummaryAverageText: string; + // 拖拽选区期间聚合值只是占位符,父组件把该状态传下来,值不可复制 + selectionSummaryPending?: boolean; loading: boolean; infiniteScrollEnabled: boolean; infiniteScrollAllLoaded: boolean; @@ -33,7 +35,7 @@ const props = withDefaults( canGoNextPage: boolean; canJumpLastPage: boolean; }>(), - { paginationEnabled: true, loadAllRowsActive: false, loadAllRowsEnabled: true, canLoadAllRows: false, canExport: true }, + { paginationEnabled: true, loadAllRowsActive: false, loadAllRowsEnabled: true, canLoadAllRows: false, canExport: true, selectionSummaryPending: false }, ); const customPageSizeInput = defineModel("customPageSizeInput", { default: "" }); @@ -56,8 +58,18 @@ const emit = defineEmits<{ loadAllRows: []; selectExport: [value: string]; applyCustomPageSizeAndSetDefault: []; + // 载荷是聚合值当前显示出来的文本,保证复制到的就是用户看到的那个数 + copySelectionSummary: [text: string]; }>(); +// 拖拽选区中聚合值显示为占位符 "…",此时不给复制入口,避免复制出一个假值 +const selectionSummaryValueClass = computed(() => (props.selectionSummaryPending ? "" : "cursor-pointer transition-colors hover:text-foreground")); + +function copySelectionSummaryValue(text: string) { + if (props.selectionSummaryPending) return; + emit("copySelectionSummary", text); +} + watch( () => props.currentPage, (page) => { @@ -93,8 +105,12 @@ function handlePageInputKeydown(event: KeyboardEvent) {