feat(target-lists): 切换至B方案行内编辑布局

- 名单管理页改为左侧分类导航、右侧宽表格,编辑在对应记录行下展开
- 新增条目按钮触发行内表单,筛选或分页时草稿保留在表格顶部
- 登记模块增加beforeunload保护,区分保存中与未保存状态
- 外观模块增加beforeunload保护并修复偏好拉取的竞态问题
- 地图定位面板调整底部内边距和标题间距
- 更新相关测试脚本适配新交互流程
```
This commit is contained in:
2026-10-23 17:42:17 +08:00
parent 461e2c8e7f
commit 18c5178d8f
14 changed files with 196 additions and 27 deletions
+2 -2
View File
@@ -8,8 +8,8 @@
</div><nav class="pagination" aria-label="档案分页"><span id="page-status" aria-live="polite"></span><div><button id="previous-page" type="button">上一页</button><button id="next-page" type="button">下一页</button></div></nav>
<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"><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}" placeholder="输入完整模块序列号"></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" placeholder="8 位数字 · 留空自动生成"></div></div><p id="fpv-hint" class="registry-help">已有编号仅填写后 8 位数字。<br>留空时,保存后自动生成。</p></div></section>
<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>选填 · 最多 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>
+69 -2
View File
@@ -410,10 +410,63 @@ fn saving_controls(state: &Shared, busy: bool) {
page_buttons(state);
}
}
fn clear_field_error(id: &str) {
input(id).set_custom_validity("");
let _ = el(id).remove_attribute("aria-invalid");
text(&format!("{id}-error"), "");
hidden(&format!("{id}-error"), true);
}
fn validate_registration() -> bool {
for id in ["serial-no", "uas-code"] {
clear_field_error(id);
let field = input(id);
let value = value(id);
field.set_value(&value);
let error = if id == "serial-no" {
if value.is_empty() {
Some("请填写模块 SN(设备实际序列号),不是 FPV 编号。")
} else if !value
.bytes()
.all(|b| b.is_ascii_alphanumeric() || b == b'-')
{
Some("模块 SN 只能包含英文字母、数字或半角连字符 -,不能包含中文、空格或其他符号。")
} else if !(6..=40).contains(&value.len()) {
Some("模块 SN 长度须为 6–40 位,请核对设备实际序列号。")
} else {
None
}
} else if !value.is_empty()
&& (value.len() != 8 || !value.bytes().all(|b| b.is_ascii_digit()))
{
Some("FPV 编号请只填写 8 位数字;没有已有编号时请留空,保存后自动生成。")
} else {
None
};
if let Some(error) = error {
field.set_custom_validity(error);
let _ = field.set_attribute("aria-invalid", "true");
message(&format!("{id}-error"), error, true);
hidden(&format!("{id}-error"), false);
if let Ok(Some(container)) = field.closest(".registration-field") {
container.scroll_into_view_with_bool(true);
}
let _ = field.focus();
field.report_validity();
return false;
}
}
true
}
async fn save(state: Shared, editing: bool) -> Result<()> {
if state.borrow().busy {
return Ok(());
}
if !editing {
message("form-message", "", false);
if !validate_registration() {
return Ok(());
}
}
state.borrow_mut().busy = true;
close_menu(&state, false);
saving_controls(&state, true);
@@ -628,6 +681,12 @@ pub fn init() {
{
state.borrow_mut().dirty = true;
text("draft-state", "有未保存的修改");
message("form-message", "", false);
if let Some(target) = event.target().and_then(|t| t.dyn_into::<Element>().ok())
&& matches!(target.id().as_str(), "serial-no" | "uas-code")
{
clear_field_error(&target.id());
}
}
if event
.target()
@@ -808,6 +867,9 @@ pub fn init() {
}
state.borrow_mut().dirty = false;
text("draft-state", "保存时校验 SN 与编号");
for id in ["serial-no", "uas-code"] {
clear_field_error(id);
}
for id in [
"serial-no",
"model-name",
@@ -991,9 +1053,14 @@ pub fn init() {
let state = state.clone();
let unloading = Closure::<dyn FnMut(web_sys::BeforeUnloadEvent)>::new(
move |event: web_sys::BeforeUnloadEvent| {
if state.borrow().busy {
let s = state.borrow();
if s.busy || s.dirty {
event.prevent_default();
event.set_return_value("正在保存,请稍候");
event.set_return_value(if s.busy {
"正在保存,请稍候"
} else {
"登记内容尚未保存"
});
}
},
);
File diff suppressed because one or more lines are too long
+27 -2
View File
@@ -176,6 +176,7 @@ fn apply(state: &Shared) {
);
}
async fn fetch_preferences(state: Shared) {
let generation = state.borrow().generation;
let result = async {
let r = Request::get("/api/appearance")
.send()
@@ -190,7 +191,11 @@ async fn fetch_preferences(state: Shared) {
match result {
Ok(p) => {
let mut s = state.borrow_mut();
if s.busy || s.dirty {
if s.busy
|| s.dirty
|| s.generation != generation
|| p["revision"].as_u64().unwrap_or(0) < s.prefs["revision"].as_u64().unwrap_or(0)
{
return;
}
s.prefs = p;
@@ -198,7 +203,12 @@ async fn fetch_preferences(state: Shared) {
drop(s);
apply(&state);
}
Err(e) => message(&e, true),
Err(e) => {
let s = state.borrow();
if s.generation == generation && !s.busy && !s.dirty {
message(&e, true);
}
}
}
}
fn queue_save(state: Shared) {
@@ -533,6 +543,21 @@ pub fn init(realtime: bool) {
dirty: false,
}));
apply(&state);
let pending = state.clone();
let unloading = Closure::<dyn FnMut(web_sys::BeforeUnloadEvent)>::new(
move |event: web_sys::BeforeUnloadEvent| {
let s = pending.borrow();
if s.busy || s.dirty {
event.prevent_default();
event.set_return_value("外观尚未保存,请稍候");
}
},
);
if let Some(window) = web_sys::window() {
let _ = window
.add_event_listener_with_callback("beforeunload", unloading.as_ref().unchecked_ref());
}
unloading.forget();
if let Some(body) = document().body() {
let collapsed = web_sys::window()
.and_then(|w| w.session_storage().ok().flatten())