Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(grid): 添加多行转置功能和相关界面支持 (#909)

二丫讲梵f8834aee09b1
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index a488cfb297..dd2e7c2513 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -105,6 +105,7 @@ import {
nextKeyboardTransposeState,
nextTransposeState,
nextTransposeStateForRecordCount,
+ transposeRecordIndexesForMode,
transposeFieldWidth,
transposeScrollLeftForRecord,
visibleTransposeRecordWindow,
@@ -460,6 +461,7 @@ const previewDialogOpen = ref(false);
const previewDialogConfig = shallowRef<{ component: any; props: Record<string, any> } | null>(null);
const transposeRowIndex = ref<number | null>(null);
const showTranspose = ref(false);
+const multiRowTranspose = ref(false);
const preserveTransposeOnNextResult = ref(false);
const transposeScrollRef = ref<HTMLElement | { $el?: HTMLElement }>();
const transposeScrollLeft = ref(0);
@@ -4836,22 +4838,37 @@ const visibleTransposeRecordIndexes = computed(() => {
const window = transposeRecordWindow.value;
return Array.from({ length: window.end - window.start }, (_, offset) => window.start + offset);
});
+const activeTransposeRecordIndexes = computed(() =>
+ transposeRecordIndexesForMode({
+ multiRow: multiRowTranspose.value,
+ activeRecordIndex: transposeRowIndex.value,
+ totalRecords: displayRowCount.value,
+ visibleRecordIndexes: visibleTransposeRecordIndexes.value,
+ }),
+);
+const transposeBeforeSpacerWidth = computed(() =>
+ multiRowTranspose.value ? transposeRecordWindow.value.beforeWidth : 0,
+);
+const transposeAfterSpacerWidth = computed(() =>
+ multiRowTranspose.value ? transposeRecordWindow.value.afterWidth : 0,
+);
const transposeRows = computed(() => {
return buildVisibleTransposeRows({
columns: visibleColumns.value,
records: displayRowRefs.value.map((_, index) => displayItemAt(index)?.data ?? []),
- recordIndexes: visibleTransposeRecordIndexes.value,
+ recordIndexes: activeTransposeRecordIndexes.value,
valueIndexes: visibleColumnIndexes.value,
typeByColumn: columnTypeMap.value,
displayValue: (value, _column, index) => formatCellCached(value, visibleColumnIndexes.value[index]),
});
});
const isTransposeMode = computed(() => showTranspose.value && transposeRows.value.length > 0);
-const transposeTotalWidth = computed(
- () =>
- transposePinnedWidth.value +
- Array.from({ length: displayRowCount.value }, (_, i) => getTransposeRecordWidth(i)).reduce((sum, w) => sum + w, 0),
-);
+const transposeTotalWidth = computed(() => {
+ const recordIndexes = multiRowTranspose.value
+ ? Array.from({ length: displayRowCount.value }, (_, i) => i)
+ : activeTransposeRecordIndexes.value;
+ return transposePinnedWidth.value + recordIndexes.reduce((sum, i) => sum + getTransposeRecordWidth(i), 0);
+});
function transposeScrollElement(): HTMLElement | undefined {
const raw = transposeScrollRef.value;
@@ -4888,6 +4905,26 @@ function scrollTransposeRecordIntoView(rowIndex: number) {
});
}
+function setMultiRowTranspose(value: boolean) {
+ multiRowTranspose.value = value;
+ if (!showTranspose.value) return;
+ nextTick(updateTransposeViewport);
+ if (value && transposeRowIndex.value !== null) {
+ scrollTransposeRecordIntoView(transposeRowIndex.value);
+ } else {
+ nextTick(() => {
+ const el = transposeScrollElement();
+ if (!el) return;
+ el.scrollLeft = 0;
+ updateTransposeViewport();
+ });
+ }
+}
+
+function toggleMultiRowTranspose() {
+ setMultiRowTranspose(!multiRowTranspose.value);
+}
+
function applyTransposeState(next: { showTranspose: boolean; transposeRowIndex: number | null }) {
showTranspose.value = next.showTranspose;
transposeRowIndex.value = next.transposeRowIndex;
@@ -5624,6 +5661,9 @@ defineExpose({
toggleDdl: toggleTableInfo,
showTableInfo,
toggleTableInfo,
+ multiRowTranspose,
+ setMultiRowTranspose,
+ toggleMultiRowTranspose,
focusSearch,
visibleColumnCount,
displayableColumnCount,
@@ -6436,6 +6476,11 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<span class="text-xs text-muted-foreground">
{{ t("grid.rowNumber") }} {{ (transposeRowIndex ?? 0) + 1 }}
</span>
+ <span
+ class="rounded border border-border bg-background px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground"
+ >
+ {{ multiRowTranspose ? t("grid.transposeMultiRow") : t("grid.transposeSingleRow") }}
+ </span>
<span class="flex-1" />
<Button
variant="ghost"
@@ -6488,9 +6533,9 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
@mousedown.stop="onTransposePinnedResizeStart"
/>
</div>
- <div class="shrink-0" :style="{ width: `${transposeRecordWindow.beforeWidth}px` }" />
+ <div class="shrink-0" :style="{ width: `${transposeBeforeSpacerWidth}px` }" />
<div
- v-for="recordIndex in visibleTransposeRecordIndexes"
+ v-for="recordIndex in activeTransposeRecordIndexes"
:key="`transpose-head-${recordIndex}`"
class="shrink-0 border-r border-border px-2 py-1.5 text-center tabular-nums relative"
:class="{
@@ -6514,7 +6559,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
@dblclick.stop="autoFitTransposeRecord(recordIndex)"
/>
</div>
- <div class="shrink-0" :style="{ width: `${transposeRecordWindow.afterWidth}px` }" />
+ <div class="shrink-0" :style="{ width: `${transposeAfterSpacerWidth}px` }" />
</div>
</template>
<template #default="{ item }">
@@ -6529,7 +6574,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
>
{{ item.column }}
</div>
- <div class="shrink-0" :style="{ width: `${transposeRecordWindow.beforeWidth}px` }" />
+ <div class="shrink-0" :style="{ width: `${transposeBeforeSpacerWidth}px` }" />
<div
v-for="cell in item.values"
:key="`${item.id}:${cell.recordIndex}`"
@@ -6647,7 +6692,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
</div>
</template>
</div>
- <div class="shrink-0" :style="{ width: `${transposeRecordWindow.afterWidth}px` }" />
+ <div class="shrink-0" :style="{ width: `${transposeAfterSpacerWidth}px` }" />
</div>
</template>
</RecycleScroller>
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue
index 9b06181e1d..e3bca53004 100644
--- a/apps/desktop/src/components/layout/ContentArea.vue
+++ b/apps/desktop/src/components/layout/ContentArea.vue
@@ -23,6 +23,8 @@ import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
+import { Switch } from "@/components/ui/switch";
+import LightTooltip from "@/components/ui/LightTooltip.vue";
import QueryEditor from "@/components/editor/QueryEditor.vue";
import ColumnInfoPanel from "@/components/editor/ColumnInfoPanel.vue";
import type { ColumnInfo } from "@/components/editor/ColumnInfoPanel.vue";
@@ -81,6 +83,8 @@ type DataGridHandle = {
toggleAllNullColumns: () => void;
showDdl: boolean;
toggleDdl: () => void;
+ multiRowTranspose: boolean;
+ setMultiRowTranspose: (value: boolean) => void;
};
type SearchableBrowserHandle = {
@@ -864,7 +868,9 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
variant="ghost"
size="icon"
class="h-6 w-7 shrink-0 text-foreground hover:bg-accent"
- :class="{ 'bg-accent text-foreground': dataGridRef?.nullColumnsHidden }"
+ :class="{
+ 'bg-accent text-foreground': dataGridRef?.nullColumnsHidden || dataGridRef?.multiRowTranspose,
+ }"
:title="t('grid.viewOptions')"
:aria-label="t('grid.viewOptions')"
>
@@ -880,6 +886,28 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
<div class="border-b bg-muted/40 px-3 py-2">
<div class="text-xs font-semibold">{{ t("grid.viewOptions") }}</div>
</div>
+ <LightTooltip
+ :text="t('grid.transposeMultiRowHint')"
+ side="left"
+ :side-offset="6"
+ :delay="0"
+ :open-on-focus="false"
+ >
+ <label class="flex cursor-pointer items-center justify-between gap-3 px-3 py-2 text-xs hover:bg-accent">
+ <span class="min-w-0 flex items-center gap-1.5 font-medium">
+ {{ t("grid.transposeMultiRowToggle") }}
+ <span class="text-muted-foreground">
+ {{ dataGridRef?.multiRowTranspose ? t("grid.transposeMultiRow") : t("grid.transposeSingleRow") }}
+ </span>
+ </span>
+ <Switch
+ size="sm"
+ :model-value="!!dataGridRef?.multiRowTranspose"
+ :aria-label="t('grid.transposeMultiRow')"
+ @update:model-value="(value: boolean) => dataGridRef?.setMultiRowTranspose(value)"
+ />
+ </label>
+ </LightTooltip>
<label
class="flex cursor-pointer items-center gap-2 px-3 py-2 text-xs hover:bg-accent"
:class="{ 'cursor-not-allowed opacity-60': !dataGridRef?.canToggleAllNullColumns }"
diff --git a/apps/desktop/src/components/ui/LightTooltip.vue b/apps/desktop/src/components/ui/LightTooltip.vue
index 7794573921..70125875df 100644
--- a/apps/desktop/src/components/ui/LightTooltip.vue
+++ b/apps/desktop/src/components/ui/LightTooltip.vue
@@ -8,12 +8,14 @@ const props = withDefaults(
side?: "top" | "right" | "bottom" | "left";
sideOffset?: number;
delay?: number;
+ openOnFocus?: boolean;
}>(),
{
disabled: false,
side: "top",
sideOffset: 8,
delay: 300,
+ openOnFocus: true,
},
);
@@ -147,6 +149,11 @@ function scheduleOpen() {
timer = setTimeout(open, props.delay);
}
+function scheduleFocusOpen() {
+ if (!props.openOnFocus) return;
+ scheduleOpen();
+}
+
onBeforeUnmount(close);
watch(
@@ -164,7 +171,7 @@ watch(
class="contents"
@mouseenter="scheduleOpen"
@mouseleave="close"
- @focusin="scheduleOpen"
+ @focusin="scheduleFocusOpen"
@focusout="close"
>
<slot />
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 1be4b66135..880c6575b1 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -656,6 +656,11 @@ export default {
copyAlterSqlFailed: "Copy failed: {message}",
copySqlCondition: "Copy SQL Condition",
transpose: "Transpose Row",
+ transposeMultiRowToggle: "Multi-row",
+ transposeSingleRow: "Current row",
+ transposeMultiRow: "Multi-row",
+ transposeMultiRowHint:
+ "When enabled, transpose view shows multiple rows. When disabled, it only shows the current row.",
rowsPerPageShort: " rows",
columnDetails: "Column Details",
tableInfo: "Table Info",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 59e35b1a34..07d6fa7679 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -590,6 +590,11 @@ export default {
copyColumnName: "Copiar nombre de columna",
copySqlCondition: "Copiar condición SQL",
transpose: "Transponer fila",
+ transposeMultiRowToggle: "Varias filas",
+ transposeSingleRow: "Fila actual",
+ transposeMultiRow: "Varias filas",
+ transposeMultiRowHint:
+ "Cuando está activado, la vista transpuesta muestra varias filas. Cuando está desactivado, solo muestra la fila actual.",
rowsPerPageShort: " filas",
columnDetails: "Detalles de columna",
tableInfoSearch: "Buscar...",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 4e6242d429..77c5d48d3a 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -634,6 +634,11 @@ export default {
copyAlterSqlFailed: "Copia non riuscita: {message}",
copySqlCondition: "Copia Condizione SQL",
transpose: "Traspone Riga",
+ transposeMultiRowToggle: "Più righe",
+ transposeSingleRow: "Riga corrente",
+ transposeMultiRow: "Più righe",
+ transposeMultiRowHint:
+ "Quando è attiva, la vista trasposta mostra più righe. Quando è disattiva, mostra solo la riga corrente.",
rowsPerPageShort: " righe",
columnDetails: "Dettagli Colonna",
tableInfo: "Informazioni Tabella",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index fa178a91f1..cfbc7b0081 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -633,6 +633,11 @@ export default {
copyAlterSqlFailed: "Falha ao copiar: {message}",
copySqlCondition: "Copiar Condição SQL",
transpose: "Transpor Linha",
+ transposeMultiRowToggle: "Várias linhas",
+ transposeSingleRow: "Linha atual",
+ transposeMultiRow: "Várias linhas",
+ transposeMultiRowHint:
+ "Quando ativado, a visualização transposta mostra várias linhas. Quando desativado, mostra apenas a linha atual.",
rowsPerPageShort: " linhas",
columnDetails: "Detalhes da Coluna",
tableInfo: "Informações da Tabela",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 14e3ab9541..419517821a 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -651,6 +651,10 @@ export default {
copyAlterSqlFailed: "复制失败:{message}",
copySqlCondition: "复制 SQL 条件",
transpose: "转置查看",
+ transposeMultiRowToggle: "多行转置",
+ transposeSingleRow: "当前行",
+ transposeMultiRow: "多行",
+ transposeMultiRowHint: "开启后,转置视图会同时显示多行;关闭时仅显示当前行。",
rowsPerPageShort: " 行/页",
columnDetails: "列详情",
tableInfo: "表属性",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index ea17457138..d17e32b1d2 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -624,6 +624,10 @@ export default {
copyAlterSqlFailed: "複製失敗:{message}",
copySqlCondition: "複製 SQL 條件",
transpose: "轉置檢視",
+ transposeMultiRowToggle: "多列轉置",
+ transposeSingleRow: "目前列",
+ transposeMultiRow: "多列",
+ transposeMultiRowHint: "開啟後,轉置檢視會同時顯示多列;關閉時僅顯示目前列。",
rowsPerPageShort: " 筆/頁",
columnDetails: "欄位詳情",
tableInfo: "資料表屬性",
diff --git a/apps/desktop/src/lib/dataGridTranspose.ts b/apps/desktop/src/lib/dataGridTranspose.ts
index 9541354538..e4d838b87b 100644
--- a/apps/desktop/src/lib/dataGridTranspose.ts
+++ b/apps/desktop/src/lib/dataGridTranspose.ts
@@ -92,6 +92,13 @@ export interface TransposeScrollLeftOptions {
recordWidth: number;
}
+export interface TransposeRecordIndexesForModeOptions {
+ multiRow: boolean;
+ activeRecordIndex: number | null;
+ totalRecords: number;
+ visibleRecordIndexes: number[];
+}
+
export function nextTransposeState(
showTranspose: boolean,
transposeRowIndex: number | null,
@@ -201,6 +208,13 @@ export function visibleTransposeRecordWindow(options: TransposeRecordWindowOptio
};
}
+export function transposeRecordIndexesForMode(options: TransposeRecordIndexesForModeOptions): number[] {
+ if (options.totalRecords <= 0) return [];
+ if (options.multiRow) return options.visibleRecordIndexes;
+ const requested = options.activeRecordIndex ?? 0;
+ return [Math.max(0, Math.min(options.totalRecords - 1, requested))];
+}
+
export function transposeAnchorRowIndex(options: TransposeAnchorOptions): number {
const requestedRowId = options.rowIds[options.requestedRowIndex];
if (requestedRowId !== undefined && options.selectedRowIds.size > 1 && options.selectedRowIds.has(requestedRowId)) {
diff --git a/packages/app-tests/dataGridTranspose.test.ts b/packages/app-tests/dataGridTranspose.test.ts
index 40d834d4ed..2ff9ce5439 100644
--- a/packages/app-tests/dataGridTranspose.test.ts
+++ b/packages/app-tests/dataGridTranspose.test.ts
@@ -3,6 +3,7 @@ import { test } from "vitest";
import {
buildTransposeRows,
buildVisibleTransposeRows,
+ transposeRecordIndexesForMode,
nextContextTransposeState,
nextAppendedTransposeState,
nextKeyboardTransposeState,
@@ -154,6 +155,42 @@ test("builds visible transpose rows from mapped source column indexes", () => {
assert.equal(rows[0].values[0].valueIndex, 1);
});
+test("single-row transpose only includes the active record", () => {
+ assert.deepEqual(
+ transposeRecordIndexesForMode({
+ multiRow: false,
+ activeRecordIndex: 3,
+ totalRecords: 10,
+ visibleRecordIndexes: [1, 2, 3, 4],
+ }),
+ [3],
+ );
+});
+
+test("single-row transpose clamps the active record into range", () => {
+ assert.deepEqual(
+ transposeRecordIndexesForMode({
+ multiRow: false,
+ activeRecordIndex: 12,
+ totalRecords: 10,
+ visibleRecordIndexes: [7, 8, 9],
+ }),
+ [9],
+ );
+});
+
+test("multi-row transpose keeps the visible record window", () => {
+ assert.deepEqual(
+ transposeRecordIndexesForMode({
+ multiRow: true,
+ activeRecordIndex: 3,
+ totalRecords: 10,
+ visibleRecordIndexes: [1, 2, 3, 4],
+ }),
+ [1, 2, 3, 4],
+ );
+});
+
test("keyboard transpose opens from the selected cell row and closes when active", () => {
assert.deepEqual(
nextKeyboardTransposeState({