| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- // Page routing only. Changing the visible page never changes a device session.
- (() => {
- const pages = new Set(['overview', 'thermal', 'connections', 'plan', 'uip', 'amt', 'testing', 'records', 'queue']);
- function show(value, updateHash = true) {
- const normalized = value === 'plans' ? 'plan' : value;
- const page = pages.has(normalized) ? normalized : 'overview';
- document.body.dataset.currentPage = page;
- if (page !== 'overview') {
- const split = document.querySelector('.workspace-split.console-expanded');
- if (split) {
- split.classList.remove('console-expanded');
- const expandBtn = document.getElementById('btn-console-expand');
- if (expandBtn) expandBtn.textContent = '放大终端';
- }
- }
- window.stlStore?.set?.('page', page, 'nav');
- document.querySelectorAll('[data-pages]').forEach(node => {
- node.hidden = !node.dataset.pages.split(' ').includes(page);
- });
- document.querySelectorAll('.workspace-tab').forEach(button => {
- const selected = button.dataset.page === page;
- button.classList.toggle('selected', selected);
- button.setAttribute('aria-selected', String(selected));
- button.tabIndex = selected ? 0 : -1;
- });
- if (updateHash && location.hash !== '#' + page) history.replaceState(null, '', '#' + page);
- window.dispatchEvent(new CustomEvent('stl:page-change', {detail:{page}}));
- }
- document.querySelectorAll('.workspace-tab').forEach(button => {
- button.addEventListener('click', () => show(button.dataset.page));
- button.addEventListener('keydown', event => {
- if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
- event.preventDefault();
- const buttons = [...document.querySelectorAll('.workspace-tab')];
- const i = buttons.indexOf(button);
- const next = event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : (i + (event.key === 'ArrowRight' ? 1 : -1) + buttons.length) % buttons.length;
- show(buttons[next].dataset.page); buttons[next].focus();
- });
- });
- document.querySelectorAll('[data-nav-page]').forEach(button => button.addEventListener('click', () => show(button.dataset.navPage)));
- document.getElementById('nav-station').addEventListener('change', event => {
- window.dispatchEvent(new CustomEvent('stl:station-select', {detail:{stationId:event.target.value}}));
- });
- window.addEventListener('hashchange', () => show(location.hash.slice(1), false));
- window.stlNavigation = {
- show,
- current: () => document.body.dataset.currentPage,
- updateStations(stations, selected) {
- const select = document.getElementById('nav-station');
- const signature = JSON.stringify(stations.map(s => [s.station_id, s.name]));
- if (select.dataset.signature !== signature) {
- select.replaceChildren(...stations.map(s => {
- const option = document.createElement('option');
- option.value = s.station_id; option.textContent = `${s.station_id} · ${s.name || s.station_id}`;
- return option;
- }));
- select.dataset.signature = signature;
- document.querySelectorAll('select[data-dynamic-stations="all"]').forEach(sel => {
- const prev = sel.value;
- const allOpt = document.createElement('option');
- allOpt.value = '';
- allOpt.textContent = '全部工位';
- sel.replaceChildren(allOpt, ...stations.map(s => {
- const o = document.createElement('option');
- o.value = s.station_id;
- o.textContent = s.station_id;
- return o;
- }));
- sel.value = stations.some(s => s.station_id === prev) ? prev : '';
- });
- }
- select.value = selected;
- },
- };
- show(location.hash.slice(1), false);
- })();
|