Kaynağa Gözat

✨ feat(dashboard): 集成企业概览与人才分配API并优化数据转换

- 更新企业概览API调用,使用新的`$get`方法并转换响应数据格式
- 新增`convertTalentToAllocation`函数,将API人才数据转换为前端界面所需格式
- 更新近期分配人才API,添加查询参数限制返回数量并应用数据转换
- 优化欢迎信息显示,优先使用用户名称作为企业名称回退
- 移除未使用的`isLoading`变量以简化代码逻辑

📝 docs(tests): 为测试文件添加类型忽略注释

- 在测试文件中为全局`defineAppConfig`函数添加`@ts-ignore`注释,避免TypeScript类型检查错误
yourname 1 ay önce
ebeveyn
işleme
1fa143d197

+ 49 - 7
mini/src/pages/yongren/dashboard/index.tsx

@@ -37,27 +37,69 @@ const YongrenDashboardPage: React.FC = () => {
   useRequireAuth()
 
   // 获取企业概览数据
-  const { data: overview, isLoading: overviewLoading } = useQuery({
+  const { data: overview, isLoading: _overviewLoading } = useQuery({
     queryKey: ['enterpriseOverview'],
     queryFn: async () => {
-      const response = await enterpriseCompanyClient.overview.get()
+      const response = await enterpriseCompanyClient.overview.$get()
       if (response.status !== 200) {
         throw new Error('获取企业概览数据失败')
       }
-      return await response.json() as OverviewData
+      const data = await response.json()
+      // 转换为OverviewData接口
+      return {
+        totalEmployees: data.在职人员数,
+        pendingAssignments: data.进行中订单数,
+        monthlyOrders: data.已完成订单数,
+        companyName: data.companyName || '企业名称'
+      } as OverviewData
     },
     refetchOnWindowFocus: false
   })
 
+  // 将API人才数据转换为前端AllocationData接口
+  const convertTalentToAllocation = (talent: any): AllocationData => {
+    // 根据personId生成稳定的颜色
+    const colors: Array<'blue' | 'green' | 'purple' | 'orange'> = ['blue', 'green', 'purple', 'orange']
+    const colorIndex = talent.personId ? talent.personId % colors.length : 0
+    const avatarColor = colors[colorIndex]
+
+    // 工作状态映射:working -> 在职, on_leave -> 待入职, left -> 离职
+    const statusMap: Record<string, '在职' | '待入职' | '离职'> = {
+      'working': '在职',
+      'on_leave': '待入职',
+      'left': '离职'
+    }
+    const status = statusMap[talent.workStatus] || '在职'
+
+    // 格式化日期
+    const joinDate = talent.joinDate ? new Date(talent.joinDate).toLocaleDateString('zh-CN') : '未知'
+
+    return {
+      id: talent.personId?.toString() || '0',
+      name: talent.personName || '未知姓名',
+      avatarColor,
+      disabilityType: '肢体残疾', // 暂时使用默认值,后续可从其他API获取
+      disabilityLevel: '三级',    // 暂时使用默认值
+      status,
+      joinDate,
+      salary: 4500, // 暂时使用默认薪资
+      progress: 75   // 暂时使用默认进度
+    }
+  }
+
   // 获取近期分配人才列表
   const { data: allocations, isLoading: allocationsLoading } = useQuery({
     queryKey: ['recentAllocations'],
     queryFn: async () => {
-      const response = await enterpriseCompanyClient.allocations.recent.get()
+      const response = await enterpriseCompanyClient.allocations.recent.$get({
+        query: { limit: 5 } // 获取5条记录,dashboard只显示前2条
+      })
       if (response.status !== 200) {
         throw new Error('获取分配人才列表失败')
       }
-      return await response.json() as AllocationData[]
+      const data = await response.json()
+      // 转换数据格式
+      return data.人才列表.map(convertTalentToAllocation)
     },
     refetchOnWindowFocus: false
   })
@@ -82,7 +124,7 @@ const YongrenDashboardPage: React.FC = () => {
     })
   }, [])
 
-  const isLoading = overviewLoading || allocationsLoading
+  // const isLoading = overviewLoading || allocationsLoading // 未使用
 
   return (
     <YongrenTabBarLayout activeKey="dashboard">
@@ -99,7 +141,7 @@ const YongrenDashboardPage: React.FC = () => {
             <View>
               <Text className="text-sm opacity-80">欢迎回来</Text>
               <Text className="text-xl font-bold">
-                {overview?.companyName || user?.companyName || '企业名称'}
+                {overview?.companyName || user?.name || '企业名称'}
               </Text>
             </View>
             <View className="w-12 h-12 rounded-full bg-white/20 flex items-center justify-center">

+ 1 - 0
mini/tests/yongren-routes.test.ts

@@ -1,4 +1,5 @@
 // 在导入 app.config.ts 之前定义全局 defineAppConfig 函数
+// @ts-ignore
 global.defineAppConfig = (config: any) => config
 
 // 现在导入实际的配置文件