|
@@ -1,54 +1,36 @@
|
|
|
import api from '@/utils/http'
|
|
import api from '@/utils/http'
|
|
|
-import type { BaseResult } from '@/types/axios'
|
|
|
|
|
-import { ApiStatus } from '@/utils/http/status'
|
|
|
|
|
|
|
|
|
|
-// ==================== 用户管理 API ====================
|
|
|
|
|
|
|
+// ==================== 用户管理 API(遗留,地磅独立用户;门户登录请用 authApi) ====================
|
|
|
|
|
|
|
|
export interface User {
|
|
export interface User {
|
|
|
- id: number
|
|
|
|
|
|
|
+ id: string
|
|
|
username: string
|
|
username: string
|
|
|
- role: 'admin' | 'operator'
|
|
|
|
|
|
|
+ role: string
|
|
|
createdAt?: string
|
|
createdAt?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface UserCreate {
|
|
export interface UserCreate {
|
|
|
username: string
|
|
username: string
|
|
|
password: string
|
|
password: string
|
|
|
- role: 'admin' | 'operator'
|
|
|
|
|
|
|
+ role: string
|
|
|
remark?: string
|
|
remark?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface UserUpdate {
|
|
export interface UserUpdate {
|
|
|
username?: string
|
|
username?: string
|
|
|
password?: string
|
|
password?: string
|
|
|
- role?: 'admin' | 'operator'
|
|
|
|
|
|
|
+ role?: string
|
|
|
remark?: string
|
|
remark?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 登录响应
|
|
|
|
|
-export interface LoginResponse {
|
|
|
|
|
- accessToken: string
|
|
|
|
|
- refreshToken?: string
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 用户信息(用于登录后获取)
|
|
|
|
|
-export interface UserInfo {
|
|
|
|
|
- id: number
|
|
|
|
|
- username: string
|
|
|
|
|
- name?: string
|
|
|
|
|
- avatar?: string
|
|
|
|
|
- email?: string
|
|
|
|
|
- role?: 'admin' | 'operator'
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 用户管理 API(CRUD)
|
|
|
|
|
|
|
+/** @deprecated 旧地磅用户 CRUD,门户体系下不再使用 */
|
|
|
export const userApi = {
|
|
export const userApi = {
|
|
|
list: async (): Promise<User[]> => {
|
|
list: async (): Promise<User[]> => {
|
|
|
return api.get<User[]>({
|
|
return api.get<User[]>({
|
|
|
url: '/users'
|
|
url: '/users'
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- get: async (id: number): Promise<User> => {
|
|
|
|
|
|
|
+ get: async (id: string): Promise<User> => {
|
|
|
return api.get<User>({
|
|
return api.get<User>({
|
|
|
url: `/users/${id}`
|
|
url: `/users/${id}`
|
|
|
})
|
|
})
|
|
@@ -59,68 +41,27 @@ export const userApi = {
|
|
|
data: payload
|
|
data: payload
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- update: async (id: number, payload: UserUpdate): Promise<User> => {
|
|
|
|
|
|
|
+ update: async (id: string, payload: UserUpdate): Promise<User> => {
|
|
|
return api.put<User>({
|
|
return api.put<User>({
|
|
|
url: `/users/${id}`,
|
|
url: `/users/${id}`,
|
|
|
data: payload
|
|
data: payload
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- delete: async (id: number): Promise<void> => {
|
|
|
|
|
|
|
+ delete: async (id: string): Promise<void> => {
|
|
|
return api.del({
|
|
return api.del({
|
|
|
url: `/users/${id}`
|
|
url: `/users/${id}`
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 用户服务(登录、获取用户信息等)
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * @deprecated 请使用 `@/api/authApi` 的 `fetchLogin`(门户 RSA + JWT)
|
|
|
|
|
+ */
|
|
|
export const UserService = {
|
|
export const UserService = {
|
|
|
- // 登录
|
|
|
|
|
- login: async (username: string, password: string): Promise<BaseResult<LoginResponse & { user?: UserInfo }>> => {
|
|
|
|
|
- try {
|
|
|
|
|
- const response = await api.post<LoginResponse & { user?: UserInfo }>({
|
|
|
|
|
- url: '/auth/login',
|
|
|
|
|
- data: {
|
|
|
|
|
- username,
|
|
|
|
|
- password
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 后端直接返回 LoginResponse,需要包装成 BaseResult 格式
|
|
|
|
|
- return {
|
|
|
|
|
- code: ApiStatus.success,
|
|
|
|
|
- message: '登录成功',
|
|
|
|
|
- data: response
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error: any) {
|
|
|
|
|
- const errorMessage = error.response?.data?.detail || error.response?.data?.message || error.message || '登录失败'
|
|
|
|
|
- return {
|
|
|
|
|
- code: error.response?.status || 500,
|
|
|
|
|
- message: errorMessage,
|
|
|
|
|
- data: null as any
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ login: async (_username: string, _password: string): Promise<never> => {
|
|
|
|
|
+ throw new Error('请使用 fetchLogin(@/api/authApi)登录门户账号')
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- // 获取用户信息
|
|
|
|
|
- getUserInfo: async (): Promise<BaseResult<UserInfo>> => {
|
|
|
|
|
- try {
|
|
|
|
|
- const response = await api.get<UserInfo>({
|
|
|
|
|
- url: '/auth/userinfo'
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // 后端直接返回 UserInfo,需要包装成 BaseResult 格式
|
|
|
|
|
- return {
|
|
|
|
|
- code: ApiStatus.success,
|
|
|
|
|
- message: '获取成功',
|
|
|
|
|
- data: response
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error: any) {
|
|
|
|
|
- const errorMessage = error.response?.data?.detail || error.response?.data?.message || error.message || '获取用户信息失败'
|
|
|
|
|
- return {
|
|
|
|
|
- code: error.response?.status || 500,
|
|
|
|
|
- message: errorMessage,
|
|
|
|
|
- data: null as any
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ getUserInfo: async (): Promise<never> => {
|
|
|
|
|
+ throw new Error('请使用门户 /web/auth/current-user 获取用户信息')
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|