chore(mobile-h5): deprecate legacy UserService login paths
Point callers away from old /auth/login toward portal fetchLogin. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c3f183cfba
commit
f1be6bdc8c
1 file changed
+16
-75
@@ -1,54 +1,36 @@
|
||||
import api from '@/utils/http'
|
||||
import type { BaseResult } from '@/types/axios'
|
||||
import { ApiStatus } from '@/utils/http/status'
|
||||
|
||||
// ==================== 用户管理 API ====================
|
||||
// ==================== 用户管理 API(遗留,地磅独立用户;门户登录请用 authApi) ====================
|
||||
|
||||
export interface User {
|
||||
id: number
|
||||
id: string
|
||||
username: string
|
||||
role: 'admin' | 'operator'
|
||||
role: string
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
export interface UserCreate {
|
||||
username: string
|
||||
password: string
|
||||
role: 'admin' | 'operator'
|
||||
role: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface UserUpdate {
|
||||
username?: string
|
||||
password?: string
|
||||
role?: 'admin' | 'operator'
|
||||
role?: 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 = {
|
||||
list: async (): Promise<User[]> => {
|
||||
return api.get<User[]>({
|
||||
url: '/users'
|
||||
})
|
||||
},
|
||||
get: async (id: number): Promise<User> => {
|
||||
get: async (id: string): Promise<User> => {
|
||||
return api.get<User>({
|
||||
url: `/users/${id}`
|
||||
})
|
||||
@@ -59,68 +41,27 @@ export const userApi = {
|
||||
data: payload
|
||||
})
|
||||
},
|
||||
update: async (id: number, payload: UserUpdate): Promise<User> => {
|
||||
update: async (id: string, payload: UserUpdate): Promise<User> => {
|
||||
return api.put<User>({
|
||||
url: `/users/${id}`,
|
||||
data: payload
|
||||
})
|
||||
},
|
||||
delete: async (id: number): Promise<void> => {
|
||||
delete: async (id: string): Promise<void> => {
|
||||
return api.del({
|
||||
url: `/users/${id}`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 用户服务(登录、获取用户信息等)
|
||||
/**
|
||||
* @deprecated 请使用 `@/api/authApi` 的 `fetchLogin`(门户 RSA + JWT)
|
||||
*/
|
||||
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 获取用户信息')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user