|
@@ -4,29 +4,8 @@ import { QueryClient, useQuery, useMutation, useQueryClient } from '@tanstack/re
|
|
|
import { talentAuthClient } from '../api'
|
|
import { talentAuthClient } from '../api'
|
|
|
import type { InferResponseType } from 'hono'
|
|
import type { InferResponseType } from 'hono'
|
|
|
|
|
|
|
|
-export interface TalentUserInfo {
|
|
|
|
|
- userId: number
|
|
|
|
|
- username: string
|
|
|
|
|
- userType: 'talent'
|
|
|
|
|
- personId?: number
|
|
|
|
|
- phone?: string | null
|
|
|
|
|
- nickname?: string | null
|
|
|
|
|
- name?: string | null
|
|
|
|
|
- // 从 disabled_person 表获取的人才详情
|
|
|
|
|
- personInfo?: {
|
|
|
|
|
- personId: number
|
|
|
|
|
- name: string
|
|
|
|
|
- disabilityType: string
|
|
|
|
|
- idCard: string
|
|
|
|
|
- disabilityId: string
|
|
|
|
|
- phone: string
|
|
|
|
|
- province: string
|
|
|
|
|
- city: string
|
|
|
|
|
- district?: string | null
|
|
|
|
|
- detailedAddress?: string | null
|
|
|
|
|
- jobStatus: number
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// 使用RPC类型推断,确保类型与后端API完全一致
|
|
|
|
|
+export type TalentUserInfo = InferResponseType<typeof talentAuthClient.me.$get, 200>
|
|
|
|
|
|
|
|
export interface AuthContextType {
|
|
export interface AuthContextType {
|
|
|
isLoggedIn: boolean
|
|
isLoggedIn: boolean
|
|
@@ -68,29 +47,8 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
|
|
|
throw new Error('获取用户信息失败')
|
|
throw new Error('获取用户信息失败')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 转换API响应为UserInfo格式
|
|
|
|
|
- const userInfo: TalentUserInfo = {
|
|
|
|
|
- userId: response.id,
|
|
|
|
|
- username: response.username,
|
|
|
|
|
- userType: 'talent',
|
|
|
|
|
- personId: response.personId || undefined,
|
|
|
|
|
- phone: response.phone,
|
|
|
|
|
- nickname: response.nickname,
|
|
|
|
|
- name: response.name,
|
|
|
|
|
- personInfo: response.personInfo ? {
|
|
|
|
|
- personId: response.personInfo.id,
|
|
|
|
|
- name: response.personInfo.name,
|
|
|
|
|
- disabilityType: response.personInfo.disabilityType,
|
|
|
|
|
- idCard: response.personInfo.idCard,
|
|
|
|
|
- disabilityId: response.personInfo.disabilityId,
|
|
|
|
|
- phone: response.personInfo.phone,
|
|
|
|
|
- province: response.personInfo.province,
|
|
|
|
|
- city: response.personInfo.city,
|
|
|
|
|
- district: response.personInfo.district,
|
|
|
|
|
- detailedAddress: response.personInfo.detailedAddress,
|
|
|
|
|
- jobStatus: response.personInfo.jobStatus,
|
|
|
|
|
- } : undefined
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 直接使用响应数据,类型已通过RPC推断保证一致
|
|
|
|
|
+ const userInfo = response
|
|
|
|
|
|
|
|
// 缓存到本地存储
|
|
// 缓存到本地存储
|
|
|
Taro.setStorageSync(USER_KEY, userInfo)
|
|
Taro.setStorageSync(USER_KEY, userInfo)
|
|
@@ -127,29 +85,8 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
|
|
|
throw new Error('登录失败')
|
|
throw new Error('登录失败')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 转换API响应为UserInfo格式
|
|
|
|
|
- const userInfo: TalentUserInfo = {
|
|
|
|
|
- userId: response.user.id,
|
|
|
|
|
- username: response.user.username,
|
|
|
|
|
- userType: 'talent',
|
|
|
|
|
- personId: response.user.personId || undefined,
|
|
|
|
|
- phone: response.user.phone,
|
|
|
|
|
- nickname: response.user.nickname,
|
|
|
|
|
- name: response.user.name,
|
|
|
|
|
- personInfo: response.user.personInfo ? {
|
|
|
|
|
- personId: response.user.personInfo.id,
|
|
|
|
|
- name: response.user.personInfo.name,
|
|
|
|
|
- disabilityType: response.user.personInfo.disabilityType,
|
|
|
|
|
- idCard: response.user.personInfo.idCard,
|
|
|
|
|
- disabilityId: response.user.personInfo.disabilityId,
|
|
|
|
|
- phone: response.user.personInfo.phone,
|
|
|
|
|
- province: response.user.personInfo.province,
|
|
|
|
|
- city: response.user.personInfo.city,
|
|
|
|
|
- district: response.user.personInfo.district,
|
|
|
|
|
- detailedAddress: response.user.personInfo.detailedAddress,
|
|
|
|
|
- jobStatus: response.user.personInfo.jobStatus,
|
|
|
|
|
- } : undefined
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 直接使用响应数据,类型已通过RPC推断保证一致
|
|
|
|
|
+ const userInfo = response.user
|
|
|
|
|
|
|
|
// 保存到本地存储
|
|
// 保存到本地存储
|
|
|
Taro.setStorageSync(TOKEN_KEY, response.token)
|
|
Taro.setStorageSync(TOKEN_KEY, response.token)
|