1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
<script lang="ts">
import type { Route } from '../lib/router';
import { go } from '../lib/router';
import { session } from '../lib/session.svelte';
import { postLogout } from '../lib/client';
import { projectsStore, projectOf, projectInvisible } from '../lib/listsStore.svelte';
import { Button } from '$lib/components/ui/button';
interface Props {
route: Route;
children?: import('svelte').Snippet;
}
let { route, children }: Props = $props();
const topLeft: { name: string; label: string }[] = [
{ name: 'projects', label: '我的项目' },
{ name: 'datasets', label: '数据集' },
{ name: 'runs', label: '实验记录' },
{ name: 'usage', label: 'AI 用量' }
];
const bottom: { name: string; label: string }[] =
session.me?.role === 'admin'
? [
{ name: 'account', label: '账户与安全' },
{ name: 'admin', label: '管理员' }
]
: [{ name: 'account', label: '账户与安全' }];
async function logout() {
await postLogout().catch(() => undefined);
session.set(null);
// drop cached projects/failure marks: the next session on this browser
// must not see (or be marked invisible by) the previous user's projects
projectsStore.clear();
go('/login');
}
const isProject = $derived(route.name.startsWith('project-'));
const projectTab = $derived(isProject ? route.name.replace('project-', '') : '');
const projectNav: [string, string][] = [
['data', '数据'],
['strategy', '策略'],
['backtest', '回测'],
['results', '结果']
];
const activeProject = $derived(isProject ? projectOf(route.params.id) : null);
const projectHidden =
$derived(isProject && !activeProject && projectInvisible(route.params.id));
// Deep link / first navigation into a project tab: the sidebar store may not
// contain the project yet (ProjectsPage was never visited). Fetch it once so
// the 当前项目 name resolves without waiting for the tab's own lifecycle.
$effect(() => {
const id = isProject ? route.params.id : null;
if (id && !activeProject) void projectsStore.ensure(id).catch(() => undefined);
});
</script>
<div class="layout">
<aside class="sidebar" aria-label="全局导航">
<a href="#/projects" class="brand">
<span class="brand-mark" aria-hidden="true"></span>
<span class="brand-text">策研 <span class="brand-sub">Strategy Lab</span></span>
</a>
{#if isProject}
<div class="projctx">
<div class="nav-title">当前项目</div>
<div class="projname">{activeProject?.name ?? (projectHidden ? '不可见项目' : '加载中…')}</div>
{#each projectNav as [t, label] (t)}
<a
class="navlink"
href={`#/projects/${route.params.id}/${t}`}
aria-current={projectTab === t ? 'page' : undefined}
>{label}</a>
{/each}
<div class="divider" aria-hidden="true"></div>
</div>
{/if}
<div class="nav-title">工作台</div>
{#each topLeft as item (item.name)}
<a class="navlink" href={`#/${item.name}`} aria-current={route.name === item.name ? 'page' : undefined}>
{item.label}
</a>
{/each}
<div class="push"></div>
<div class="nav-title">账户</div>
{#each bottom as item (item.name)}
<a class="navlink" href={`#/${item.name}`} aria-current={route.name === item.name ? 'page' : undefined}>
{item.label}
</a>
{/each}
{#if session.me}
<div class="me">
<span class="me-name">{session.me.name}{session.me.role === 'admin' ? ' · 管理员' : ''}</span>
<Button variant="ghost" size="sm" onclick={() => logout()}>退出</Button>
</div>
{/if}
</aside>
<main class="content" aria-label="主内容">
{@render children?.()}
</main>
</div>
<style>
.layout {
display: grid;
grid-template-columns: 208px minmax(0, 1fr);
min-height: 100vh;
}
.sidebar {
background: var(--sidebar);
border-right: 1px solid var(--border);
padding: 1rem 0.75rem;
display: flex;
flex-direction: column;
gap: 0.5rem;
position: sticky;
top: 0;
height: 100vh;
overflow-y: auto;
}
.brand {
display: flex;
align-items: center;
gap: 0.55rem;
padding: 0.3rem 0.4rem 0.6rem;
border-bottom: 1px solid var(--border);
margin-bottom: 0.4rem;
color: var(--foreground);
}
.brand:hover { text-decoration: none; }
.brand-mark {
width: 22px;
height: 22px;
border-radius: calc(var(--radius) * 1.2);
background: var(--primary);
flex-shrink: 0;
position: relative;
overflow: hidden;
}
.brand-mark::after {
content: '';
position: absolute;
inset: 4px;
background: linear-gradient(
to top,
transparent 4px,
#f0fdfa 4px,
#f0fdfa 7px,
transparent 7px,
transparent 11px,
#f0fdfa 11px,
#f0fdfa 15px,
transparent 15px
) left/ 3px 100% no-repeat;
opacity: 0.9;
}
.brand-text { font-weight: 700; font-size: 0.98rem; letter-spacing: 0.01em; }
.brand-sub { color: var(--text-3); font-weight: 500; font-size: 0.68rem; display: block; }
.nav-title {
font-size: 0.68rem;
text-transform: uppercase;
letter-spacing: 0.08em;
color: var(--text-3);
padding: 0.35rem 0.5rem 0.1rem;
font-weight: 700;
}
.navlink {
display: block;
padding: 0.32rem 0.55rem;
border-radius: var(--radius);
color: var(--text-2);
font-size: 0.9rem;
line-height: 1.5;
}
.navlink:hover { background: var(--secondary); text-decoration: none; color: var(--foreground); }
.navlink[aria-current='page'] {
background: var(--primary);
color: var(--primary-foreground);
font-weight: 600;
}
.projctx .navlink { font-size: 0.85rem; }
.projname {
font-weight: 600;
padding: 0 0.6rem 0.25rem;
font-size: 0.9rem;
overflow-wrap: anywhere;
color: var(--foreground);
}
.divider {
height: 1px;
background: var(--border);
margin: 0.6rem 0.3rem;
}
.push { flex: 1; min-height: 1rem; }
.me {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.4rem;
padding: 0.4rem;
background: var(--secondary);
border-radius: var(--radius);
font-size: 0.84rem;
}
.me-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--text-2);
min-width: 0;
}
.content {
padding: 1.5rem 2rem 3rem;
max-width: 1360px;
width: 100%;
/* grid/flex children default to min-content sizing; without min-width:0 a
wide table cell propagates min-content into the column and inflates the
whole document (375px probe measured 552px). */
min-width: 0;
}
@media (max-width: 900px) {
.layout { grid-template-columns: minmax(0, 1fr); }
.sidebar {
position: static;
height: auto;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
border-bottom: 1px solid var(--border);
border-right: none;
gap: 0.25rem;
min-width: 0;
}
.nav-title, .divider, .push { display: none; }
.navlink { padding: 0.45rem 0.7rem; }
/* the project tab row must wrap, not force one long line */
.projctx { display: flex; flex-wrap: wrap; gap: 0.25rem; min-width: 0; }
.projname { max-width: 100%; overflow-wrap: anywhere; }
.content { padding: 1.1rem 1rem 3rem; max-width: 100%; }
}
</style>
|