polish single vehicle entry workspace

This commit is contained in:
lingniu
2026-07-18 11:09:27 +08:00
parent 5805635ccf
commit 622c4398ec
7 changed files with 45 additions and 28 deletions

View File

@@ -77,11 +77,14 @@ test('marks the content as a full-height track workspace after sidebar navigatio
<Routes><Route element={<AppShell />}><Route path="*" element={<span></span>} /></Route></Routes>
</MemoryRouter>);
expect(document.querySelector('.v2-content')).not.toHaveClass('is-track-workspace');
const content = document.querySelector<HTMLElement>('.v2-content')!;
expect(content).not.toHaveClass('is-track-workspace');
content.scrollTop = 240;
scrollTo.mockClear();
fireEvent.click(screen.getByRole('link', { name: '轨迹回放' }));
await waitFor(() => expect(document.querySelector('.v2-content')).toHaveClass('is-track-workspace'));
expect(document.querySelector<HTMLElement>('.v2-content')?.scrollTop).toBe(0);
expect(scrollTo).toHaveBeenCalledWith({ top: 0, left: 0, behavior: 'auto' });
expect(screen.getByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
});

View File

@@ -124,12 +124,17 @@ export function AppShell() {
const roleLabel = { viewer: '只读', operator: '处置员', admin: '管理员', customer: '客户' }[session.role];
useEffect(() => scheduleIdleRoutePreloads({ activePathname: activeRoutePath }), [activeRoutePath]);
useLayoutEffect(() => {
const content = document.querySelector<HTMLElement>('.v2-content');
if (!content) return;
const reset = () => {
content.scrollTop = 0;
content.scrollLeft = 0;
content.scrollTo?.({ top: 0, left: 0, behavior: 'auto' });
for (const content of document.querySelectorAll<HTMLElement>('.v2-content')) {
content.scrollTop = 0;
content.scrollLeft = 0;
content.scrollTo?.({ top: 0, left: 0, behavior: 'auto' });
const routeRoot = content.firstElementChild;
if (routeRoot instanceof HTMLElement) {
routeRoot.scrollTop = 0;
routeRoot.scrollLeft = 0;
}
}
};
reset();
let trailingFrame = 0;