Files
ucvl-home-vision/web/ui/assets/tv-BtFxErTq.js
T

2 lines
9.1 KiB
JavaScript

import{w as ie,f as ue,g as ce,o as i,c as u,a as e,e as D,t as a,F as T,j as C,h as f,u as te,k as L,l as h,r as y,n as ae,B as ve}from"./bootstrap.min-z2h-5aUQ.js";function de(c){const o=Object.fromEntries(new Intl.DateTimeFormat("en-GB",{timeZone:"Asia/Shanghai",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}).formatToParts(c).map(_=>[_.type,_.value])),d=new Date(Date.UTC(+o.year,+o.month-1,+o.day)),v=d.getUTCDay(),m=new Date(d);m.setUTCDate(d.getUTCDate()+4-(v||7));const w=new Date(Date.UTC(m.getUTCFullYear(),0,1));return{...o,weekday:"星期"+"日一二三四五六"[v],week:Math.ceil(((m-w)/864e5+1)/7),weekYear:m.getUTCFullYear(),date:`${o.year}-${o.month}-${o.day}`}}const le=c=>c===0?"晴":c<=3?"多云":c<=48?"有雾":c<=67?"有雨":c<=77?"有雪":c<=82?"阵雨":c<=86?"阵雪":c>=95?"雷雨":"天气更新中",me={class:"tv-shell"},he={class:"tv-top"},ye={class:"tv-upper"},_e={class:"square-clock","aria-label":"北京时间时钟"},ge=["aria-label"],pe=["transform"],fe=["y1","y2"],we=["x","y"],ke=["transform"],be=["transform"],xe=["transform"],De={x:"220",y:"303",class:"digital-time"},Te={class:"tv-home"},Ce={class:"tv-greeting"},Me={class:"tv-date"},Ie={class:"tv-date-extra"},Le={key:0},Ee={class:"tv-weather tv-card","aria-label":"天气"},Se={class:"weather-current"},$e={class:"section-label"},ze={class:"weather-big"},Fe={class:"weather-symbol"},Ue={key:0},Be={class:"weather-note"},Ae={key:0,class:"weather-forecast"},Pe={class:"tv-bottom"},qe={class:"tv-card tv-devices"},Ne={class:"tv-section-heading"},Ye={class:"tv-device-grid"},je={class:"device-emblem"},Ve={key:0,class:"tv-empty"},Oe={key:0,class:"tv-page-count"},Ze={class:"tv-footer"},Ge={key:0,class:"sync-error"},Re={__name:"Television",setup(c){const o=y(null),d=y(Date.now()),v=y(""),m=y(0),w=y(0),_=y(0),E=y(!1);let S,$,z,g,k="",M=0,b;try{const s=new URLSearchParams(location.hash.slice(1)).get("display");s&&(localStorage.setItem("zhao.display",s),history.replaceState(null,"",location.pathname)),k=localStorage.getItem("zhao.display")||""}catch(s){}const n=h(()=>de(new Date(d.value+_.value))),F=h(()=>+n.value.hour>=20||+n.value.hour<7),U=s=>(F.value?["#978469","#739486","#8299aa","#ab8278"]:["#ee8a25","#148a7e","#2585cb","#d44e6b"])[s%4];ie(F,s=>document.documentElement.dataset.theme=s?"night":"day",{immediate:!0});const B=h(()=>{try{return new Intl.DateTimeFormat("zh-CN-u-ca-chinese",{timeZone:"Asia/Shanghai",month:"long",day:"numeric"}).format(new Date(d.value+_.value))}catch(s){return""}}),se=h(()=>+n.value.hour<6?"夜深了,愿你好梦":+n.value.hour<11?"早安,新的一天":+n.value.hour<14?"午安,慢慢生活":+n.value.hour<18?"午后,家有暖意":"晚安时光,灯火可亲"),I=h(()=>({hour:+n.value.hour%12*30+ +n.value.minute/2,minute:+n.value.minute*6,second:+n.value.second*6})),A=h(()=>{var t;const s=((t=o.value)==null?void 0:t.devices)||[];return s.slice(w.value%Math.max(1,Math.ceil(s.length/4))*4,w.value%Math.max(1,Math.ceil(s.length/4))*4+4)}),r=h(()=>{var s;return(s=o.value)==null?void 0:s.weather}),ne=h(()=>m.value?d.value-m.value>9e4?"网络暂时中断 · 显示上次资料":"家庭资料已同步":"正在连接家庭"),x=s=>typeof s=="number"?Math.round(s):"—";async function P(){if(!k){v.value="请从家庭设备页获取这台电视的展示授权";return}g=new AbortController;const s=setTimeout(()=>g.abort(),12e3);try{const t=await fetch("/api/display/snapshot",{headers:{Authorization:"Bearer "+k},signal:g.signal,cache:"no-store"}),p=await t.json();if(!t.ok)throw(t.status===401||t.status===403)&&(o.value=null,localStorage.removeItem("zhao.display"),k=""),Error(p.error||"暂时无法同步");o.value=p,_.value=new Date(p.serverTime).getTime()-Date.now(),m.value=Date.now(),v.value="",M=0}catch(t){v.value=t.name==="AbortError"?"家庭连接暂时超时":t.message,M++}finally{clearTimeout(s),k&&(S=setTimeout(P,Math.min(12e4,3e4*Math.max(1,M))))}}async function oe(){try{document.fullscreenElement?await document.exitFullscreen():await document.documentElement.requestFullscreen(),E.value=!!document.fullscreenElement,navigator.wakeLock&&(b=await navigator.wakeLock.request("screen"))}catch(s){}}const q=()=>{!document.hidden&&navigator.wakeLock&&navigator.wakeLock.request("screen").then(s=>b=s).catch(()=>{})};return ue(()=>{P(),$=setInterval(()=>d.value=Date.now(),1e3),z=setInterval(()=>w.value++,15e3),document.addEventListener("visibilitychange",q)}),ce(()=>{clearTimeout(S),clearInterval($),clearInterval(z),g==null||g.abort(),b==null||b.release(),document.removeEventListener("visibilitychange",q)}),(s,t)=>{var p,N,Y,j,V,O,Z,G,R,H,J,K,Q,W,X,ee;return i(),u("div",me,[e("header",he,[t[0]||(t[0]=e("span",{class:"tv-brand"},[e("img",{src:"/zhao-icon.png",alt:"赵"}),D("赵府 "),e("span",null,"家庭时光")],-1)),e("button",{class:"tv-fullscreen",onClick:oe,"aria-label":"切换全屏"},a(E.value?"退出全屏":"全屏展示")+" ⛶",1)]),e("div",ye,[e("section",_e,[(i(),u("svg",{viewBox:"0 0 440 440",role:"img","aria-label":`${n.value.hour}:${n.value.minute}:${n.value.second}`},[(i(),u(T,null,C(60,l=>e("g",{key:l,transform:`rotate(${l*6} 220 220)`},[e("line",{x1:"220",y1:l%5===0?29:32,x2:"220",y2:l%5===0?46:39,style:ae(l%5===0?{stroke:U(l/5)}:{}),class:L(l%5===0?"hour-mark":"minute-mark")},null,14,fe)],8,pe)),64)),(i(),u(T,null,C(12,l=>e("text",{key:"n"+l,x:220+148*Math.sin(l*Math.PI/6),y:220-148*Math.cos(l*Math.PI/6)+10,style:ae({fill:U(l)}),class:"clock-number"},a(l),13,we)),64)),t[1]||(t[1]=e("text",{x:"220",y:"140",class:"clock-word"},"家 · 在 此 刻",-1)),e("line",{x1:"220",y1:"231",x2:"220",y2:"127",class:"clock-hour",transform:`rotate(${I.value.hour} 220 220)`},null,8,ke),e("line",{x1:"220",y1:"234",x2:"220",y2:"91",class:"clock-minute",transform:`rotate(${I.value.minute} 220 220)`},null,8,be),e("line",{x1:"220",y1:"247",x2:"220",y2:"65",class:"clock-second",transform:`rotate(${I.value.second} 220 220)`},null,8,xe),t[2]||(t[2]=e("circle",{cx:"220",cy:"220",r:"8",fill:"#a66645"},null,-1)),t[3]||(t[3]=e("circle",{cx:"220",cy:"220",r:"3",fill:"#fffaf0"},null,-1)),e("text",De,a(n.value.hour)+":"+a(n.value.minute),1),t[4]||(t[4]=e("text",{x:"220",y:"329",class:"clock-zone"},"北京时间",-1))],8,ge))]),e("section",Te,[e("div",Ce,a(se.value),1),e("h1",null,a(((p=o.value)==null?void 0:p.home.name)||"欢迎回家"),1),e("div",Me,[D(a(n.value.year)+" 年 "+a(+n.value.month)+" 月 "+a(+n.value.day)+" 日 ",1),e("b",null,a(n.value.weekday),1)]),e("div",Ie,[B.value?(i(),u("span",Le,"农历 "+a(B.value),1)):f("",!0),e("span",null,a(n.value.weekYear)+" 年 · 第 "+a(n.value.week)+" 周",1)])])]),e("section",Ee,[e("div",Se,[e("div",$e,a(((N=r.value)==null?void 0:N.city)||((Y=o.value)==null?void 0:Y.home.city)||"本地")+" · 天气",1),e("div",ze,[e("span",Fe,a((j=r.value)!=null&&j.available&&r.value.current.weather_code<3?"☀":"☁"),1),e("strong",null,[D(a((V=r.value)!=null&&V.available?x(r.value.current.temperature_2m):"—"),1),t[5]||(t[5]=e("small",null,"°",-1))]),e("div",null,[e("b",null,a((O=r.value)!=null&&O.available?te(le)(r.value.current.weather_code):"天气更新中"),1),(Z=r.value)!=null&&Z.available?(i(),u("span",Ue,"体感 "+a(x(r.value.current.apparent_temperature))+"° · 湿度 "+a(x(r.value.current.relative_humidity_2m))+"%",1)):f("",!0)])]),e("div",Be,a((G=r.value)!=null&&G.stale?"上次天气 · 待更新":(R=r.value)!=null&&R.available?"室外天气 · "+(r.value.current.time||"").slice(11,16)+" 更新":((H=r.value)==null?void 0:H.message)||"正在连接天气服务"),1)]),(J=r.value)!=null&&J.available?(i(),u("div",Ae,[(i(!0),u(T,null,C(r.value.days,(l,re)=>(i(),u("div",{key:l.date},[e("span",null,a(["今天","明天","后天"][re]),1),e("b",null,a(te(le)(l.code)),1),e("span",null,a(x(l.low))+"° / "+a(x(l.high))+"°",1)]))),128))])):f("",!0)]),e("div",Pe,[e("section",qe,[e("div",Ne,[t[6]||(t[6]=e("h2",null,"家中设备",-1)),e("span",null,a((Q=(K=o.value)==null?void 0:K.home.deviceCount)!=null?Q:"—")+" 台 · "+a((X=(W=o.value)==null?void 0:W.home.spaces)!=null?X:"—")+" 处区域",1)]),e("div",Ye,[(i(!0),u(T,null,C(A.value,l=>(i(),u("article",{key:l.id,class:"tv-device"},[e("div",je,a(/电视|显示/.test(l.type)?"▣":/摄像/.test(l.type)?"◉":/路由|网关/.test(l.type)?"⌁":"◇"),1),e("div",null,[e("h3",null,a(l.name),1),e("p",null,a(l.location),1),e("span",{class:L(["tv-status",l.status])},[t[7]||(t[7]=e("i",null,null,-1)),D(a(l.statusLabel),1)],2)])]))),128)),A.value.length?f("",!0):(i(),u("div",Ve,"设备接入后,会在这里与你见面。"))]),(((ee=o.value)==null?void 0:ee.devices.length)||0)>4?(i(),u("div",Oe,"设备分组自动轮换 · 每 15 秒")):f("",!0)]),t[8]||(t[8]=e("section",{class:"tv-family-presence tv-card"},[e("div",null,[e("h2",null,"家人位置"),e("p",null,"等待家人主动开启位置共享")]),e("span",null,"共享关闭")],-1))]),e("footer",Ze,[e("span",{class:L({warning:!!v.value})},[t[9]||(t[9]=e("i",null,null,-1)),D(a(ne.value),1)],2),v.value?(i(),u("span",Ge,a(v.value),1)):f("",!0),t[10]||(t[10]=e("span",null,"愿每个平常日,都有家的温度",-1)),t[11]||(t[11]=e("a",{href:"https://open-meteo.com/",target:"_blank",rel:"noreferrer"},"天气 Open-Meteo",-1))])])}}};ve(Re).mount("#app");