2 lines
9.4 KiB
JavaScript
2 lines
9.4 KiB
JavaScript
import{f as re,g as ie,o as r,c as i,a as e,e as D,t as a,F as T,j as C,h,u as te,k as L,r as y,l as p,B as ue}from"./bootstrap.min-z2h-5aUQ.js";function ce(c){const n=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(g=>[g.type,g.value])),d=new Date(Date.UTC(+n.year,+n.month-1,+n.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{...n,weekday:"星期"+"日一二三四五六"[v],week:Math.ceil(((m-w)/864e5+1)/7),weekYear:m.getUTCFullYear(),date:`${n.year}-${n.month}-${n.day}`}}const ae=c=>c===0?"晴":c<=3?"多云":c<=48?"有雾":c<=67?"有雨":c<=77?"有雪":c<=82?"阵雨":c<=86?"阵雪":c>=95?"雷雨":"天气更新中",ve={class:"tv-shell"},de={class:"tv-top"},me={class:"tv-upper"},he={class:"square-clock","aria-label":"北京时间时钟"},ye=["aria-label"],pe=["transform"],ge=["y1","y2"],_e=["x","y"],fe=["transform"],we=["transform"],ke=["transform"],be={x:"220",y:"303",class:"digital-time"},xe={class:"tv-home"},De={class:"tv-greeting"},Te={class:"tv-date"},Ce={class:"tv-date-extra"},Me={key:0},Ie={class:"tv-weather tv-card","aria-label":"天气"},Le={class:"weather-current"},$e={class:"section-label"},Ee={class:"weather-big"},Fe={class:"weather-symbol"},Se={key:0},Ue={class:"weather-note"},ze={key:0,class:"weather-forecast"},Be={class:"tv-bottom"},Ae={class:"tv-card tv-devices"},Pe={class:"tv-section-heading"},qe={class:"tv-device-grid"},Ne={class:"device-emblem"},Ye={key:0,class:"tv-empty"},je={key:0,class:"tv-page-count"},Ve={class:"tv-card tv-agenda"},Oe={key:0,class:"agenda-empty"},Ze={class:"tv-footer"},Ge={key:0,class:"sync-error"},Re={__name:"Television",setup(c){const n=y(null),d=y(Date.now()),v=y(""),m=y(0),w=y(0),g=y(0),$=y(!1);let E,F,S,_,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 o=p(()=>ce(new Date(d.value+g.value))),U=p(()=>{try{return new Intl.DateTimeFormat("zh-CN-u-ca-chinese",{timeZone:"Asia/Shanghai",month:"long",day:"numeric"}).format(new Date(d.value+g.value))}catch(s){return""}}),le=p(()=>+o.value.hour<6?"夜深了,愿你好梦":+o.value.hour<11?"早安,新的一天":+o.value.hour<14?"午安,慢慢生活":+o.value.hour<18?"午后,家有暖意":"晚安时光,灯火可亲"),I=p(()=>({hour:+o.value.hour%12*30+ +o.value.minute/2,minute:+o.value.minute*6,second:+o.value.second*6})),z=p(()=>{var t;const s=((t=n.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)}),u=p(()=>{var s;return(s=n.value)==null?void 0:s.weather}),se=p(()=>m.value?d.value-m.value>9e4?"网络暂时中断 · 显示上次资料":"家庭资料已同步":"正在连接家庭"),x=s=>typeof s=="number"?Math.round(s):"—";async function B(){if(!k){v.value="请从家庭设备页获取这台电视的展示授权";return}_=new AbortController;const s=setTimeout(()=>_.abort(),12e3);try{const t=await fetch("/api/display/snapshot",{headers:{Authorization:"Bearer "+k},signal:_.signal,cache:"no-store"}),f=await t.json();if(!t.ok)throw(t.status===401||t.status===403)&&(n.value=null,localStorage.removeItem("zhao.display"),k=""),Error(f.error||"暂时无法同步");n.value=f,g.value=new Date(f.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&&(E=setTimeout(B,Math.min(12e4,3e4*Math.max(1,M))))}}async function ne(){try{document.fullscreenElement?await document.exitFullscreen():await document.documentElement.requestFullscreen(),$.value=!!document.fullscreenElement,navigator.wakeLock&&(b=await navigator.wakeLock.request("screen"))}catch(s){}}const A=()=>{!document.hidden&&navigator.wakeLock&&navigator.wakeLock.request("screen").then(s=>b=s).catch(()=>{})};return re(()=>{B(),F=setInterval(()=>d.value=Date.now(),1e3),S=setInterval(()=>w.value++,15e3),document.addEventListener("visibilitychange",A)}),ie(()=>{clearTimeout(E),clearInterval(F),clearInterval(S),_==null||_.abort(),b==null||b.release(),document.removeEventListener("visibilitychange",A)}),(s,t)=>{var f,P,q,N,Y,j,V,O,Z,G,R,H,J,K,Q,W,X,ee;return r(),i("div",ve,[e("header",de,[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:ne,"aria-label":"切换全屏"},a($.value?"退出全屏":"全屏展示")+" ⛶",1)]),e("div",me,[e("section",he,[(r(),i("svg",{viewBox:"0 0 440 440",role:"img","aria-label":`${o.value.hour}:${o.value.minute}:${o.value.second}`},[(r(),i(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,class:L(l%5===0?"hour-mark":"minute-mark")},null,10,ge)],8,pe)),64)),(r(),i(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,class:"clock-number"},a(l),9,_e)),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,fe),e("line",{x1:"220",y1:"234",x2:"220",y2:"91",class:"clock-minute",transform:`rotate(${I.value.minute} 220 220)`},null,8,we),e("line",{x1:"220",y1:"247",x2:"220",y2:"65",class:"clock-second",transform:`rotate(${I.value.second} 220 220)`},null,8,ke),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",be,a(o.value.hour)+":"+a(o.value.minute),1),t[4]||(t[4]=e("text",{x:"220",y:"329",class:"clock-zone"},"北京时间",-1))],8,ye))]),e("section",xe,[e("div",De,a(le.value),1),e("h1",null,a(((f=n.value)==null?void 0:f.home.name)||"欢迎回家"),1),e("div",Te,[D(a(o.value.year)+" 年 "+a(+o.value.month)+" 月 "+a(+o.value.day)+" 日 ",1),e("b",null,a(o.value.weekday),1)]),e("div",Ce,[U.value?(r(),i("span",Me,"农历 "+a(U.value),1)):h("",!0),e("span",null,a(o.value.weekYear)+" 年 · 第 "+a(o.value.week)+" 周",1)])])]),e("section",Ie,[e("div",Le,[e("div",$e,a(((P=u.value)==null?void 0:P.city)||((q=n.value)==null?void 0:q.home.city)||"本地")+" · 天气",1),e("div",Ee,[e("span",Fe,a((N=u.value)!=null&&N.available&&u.value.current.weather_code<3?"☀":"☁"),1),e("strong",null,[D(a((Y=u.value)!=null&&Y.available?x(u.value.current.temperature_2m):"—"),1),t[5]||(t[5]=e("small",null,"°",-1))]),e("div",null,[e("b",null,a((j=u.value)!=null&&j.available?te(ae)(u.value.current.weather_code):"天气更新中"),1),(V=u.value)!=null&&V.available?(r(),i("span",Se,"体感 "+a(x(u.value.current.apparent_temperature))+"° · 湿度 "+a(x(u.value.current.relative_humidity_2m))+"%",1)):h("",!0)])]),e("div",Ue,a((O=u.value)!=null&&O.stale?"上次天气 · 待更新":(Z=u.value)!=null&&Z.available?"室外天气 · "+(u.value.current.time||"").slice(11,16)+" 更新":((G=u.value)==null?void 0:G.message)||"正在连接天气服务"),1)]),(R=u.value)!=null&&R.available?(r(),i("div",ze,[(r(!0),i(T,null,C(u.value.days,(l,oe)=>(r(),i("div",{key:l.date},[e("span",null,a(["今天","明天","后天"][oe]),1),e("b",null,a(te(ae)(l.code)),1),e("span",null,a(x(l.low))+"° / "+a(x(l.high))+"°",1)]))),128))])):h("",!0)]),e("div",Be,[e("section",Ae,[e("div",Pe,[t[6]||(t[6]=e("h2",null,"家中设备",-1)),e("span",null,a((J=(H=n.value)==null?void 0:H.home.deviceCount)!=null?J:"—")+" 台 · "+a((Q=(K=n.value)==null?void 0:K.home.spaces)!=null?Q:"—")+" 处区域",1)]),e("div",qe,[(r(!0),i(T,null,C(z.value,l=>(r(),i("article",{key:l.id,class:"tv-device"},[e("div",Ne,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)),z.value.length?h("",!0):(r(),i("div",Ye,"设备接入后,会在这里与你见面。"))]),(((W=n.value)==null?void 0:W.devices.length)||0)>4?(r(),i("div",je,"设备分组自动轮换 · 每 15 秒")):h("",!0)]),e("section",Ve,[t[9]||(t[9]=e("div",{class:"tv-section-heading"},[e("h2",null,"近期日程"),e("span",null,"未来 60 天")],-1)),(X=n.value)!=null&&X.events.length?h("",!0):(r(),i("div",Oe,[...t[8]||(t[8]=[e("span",{class:"agenda-line"},"日子从容,家有余闲。",-1),e("p",null,"暂没有已发布的家庭安排",-1)])])),(r(!0),i(T,null,C((ee=n.value)==null?void 0:ee.events.slice(0,3),l=>(r(),i("article",{key:l.id,class:"tv-event"},[e("time",null,a(l.date.slice(5).replace("-"," / ")),1),e("h3",null,a(l.title),1)]))),128)),t[10]||(t[10]=e("div",{class:"agenda-source"},"来自本家庭已发布的重大记事",-1))])]),t[14]||(t[14]=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[11]||(t[11]=e("i",null,null,-1)),D(a(se.value),1)],2),v.value?(r(),i("span",Ge,a(v.value),1)):h("",!0),t[12]||(t[12]=e("span",null,"愿每个平常日,都有家的温度",-1)),t[13]||(t[13]=e("a",{href:"https://open-meteo.com/",target:"_blank",rel:"noreferrer"},"天气 Open-Meteo",-1))])])}}};ue(Re).mount("#app");
|