Просмотр исходного кода

fix: 企业小程序数据统计页添加下拉刷新功能

- 启用原生下拉刷新 (enablePullDownRefresh: true)
- 添加 usePullDownRefresh Hook 处理刷新逻辑
- 使用 invalidateQueries 刷新所有统计数据
- 保留 5 分钟缓存以平衡性能和数据新鲜度

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 день назад
Родитель
Сommit
a60fad3ceb

+ 15 - 1
mini-ui-packages/yongren-statistics-ui/src/pages/Statistics/Statistics.tsx

@@ -1,6 +1,7 @@
 import React, { useState, useEffect, memo } from 'react'
+import Taro, { usePullDownRefresh } from '@tarojs/taro'
 import { View, Text, ScrollView } from '@tarojs/components'
-import { useQuery } from '@tanstack/react-query'
+import { useQuery, useQueryClient } from '@tanstack/react-query'
 import { YongrenTabBarLayout } from '@d8d/yongren-shared-ui/components/YongrenTabBarLayout'
 import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
 import { ColumnChart } from '@d8d/mini-charts/components/ColumnChart'
@@ -83,6 +84,9 @@ export interface StatisticsProps {
 }
 
 const Statistics: React.FC<StatisticsProps> = () => {
+  // Query Client 用于刷新数据
+  const queryClient = useQueryClient()
+
   // 状态:图表懒加载控制 - 哪些图表已经加载
   const [loadedCharts, setLoadedCharts] = useState<Set<string>>(new Set(['disability', 'gender'])) // 默认加载前两个关键图表
 
@@ -112,6 +116,16 @@ const Statistics: React.FC<StatisticsProps> = () => {
     }
   }, [])
 
+  // 下拉刷新:刷新所有统计数据
+  usePullDownRefresh(async () => {
+    try {
+      // 使所有统计查询失效,触发重新获取
+      await queryClient.invalidateQueries({ queryKey: ['statistics'] })
+    } finally {
+      Taro.stopPullDownRefresh()
+    }
+  })
+
   // 获取在职人数统计(简化版:无查询参数)
   const { data: employmentCountData, isLoading: isLoadingEmploymentCount } = useQuery({
     queryKey: ['statistics', 'employment-count'],

+ 1 - 1
mini/src/pages/yongren/statistics/index.config.ts

@@ -1,4 +1,4 @@
 export default {
   navigationBarTitleText: '数据统计',
-  enablePullDownRefresh: false,
+  enablePullDownRefresh: true,
 }