Release 0.1.49: self-hosted maps and consented cloud location history
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<script setup>
|
||||
import {ref,computed,watch,onBeforeUnmount} from 'vue'
|
||||
import {snapshot,bridge} from '../composables/bridge.js'
|
||||
import LocalChart from './LocalChart.vue'
|
||||
import FamilyMap from './FamilyMap.vue'
|
||||
import LocationHistory from './LocationHistory.vue'
|
||||
const result=ref(null),error=ref(''),consent=ref(false),days=ref(7),code=ref(''),expires=ref(0),busy=ref(false),selected=ref('')
|
||||
const memberId=ref(''),viewerIds=ref([]),displayIds=ref([]),phoneIds=ref([]),viewOnly=ref(true)
|
||||
const binding=computed(()=>result.value?.bindings?.find(x=>x.memberId===memberId.value))
|
||||
@@ -12,10 +13,6 @@ const items=computed(()=>result.value?.items||[])
|
||||
const time=n=>n?new Date(n*1000).toLocaleString('zh-CN'):'尚未收到'
|
||||
const status=d=>d.status==='stale'?'位置更新中断':d.status==='live'?'位置已更新':'等待手机定位'
|
||||
const location=d=>d.position?`${d.position.latitude.toFixed(4)}°, ${d.position.longitude.toFixed(4)}° · 精度约 ${Math.round(d.position.accuracy)} 米`:'尚无有效位置'
|
||||
const option=computed(()=>{
|
||||
const focus=items.value.find(x=>x.id===selected.value)?.position
|
||||
return {geo:{map:'world-land',roam:true,center:focus?[focus.longitude,focus.latitude]:[0,10],zoom:focus?5:1,boundingCoords:[[-180,90],[180,-90]],itemStyle:{areaColor:'#d9e4df',borderColor:'#94b2a6'},emphasis:{disabled:true},silent:false},tooltip:{show:false},series:[{type:'scatter',coordinateSystem:'geo',symbolSize:14,label:{show:true,position:'top',formatter:'{b}'},data:items.value.filter(d=>d.position).map(d=>({name:d.name,targetId:d.id,value:[d.position.longitude,d.position.latitude],itemStyle:{color:d.status==='stale'?'#c18d3e':'#257a68'}}))}]}
|
||||
})
|
||||
async function load(){const e=epoch,r=++requestId;if(!active.value)return
|
||||
try{const value=await bridge().api('/api/locations');if(e===epoch&&r===requestId){result.value=value;error.value=''}}
|
||||
catch(err){if(e===epoch&&r===requestId){result.value=null;error.value=err.message}}
|
||||
@@ -30,10 +27,11 @@ watch([memberId,viewerIds,displayIds,phoneIds,viewOnly,days],()=>{code.value=''}
|
||||
onBeforeUnmount(()=>{epoch++;clearTimeout(timer)})
|
||||
</script>
|
||||
<template><section v-if="active" class="panel family-locations mb-4" aria-label="家庭位置共享">
|
||||
<div class="d-flex flex-wrap justify-content-between gap-2"><div><h2>家人位置</h2><p class="text-secondary small">{{home?.name}} · {{items.length}} 位家人正在共享 · 只显示本人同意分享的最新位置</p></div><button class="btn btn-sm btn-outline-secondary align-self-start" @click="selected=''">查看全球</button></div>
|
||||
<div class="d-flex flex-wrap justify-content-between gap-2"><div><h2>家人位置</h2><p class="text-secondary small">{{home?.name}} · {{items.length}} 位家人正在共享 · 只显示本人同意分享的最新位置</p></div><button class="btn btn-sm btn-outline-secondary align-self-start" @click="selected=''">查看全部位置</button></div>
|
||||
<div v-if="items.some(d=>d.status==='stale')" class="alert alert-warning" role="status">{{items.filter(d=>d.status==='stale').map(d=>d.name).join('、')}}的位置超过 15 分钟未更新。请检查手机网络、定位权限或省电设置;这不代表人员失联。</div>
|
||||
<div class="row g-3"><div class="col-12 col-lg-8"><LocalChart :option="option" :height="360" label="家庭位置世界平面图,详细位置见右侧列表" @select="selected=$event"/><p class="small text-secondary mb-0">可拖动缩放,点击家人定位。底图:Natural Earth 陆地轮廓(本地资源);定位采用 WGS84 经纬度。</p></div>
|
||||
<div class="row g-3"><div class="col-12 col-lg-8"><FamilyMap :items="items" :selected="selected" :height="420" @select="selected=$event"/><p class="small text-secondary mb-0">点击家人卡片定位,圆圈表示定位精度范围。底图由智家提供,位置仅对获授权的人显示。</p></div>
|
||||
<div class="col-12 col-lg-4"><div v-if="!items.length" class="location-empty"><span>⌖</span><h3 class="fs-5">等待家人主动分享</h3><p>家人无需注册账号。手机配对、本人同意并开启共享后,获准的查看人才能看到位置。</p></div><button v-for="d in items" :key="d.id" class="location-person w-100 text-start" :class="{'location-selected':selected===d.id}" @click="selected=d.id"><strong>{{d.name}}</strong><span :class="d.status==='stale'?'text-warning-emphasis':'text-success'">{{status(d)}}</span><small>{{location(d)}}</small><small>定位时间:{{time(d.position?.at)}}</small><small v-if="d.signal==='permission_denied'||d.signal==='location_disabled'">手机定位或权限未开启</small></button></div></div>
|
||||
<LocationHistory :members="[...items,...(result?.members||[]).filter(m=>!items.some(i=>i.id===m.id))]"/>
|
||||
<details class="mt-3 border-top pt-3"><summary>为家庭成员配对手机</summary>
|
||||
<p class="small text-secondary mt-2">老人和孩子无需登录。先选择真实成员及具体查看人,再将配对码输入本人的手机。本人核对授权内容、允许定位并打开共享后才上传;管理员生成配对码不能代替本人同意。家庭屏需单独勾选。</p>
|
||||
<p v-if="!result?.members?.length" class="alert alert-info">请先在“家庭成员”登记本人或家人;普通账号需关联本人档案。</p>
|
||||
@@ -43,7 +41,7 @@ onBeforeUnmount(()=>{epoch++;clearTimeout(timer)})
|
||||
<p v-if="binding">{{binding.enabled?'手机已开启共享':'手机已绑定,共享关闭'}} · {{time(binding.expires)}} 到期</p>
|
||||
<div class="d-flex flex-wrap gap-2 mt-3"><button class="btn btn-primary" :disabled="busy||!memberId||(!viewOnly&&!viewerIds.length&&!displayIds.length&&!phoneIds.length)">生成配对码</button><button v-if="binding||code" type="button" class="btn btn-outline-danger" :disabled="busy" @click="action('stop')">解除该手机授权</button><a class="btn btn-outline-secondary" href="/downloads" target="_blank" rel="noreferrer">下载配套 App</a></div>
|
||||
<div v-if="code" class="alert alert-success mt-3" role="status">配对码 <strong class="font-monospace fs-3">{{code}}</strong> · 10 分钟内使用一次<br>请在成员本人的手机核对姓名与查看名单,手机授权有效至 {{time(expires)}}。重新配对会替换旧手机授权。</div>
|
||||
</form><p class="small text-secondary mt-3">手机可在“我的位置设置”选择实时(约 10 秒)、1 分钟或 5 分钟上传,默认 5 分钟;仅保存内存中的最新位置。关闭共享后清除;定位或网络中断超过 15 分钟隐藏旧坐标,提示更新中断,不表示人员失联。</p></details>
|
||||
</form><p class="small text-secondary mt-3">手机可在“我的位置设置”选择实时(约 10 秒)、1 分钟或 5 分钟上传,默认 5 分钟。实时位置仅在内存中保存,关闭共享后清除;本人可另行开启历史保存,长期归档到百度网盘并手动删除。定位或网络中断超过 15 分钟隐藏旧坐标,提示更新中断,不表示人员失联。</p></details>
|
||||
<p v-if="error" class="text-danger mt-2" role="alert">{{error}}</p>
|
||||
</section></template>
|
||||
<style scoped>.family-locations h2{font-size:1.3rem}.location-empty{display:grid;align-content:center;min-height:270px;text-align:center;color:var(--ui-muted,#64776f);padding:1rem}.location-empty>span{font-size:3rem;color:#6c9685}.location-person{display:flex;flex-direction:column;gap:.35rem;background:var(--panel,#fff);border:1px solid var(--ui-line,#d9e3dd);border-radius:12px;padding:14px;margin-bottom:10px;color:var(--ink,#243c32)}.location-person>span,.location-person small{font-size:.85rem}.location-selected{border-color:#257a68;box-shadow:inset 3px 0 #257a68}.family-locations summary{cursor:pointer}.family-locations input[type=checkbox]{min-width:18px;width:18px;min-height:18px}</style>
|
||||
|
||||
Reference in New Issue
Block a user