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 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录响应
|
/** @deprecated 旧地磅用户 CRUD,门户体系下不再使用 */
|
||||||
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)
|
|
||||||
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<never> => {
|
||||||
login: async (username: string, password: string): Promise<BaseResult<LoginResponse & { user?: UserInfo }>> => {
|
throw new Error('请使用 fetchLogin(@/api/authApi)登录门户账号')
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
getUserInfo: async (): Promise<never> => {
|
||||||
// 获取用户信息
|
throw new Error('请使用门户 /web/auth/current-user 获取用户信息')
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user