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

fix: 修复人才小程序首页和更多页薪资显示问题

- 首页: 将"上月薪资"改回"本月薪资",数据从就业状态API的salaryLevel获取
- 更多页: 将固定值4800改为从就业状态API的salaryLevel获取
- 两个页面现在保持一致,都显示当前订单的薪资水平

故障4原本是关于就业信息页的薪资记录列表,之前被误理解为首页的薪资显示,
现已修正这个误解。

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 4 недель назад
Родитель
Сommit
3ea56c401f
2 измененных файлов с 30 добавлено и 19 удалено
  1. 10 17
      mini-talent/src/pages/index/index.tsx
  2. 20 2
      mini-talent/src/pages/settings/index.tsx

+ 10 - 17
mini-talent/src/pages/index/index.tsx

@@ -8,7 +8,7 @@ import { useAuth, useRequireAuth } from '../../hooks'
 import { talentDashboardClient, talentEmploymentClient } from '../../api'
 import type { InferResponseType } from 'hono'
 import { generateMockAttendanceData, getCurrentYearMonth } from '../../utils/mockAttendanceData'
-import type { SalaryRecord } from '../../types/employment'
+import type { CurrentEmploymentStatus } from '../../types/employment'
 
 /**
  * 人才小程序首页/个人主页
@@ -90,23 +90,16 @@ const Dashboard: React.FC = () => {
     return generateMockAttendanceData(year, month)
   })()
 
-  // 获取上个月的薪资记录(用于首页显示
-  const { data: lastMonthSalaryData } = useQuery({
-    queryKey: ['last-month-salary'],
+  // 获取当前就业状态(用于显示本月薪资水平
+  const { data: currentEmploymentStatus } = useQuery({
+    queryKey: ['current-employment-status'],
     queryFn: async () => {
-      // 计算上个月份
-      const now = new Date()
-      const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1)
-      const monthStr = `${lastMonth.getFullYear()}-${String(lastMonth.getMonth() + 1).padStart(2, '0')}`
-
-      const res = await talentEmploymentClient.employment['salary-records'].$get({
-        query: { month: monthStr, take: 1 }
-      })
+      const res = await talentEmploymentClient.employment.status.$get()
       if (!res.ok) {
-        throw new Error('获取薪资记录失败')
+        throw new Error('获取就业状态失败')
       }
       const data = await res.json()
-      return (data.data || []) as SalaryRecord[]
+      return data as CurrentEmploymentStatus | null
     },
     staleTime: 10 * 60 * 1000, // 10分钟缓存
   })
@@ -259,11 +252,11 @@ const Dashboard: React.FC = () => {
               </View>
               <View className="flex flex-col items-center">
                 <Text className="text-white text-2xl font-bold">
-                  {lastMonthSalaryData && lastMonthSalaryData.length > 0
-                    ? `¥${(lastMonthSalaryData[0].salaryAmount || 0).toLocaleString()}`
+                  {currentEmploymentStatus?.salaryLevel
+                    ? `¥${currentEmploymentStatus.salaryLevel.toLocaleString()}`
                     : '--'}
                 </Text>
-                <Text className="text-white/80 text-xs">月薪资</Text>
+                <Text className="text-white/80 text-xs">月薪资</Text>
               </View>
             </View>
           </View>

+ 20 - 2
mini-talent/src/pages/settings/index.tsx

@@ -8,8 +8,9 @@ import { useRequireAuth, useAuth } from '../../hooks'
 import { UserProfileSummary } from '../../components/UserProfileSummary'
 import { MenuSection } from '../../components/MenuSection'
 import { LogoutButton } from '../../components/LogoutButton'
-import { talentSettingsClient } from '../../api'
+import { talentSettingsClient, talentEmploymentClient } from '../../api'
 import type { MenuSection as MenuSectionType } from '../../types/settings'
+import type { CurrentEmploymentStatus } from '../../types/employment'
 import { generateMockAttendanceData, getCurrentYearMonth } from '../../utils/mockAttendanceData'
 
 /**
@@ -36,6 +37,20 @@ const SettingsPage: React.FC = () => {
     }
   })
 
+  // 获取当前就业状态(用于显示本月薪资水平)
+  const { data: currentEmploymentStatus } = useQuery({
+    queryKey: ['current-employment-status'],
+    queryFn: async () => {
+      const res = await talentEmploymentClient.employment.status.$get()
+      if (!res.ok) {
+        throw new Error('获取就业状态失败')
+      }
+      const data = await res.json()
+      return data as CurrentEmploymentStatus | null
+    },
+    staleTime: 10 * 60 * 1000, // 10分钟缓存
+  })
+
   // 功能入口菜单配置
   const menuSections = useMemo<MenuSectionType[]>(() => [
     {
@@ -212,6 +227,9 @@ const SettingsPage: React.FC = () => {
       return generateMockAttendanceData(year, month)
     })()
 
+    // 获取本月薪资水平(从就业状态API)
+    const thisMonthSalary = currentEmploymentStatus?.salaryLevel || 0
+
     return profile ? {
       id: profile.id,
       name: profile.name || profile.nickname || '用户',
@@ -220,7 +238,7 @@ const SettingsPage: React.FC = () => {
       stats: {
         thisMonthAttendance: attendanceData.normalDays,
         totalAttendance: attendanceData.normalDays, // 累计出勤暂时显示本月值
-        thisMonthSalary: 4800 // 薪资保持不变
+        thisMonthSalary
       }
     } : mockProfile
   })()