```
feat(target-lists): 切换至B方案行内编辑布局 - 名单管理页改为左侧分类导航、右侧宽表格,编辑在对应记录行下展开 - 新增条目按钮触发行内表单,筛选或分页时草稿保留在表格顶部 - 登记模块增加beforeunload保护,区分保存中与未保存状态 - 外观模块增加beforeunload保护并修复偏好拉取的竞态问题 - 地图定位面板调整底部内边距和标题间距 - 更新相关测试脚本适配新交互流程 ```
This commit is contained in:
@@ -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 {
|
||||
"登记内容尚未保存"
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user