优化交互

This commit is contained in:
iqudoo
2026-06-13 04:40:15 +08:00
parent 3d945f9947
commit c25319e0de
5 changed files with 335 additions and 66 deletions

View File

@@ -565,6 +565,36 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
}
};
const deletableSelectedIds = useMemo(
() =>
selectedElementIds.filter((id) => {
const el = template.elements.find((item) => item.id === id);
return el && !el.locked;
}),
[selectedElementIds, template.elements]
);
const deleteSelectedElements = async () => {
if (deletableSelectedIds.length === 0) return;
const message =
deletableSelectedIds.length === 1
? `确定删除「${template.elements.find((item) => item.id === deletableSelectedIds[0])?.name ?? '未命名'}」吗?此操作无法撤销。`
: `确定删除选中的 ${deletableSelectedIds.length} 个元素吗?此操作无法撤销。`;
const confirmed = await showConfirm(message, {
title: '删除元素',
confirmLabel: '删除',
variant: 'error',
});
if (!confirmed) return;
const idSet = new Set(deletableSelectedIds);
const remaining = template.elements.filter((el) => !idSet.has(el.id));
onChangeTemplate({ ...template, elements: remaining });
onSelectElements?.(selectedElementIds.filter((id) => remaining.some((el) => el.id === id)));
};
const renderContentPanelBody = () => {
if (!selectedElem) {
return (
@@ -1985,6 +2015,18 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
<span>{item.label}</span>
</button>
))}
<div className="mobile-design-props-nav-spacer" aria-hidden />
<button
type="button"
onClick={() => void deleteSelectedElements()}
disabled={deletableSelectedIds.length === 0}
className="mobile-design-props-nav-btn mobile-design-props-nav-delete"
aria-label="删除选中元素"
title="删除选中元素"
>
<Trash2 className="w-4 h-4" />
<span></span>
</button>
</nav>
<div className="mobile-design-props-panel scrollbar-hide">
{mobileModule === 'content' && (