Files
gongxue-base/apps/admin/src/api/queryClient.ts
wangziqi 9565a0f23c feat(admin): 深化 TanStack Query 数据层
- 新增 queryKeys.ts 统一 QueryKey 工厂(覆盖全部模块,invalidate/refetch/prefetch 同源)
- 新增 queryClient.ts 全局配置:retry 1、staleTime 30s、gcTime 5min、refetchOnWindowFocus false
- 新增 useApiQuery:zod schema 校验 + 类型收敛 + select 转换,消除页面重复 validateResponse 样板
- useApiMutation 支持 onMutate/onSettled/context(乐观更新)
- 示范迁移:Organizations(useApiQuery + 乐观更新归档/恢复)、Students(useApiQuery + queryKeys + 打开抽屉前 prefetch 档案聚合)
- StudentProfileContent queryKey 统一为 queryKeys.archive.detail,prefetch 可命中缓存
2026-08-08 18:37:55 +08:00

21 lines
641 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { QueryClient } from '@tanstack/react-query';
/**
* 全局 QueryClient统一缓存/重试策略。
* - retry 1接口失败最多重试 1 次,避免瞬时错误直接白屏
* - staleTime 30s30 秒内重复请求走缓存
* - gcTime 5min不活跃缓存 5 分钟后回收
* - refetchOnWindowFocus false切回窗口不自动全量刷新
* 保活页面由 useVisibleRefetch 按需刷新,避免重复请求
*/
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 1,
staleTime: 30_000,
gcTime: 5 * 60_000,
refetchOnWindowFocus: false,
},
},
});