Răsfoiți Sursa

feat: 企业端首页添加统计API查询基础结构

- 添加 enterpriseStatisticsClient 导入
- 添加 EmploymentRateResponse 和 AverageSalaryResponse 类型导入
- 添加 isEmploymentRateSuccess 和 isAverageSalarySuccess 类型守卫函数
- 添加在职率和平均薪资的 useQuery 钩子

下一步将修改显示逻辑

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 zi în urmă
părinte
comite
0aa05e63cf
1 a modificat fișierele cu 38 adăugiri și 0 ștergeri
  1. 38 0
      mini/src/pages/yongren/dashboard/index.tsx

+ 38 - 0
mini/src/pages/yongren/dashboard/index.tsx

@@ -6,7 +6,12 @@ import dayjs from 'dayjs'
 import { YongrenTabBarLayout } from '@/components/YongrenTabBarLayout'
 import { Navbar } from '@d8d/mini-shared-ui-components/components/navbar'
 import { enterpriseCompanyClient } from '@/api'
+import { enterpriseStatisticsClient } from '@/api/enterpriseStatisticsClient'
 import { useAuth, useRequireAuth } from '@/hooks'
+import type {
+  EmploymentRateResponse,
+  AverageSalaryResponse
+} from '@/types/statisticsTypes'
 // import './Dashboard.css'
 
 // 类型定义
@@ -29,6 +34,15 @@ interface AllocationData {
   progress: number
 }
 
+// 类型守卫:检查响应是否成功
+const isEmploymentRateSuccess = (data: any): data is EmploymentRateResponse => {
+  return data && typeof data === 'object' && !('code' in data && 'message' in data) && 'rate' in data
+}
+
+const isAverageSalarySuccess = (data: any): data is AverageSalaryResponse => {
+  return data && typeof data === 'object' && !('code' in data && 'message' in data) && 'average' in data
+}
+
 const Dashboard: React.FC = () => {
   const { user } = useAuth()
   const queryClient = useQueryClient()
@@ -104,6 +118,30 @@ const Dashboard: React.FC = () => {
     refetchOnWindowFocus: false
   })
 
+  // 获取在职率统计
+  const { data: employmentRateData, isLoading: isLoadingEmploymentRate } = useQuery({
+    queryKey: ['dashboard', 'employment-rate'],
+    queryFn: async () => {
+      const response = await enterpriseStatisticsClient['employment-rate'].$get()
+      return await response.json()
+    },
+    staleTime: 5 * 60 * 1000, // 5分钟缓存
+    gcTime: 10 * 60 * 1000,
+    refetchOnWindowFocus: false
+  })
+
+  // 获取平均薪资统计
+  const { data: averageSalaryData, isLoading: isLoadingAverageSalary } = useQuery({
+    queryKey: ['dashboard', 'average-salary'],
+    queryFn: async () => {
+      const response = await enterpriseStatisticsClient['average-salary'].$get()
+      return await response.json()
+    },
+    staleTime: 5 * 60 * 1000,
+    gcTime: 10 * 60 * 1000,
+    refetchOnWindowFocus: false
+  })
+
   // 使用页面级下拉刷新
   usePullDownRefresh(async () => {
     try {