2 lines
9.1 KiB
JavaScript
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.requestFull
|