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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat(ui): add tab drag-and-drop reordering
dqnbe9b07147311
diff --git a/apps/desktop/src/components/layout/AppTabBar.vue b/apps/desktop/src/components/layout/AppTabBar.vueindex 5a08d0f5f7..74ccddcf13 100644--- a/apps/desktop/src/components/layout/AppTabBar.vue+++ b/apps/desktop/src/components/layout/AppTabBar.vue@@ -22,6 +22,7 @@ import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltipimport { useQueryStore } from "@/stores/queryStore";import { useSettingsStore } from "@/stores/settingsStore";import { useTabScroll } from "@/composables/useTabScroll";+import { useTabDrag } from "@/composables/useTabDrag";import {connectionColor,shouldShowTabOverflowControls,@@ -44,6 +45,9 @@ const emit = defineEmits<{const { t } = useI18n();const queryStore = useQueryStore();const settingsStore = useSettingsStore();+const tabDrag = useTabDrag((draggedId, targetId, position) => {+ queryStore.reorderTab(draggedId, targetId, position);+});const editingTabId = ref<string | null>(null);const editingTitle = ref("");const compactTabTitle = computed({@@ -231,6 +235,22 @@ function activateTab(tabId: string) {emit("close-driver-store");}+function handleTabClick(tab: QueryTab) {+ if (tabDrag.state.wasDragged) return;+ activateTab(tab.id);+}++function tabDropStyle(tabId: string) {+ if (!tabDrag.state.active) return {};+ if (tabDrag.state.draggedId === tabId) return { opacity: 0.4 };+ if (tabDrag.state.targetId !== tabId) return {};+ const dropColor = `var(--ring)`;+ if (tabDrag.state.dropPosition === "before") {+ return { boxShadow: `inset 3px 0 0 0 ${dropColor}` };+ }+ return { boxShadow: `inset -3px 0 0 0 ${dropColor}` };+}+const tabsContainerStyle = computed<CSSProperties>(() => ({msOverflowStyle: "none",scrollbarWidth: "none",@@ -306,14 +326,14 @@ const tabOverflowControlClass = computed(() =>: 'border-border/60 text-foreground/70 hover:border-border hover:text-foreground/90',]"- :style="tabColorStyle(tab)"+ :style="[tabColorStyle(tab), tabDropStyle(tab.id)]":data-active-tab="tab.id === queryStore.activeTabId && !showDriverStore"- @click="- queryStore.activeTabId = tab.id;- emit('close-driver-store');- "+ @click="handleTabClick(tab)"@dblclick.stop="startRenameTab(tab)"@mousedown.middle.prevent="queryStore.closeTab(tab.id)"+ @mousedown="tabDrag.startDrag($event, tab.id)"+ @mouseenter="tabDrag.updateTarget($event, tab.id)"+ @mouseleave="tabDrag.clearTarget(tab.id)"><span class="shrink-0" :class="tabIconClass(tab)"><Table2 v-if="tab.mode === 'data'" class="h-3.5 w-3.5" />diff --git a/apps/desktop/src/composables/useTabDrag.ts b/apps/desktop/src/composables/useTabDrag.tsnew file mode 100644index 0000000000..1d5fca6504--- /dev/null+++ b/apps/desktop/src/composables/useTabDrag.ts@@ -0,0 +1,175 @@+import { reactive, readonly } from "vue";++export type TabDropPosition = "before" | "after";++interface TabDragState {+ active: boolean;+ draggedId: string | null;+ targetId: string | null;+ dropPosition: TabDropPosition | null;+ wasDragged: boolean;+ startX: number;+ startY: number;+}++const DRAG_THRESHOLD = 5;++const state = reactive<TabDragState>({+ active: false,+ draggedId: null,+ targetId: null,+ dropPosition: null,+ wasDragged: false,+ startX: 0,+ startY: 0,+});++let pending: {+ id: string;+ x: number;+ y: number;+ sourceEl: HTMLElement | null;+} | null = null;+let onDropCallback: ((draggedId: string, targetId: string, position: TabDropPosition) => void) | null = null;+let ghostEl: HTMLElement | null = null;++function createGhost(sourceEl: HTMLElement, x: number, y: number) {+ const ghost = document.createElement("div");+ const textNode = sourceEl.querySelector(".truncate");+ ghost.textContent = textNode?.textContent || "";+ ghost.style.cssText = `+ position: fixed;+ pointer-events: none;+ z-index: 9999;+ opacity: 0.9;+ box-shadow: 0 2px 8px rgba(0,0,0,0.15);+ border-radius: 6px;+ background: var(--background, #fff);+ border: 1px solid var(--border, #e5e7eb);+ max-width: 200px;+ height: 28px;+ padding: 0 12px;+ font-size: 12px;+ line-height: 28px;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ left: ${x + 12}px;+ top: ${y - 14}px;+ `;+ document.body.appendChild(ghost);+ return ghost;+}++function moveGhost(x: number, y: number) {+ if (!ghostEl) return;+ ghostEl.style.left = `${x + 8}px`;+ ghostEl.style.top = `${y - 14}px`;+}++function removeGhost() {+ if (ghostEl) {+ ghostEl.remove();+ ghostEl = null;+ }+}++function onMouseMove(event: MouseEvent) {+ if (!pending && !state.active) return;++ if (pending && !state.active) {+ const dx = event.clientX - pending.x;+ const dy = event.clientY - pending.y;+ if (Math.abs(dx) < DRAG_THRESHOLD && Math.abs(dy) < DRAG_THRESHOLD) return;+ state.active = true;+ state.wasDragged = true;+ state.draggedId = pending.id;+ state.startX = pending.x;+ state.startY = pending.y;+ if (pending.sourceEl) {+ ghostEl = createGhost(pending.sourceEl, event.clientX, event.clientY);+ }+ pending = null;+ document.body.style.cursor = "grabbing";+ document.body.style.userSelect = "none";+ }++ if (state.active) {+ moveGhost(event.clientX, event.clientY);+ }+}++function onMouseUp() {+ if (state.active && state.draggedId && state.targetId && state.dropPosition && onDropCallback) {+ onDropCallback(state.draggedId, state.targetId, state.dropPosition);+ }+ reset();+}++function reset() {+ state.active = false;+ state.draggedId = null;+ state.targetId = null;+ state.dropPosition = null;+ state.startX = 0;+ state.startY = 0;+ pending = null;+ removeGhost();+ document.body.style.cursor = "";+ document.body.style.userSelect = "";+}++let listenersAttached = false;++function ensureListeners() {+ if (listenersAttached) return;+ document.addEventListener("mousemove", onMouseMove, true);+ document.addEventListener("mouseup", onMouseUp, true);+ listenersAttached = true;+}++export function useTabDrag(onDrop: (draggedId: string, targetId: string, position: TabDropPosition) => void) {+ ensureListeners();+ onDropCallback = onDrop;++ function startDrag(event: MouseEvent, tabId: string) {+ if (event.button !== 0) return;+ const target = event.target as HTMLElement;+ if (target.closest("button, input, [data-tab-title-input]")) return;+ state.wasDragged = false;+ const el = (event.currentTarget as HTMLElement) || null;+ pending = { id: tabId, x: event.clientX, y: event.clientY, sourceEl: el };+ }++ function updateTarget(event: MouseEvent, tabId: string) {+ if (!state.active || tabId === state.draggedId) {+ if (state.targetId === tabId) {+ state.targetId = null;+ state.dropPosition = null;+ }+ return;+ }++ state.targetId = tabId;++ const el = event.currentTarget as HTMLElement;+ const rect = el.getBoundingClientRect();+ const x = event.clientX - rect.left;++ state.dropPosition = x < rect.width / 2 ? "before" : "after";+ }++ function clearTarget(tabId: string) {+ if (state.targetId === tabId) {+ state.targetId = null;+ state.dropPosition = null;+ }+ }++ return {+ state: readonly(state),+ startDrag,+ updateTarget,+ clearTarget,+ };+}diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.tsindex 42f3222b29..37a1b5d7fc 100644--- a/apps/desktop/src/stores/queryStore.ts+++ b/apps/desktop/src/stores/queryStore.ts@@ -470,6 +470,15 @@ export const useQueryStore = defineStore("query", () => {tabs.value = orderPinnedFirst(tabs.value, (item) => !!item.pinned);}+ function reorderTab(id: string, targetId: string, position: "before" | "after") {+ const fromIdx = tabs.value.findIndex((t) => t.id === id);+ const toIdx = tabs.value.findIndex((t) => t.id === targetId);+ if (fromIdx < 0 || toIdx < 0 || fromIdx === toIdx) return;+ const [tab] = tabs.value.splice(fromIdx, 1);+ const newToIdx = tabs.value.findIndex((t) => t.id === targetId);+ tabs.value.splice(newToIdx + (position === "after" ? 1 : 0), 0, tab);+ }+function updateDatabase(id: string, database: string) {const tab = tabs.value.find((t) => t.id === id);if (!tab || tab.database === database) return;@@ -1358,6 +1367,7 @@ export const useQueryStore = defineStore("query", () => {linkSavedSql,openSavedSql,togglePinnedTab,+ reorderTab,updateDatabase,updateSchema,updateConnection,