@@ -0,0 +1,45 @@
< script setup >
import { ref , watch , onUnmounted , computed } from 'vue'
import { snapshot , bridge } from '../composables/bridge.js'
const props = defineProps ( { device : Object } )
const open = ref ( false ) , result = ref ( null ) , grants = ref ( [ ] ) , error = ref ( '' ) , busy = ref ( false ) , link = ref ( '' ) , preview = ref ( '' ) , previewUntil = ref ( 0 )
let timer , epoch = 0 , blob = ''
const home = computed ( ( ) => snapshot . value . state . households ? . find ( h => h . id === snapshot . value . state . familyId ) )
const city = ref ( '' ) , latitude = ref ( '' ) , longitude = ref ( '' )
const pairingCode = ref ( '' )
const endpoint = path => path + '?deviceId=' + encodeURIComponent ( props . device . id )
const hardware = computed ( ( ) => result . value ? . hardware || { } )
const number = ( value , digits = 1 ) => typeof value === 'number' ? value . toFixed ( digits ) : '未提供'
const formatTime = value => value ? new Date ( value * 1000 ) . toLocaleString ( 'zh-CN' ) : '尚未上报'
async function reload ( ) { const e = epoch ; if ( ! open . value ) return
try { const value = await bridge ( ) . api ( endpoint ( '/api/displays/hardware' ) ) ; if ( e !== epoch ) return ; result . value = value
if ( Date . now ( ) < previewUntil .value & & value.previewAt ) { const response = await fetch ( endpoint ( ' / api / displays / preview ' ) , { headers : { ' X -Household -Id ' : snapshot.value.state.familyId } , cache : ' no -store ' } ) ; if ( response.ok ) { const image = await response.blob ( ) ; if ( e ! = = epoch ) return ; if ( blob ) URL.revokeObjectURL ( blob ) ; blob = URL.createObjectURL ( image ) ; preview.value = blob }}
} catch ( e2 ) { if ( e = = = epoch ) error.value = e2.message } finally { if ( e = = = epoch & & open.value ) timer = setTimeout ( reload , 5000 ) }
}
async function change ( action , id ) { busy.value = true ; error.value = ' ' ; const e = epoch
try { const value = await bridge ( ) .api ( ' / api / displays ' , { action , deviceId : props.device.id , id , city : city.value , latitude : latitude.value , longitude : longitude.value } ) ; if ( e ! = = epoch ) return
if ( value.path ) link.value = location.origin + value.path
if ( value.pairingCode ) pairingCode.value = value.pairingCode
if ( action = = = ' preview ' ) previewUntil.value = Date.now ( ) + 60000
if ( action = = = ' revoke ' ) { link.value = ' ' ; pairingCode.value = ' ' ; preview.value = ' ' ; previewUntil.value = 0 }
grants.value = ( await bridge ( ) .api ( endpoint ( ' / api / displays ' ) ) ) .items ; clearTimeout ( timer ) ; reload ( )
} catch ( e2 ) { if ( e = = = epoch ) error.value = e2.message } finally { if ( e = = = epoch ) busy.value = false }
}
watch ( open , async value = > { epoch ++ ; clearTimeout ( timer ) ; link . value = '' ; error . value = '' ; preview . value = '' ; previewUntil . value = 0 ; if ( blob ) { URL . revokeObjectURL ( blob ) ; blob = '' } if ( value ) { city . value = home . value ? . city || '' ; latitude . value = city . value === '济南市' ? '36.67' : '' ; longitude . value = city . value === '济南市' ? '116.99' : '' ; reload ( ) ; try { grants . value = ( await bridge ( ) . api ( endpoint ( '/api/displays' ) ) ) . items } catch ( e ) { error . value = e . message } } } )
watch ( ( ) => [ snapshot . value . state . familyId , snapshot . value . session , snapshot . value . page , props . device . id ] . join ( '|' ) , ( ) => open . value = false )
onUnmounted ( ( ) => { epoch ++ ; clearTimeout ( timer ) ; if ( blob ) URL . revokeObjectURL ( blob ) } )
< / script >
< template > < div v-if = "snapshot.admin" class="display-manager mt-3"><button class="btn btn-outline-primary btn-sm" @click="open=!open" > {{ open ? ' 收起电视管理 ' : ' 电视管理 · 状态与模拟屏 ' }} < / button >
< section v-if = "open" class="border rounded-3 p-3 mt-3" >
< div class = "d-flex justify-content-between align-items-center gap-2 mb-3" > < strong > { { device . name } } < / strong > < span class = "badge" :class = "result?.online?'text-bg-success':'text-bg-secondary'" > { { result ? . online ? '在线 · 心跳正常' : result ? . paired ? '未收到心跳' : '尚未绑定' } } < / span > < / div >
< p class = "small text-secondary" > 所属 : { { home ? . name } } · 最后心跳 { { formatTime ( result ? . lastSeen ) } } < / p >
< div class = "row g-2 hardware-grid" > < div class = "col-6" > < span > 处理器温度 < / span > < strong > { { number ( hardware . temperatureC ) } } { { hardware . temperatureC != null ? ' °C' : '' } } < / strong > < small > { { hardware . temperatureSource || '等待传感器上报' } } < / small > < / div > < div class = "col-6" > < span > 整机功率 < / span > < strong > { { number ( hardware . powerW ) } } { { hardware . powerW != null ? ' W' : '' } } < / strong > < small > { { hardware . powerSource || '需设备传感器或计量插座' } } < / small > < / div > < div class = "col-6" > < span > 可用内存 < / span > < strong > { { number ( hardware . memoryAvailableMB , 0 ) } } / { { number ( hardware . memoryTotalMB , 0 ) } } MB < / strong > < / div > < div class = "col-6" > < span > 可用存储 < / span > < strong > { { number ( hardware . storageAvailableGB ) } } / { { number ( hardware . storageTotalGB ) } } GB < / strong > < / div > < / div >
< p class = "small text-secondary mt-3" > { { hardware . model || device . model } } · Android { { hardware . osVersion || '—' } } · IP { { hardware . ip || device . managementHost || '—' } } < br > { { hardware . screenWidth || '—' } } × { { hardware . screenHeight || '—' } } · { { hardware . foreground ? '看板在前台' : '看板未在前台' } } · { { hardware . screenOn ? '屏幕亮' : '屏幕状态待确认' } } < span v-if = "!result?.online" > · 当前数值为最后一次上报 < / span > < / p >
< h4 class = "fs-6" > 异常与报警 < / h4 > < p v-if = "!result?.alerts?.some(a=>!a.cleared)" class="small text-secondary">{{result?.online?'当前无活动报警':'连接恢复后继续检查硬件状态'}}</p><div v-for="a in result?.alerts?.filter(a=>!a.cleared)" :key="a.code" class="alert py-2 small" :class="a.severity==='critical'?'alert-danger':'alert-warning'" > {{ a.message }} · {{ formatTime ( a.opened ) }} < / div >
< details class = "small mb-3" > < summary > 报警记录与规则 < / summary > < p > 心跳中断超过 100 秒 ; 处理器 ≥ 75 ° C 提醒 、 ≥ 85 ° C 严重 ; 可用内存低于 5 % ; 可用存储低于 0.5 GB ; 看板退出前台 。 数值来自电视上报 。 < / p > < div v-for = "(a,i) in result?.alerts" :key="i" > {{ a.cleared ? ' 已恢复 ' : ' 处理中 ' }} · {{ a.message }} · {{ formatTime ( a.opened ) }} < / div > < / details >
< button class = "btn btn-primary btn-sm" :disabled = "busy||!result?.online" @click ="change('preview')" > 查看模拟屏 · 60 秒 < / button > < p class = "small text-secondary mt-2" > 显示电视当前家庭看板的应用画面 , 约 20 秒更新一次 ; 退出看板后不显示其他应用 。 预览仅短时保存在内存 。 < / p > < figure v-if = "preview" class="tv-remote-preview"><img :src="preview" alt="电视家庭看板的真实应用画面"><figcaption class="small text-secondary" > 画面时间 : {{ formatTime ( result ? .previewAt ) }} < / figcaption > < / figure >
< details class = "mt-3" > < summary > 展示授权与天气设置 < / summary > < div class = "row g-2 my-2" > < label class = "col-12" > 天气城市 < input v-model = "city" class="form-control" maxlength="60"></label><label class="col-6">纬度<input v-model="latitude" class="form-control" type="number" step="0.0001" min="-90" max="90"></label><label class="col-6">经度<input v-model="longitude" class="form-control" type="number" step="0.0001" min="-180" max="180"></label></div><p class="small text-secondary">链接有效期一年,仅可展示本家庭概况、设备状态与已发布日程。重新生成会停用旧链接。</p><button class="btn btn-outline-primary btn-sm" :disabled="busy" @click="change('create')">生成新的电视展示链接</button><div v-if="link" class="my-3"><label>本次展示链接(请仅交给这台电视)<input class="form-control" :value="link" readonly @focus="$event.target.select()"></label><a class="btn btn-sm btn-outline-secondary mt-2" :href="link" target="_blank" rel="noreferrer">打开看板</a></div><div v-for="g in grants.filter(g=>!g.revoked)" :key="g.id" class="d-flex gap-2 align-items-center small mt-2"><span>授权至 {{formatTime(g.expires_at)}}</span><button class="btn btn-sm btn-outline-danger" :disabled="busy" @click="change('revoke',g.id)" > 停用展示权限 < / button > < / div > < / details >
< div v-if = "pairingCode&&link" class="alert alert-success mt-3">App 配对码:<strong class="fs-3 font-monospace">{{pairingCode}}</strong><div class="small" > 在 “ 赵府家庭屏 ” App 输入 , 10 分钟内有效 , 使用一次即失效 。 App 摄像头画面在本地网络直接播放 。 < / div > < / div >
< p v-if = "error" class="text-danger mt-2" role="alert" > {{ error }} < / p >
< / section > < / div > < / template >
< style scoped > . hardware - grid > div { display : flex ; flex - direction : column ; gap : 4 px ; background : # f5f7f7 ; padding : 12 px ; border : 3 px solid white ; border - radius : 12 px } . hardware - grid span , . hardware - grid small { font - size : 12 px ; color : # 637471 } . hardware - grid strong { font - size : 18 px } . tv - remote - preview { margin : 16 px 0 ; text - align : center } . tv - remote - preview img { max - height : 640 px ; max - width : 100 % ; border : 6 px solid # 303 b38 ; border - radius : 12 px } . display - manager summary { cursor : pointer } details p { margin - top : 12 px } < / style >