|
1 | 1 | <script setup lang="ts"> |
2 | | -import { computed, onMounted, onUnmounted, ref, watch, type WatchStopHandle } from 'vue' |
3 | | -import { RouterLink, useRoute, useRouter } from 'vue-router' |
4 | | -import { |
5 | | - AppWindow, Braces, Clock3, FileKey2, FileSearch2, FolderKey, Hash, |
6 | | - Home, KeyRound, Menu, MonitorUp, QrCode, ScanText, Settings, ShieldCheck, |
7 | | - Shuffle, X, type LucideIcon, |
8 | | -} from 'lucide-vue-next' |
9 | | -import { listen } from '@tauri-apps/api/event' |
10 | | -import { getCurrentWindow } from '@tauri-apps/api/window' |
| 2 | +import SboxApp from '@sbox/ui/app' |
11 | 3 | import { UpdaterDialog } from '@while-coder/tauri-updater-vue' |
12 | | -import { toolNavGroups } from './shell/registry' |
13 | | -// 深路径按需导入:从包入口导入会把全部组件拖进主包(SFC tree-shake 不可靠) |
14 | | -import SMessageHost from '@qingfeng346/ui-kit/components/SMessageHost.vue' |
15 | | -import { ALL_TOOLS } from './shell/registry' |
16 | | -import { loadSettings } from './shell/settings' |
17 | | -import { setupCloseToTray, applyBossKey, watchBossKey, refreshAutostart } from './shell/system' |
18 | | -import { ensureOverlay } from './tools/media/screenshot/screenshot' |
19 | | -
|
20 | | -const route = useRoute() |
21 | | -const router = useRouter() |
22 | | -const sidebarOpen = ref(false) |
23 | | -const isOverlay = computed(() => route.path === '/screenshot-overlay') |
24 | | -const toolGroups = computed(() => toolNavGroups(ALL_TOOLS)) |
25 | | -let stopShortcutWatch: WatchStopHandle | undefined |
26 | | -let unlistenOpenSettings: (() => void) | undefined |
27 | | -
|
28 | | -const toolIcons: Record<string, LucideIcon> = { |
29 | | - 'file-locks': FileSearch2, screenshot: MonitorUp, 'keystore-gen': FolderKey, |
30 | | - 'ssh-keygen': KeyRound, translator: ScanText, 'xiaoai-login': AppWindow, |
31 | | - 'gdrive-login': AppWindow, codec: Braces, json: Braces, 'json-convert': Shuffle, |
32 | | - jwt: ShieldCheck, timestamp: Clock3, 'random-gen': Shuffle, checksum: Hash, |
33 | | - qrcode: QrCode, |
34 | | -} |
35 | | -
|
36 | | -function iconFor(toolKey: string): LucideIcon { |
37 | | - return toolIcons[toolKey] ?? FileKey2 |
38 | | -} |
39 | | -
|
40 | | -function closeSidebar() { |
41 | | - sidebarOpen.value = false |
42 | | -} |
43 | | -
|
44 | | -watch(() => route.fullPath, closeSidebar) |
45 | | -
|
46 | | -onMounted(async () => { |
47 | | - if (getCurrentWindow().label !== 'main') return |
48 | | - // 尽早创建并定尺寸隐藏截图覆盖层,避免第一次截图临时创建默认大小的窗口。 |
49 | | - void ensureOverlay().catch((e) => console.error('初始化截图覆盖层失败:', e)) |
50 | | - loadSettings() |
51 | | - void refreshAutostart() |
52 | | - await setupCloseToTray() |
53 | | - await applyBossKey() |
54 | | - stopShortcutWatch = watchBossKey() |
55 | | - unlistenOpenSettings = await listen('open-settings', () => router.push('/settings')) |
56 | | -}) |
57 | | -
|
58 | | -onUnmounted(() => { |
59 | | - stopShortcutWatch?.() |
60 | | - unlistenOpenSettings?.() |
61 | | -}) |
62 | 4 | </script> |
63 | 5 |
|
64 | 6 | <template> |
65 | | - <!-- 截图覆盖层:全屏无外壳 --> |
66 | | - <router-view v-if="isOverlay" /> |
67 | | - |
68 | | - <div v-else class="app-shell"> |
69 | | - <a class="skip-link" href="#main-content">跳到内容</a> |
70 | | - <aside class="sidebar" :class="{ open: sidebarOpen }" aria-label="主菜单"> |
71 | | - <div class="brand"> |
72 | | - <div class="brand-mark" aria-hidden="true"><span>S</span></div> |
73 | | - <div> |
74 | | - <div class="brand-name">sbox</div> |
75 | | - <div class="brand-subtitle">实用工具箱</div> |
76 | | - </div> |
77 | | - <button class="sidebar-close" type="button" aria-label="关闭菜单" @click="closeSidebar"> |
78 | | - <X :size="18" /> |
79 | | - </button> |
80 | | - </div> |
81 | | - |
82 | | - <nav class="sidebar-nav"> |
83 | | - <RouterLink class="nav-item overview" to="/"> |
84 | | - <Home :size="17" stroke-width="1.8" /> |
85 | | - <span>工具概览</span> |
86 | | - </RouterLink> |
87 | | - |
88 | | - <section v-for="group in toolGroups" :key="group.key" class="nav-group"> |
89 | | - <h2>{{ group.label }}</h2> |
90 | | - <RouterLink |
91 | | - v-for="tool in group.tools" |
92 | | - :key="tool.key" |
93 | | - class="nav-item" |
94 | | - :to="`/${tool.key}`" |
95 | | - :title="tool.description" |
96 | | - > |
97 | | - <component :is="iconFor(tool.key)" :size="17" stroke-width="1.8" /> |
98 | | - <span>{{ tool.label }}</span> |
99 | | - </RouterLink> |
100 | | - </section> |
101 | | - </nav> |
102 | | - |
103 | | - <div class="sidebar-footer"> |
104 | | - <RouterLink class="nav-item" to="/settings"> |
105 | | - <Settings :size="17" stroke-width="1.8" /> |
106 | | - <span>设置</span> |
107 | | - </RouterLink> |
108 | | - </div> |
109 | | - </aside> |
110 | | - |
111 | | - <div v-if="sidebarOpen" class="sidebar-scrim" aria-hidden="true" @click="closeSidebar" /> |
112 | | - |
113 | | - <section class="content-shell"> |
114 | | - <header class="mobile-topbar"> |
115 | | - <button class="menu-button" type="button" aria-label="打开菜单" @click="sidebarOpen = true"> |
116 | | - <Menu :size="20" /> |
117 | | - </button> |
118 | | - <span>sbox</span> |
119 | | - </header> |
120 | | - <main id="main-content" class="app-main" tabindex="-1"> |
121 | | - <router-view /> |
122 | | - </main> |
123 | | - </section> |
124 | | - <UpdaterDialog /> |
125 | | - <!-- toast / confirm / loading 的全局渲染宿主(@qingfeng346/ui-kit 的反馈类组合式函数) --> |
126 | | - <SMessageHost /> |
127 | | - </div> |
| 7 | + <SboxApp><template #updater><UpdaterDialog /></template></SboxApp> |
128 | 8 | </template> |
129 | | - |
130 | | -<style> |
131 | | -.app-shell { display: flex; height: 100%; min-width: 0; overflow: hidden; } |
132 | | -.sidebar { |
133 | | - display: flex; flex: 0 0 252px; flex-direction: column; min-width: 0; |
134 | | - border-right: 1px solid var(--border); background: var(--card); |
135 | | -} |
136 | | -.brand { display: flex; align-items: center; gap: 10px; min-height: 68px; padding: 14px 18px; border-bottom: 1px solid var(--border); } |
137 | | -.brand-mark { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 750; box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 25%, transparent); } |
138 | | -.brand-name { font-size: 16px; font-weight: 650; line-height: 1.2; } |
139 | | -.brand-subtitle { margin-top: 2px; color: var(--fg-muted); font-size: 11px; } |
140 | | -.sidebar-close { display: none; } |
141 | | -.sidebar-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 10px; } |
142 | | -.nav-group { margin: 18px 0 0; } |
143 | | -.nav-group h2 { margin: 0 0 5px; padding: 0 9px; color: var(--fg-muted); font-size: 11px; font-weight: 650; letter-spacing: .04em; } |
144 | | -.nav-item { |
145 | | - display: flex; align-items: center; gap: 10px; min-height: 38px; margin: 2px 0; padding: 7px 9px; |
146 | | - border-radius: 6px; color: var(--fg); text-decoration: none; line-height: 1.3; |
147 | | -} |
148 | | -.nav-item svg { flex: 0 0 auto; color: var(--fg-muted); } |
149 | | -.nav-item:hover { background: color-mix(in srgb, var(--primary) 7%, transparent); color: var(--fg); } |
150 | | -.nav-item.router-link-exact-active { background: color-mix(in srgb, var(--primary) 13%, var(--card)); color: var(--primary); font-weight: 600; } |
151 | | -.nav-item.router-link-exact-active svg { color: var(--primary); } |
152 | | -.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); } |
153 | | -.content-shell { display: flex; flex: 1 1 auto; min-width: 0; flex-direction: column; } |
154 | | -.app-main { flex: 1 1 auto; min-width: 0; overflow: auto; padding: 34px clamp(24px, 5vw, 72px); } |
155 | | -.app-main:focus { outline: 0; } |
156 | | -.mobile-topbar, .menu-button, .sidebar-scrim { display: none; } |
157 | | -.skip-link { position: fixed; z-index: 10; top: -48px; left: 16px; padding: 8px 12px; border-radius: 6px; background: var(--primary); color: #fff; text-decoration: none; } |
158 | | -.skip-link:focus { top: 12px; } |
159 | | -
|
160 | | -button.btn { |
161 | | - background: var(--primary); color: #fff; border: none; |
162 | | - padding: 8px 16px; border-radius: var(--radius); cursor: pointer; |
163 | | - font-size: 14px; font-weight: 500; |
164 | | - /* 按钮不换行、不被 flex 压缩(如路径输入行右侧的操作按钮) */ |
165 | | - white-space: nowrap; flex-shrink: 0; |
166 | | -} |
167 | | -button.btn:hover:not(:disabled) { background: var(--primary-hover); } |
168 | | -button.btn:disabled { opacity: 0.5; cursor: not-allowed; } |
169 | | -button.btn-outline { background: transparent; color: var(--fg); border: 1px solid var(--border); } |
170 | | -button.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); } |
171 | | -
|
172 | | -@media (max-width: 760px) { |
173 | | - .sidebar { position: fixed; z-index: 4; top: 0; bottom: 0; left: 0; width: min(300px, calc(100vw - 48px)); transform: translateX(-100%); transition: transform 180ms ease; box-shadow: none; } |
174 | | - .sidebar.open { transform: translateX(0); box-shadow: 10px 0 28px rgb(0 0 0 / 16%); } |
175 | | - .sidebar-close { display: grid; width: 32px; height: 32px; margin-left: auto; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--fg-muted); } |
176 | | - .sidebar-scrim { display: block; position: fixed; z-index: 3; inset: 0; background: rgb(0 0 0 / 32%); } |
177 | | - .mobile-topbar { display: flex; align-items: center; gap: 10px; flex: 0 0 52px; padding: 0 14px; border-bottom: 1px solid var(--border); background: var(--card); font-size: 15px; font-weight: 650; } |
178 | | - .menu-button { display: grid; width: 36px; height: 36px; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--fg); } |
179 | | - .menu-button:hover, .sidebar-close:hover { background: var(--bg); } |
180 | | - .app-main { padding: 22px 16px; } |
181 | | -} |
182 | | -@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } } |
183 | | -</style> |
0 commit comments