'use strict'; let deviceContext=null,scopeEntered=false; Object.assign(pageInfo,{overview:['场所总览','人、区域与设备,在这里各有归属。'],device:['设备档案','查看这台设备的位置、责任人与功能。'],heritage:['家庭传承','把人物、记忆、文化与物品的来历留存下来。']}); function currentHome(){return (state.households||[]).find(h=>h.id===state.familyId);} function scopeReturn(page,device){ if(page==='overview')return {page:'households',label:'所有家庭与场所'}; if(device||page==='sites')return {page:'objects',label:'返回区域与设备'}; if(['family','heritage-records'].includes(page))return {page:'heritage',label:'返回家庭传承'}; return {page:'overview',label:'返回场所总览'}; } function selectedDevice(){return deviceContext?ZhaoDevices.catalog(state).find(d=>d.id===deviceContext.id&&d.source===deviceContext.source):null;} function deviceCameras(cameras,context=deviceContext){ if(!context)return cameras; if(context.source==='camera')return cameras.filter(c=>c.assetId===context.id); if(context.source==='recorder')return cameras.filter(c=>c.recorderId===context.id||c.archiveRecorderId===context.id); return []; } function enterDevice(source,id,tab='device'){ const device=ZhaoDevices.catalog(state).find(d=>d.source===source&&d.id===id); if(!device){toast('该设备不存在或未获授权');return;} stopPlayers();resetPlayback();if(typeof closePtz==='function')closePtz(); const returnSite=$('#site-filter').value;$('#site-filter').value='';deviceContext={source,id,returnSite};scopeEntered=true; showPage(tab==='device'&&source==='camera'&&deviceCameras(state.cameras).length?'live':tab); } function renderSteward(){ const home=currentHome(),device=selectedDevice(),within=loggedIn&&scopeEntered&&!!home; if(deviceContext&&!device&&loggedIn){deviceContext=null;stopPlayers();resetPlayback();showPage('objects');return;} $('#scope-navigation').hidden=!within; $('#scope-nav-name').textContent=home?.name||''; $('#household-context').hidden=!within||['settings','storage'].includes(activePage); $('#household-context-note').textContent=home?scopeKind(home)+' · '+home.name:''; $('#device-context').hidden=!device||!['device','live','playback','cameras'].includes(activePage); $('#wall-context').hidden=activePage!=='live'||!!device; $('#device-breadcrumb').textContent=device?[home?.name,siteName(device.siteId),device.name].filter(Boolean).join(' / '):''; $('#scope-back').textContent=scopeReturn(activePage,device).label; const hasVideo=device&&['camera','recorder'].includes(device.source); $$('[data-device-tab]').forEach(b=>{b.hidden=b.dataset.deviceTab!=='device'&&(!hasVideo||b.dataset.deviceTab==='cameras'&&!isAdmin());b.classList.toggle('active',b.dataset.deviceTab===activePage);}); if(device&&['device','live','playback','cameras'].includes(activePage)){ $('#page-title').textContent=device.name; $('#page-note').textContent=pageInfo[activePage][0]+' · '+(home?.name||''); } if(activePage==='live')$('#live-heading').textContent=device?'实时画面 · 镜头':'本场所监控墙'; if(activePage==='overview')renderOverview(); if(activePage==='device')renderDeviceDetail(device); if(activePage==='heritage')renderHeritageHome(); const homeKind=!home?.kind||home.kind==='home'; $('nav [data-page="heritage"]').hidden=!homeKind||(!isAdmin()&¤tUser?.familyAccess==='none'&¤tUser?.heritageAccess!=='read'&¤tUser?.heritageAccess!=='edit'); } function renderOverview(){ const home=currentHome();if(!home){$('#scope-overview').replaceChildren();return;} const devices=ZhaoDevices.catalog(state),homeKind=!home.kind||home.kind==='home'; $('#scope-overview').innerHTML=`
${esc(home.note||'从每一处空间,照看每一件事物。')}
${esc(device.note||'')}
${videoDeviceActions(device)}${device.source==='device'?'当前已登记档案;自动控制需按实际设备协议接入。
':''}${device.source==='recorder'?'可查看已关联镜头。录像机硬盘的历史检索与回放仍待设备适配。
':''}这里整理家谱、家族重大记事、文化和物品来历。个人近况与日常分享,请进入“记事与阅历”。
文化与财产档案须由家庭管理员另行授权。
'}