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

View File

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