From 4390ca3472b8a4a201835e358ad0ad2065e8b7c6 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Fri, 18 Sep 2026 09:50:57 +0800 Subject: feat(frontend): 375px 底部 Tab Bar、窄标题栏与项目面包屑 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [变更性质] 新增移动端导航形态,前端重设计第二轮之二。 [新增功能] ≤767px 呈现底部 Tab Bar(projects/datasets/runs/account 徽标+标签+aria-current)与窄标题栏(品牌/面包屑/账户),≥768px 原桌面布局不变;ProjectPage 顶部新增"我的项目/项目名/功能页"面包屑。 [实现方案] matchMedia('(max-width: 767px)') 反应式驱动的 (Safari <14 兼容addListener 回退),tests 以 matchMedia stub 驱动真实渲染断言;保留 900px 既有断点结构以兼容 mobileCss.test.ts 正则。 [影响范围] Layout.svelte、ProjectPage.svelte;新增 mobileTabbar.test.ts。 --- frontend/src/components/Layout.svelte | 144 ++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) (limited to 'frontend/src/components/Layout.svelte') diff --git a/frontend/src/components/Layout.svelte b/frontend/src/components/Layout.svelte index 3ccf913..ddd5090 100644 --- a/frontend/src/components/Layout.svelte +++ b/frontend/src/components/Layout.svelte @@ -54,9 +54,57 @@ const id = isProject ? route.params.id : null; if (id && !activeProject) void projectsStore.ensure(id).catch(() => undefined); }); + + // ---- 移动端导航重设计(375 → 底部 Tab Bar)---- + // 小型 matchMedia 反应式:jsdom 没有布局,真实渲染断言 + // (mobileTabbar.test.ts)通过 matchMedia stub 驱动 phone/桌面两种形态。 + import { onDestroy } from 'svelte'; + let phoneMode = $state(false); + let mqListener: ((e: MediaQueryListEvent) => void) | null = null; + $effect(() => { + if (typeof window === 'undefined' || !window.matchMedia) { + phoneMode = false; + return; + } + const mq = window.matchMedia('(max-width: 767px)'); + phoneMode = !!mq.matches; + const fn: (e: MediaQueryListEvent) => void = (e) => (phoneMode = e.matches); + if (mq.addEventListener) mq.addEventListener('change', fn); + else mq.addListener?.(fn as never); + mqListener = fn; + return () => { + if (mq.removeEventListener) mq.removeEventListener('change', mqListener as never); + else mq.removeListener?.(mqListener as never); + mqListener = null; + }; + }); + + const mobile = $derived(phoneMode); + + const tabs: { name: string; label: string; icon: 'project' | 'dataset' | 'run' | 'user' }[] = [ + { name: 'projects', label: '我的项目', icon: 'project' }, + { name: 'datasets', label: '数据集', icon: 'dataset' }, + { name: 'runs', label: '实验记录', icon: 'run' }, + { name: 'account', label: '我的', icon: 'user' } + ]; + const activeTab = $derived( + isProject || route.name === 'admin' ? 'projects' : route.name === 'account' ? 'account' : route.name + );
+ {#if mobile} +
+ 策研 Strategy Lab + {#if isProject} + {activeProject?.name ?? '项目'} · {projectNav.find(([t]) => t === projectTab)?.[1] ?? ''} + {/if} + +
+ {/if} +
+{#if mobile} + +{/if} + -- cgit v1.2.3