```
feat(protocol): Observation坐标字段可选化及协议v2扩展 - 将Observation中longitude/latitude/altitude_m/heading_deg改为Option类型, 支持无位置信息的观测数据 - 新增DeviceTelemetry结构体承载设备遥测扩展字段(serial, mac, model, rssi, speed, vertical_speed, pressure_altitude, geometric_altitude, height_agl, pilot_position等) - 新增LegacyObservation兼容结构体及From转换,保持旧接收器协议输入兼容 - PROTOCOL_VERSION从1升至2 - 新增coordinates()辅助方法统一提取有效坐标 - validate()适配Option类型,允许坐标字段同时缺失 - Store新增position_generation机制追踪位置可用性变化,确保合并帧间的 位置丢失仍能正确断开轨迹 - geofence-map-adapter过滤无效坐标避免渲染异常 - 新增appearance.css外观主题系统,支持blue/graphite/white三套配色 ```
This commit is contained in:
@@ -548,9 +548,9 @@ async fn poll_targets(s: Shared) {
|
||||
let frame:rid_shared::Frame=serde_json::from_value(request("/api/realtime/snapshot","GET",None).await?).map_err(|_|"目标响应无效".to_owned())?;
|
||||
let lists:rid_shared::target_lists::Snapshot=serde_json::from_value(request("/api/target-lists","GET",None).await?).map_err(|_|"名单响应无效".to_owned())?;
|
||||
let fences=s.borrow().snapshot.as_ref().map(|p|p.entries.clone()).unwrap_or_default();
|
||||
let items=frame.targets.iter().filter(|t|frame.server_time_ms.saturating_sub(t.received_at_ms)<30000).map(|t|{
|
||||
let items=frame.targets.iter().filter(|t|frame.server_time_ms.saturating_sub(t.received_at_ms)<30000 && t.observation.coordinates().is_some()).map(|t|{
|
||||
let o=&t.observation;let kind=lists.entries.iter().find(|e|e.target_id==o.target_id).map(|e|e.list_kind);
|
||||
let inside=fences.iter().filter(|f|f.enabled&&f.geometry.contains([o.longitude,o.latitude])).map(|f|f.name.as_str()).collect::<Vec<_>>().join("、");
|
||||
let inside=fences.iter().filter(|f|f.enabled&&o.coordinates().is_some_and(|p|f.geometry.contains(p))).map(|f|f.name.as_str()).collect::<Vec<_>>().join("、");
|
||||
json!({"target_id":o.target_id,"longitude":o.longitude,"latitude":o.latitude,"inside":inside,"list_kind":match kind{Some(rid_shared::target_lists::ListKind::White)=>"white",Some(rid_shared::target_lists::ListKind::Black)=>"black",None=>"unknown"}})
|
||||
}).collect::<Vec<_>>();map("targets",json!(items));Ok::<(),String>(())
|
||||
}.await;
|
||||
|
||||
@@ -151,6 +151,7 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
let query = RwSignal::new(String::new());
|
||||
let selected = RwSignal::new(String::new());
|
||||
let position = RwSignal::new(None::<[f64; 4]>);
|
||||
let details = RwSignal::new(HashMap::<String, Value>::new());
|
||||
let age = RwSignal::new(0u64);
|
||||
let status = RwSignal::new("连接中".to_owned());
|
||||
let record = RwSignal::new(None::<Value>);
|
||||
@@ -193,7 +194,7 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
a.get(2).as_f64()?,
|
||||
a.get(3).as_f64()?,
|
||||
];
|
||||
p.iter().all(|x| x.is_finite()).then_some(p)
|
||||
p[..2].iter().all(|x| x.is_finite()).then_some(p)
|
||||
}));
|
||||
};
|
||||
let active_black = Memo::new(move |_| {
|
||||
@@ -426,9 +427,25 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
lookup.set("请选择目标".into());
|
||||
}
|
||||
}
|
||||
let incoming_details = get("details");
|
||||
if !incoming_details.is_undefined()
|
||||
&& let Ok(text) = js_sys::JSON::stringify(&incoming_details)
|
||||
&& let Some(parsed) = text
|
||||
.as_string()
|
||||
.and_then(|s| serde_json::from_str::<HashMap<String, Value>>(&s).ok())
|
||||
{
|
||||
let active = ids
|
||||
.get_untracked()
|
||||
.into_iter()
|
||||
.collect::<std::collections::HashSet<_>>();
|
||||
details.update(|current| {
|
||||
current.retain(|id, _| active.contains(id));
|
||||
current.extend(parsed);
|
||||
});
|
||||
}
|
||||
let positions = get("positions");
|
||||
if !positions.is_undefined() {
|
||||
let _ = map_call("update", &[positions, incoming]);
|
||||
let _ = map_call("update", &[positions, incoming, get("generations")]);
|
||||
let _ = map_call("workerMemory", &[get("wasmMemoryBytes")]);
|
||||
age.set(get("serverAgeMs").as_f64().unwrap_or(0.0) as u64);
|
||||
if !selected.get_untracked().is_empty() {
|
||||
@@ -445,7 +462,7 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
a.get(2).as_f64()?,
|
||||
a.get(3).as_f64()?,
|
||||
];
|
||||
p.iter().all(|v| v.is_finite()).then_some(p)
|
||||
p[..2].iter().all(|v| v.is_finite()).then_some(p)
|
||||
}));
|
||||
}
|
||||
let sequence = get("sequence");
|
||||
@@ -595,7 +612,7 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
<span class="live-data-label rt-status">{move||status.get()}</span>
|
||||
<input class="live-search" aria-label="搜索实时目标" placeholder="搜索目标标识" prop:value=move||query.get() on:input=move|e|{query.set(event_target_value(&e));page.set(0);}/>
|
||||
<span class="live-data-label">{move||format!("目标 {} · 数据年龄 {} ms",ids.get().len(),age.get())}</span><div class="rt-target-list-filters" role="group" aria-label="目标名单筛选">{[Filter::All,Filter::White,Filter::Black,Filter::Unknown].into_iter().map(move |filter|view!{<button type="button" disabled=move||!lists.ready.get() aria-pressed=move||(lists.filter.get()==filter).to_string() on:click=move |_|{lists.filter.set(filter);page.set(0);}>{filter.label()}" "{move||{if !lists.ready.get() && filter!=Filter::All {"—".to_owned()}else{let kinds=classification.get();ids.with(|targets|targets.iter().filter(|id|filter.matches(kinds.get(*id).copied())).count()).to_string()}}}</button>}).collect_view()}</div><p class="rt-list-sync-error" role="status" hidden=move||lists.sync_error.get().is_empty()>{move||lists.sync_error.get()}<button type="button" on:click=move |_|spawn_local(lists.refresh())>"重试"</button></p>
|
||||
</div><div class="live-list-body"><div class="live-target-list">{move||filtered.get().into_iter().skip(visible_page.get()*100).take(100).map(|id|{let check=id.clone();let pick=id.clone();let badge_id=id.clone();let description_id=id.clone();view!{<button class="rt-target" aria-label=id.clone() aria-description=move||if lists.ready.get(){super::target_lists::label(lists.kind(&description_id))}else{"名单未知"} aria-pressed=move||(selected.get()==check).to_string() on:click=move |_|choose(pick.clone())><span aria-hidden="true">"◈"</span><span class="rt-target-id">{id.clone()}</span><Badge lists=lists target=badge_id/></button>}}).collect_view()}</div>
|
||||
</div><div class="live-list-body"><div class="live-target-list">{move||filtered.get().into_iter().skip(visible_page.get()*100).take(100).map(|id|{let check=id.clone();let pick=id.clone();let badge_id=id.clone();let description_id=id.clone();let location_id=id.clone();view!{<button class="rt-target" aria-label=id.clone() aria-description=move||if lists.ready.get(){super::target_lists::label(lists.kind(&description_id))}else{"名单未知"} aria-pressed=move||(selected.get()==check).to_string() on:click=move |_|choose(pick.clone())><span aria-hidden="true">"◈"</span><span class="rt-target-id"><span class="rt-device-id">{id.clone()}</span><small class="rt-position-state">{move||if details.with(|d|d.get(&location_id).is_some_and(|o|o["longitude"].is_number()&&o["latitude"].is_number())){"已定位"}else{"未定位"}}</small></span><Badge lists=lists target=badge_id/></button>}}).collect_view()}</div>
|
||||
<p class="live-empty" hidden=move||!filtered.get().is_empty()>{move||if ids.get().is_empty(){"暂无目标。请检查接收器和数据源。"}else{"没有匹配的目标。"}}</p>
|
||||
</div><nav class="pagination"><button disabled=move||{visible_page.get()==0} on:click=move |_|page.set(visible_page.get().saturating_sub(1))>"上一组"</button><span>{move||format!("{} / {}",visible_page.get()+1,filtered.get().len().div_ceil(100).max(1))}</span><button disabled=move||{(visible_page.get()+1)*100>=filtered.get().len()} on:click=move |_|page.set(visible_page.get()+1)>"下一组"</button></nav>
|
||||
</aside>
|
||||
@@ -604,10 +621,12 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
<div class="live-detail-body"><button class="live-back" hidden=move||!layout.compact.get() on:click=move |_|layout.mobile.set(1)>"‹ 返回目标目录"</button>
|
||||
<div class="live-target-heading">{move||if selected.get().is_empty(){"请选择目标".into()}else{selected.get()}}</div>
|
||||
<p class="live-data-label">{move||lookup.get()}</p>
|
||||
<p class="live-data-label" role="status">{move||if selected.get().is_empty(){""}else if position.get().is_some(){"已定位"}else{"已接收 · 未定位"}}</p>
|
||||
<super::target_binding::TargetBinding target=selected record=record lookup=lookup/>
|
||||
<div class="rt-detail-classification" hidden=move||selected.get().is_empty()>{move||view!{<Badge lists=lists target=selected.get()/>}}<p>{move||lists.snapshot.with(|snapshot|snapshot.entries.iter().find(|entry|entry.target_id==selected.get()).map(|entry|entry.note.clone()).unwrap_or_default())}</p><div class="rt-detail-list-actions"><button class="rt-white-action" disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.mark(selected.get_untracked(),ListKind::White)>"加入白名单"</button><button class="rt-black-action" disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.mark(selected.get_untracked(),ListKind::Black)>"加入黑名单"</button><button disabled=move||selected.get().is_empty()||!lists.ready.get()||lists.busy.get() on:click=move |_|lists.edit(selected.get_untracked())>"编辑名单备注"</button></div><p class="rt-list-inline-feedback" role="status" class:error=move||lists.failed.get()>{move||lists.message.get()}</p></div>
|
||||
|
||||
<div class="live-metrics"><div><span>"经度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[0])).unwrap_or_else(||"—".into())}</strong></div><div><span>"纬度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[1])).unwrap_or_else(||"—".into())}</strong></div><div><span>"高度(数据源)"</span><strong>{move||position.get().map(|p|format!("{:.1} m",p[2])).unwrap_or_else(||"—".into())}</strong></div><div><span>"航向"</span><strong>{move||position.get().map(|p|format!("{:.0}°",p[3])).unwrap_or_else(||"—".into())}</strong></div></div>
|
||||
<div class="live-metrics"><div><span>"经度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[0])).unwrap_or_else(||"—".into())}</strong></div><div><span>"纬度"</span><strong>{move||position.get().map(|p|format!("{:.6}",p[1])).unwrap_or_else(||"—".into())}</strong></div><div><span>"高度(数据源)"</span><strong>{move||position.get().filter(|p|p[2].is_finite()).map(|p|format!("{:.1} m",p[2])).unwrap_or_else(||"—".into())}</strong></div><div><span>"航向"</span><strong>{move||details.with(|d|d.get(&selected.get()).and_then(|o|o["heading_deg"].as_f64()).map(|v|format!("{v:.0}°"))).unwrap_or_else(||"—".into())}</strong></div></div>
|
||||
<dl>{move||details.with(|d|device_detail_rows(d.get(&selected.get()))).into_iter().map(|(label,value)|view!{<dt>{label}</dt><dd>{value}</dd>}).collect_view()}</dl>
|
||||
<dl><dt>"登记机型"</dt><dd>{move||record.get().and_then(|r|r["modelName"].as_str().map(str::to_owned)).unwrap_or_else(||"—".into())}</dd><dt>"登记人"</dt><dd>{move||record.get().and_then(|r|r["ownerName"].as_str().map(str::to_owned)).unwrap_or_else(||"—".into())}</dd></dl>
|
||||
<p class="live-data-label">"未收到的字段显示 —。未匹配本地记录不代表违法或未官方备案。"</p>
|
||||
</div><div class="mc-btn-row"><button class="primary" disabled=move||position.get().is_none() on:click=move |_|layout.focus()>"聚焦此目标"</button><a class="mc-btn mc-btn-secondary" aria-disabled=move||selected.get().is_empty().to_string() tabindex=move||if selected.get().is_empty(){-1}else{0} href=move||if selected.get().is_empty(){None}else{Some(format!("/?app=register&q={}",js_sys::encode_uri_component(&record.get().and_then(|r|r["serialNo"].as_str().map(str::to_owned)).unwrap_or_else(||selected.get()))))}>"查看本地登记"</a></div>
|
||||
@@ -640,3 +659,51 @@ pub fn Realtime(lists: Lists) -> impl IntoView {
|
||||
</div></main>
|
||||
}
|
||||
}
|
||||
|
||||
fn device_detail_rows(observation: Option<&Value>) -> Vec<(&'static str, String)> {
|
||||
let Some(t) = observation
|
||||
.and_then(|o| o.get("telemetry"))
|
||||
.filter(|t| t.is_object())
|
||||
else {
|
||||
return vec![];
|
||||
};
|
||||
let fields = [
|
||||
("设备 SN", "serial", ""),
|
||||
("设备机型", "model", ""),
|
||||
("设备名称", "name", ""),
|
||||
("SSID", "ssid", ""),
|
||||
("MAC", "mac", ""),
|
||||
("机型类型码", "ua_type", ""),
|
||||
("信号", "rssi", " dBm"),
|
||||
("频率", "frequency_mhz", " MHz"),
|
||||
("水平速度", "speed_mps", " m/s"),
|
||||
("垂直速度", "vertical_speed_mps", " m/s"),
|
||||
("气压高度", "pressure_altitude_m", " m"),
|
||||
("几何高度", "geometric_altitude_m", " m"),
|
||||
("离地高度", "height_agl_m", " m"),
|
||||
("设备 UTC(原始)", "utc_raw", ""),
|
||||
];
|
||||
let mut rows = fields
|
||||
.into_iter()
|
||||
.map(|(label, key, unit)| {
|
||||
let value = t[key]
|
||||
.as_str()
|
||||
.map(str::to_owned)
|
||||
.or_else(|| t[key].as_f64().map(|n| format!("{n:.1}{unit}")))
|
||||
.unwrap_or_else(|| "—".into());
|
||||
(label, value)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let pilot = t["pilot_position"]
|
||||
.as_array()
|
||||
.and_then(|p| {
|
||||
Some(format!(
|
||||
"{:.6}, {:.6}",
|
||||
p.first()?.as_f64()?,
|
||||
p.get(1)?.as_f64()?
|
||||
))
|
||||
})
|
||||
.unwrap_or_else(|| "—".into());
|
||||
rows.push(("操作者坐标", pilot));
|
||||
rows
|
||||
}
|
||||
|
||||
@@ -73,13 +73,15 @@ pub fn ReceiverControls(#[prop(default = false)] expanded: bool) -> impl IntoVie
|
||||
_ => "接收未启用",
|
||||
};
|
||||
status.set(format!(
|
||||
"{} {}\n接收 {} 字节 · 解码 {} 帧 · 接受 {} 条 · 拒绝 {} 帧\n{}",
|
||||
"{} {}\n接收 {} 字节 · 解码 {} 帧 · 接受 {} 条 · 拒绝 {} 帧\n忽略日志 {} 行 · 无效目标 {} 条\n{}",
|
||||
state,
|
||||
v["endpoint"].as_str().unwrap_or(""),
|
||||
v["receivedBytes"],
|
||||
v["decodedFrames"],
|
||||
v["acceptedObservations"],
|
||||
v["rejectedFrames"],
|
||||
v["ignoredLines"],
|
||||
v["invalidTargets"],
|
||||
v["lastError"].as_str().unwrap_or("")
|
||||
));
|
||||
capture.set(v["captureHex"].as_str().unwrap_or("").into());
|
||||
@@ -164,7 +166,8 @@ pub fn ReceiverControls(#[prop(default = false)] expanded: bool) -> impl IntoVie
|
||||
<div class="rt-form-group">
|
||||
<label class="rt-label">"报文解码格式"
|
||||
<select class="rt-select" aria-label="报文解码" prop:value=move||format.get() on:change=move|e|format.set(event_target_value(&e))>
|
||||
<option value="raw">"🔍 原始数据诊断(厂商格式待确认)"</option>
|
||||
<option value="raw">"🔍 原始数据诊断(不生成目标)"</option>
|
||||
<option value="rid-device-json">"📡 RID 设备 JSON(message / uav)"</option>
|
||||
<option value="json-lines">"📄 约定 JSON / JSON Lines"</option>
|
||||
<option value="postcard">"📦 约定 Postcard 二进制"</option>
|
||||
</select>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<p id="archive-warning" class="archive-warning" role="status" hidden><span id="archive-warning-text"></span> <button id="retry-archive" type="button">重试同步</button></p></aside>
|
||||
<section class="registration-editor" aria-labelledby="register-title"><header class="registration-heading"><div><h1 id="register-title">新建设备登记</h1><p>填写设备信息,生成本机登记二维码</p></div><span></span></header>
|
||||
<form id="register-form" aria-labelledby="register-title" novalidate><div class="registration-fields-scroll"><section class="registry-group"><div class="registry-group-heading"><h2>设备身份</h2><span>仅模块 SN 必填</span></div><div class="registration-fields"><div class="registration-field full"><label for="serial-no">模块 SN <span aria-hidden="true">*</span></label><input id="serial-no" name="serialNo" required maxlength="40" autocomplete="off" pattern="[A-Za-z0-9\-]{6,40}" aria-describedby="serial-no-hint serial-no-error" placeholder="输入完整模块序列号"><p id="serial-no-hint" class="registry-help">6–40 位英文字母、数字或半角连字符 -;请填写设备实际 SN,不支持中文名称。</p><p id="serial-no-error" class="form-message error" role="alert" hidden></p></div><div class="registration-field"><label for="model-name">机型 <small>选填</small></label><input id="model-name" name="modelName" maxlength="60" placeholder="例如:5 寸穿越机"></div><div class="registration-field"><label for="owner-name">登记人 / 备注 <small>选填</small></label><input id="owner-name" name="ownerName" maxlength="40" placeholder="方便后续查找"></div></div><p class="registry-help">SN 需与上位机模块一致;相同 SN 再次保存将更新原档案。</p></section>
|
||||
<section class="registry-group"><div class="registry-group-heading"><h2>登记编号</h2><span>自动生成或手动填写</span></div><div class="registration-number"><div class="registration-field"><label for="uas-code">FPV 编号 <small>选填</small></label><div class="registration-prefix"><span aria-hidden="true">FPV</span><input id="uas-code" name="uasDigits" maxlength="8" inputmode="numeric" pattern="[0-9]{8}" aria-describedby="fpv-hint uas-code-error" placeholder="8 位数字 · 留空自动生成"></div><p id="uas-code-error" class="form-message error" role="alert" hidden></p></div><p id="fpv-hint" class="registry-help">已有编号仅填写后 8 位数字。<br>留空时,保存后自动生成。</p></div></section>
|
||||
<section class="registry-group"><div class="registry-group-heading"><h2>登记编号</h2><span>留空,保存成功后生成</span></div><div class="registration-number"><div class="registration-field"><label for="uas-code">FPV 编号 <small>选填</small></label><div class="registration-prefix"><span aria-hidden="true">FPV</span><input id="uas-code" name="uasDigits" maxlength="8" inputmode="numeric" pattern="[0-9]{8}" aria-describedby="fpv-hint uas-code-error" placeholder="选填 8 位数字 · 保存后生成"></div><p id="uas-code-error" class="form-message error" role="alert" hidden></p></div><p id="fpv-hint" class="registry-help">已有编号仅填写后 8 位数字。<br>留空时,保存成功后自动生成并回填;相同 SN 沿用原编号。</p></div></section>
|
||||
<section class="registry-group"><div class="registry-group-heading"><h2>设备照片</h2><span>选填 · 最多 2 张</span></div><div class="registration-photos"><div class="photo-slot"><input id="photo-1" type="file" accept="image/jpeg,image/png,image/webp" data-photo-slot="0" hidden><button type="button" class="photo-pick" data-photo-choose="0" aria-label="添加照片 1"><img id="slot-preview-0" alt="照片 1预览" hidden><span class="photo-plus" aria-hidden="true">+</span><strong>添加照片 1</strong><span id="slot-name-0">点击选择本地图片</span></button><div class="photo-slot-actions"><button type="button" data-photo-remove="0" id="slot-remove-0" hidden>移除照片</button></div><button type="button" data-photo-keep="0" id="slot-keep-0" hidden>保留原选择</button><p id="slot-status-0" class="photo-status" role="status"></p></div><div class="photo-slot"><input id="photo-2" type="file" accept="image/jpeg,image/png,image/webp" data-photo-slot="1" hidden><button type="button" class="photo-pick" data-photo-choose="1" aria-label="添加照片 2"><img id="slot-preview-1" alt="照片 2预览" hidden><span class="photo-plus" aria-hidden="true">+</span><strong>添加照片 2</strong><span id="slot-name-1">点击选择本地图片</span></button><div class="photo-slot-actions"><button type="button" data-photo-remove="1" id="slot-remove-1" hidden>移除照片</button></div><button type="button" data-photo-keep="1" id="slot-keep-1" hidden>保留原选择</button><p id="slot-status-1" class="photo-status" role="status"></p></div></div><p class="registry-help">JPG、PNG、WebP · 每张不超过 5 MB · 仅保存在本机档案</p></section>
|
||||
<p class="form-message" id="form-message" role="status"></p></div><div class="registration-savebar"><span id="draft-state">保存时校验 SN 与编号</span><button class="primary" id="register-button" type="submit">保存登记并生成二维码 →</button></div></form></section><section class="result-panel registry-group" aria-labelledby="result-title" id="registration-result" tabindex="-1"><h2 id="result-title">二维码与核验</h2>
|
||||
<div id="empty-result" class="empty-state"><div class="empty-glyph"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><path d="M3 3h6v6H3z M15 3h6v6h-6z M3 15h6v6H3z M14 14h3v3h4v4h-7z"/></svg></div><div><b>等待完成登记</b><p>保存后自动生成二维码,供本地版上位机读取和核验。</p></div><ol><li>填写模块 SN</li><li>保存登记并生成二维码</li><li>在本地版上位机核验</li></ol></div><div id="record-result" class="record-result" hidden>
|
||||
|
||||
@@ -27,6 +27,7 @@ struct State {
|
||||
photos: photos::Shared,
|
||||
menu: Option<(String, String)>,
|
||||
edit_return: String,
|
||||
saved_identity: Option<(String, String)>,
|
||||
}
|
||||
type Shared = Rc<RefCell<State>>;
|
||||
type Result<T> = std::result::Result<T, String>;
|
||||
@@ -513,15 +514,21 @@ async fn save_inner(state: Shared, editing: bool) -> Result<()> {
|
||||
draw(&state, payload["record"].clone());
|
||||
}
|
||||
} else {
|
||||
let code = field(&payload["record"], "uasCode");
|
||||
input("uas-code").set_value(code.strip_prefix("FPV").unwrap_or(code));
|
||||
state.borrow_mut().saved_identity = Some((
|
||||
field(&payload["record"], "serialNo").to_owned(),
|
||||
code.to_owned(),
|
||||
));
|
||||
state.borrow_mut().dirty = false;
|
||||
text("draft-state", "已保存 · 修改后可再次保存");
|
||||
draw(&state, payload["record"].clone());
|
||||
message(
|
||||
"form-message",
|
||||
if payload["existing"] == true {
|
||||
"该 SN 已登记,照片和填写的信息已保存。"
|
||||
&if payload["existing"] == true {
|
||||
format!("该 SN 已登记,沿用编号 {code},资料已保存。")
|
||||
} else {
|
||||
"登记成功,二维码已生成。"
|
||||
format!("登记成功,编号 {code} 已回填,二维码已生成。")
|
||||
},
|
||||
false,
|
||||
);
|
||||
@@ -697,6 +704,9 @@ pub fn init() {
|
||||
&e,
|
||||
true,
|
||||
);
|
||||
if !editing {
|
||||
el("form-message").scroll_into_view_with_bool(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -716,6 +726,18 @@ pub fn init() {
|
||||
&& matches!(target.id().as_str(), "serial-no" | "uas-code")
|
||||
{
|
||||
clear_field_error(&target.id());
|
||||
if target.id() == "serial-no" {
|
||||
let saved = state.borrow().saved_identity.clone();
|
||||
if let Some((sn, code)) = saved
|
||||
&& value("serial-no") != sn
|
||||
{
|
||||
if format!("FPV{}", value("uas-code")) == code {
|
||||
input("uas-code").set_value("");
|
||||
clear_field_error("uas-code");
|
||||
}
|
||||
state.borrow_mut().saved_identity = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if event
|
||||
@@ -896,6 +918,7 @@ pub fn init() {
|
||||
photos::reset(&state.borrow().photos, index, "");
|
||||
}
|
||||
state.borrow_mut().dirty = false;
|
||||
state.borrow_mut().saved_identity = None;
|
||||
text("draft-state", "保存时校验 SN 与编号");
|
||||
for id in ["serial-no", "uas-code"] {
|
||||
clear_field_error(id);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -13,6 +13,7 @@ use web_sys::{
|
||||
|
||||
struct State {
|
||||
prefs: Value,
|
||||
saved: Value,
|
||||
generation: u64,
|
||||
busy: bool,
|
||||
ready: bool,
|
||||
@@ -67,7 +68,7 @@ fn each(selector: &str, mut f: impl FnMut(Element)) {
|
||||
fn apply(state: &Shared) {
|
||||
let s = state.borrow();
|
||||
let p = &s.prefs;
|
||||
let theme = p["theme"].as_str().unwrap_or("graphite");
|
||||
let theme = p["theme"].as_str().unwrap_or("blue");
|
||||
if let Some(body) = document().body() {
|
||||
let _ = body.set_attribute("data-theme", theme);
|
||||
let _ = body.set_attribute(
|
||||
@@ -78,13 +79,12 @@ fn apply(state: &Shared) {
|
||||
"false"
|
||||
},
|
||||
);
|
||||
// Legacy preference values remain intact; all use the approved dark material.
|
||||
let _ = body.set_attribute("class", "b R2 theme-graphite");
|
||||
let _ = body.set_attribute("class", &format!("b R2 theme-{theme}"));
|
||||
}
|
||||
let image = p["image"].as_str().map(str::to_owned).unwrap_or_else(|| {
|
||||
format!(
|
||||
"/wallpapers/{}-wallpaper.svg",
|
||||
p["wallpaper"].as_str().unwrap_or("B4")
|
||||
p["wallpaper"].as_str().unwrap_or("B5")
|
||||
)
|
||||
});
|
||||
if let Some(w) = el("workspace-wallpaper") {
|
||||
@@ -119,7 +119,32 @@ fn apply(state: &Shared) {
|
||||
if let Some(fit) = el("fit").and_then(|e| e.dyn_into::<HtmlSelectElement>().ok()) {
|
||||
fit.set_value(p["fit"].as_str().unwrap_or("cover"));
|
||||
}
|
||||
text("theme-name", "深海蓝玻璃");
|
||||
let (name, material, opacity) = match theme {
|
||||
"graphite" => ("石墨灰玻璃", "石墨灰 · 柔透", "72%"),
|
||||
"white" => ("透明白玻璃", "透明白 · 轻透", "84%"),
|
||||
_ => ("深海蓝玻璃", "深海蓝 · 高透", "40%"),
|
||||
};
|
||||
text("theme-name", name);
|
||||
text("appearance-theme-name", name);
|
||||
text("appearance-material", material);
|
||||
text("appearance-opacity", opacity);
|
||||
if let Some(button) = el("theme-shortcut") {
|
||||
let _ = button.set_attribute("aria-label", &format!("当前色调:{name},打开色调选择"));
|
||||
}
|
||||
each("[data-appearance-theme]", |e| {
|
||||
let active = e.get_attribute("data-appearance-theme").as_deref() == Some(theme);
|
||||
let _ = e.set_attribute("aria-pressed", if active { "true" } else { "false" });
|
||||
});
|
||||
each(
|
||||
"#appearance-wallpaper-controls button, #appearance-display input, #appearance-display select, #reset-wallpaper",
|
||||
|e| {
|
||||
if s.ready {
|
||||
let _ = e.remove_attribute("disabled");
|
||||
} else {
|
||||
let _ = e.set_attribute("disabled", "");
|
||||
}
|
||||
},
|
||||
);
|
||||
each("[data-wall]", |e| {
|
||||
let active = p["image"].is_null()
|
||||
&& e.get_attribute("data-wall").as_deref() == p["wallpaper"].as_str();
|
||||
@@ -153,7 +178,7 @@ fn apply(state: &Shared) {
|
||||
let wallpaper_name = if p["image"].is_string() {
|
||||
"自定义壁纸"
|
||||
} else {
|
||||
match p["wallpaper"].as_str().unwrap_or("B4") {
|
||||
match p["wallpaper"].as_str().unwrap_or("B5") {
|
||||
"B1" => "黑曜石柔光",
|
||||
"B2" => "午夜蓝丝绸",
|
||||
"B3" => "石墨空间玻璃",
|
||||
@@ -181,7 +206,7 @@ async fn fetch_preferences(state: Shared) {
|
||||
let r = Request::get("/api/appearance")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|_| "无法连接本机应用,请重新打开设置重试".to_owned())?;
|
||||
if !r.ok() {
|
||||
return Err("无法读取本机外观设置".into());
|
||||
}
|
||||
@@ -198,10 +223,17 @@ async fn fetch_preferences(state: Shared) {
|
||||
{
|
||||
return;
|
||||
}
|
||||
s.saved = p.clone();
|
||||
s.prefs = p;
|
||||
s.ready = true;
|
||||
drop(s);
|
||||
apply(&state);
|
||||
if el("wall-message").is_some_and(|e| {
|
||||
e.get_attribute("class")
|
||||
.is_some_and(|classes| classes.split_whitespace().any(|c| c == "error"))
|
||||
}) {
|
||||
message("已重新加载本机外观,可以继续调整。", false);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let s = state.borrow();
|
||||
@@ -240,7 +272,7 @@ fn queue_save(state: Shared) {
|
||||
.map_err(|e| e.to_string())?
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|_| "无法连接本机应用".to_owned())?;
|
||||
let p = r.json::<Value>().await.map_err(|e| e.to_string())?;
|
||||
if !r.ok() {
|
||||
return Err(p["error"].as_str().unwrap_or("保存失败").to_owned());
|
||||
@@ -252,6 +284,7 @@ fn queue_save(state: Shared) {
|
||||
Ok(saved) => {
|
||||
let mut s = state.borrow_mut();
|
||||
s.prefs["revision"] = saved["revision"].clone();
|
||||
s.saved = saved;
|
||||
if s.generation == version {
|
||||
s.busy = false;
|
||||
s.dirty = false;
|
||||
@@ -268,9 +301,16 @@ fn queue_save(state: Shared) {
|
||||
let mut s = state.borrow_mut();
|
||||
s.busy = false;
|
||||
s.dirty = false;
|
||||
s.generation += 1;
|
||||
s.prefs = s.saved.clone();
|
||||
s.ready = false;
|
||||
}
|
||||
apply(&state);
|
||||
fetch_preferences(state.clone()).await;
|
||||
message(&e, true);
|
||||
message(
|
||||
&format!("保存未完成:{e}。已恢复已保存的外观,请重新打开设置重试。"),
|
||||
true,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -536,7 +576,8 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
restored.forget();
|
||||
let state = Rc::new(RefCell::new(State {
|
||||
prefs: json!({"theme":"graphite","wallpaper":"B4","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
prefs: json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
saved: json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":0}),
|
||||
generation: 0,
|
||||
busy: false,
|
||||
ready: false,
|
||||
@@ -591,6 +632,8 @@ pub fn init(realtime: bool) {
|
||||
"archives"
|
||||
} else if search.contains("app=register") {
|
||||
"register"
|
||||
} else if search.contains("app=settings") {
|
||||
"settings"
|
||||
} else {
|
||||
"home"
|
||||
},
|
||||
@@ -623,6 +666,13 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
if let Some(view) = button.get_attribute("data-open") {
|
||||
show(&view, realtime);
|
||||
if button.id() == "theme-shortcut"
|
||||
&& let Some(region) =
|
||||
el("appearance-themes").and_then(|e| e.dyn_into::<HtmlElement>().ok())
|
||||
{
|
||||
region.scroll_into_view();
|
||||
let _ = region.focus();
|
||||
}
|
||||
if matches!(view.as_str(), "settings" | "display") {
|
||||
let s = clicked.clone();
|
||||
spawn_local(async move {
|
||||
@@ -631,6 +681,16 @@ pub fn init(realtime: bool) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(theme) = button.get_attribute("data-appearance-theme") {
|
||||
if clicked.borrow().ready
|
||||
&& matches!(theme.as_str(), "graphite" | "blue" | "white")
|
||||
&& clicked.borrow().prefs["theme"].as_str() != Some(theme.as_str())
|
||||
{
|
||||
clicked.borrow_mut().prefs["theme"] = json!(theme);
|
||||
queue_save(clicked.clone());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(wall) = button.get_attribute("data-wall") {
|
||||
if clicked.borrow().ready {
|
||||
let mut s = clicked.borrow_mut();
|
||||
@@ -671,7 +731,7 @@ pub fn init(realtime: bool) {
|
||||
"reset-wallpaper" => {
|
||||
if clicked.borrow().ready {
|
||||
let rev = clicked.borrow().prefs["revision"].clone();
|
||||
clicked.borrow_mut().prefs = json!({"theme":"graphite","wallpaper":"B4","dim":14,"blur":0,"fit":"cover","image":null,"revision":rev});
|
||||
clicked.borrow_mut().prefs = json!({"theme":"blue","wallpaper":"B5","dim":14,"blur":0,"fit":"cover","image":null,"revision":rev});
|
||||
queue_save(clicked.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user