From 2c6fe4375b072307282462db96a68ed31dd268e6 Mon Sep 17 00:00:00 2001 From: sexygoat <1538832180@qq.com> Date: Tue, 3 Feb 2026 10:04:59 +0800 Subject: [PATCH] =?UTF-8?q?fetch(modify):=E4=BF=AE=E5=A4=8DAPI=E7=9A=84URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 +- src/api/authApi.ts | 54 -------------- src/api/modules/account.ts | 20 ++++++ src/api/modules/auth.ts | 22 +++--- src/api/modules/customerAccount.ts | 11 ++- src/api/modules/platformAccount.ts | 8 +++ src/api/modules/shopAccount.ts | 8 +++ src/api/usersApi.ts | 39 ---------- .../business/CustomerAccountDialog.vue | 72 +++++++++---------- src/composables/useLogin.ts | 2 +- src/router/guards/beforeEach.ts | 28 ++++++++ src/types/api/permission.ts | 1 + src/types/api/role.ts | 8 --- .../platform-account/index.vue | 53 +++++++------- .../account-management/shop-account/index.vue | 43 +++++------ src/views/system/permission/index.vue | 39 ++++++++-- src/views/system/role/index.vue | 18 ++++- 17 files changed, 225 insertions(+), 205 deletions(-) delete mode 100644 src/api/authApi.ts delete mode 100644 src/api/usersApi.ts diff --git a/src/App.vue b/src/App.vue index 149296d..e9e9727 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,7 +9,7 @@ import zh from 'element-plus/es/locale/lang/zh-cn' import en from 'element-plus/es/locale/lang/en' import { systemUpgrade } from '@/utils' - import { UserService } from './api/usersApi' + import { AuthService } from '@/api/modules' import { ApiStatus } from './utils/http/status' import { setThemeTransitionClass } from '@/utils' import { checkStorageCompatibility } from '@/utils' @@ -41,7 +41,7 @@ const getUserInfo = async () => { if (userStore.isLogin && userStore.accessToken) { try { - const res = await UserService.getUserInfo() + const res = await AuthService.getUserInfo() if (res.code === ApiStatus.success && res.data) { // API 返回的是 { user, permissions },我们需要保存 user 和 permissions userStore.setUserInfo(res.data.user) diff --git a/src/api/authApi.ts b/src/api/authApi.ts deleted file mode 100644 index 42b9679..0000000 --- a/src/api/authApi.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * 认证相关 API - */ -import request from '@/utils/http' -import { - BaseResponse, - LoginParams, - LoginData, - UserInfoResponse, - RefreshTokenData -} from '@/types/api' - -export class AuthService { - /** - * 用户登录 - * @param params 登录参数 - */ - static login(params: LoginParams): Promise> { - return request.post>({ - url: '/api/admin/login', - data: params - }) - } - - /** - * 获取用户信息 - * GET /api/admin/me - */ - static getUserInfo(): Promise> { - return request.get>({ - url: '/api/admin/me' - }) - } - - /** - * 用户登出 - */ - static logout(): Promise> { - return request.post>({ - url: '/api/admin/logout' - }) - } - - /** - * 刷新 Token - * @param refreshToken 刷新令牌 - */ - static refreshToken(refreshToken: string): Promise> { - return request.post>({ - url: '/api/auth/refresh', - data: { refreshToken } - }) - } -} diff --git a/src/api/modules/account.ts b/src/api/modules/account.ts index ccf719d..26813ca 100644 --- a/src/api/modules/account.ts +++ b/src/api/modules/account.ts @@ -92,4 +92,24 @@ export class AccountService extends BaseService { static removeRoleFromAccount(accountId: number, roleId: number): Promise { return this.delete(`/api/admin/accounts/${accountId}/roles/${roleId}`) } + + /** + * 修改账号密码 + * PUT /api/admin/accounts/{id}/password + * @param id 账号ID + * @param password 新密码 + */ + static updateAccountPassword(id: number, password: string): Promise { + return this.put(`/api/admin/accounts/${id}/password`, { password }) + } + + /** + * 修改账号状态 + * PUT /api/admin/accounts/{id}/status + * @param id 账号ID + * @param status 状态 (0:禁用, 1:启用) + */ + static updateAccountStatus(id: number, status: 0 | 1): Promise { + return this.put(`/api/admin/accounts/${id}/status`, { status }) + } } diff --git a/src/api/modules/auth.ts b/src/api/modules/auth.ts index 64beff8..17111f9 100644 --- a/src/api/modules/auth.ts +++ b/src/api/modules/auth.ts @@ -16,42 +16,42 @@ import type { export class AuthService extends BaseService { /** - * 用户登录 + * 用户登录(统一认证接口) * @param params 登录参数 */ static login(params: LoginParams): Promise> { - return this.post>('/api/admin/login', params) + return this.post>('/api/auth/login', params) } /** - * 退出登录 + * 退出登录(统一认证接口) */ static logout(): Promise { - return this.post('/api/admin/logout') + return this.post('/api/auth/logout') } /** - * 获取当前用户信息 - * GET /api/admin/me + * 获取当前用户信息(统一认证接口) + * GET /api/auth/me */ static getUserInfo(): Promise> { - return this.get>('/api/admin/me') + return this.get>('/api/auth/me') } /** - * 刷新 Token + * 刷新 Token(统一认证接口) * @param params 刷新参数 */ static refreshToken(params: RefreshTokenParams): Promise> { - return this.post>('/api/auth/refresh', params) + return this.post>('/api/auth/refresh-token', params) } /** - * 修改密码 + * 修改密码(统一认证接口) * @param params 修改密码参数 */ static changePassword(params: ChangePasswordParams): Promise { - return this.post('/api/auth/change-password', params) + return this.put('/api/auth/password', params) } /** diff --git a/src/api/modules/customerAccount.ts b/src/api/modules/customerAccount.ts index 3f6431c..14dd1f1 100644 --- a/src/api/modules/customerAccount.ts +++ b/src/api/modules/customerAccount.ts @@ -1,5 +1,14 @@ /** - * 客户账号管理 API + * 客户账号管理 API (企业账号) + * + * @deprecated 此 API 已废弃,请使用统一的 AccountService 代替 + * @see AccountService - 统一账号管理接口 (/api/admin/accounts) + * + * 迁移说明: + * - 所有账号类型统一使用 /api/admin/accounts 接口 + * - 通过 user_type 参数区分账号类型 (2=平台, 3=代理, 4=企业) + * - customer-accounts 已改名为 enterprise(企业账号) + * - 详见:docs/迁移指南.md */ import { BaseService } from '../BaseService' diff --git a/src/api/modules/platformAccount.ts b/src/api/modules/platformAccount.ts index 48cb72c..385de36 100644 --- a/src/api/modules/platformAccount.ts +++ b/src/api/modules/platformAccount.ts @@ -1,5 +1,13 @@ /** * 平台账号相关 API - 匹配后端实际接口 + * + * @deprecated 此 API 已废弃,请使用统一的 AccountService 代替 + * @see AccountService - 统一账号管理接口 (/api/admin/accounts) + * + * 迁移说明: + * - 所有账号类型统一使用 /api/admin/accounts 接口 + * - 通过 user_type 参数区分账号类型 (2=平台, 3=代理, 4=企业) + * - 详见:docs/迁移指南.md */ import { BaseService } from '../BaseService' diff --git a/src/api/modules/shopAccount.ts b/src/api/modules/shopAccount.ts index 9b6965c..bef88bf 100644 --- a/src/api/modules/shopAccount.ts +++ b/src/api/modules/shopAccount.ts @@ -1,5 +1,13 @@ /** * 代理账号相关 API - 匹配后端实际接口 + * + * @deprecated 此 API 已废弃,请使用统一的 AccountService 代替 + * @see AccountService - 统一账号管理接口 (/api/admin/accounts) + * + * 迁移说明: + * - 所有账号类型统一使用 /api/admin/accounts 接口 + * - 通过 user_type 参数区分账号类型 (2=平台, 3=代理, 4=企业) + * - 详见:docs/迁移指南.md */ import { BaseService } from '../BaseService' diff --git a/src/api/usersApi.ts b/src/api/usersApi.ts deleted file mode 100644 index f194562..0000000 --- a/src/api/usersApi.ts +++ /dev/null @@ -1,39 +0,0 @@ -import request from '@/utils/http' -import { BaseResponse, UserInfoResponse } from '@/types/api' - -interface LoginParams { - username: string - password: string - device?: string -} - -interface UserListParams { - current?: number - size?: number -} - -export class UserService { - // 登录 - static login(params: LoginParams) { - return request.post({ - url: '/api/admin/login', - params - }) - } - - // 获取用户信息 - // GET /api/admin/me - static getUserInfo() { - return request.get>({ - url: '/api/admin/me' - }) - } - - // 获取用户列表 - static getUserList(params?: UserListParams) { - return request.get({ - url: '/api/user/list', - params - }) - } -} diff --git a/src/components/business/CustomerAccountDialog.vue b/src/components/business/CustomerAccountDialog.vue index aa18def..cf1e539 100644 --- a/src/components/business/CustomerAccountDialog.vue +++ b/src/components/business/CustomerAccountDialog.vue @@ -12,7 +12,7 @@ @@ -33,23 +33,25 @@