hongjli
2025-04-16 ed1c1f25a544eaf08c7a7bcd3af93d7d26c8594e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import ApiService from '@/utils/api';
 
interface UserInfo {
  id: number;
  nickname: string;
  accountName: string;
}
 
interface ApiResponse<T> {
  code: number;
  data?: T;
  message?: string;
}
 
export async function getUserInfo(): Promise<ApiResponse<UserInfo>> {
  try {
    const token = localStorage.getItem('token');
    if (!token) {
      return {
        code: 401,
        message: '未登录或token无效'
      };
    }
 
    return await ApiService.get<UserInfo>('/users/info');
  } catch (error) {
    console.error('获取用户信息失败:', error);
    return {
      code: 500,
      message: '网络请求失败'
    };
  }