|
|
@@ -82,8 +82,15 @@ export const AreasTreePage: React.FC = () => {
|
|
|
if (res.status !== 201) throw new Error('创建省市区失败');
|
|
|
});
|
|
|
},
|
|
|
- onSuccess: () => {
|
|
|
+ onSuccess: (_, variables) => {
|
|
|
+ // 更新根级缓存
|
|
|
queryClient.invalidateQueries({ queryKey: ['areas-tree-province'] });
|
|
|
+
|
|
|
+ // 如果创建的是子节点,更新父节点的子树缓存
|
|
|
+ if (variables.parentId) {
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['areas-subtree', variables.parentId] });
|
|
|
+ }
|
|
|
+
|
|
|
setIsCreateDialogOpen(false);
|
|
|
},
|
|
|
});
|
|
|
@@ -100,7 +107,14 @@ export const AreasTreePage: React.FC = () => {
|
|
|
});
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
+ // 更新根级缓存
|
|
|
queryClient.invalidateQueries({ queryKey: ['areas-tree-province'] });
|
|
|
+
|
|
|
+ // 如果更新的节点有父节点,更新父节点的子树缓存
|
|
|
+ if (selectedArea?.parentId) {
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['areas-subtree', selectedArea.parentId] });
|
|
|
+ }
|
|
|
+
|
|
|
setIsEditDialogOpen(false);
|
|
|
setSelectedArea(null);
|
|
|
},
|
|
|
@@ -117,7 +131,14 @@ export const AreasTreePage: React.FC = () => {
|
|
|
});
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
+ // 更新根级缓存
|
|
|
queryClient.invalidateQueries({ queryKey: ['areas-tree-province'] });
|
|
|
+
|
|
|
+ // 如果删除的节点有父节点,更新父节点的子树缓存
|
|
|
+ if (selectedArea?.parentId) {
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['areas-subtree', selectedArea.parentId] });
|
|
|
+ }
|
|
|
+
|
|
|
setIsDeleteDialogOpen(false);
|
|
|
setSelectedArea(null);
|
|
|
},
|
|
|
@@ -135,7 +156,14 @@ export const AreasTreePage: React.FC = () => {
|
|
|
});
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
+ // 更新根级缓存
|
|
|
queryClient.invalidateQueries({ queryKey: ['areas-tree-province'] });
|
|
|
+
|
|
|
+ // 如果状态切换的节点有父节点,更新父节点的子树缓存
|
|
|
+ if (selectedArea?.parentId) {
|
|
|
+ queryClient.invalidateQueries({ queryKey: ['areas-subtree', selectedArea.parentId] });
|
|
|
+ }
|
|
|
+
|
|
|
setIsStatusDialogOpen(false);
|
|
|
setSelectedArea(null);
|
|
|
},
|