From f1be6bdc8c3419fb0ac3fd0055533eadba623e39 Mon Sep 17 00:00:00 2001 From: zlwu <704541015@qq.com> Date: Mon, 3 Aug 2026 22:34:01 +0800 Subject: [PATCH] chore(mobile-h5): deprecate legacy UserService login paths Point callers away from old /auth/login toward portal fetchLogin. Co-authored-by: Cursor --- mobile-h5/src/api/usersApi.ts | 91 ++++++----------------------------- 1 file changed, 16 insertions(+), 75 deletions(-) diff --git a/mobile-h5/src/api/usersApi.ts b/mobile-h5/src/api/usersApi.ts index 24037dd1d..1a3cd6b15 100644 --- a/mobile-h5/src/api/usersApi.ts +++ b/mobile-h5/src/api/usersApi.ts @@ -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 => { return api.get({ url: '/users' }) }, - get: async (id: number): Promise => { + get: async (id: string): Promise => { return api.get({ url: `/users/${id}` }) @@ -59,68 +41,27 @@ export const userApi = { data: payload }) }, - update: async (id: number, payload: UserUpdate): Promise => { + update: async (id: string, payload: UserUpdate): Promise => { return api.put({ url: `/users/${id}`, data: payload }) }, - delete: async (id: number): Promise => { + delete: async (id: string): Promise => { return api.del({ url: `/users/${id}` }) } } -// 用户服务(登录、获取用户信息等) +/** + * @deprecated 请使用 `@/api/authApi` 的 `fetchLogin`(门户 RSA + JWT) + */ export const UserService = { - // 登录 - login: async (username: string, password: string): Promise> => { - try { - const response = await api.post({ - 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 => { + throw new Error('请使用 fetchLogin(@/api/authApi)登录门户账号') }, - - // 获取用户信息 - getUserInfo: async (): Promise> => { - try { - const response = await api.get({ - 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 => { + throw new Error('请使用门户 /web/auth/current-user 获取用户信息') } }