fix: 列表刷新 - refreshKey 强制重拉 + deletePoint 容错

- TemplateList: refresh 计数器触发 useEffect 重新拉取列表
- TemplateEditor: handleDeletePoint 加 try/catch,刷新失败时本地移除
- GenerateModal onClose 自动刷新生成点列表
This commit is contained in:
zwt13703 2026-07-06 22:21:33 +08:00
parent d61f80eff3
commit d155a00e51
2 changed files with 24 additions and 8 deletions

View File

@ -184,10 +184,19 @@ export default function TemplateEditor() {
};
const handleDeletePoint = async (pointId: string) => {
await pointApi.deleteGenerationPoint(pointId);
message.success("删除成功");
const updated = await pointApi.listGenerationPoints(id!);
setPoints(updated);
try {
await pointApi.deleteGenerationPoint(pointId);
message.success("删除成功");
} catch (err: unknown) {
if (err instanceof Error) message.error(err.message);
return;
}
try {
const updated = await pointApi.listGenerationPoints(id!);
setPoints(updated);
} catch {
setPoints((prev) => prev.filter((p) => p.id !== pointId));
}
};
const handleDragStart = (_e: React.DragEvent, index: number) => {
@ -496,7 +505,13 @@ export default function TemplateEditor() {
<GenerateModal
open={generateModalOpen}
onClose={() => setGenerateModalOpen(false)}
onClose={async () => {
setGenerateModalOpen(false);
try {
const updated = await pointApi.listGenerationPoints(id!);
setPoints(updated);
} catch {}
}}
templateId={id || ""}
points={points}
models={models}

View File

@ -9,6 +9,7 @@ export default function TemplateList() {
const navigate = useNavigate();
const [templates, setTemplates] = useState<TemplateListItem[]>([]);
const [loading, setLoading] = useState(false);
const [refresh, setRefresh] = useState(0);
const fetchTemplates = useCallback(async () => {
setLoading(true);
@ -24,12 +25,12 @@ export default function TemplateList() {
useEffect(() => {
fetchTemplates();
}, [fetchTemplates]);
}, [fetchTemplates, refresh]);
const handleDelete = async (id: string) => {
await templateApi.deleteTemplate(id);
message.success("删除成功");
fetchTemplates();
setRefresh((r) => r + 1);
};
const columns = [
@ -92,7 +93,7 @@ export default function TemplateList() {
try {
await templateApi.uploadTemplate(file as File);
message.success("上传成功");
fetchTemplates();
setRefresh((r) => r + 1);
onSuccess?.("ok");
} catch {
message.error("上传失败");