feat(sidebar): add collapse toggle

This commit is contained in:
t8y2
2026-06-03 01:23:04 +08:00
parent 4ce010369b
commit 1f7cdbdb59
6 changed files with 52 additions and 10 deletions
+25
View File
@@ -2,6 +2,7 @@
import { ref, computed, watch, onMounted, onUnmounted, nextTick, defineAsyncComponent } from "vue";
import { useI18n } from "vue-i18n";
import { invoke } from "@tauri-apps/api/core";
import { ChevronsRight } from "lucide-vue-next";
import { TooltipProvider } from "@/components/ui/tooltip";
import AppToolbar from "@/components/layout/AppToolbar.vue";
import AppTabBar from "@/components/layout/AppTabBar.vue";
@@ -113,6 +114,7 @@ const showDriverStore = ref(false);
const agentDriverUpdateCount = ref(0);
const showHistory = ref(false);
const showAiPanel = ref(safeLocalStorageGet("dbx-ai-panel-open") === "true");
const sidebarOpen = ref(safeLocalStorageGet("dbx-sidebar-open") !== "false");
const aiPanelReady = ref(false);
const { sidebarWidth, aiPanelWidth, historyWidth, startSidebarResize, startAiPanelResize, startHistoryResize } =
usePanelResize();
@@ -691,6 +693,11 @@ function openMcpGuide() {
openUrl("https://dbxio.com/cn/docs/mcp");
}
function setSidebarOpen(open: boolean) {
sidebarOpen.value = open;
safeLocalStorageSet("dbx-sidebar-open", open ? "true" : "false");
}
function ensureQueryTab(): string {
const tab = activeTab.value;
if (tab && tab.mode === "query") return tab.id;
@@ -987,13 +994,31 @@ onUnmounted(() => {
"
>
<AppSidebar
v-show="sidebarOpen"
ref="appSidebarRef"
:sidebar-width="sidebarWidth"
:classic-layout="isClassicLayout"
@import="dialogs.onImportClick"
@export="dialogs.onExportClick"
@start-resize="startSidebarResize"
@collapse="setSidebarOpen(false)"
/>
<div
v-show="!sidebarOpen"
class="flex h-full w-8 shrink-0 items-start justify-center border-r bg-background/80 pt-2"
:class="isClassicLayout ? '' : 'rounded-md border border-border/80'"
>
<Button
variant="ghost"
size="icon"
class="h-7 w-7"
:title="t('sidebar.expand')"
:aria-label="t('sidebar.expand')"
@click="setSidebarOpen(true)"
>
<ChevronsRight class="h-4 w-4" />
</Button>
</div>
<div
:class="
@@ -2,7 +2,7 @@
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { translateBackendError } from "@/i18n/backend-errors";
import { Upload, Download, FolderPlus, RefreshCw } from "lucide-vue-next";
import { Upload, Download, FolderPlus, RefreshCw, ChevronsLeft } from "lucide-vue-next";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
import LightDropdown from "@/components/ui/LightDropdown.vue";
@@ -19,6 +19,7 @@ const emit = defineEmits<{
import: [source: "dbx" | "navicat" | "dbeaver"];
export: [];
startResize: [event: MouseEvent];
collapse: [];
}>();
const { t } = useI18n();
@@ -58,7 +59,7 @@ defineExpose({ focusSearch });
>
<div class="h-full flex flex-col overflow-hidden">
<div
class="flex items-center px-3 text-xs font-medium text-muted-foreground border-b bg-muted/20"
class="flex items-center gap-px px-3 text-xs font-medium text-muted-foreground border-b bg-muted/20"
:class="classicLayout ? 'h-9' : 'h-10'"
>
<span class="flex self-stretch items-center truncate" data-tauri-drag-region>{{
@@ -71,8 +72,8 @@ defineExpose({ focusSearch });
:aria-label="t('sidebar.import')"
:trigger-title="t('sidebar.import')"
:trigger-icon="Upload"
trigger-class="inline-flex h-6 w-6 items-center justify-center rounded-md hover:bg-accent hover:text-accent-foreground"
trigger-icon-class="h-3.5 w-3.5"
trigger-class="inline-flex h-6 w-5 items-center justify-center rounded-md outline-none hover:bg-muted hover:text-foreground focus-visible:ring-0"
trigger-icon-class="h-4 w-4"
content-class="w-44"
:show-trigger-label="false"
:show-chevron="false"
@@ -83,28 +84,36 @@ defineExpose({ focusSearch });
/>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-6" @click="emit('export')">
<Download class="h-3.5 w-3.5" />
<Button variant="ghost" size="icon" class="h-5 w-5" @click="emit('export')">
<Download class="h-3 w-3" />
</Button>
</TooltipTrigger>
<TooltipContent>{{ t("sidebar.export") }}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-6" @click="createNewGroup">
<FolderPlus class="h-3.5 w-3.5" />
<Button variant="ghost" size="icon" class="h-5 w-5" @click="createNewGroup">
<FolderPlus class="h-3 w-3" />
</Button>
</TooltipTrigger>
<TooltipContent>{{ t("connectionGroup.createGroup") }}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-6" @click="refreshTree">
<RefreshCw class="h-3.5 w-3.5" />
<Button variant="ghost" size="icon" class="h-5 w-5" @click="refreshTree">
<RefreshCw class="h-3 w-3" />
</Button>
</TooltipTrigger>
<TooltipContent>{{ t("contextMenu.refreshChildren") }}</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon" class="h-6 w-6" @click="emit('collapse')">
<ChevronsLeft class="h-3.5 w-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>{{ t("sidebar.collapse") }}</TooltipContent>
</Tooltip>
</div>
<div class="flex-1 min-h-0">
<ConnectionTree ref="connectionTreeRef" />
+2
View File
@@ -74,6 +74,8 @@ export default {
importNavicat: "Import Navicat NCX",
importDbeaver: "Import DBeaver",
export: "Export Connections",
collapse: "Collapse sidebar",
expand: "Expand sidebar",
showMore: "Show {count} more...",
filterByType: "Filter by type",
searchScopeConnection: "Connection",
+2
View File
@@ -74,6 +74,8 @@ export default {
importNavicat: "Importar Navicat NCX",
importDbeaver: "Importar DBeaver",
export: "Exportar conexiones",
collapse: "Contraer barra lateral",
expand: "Expandir barra lateral",
showMore: "Mostrar {count} más...",
filterByType: "Filtrar por tipo",
searchScopeConnection: "Conexión",
+2
View File
@@ -73,6 +73,8 @@ export default {
importNavicat: "导入 Navicat NCX",
importDbeaver: "导入 DBeaver",
export: "导出连接",
collapse: "收起侧边栏",
expand: "展开侧边栏",
showMore: "加载更多 ({count})...",
filterByType: "按类型筛选",
searchScopeConnection: "连接",
+2
View File
@@ -73,6 +73,8 @@ export default {
importNavicat: "匯入 Navicat NCX",
importDbeaver: "匯入 DBeaver",
export: "匯出連線",
collapse: "收合側邊欄",
expand: "展開側邊欄",
showMore: "再顯示 {count} 個……",
filterByType: "依類型篩選",
searchScopeConnection: "連線",