feat: update

This commit is contained in:
2025-11-06 16:37:01 +08:00
parent c0d54b8513
commit 855f289579
59 changed files with 3398 additions and 572 deletions

123
services/authService.ts Normal file
View File

@@ -0,0 +1,123 @@
/**
* 认证服务
* 处理登录、注册等认证相关的 API 请求
*/
import { request } from '@/utils/network/api';
import type {
LoginFormData,
RegisterFormData,
ForgotPasswordFormData,
ResetPasswordFormData,
ChangePasswordFormData,
PhoneLoginFormData,
} from '@/schemas/auth';
import type { User } from '@/schemas/user';
/**
* API 响应接口
*/
interface ApiResponse<T = any> {
code: number;
message: string;
data: T;
}
/**
* 登录响应
*/
interface LoginResponse {
user: User;
token: string;
refreshToken?: string;
}
/**
* 认证服务类
*/
class AuthService {
/**
* 邮箱登录
*/
async login(data: LoginFormData): Promise<LoginResponse> {
const response = await request.post<ApiResponse<LoginResponse>>('/auth/login', data);
return response.data;
}
/**
* 手机号登录
*/
async phoneLogin(data: PhoneLoginFormData): Promise<LoginResponse> {
const response = await request.post<ApiResponse<LoginResponse>>('/auth/phone-login', data);
return response.data;
}
/**
* 注册
*/
async register(data: RegisterFormData): Promise<LoginResponse> {
const response = await request.post<ApiResponse<LoginResponse>>('/auth/register', data);
return response.data;
}
/**
* 登出
*/
async logout(): Promise<void> {
await request.post('/auth/logout');
}
/**
* 发送忘记密码邮件
*/
async forgotPassword(data: ForgotPasswordFormData): Promise<void> {
await request.post('/auth/forgot-password', data);
}
/**
* 重置密码
*/
async resetPassword(data: ResetPasswordFormData): Promise<void> {
await request.post('/auth/reset-password', data);
}
/**
* 修改密码
*/
async changePassword(data: ChangePasswordFormData): Promise<void> {
await request.post('/auth/change-password', data);
}
/**
* 发送验证码
*/
async sendVerificationCode(phone: string): Promise<void> {
await request.post('/auth/send-code', { phone });
}
/**
* 刷新 token
*/
async refreshToken(refreshToken: string): Promise<{ token: string }> {
const response = await request.post<ApiResponse<{ token: string }>>('/auth/refresh-token', {
refreshToken,
});
return response.data;
}
/**
* 验证 token 是否有效
*/
async verifyToken(): Promise<boolean> {
try {
await request.get('/auth/verify-token');
return true;
} catch {
return false;
}
}
}
// 导出单例
export const authService = new AuthService();
export default authService;

8
services/index.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* Services 模块统一导出
*/
export { default as authService } from './authService';
export { default as userService } from './userService';
export { default as tenantService } from './tenantService';

43
services/tenantService.ts Normal file
View File

@@ -0,0 +1,43 @@
/**
* 租户服务
* 处理租户相关的 API 请求
*/
import { request } from '@/utils/network/api';
// import type { User, UpdateProfileFormData } from '@/schemas/user';
/**
* API 响应接口
*/
interface ApiResponse<T = any> {
code: number;
message: string;
data: T;
}
/**
* tenant 服务类
*/
class TenantService {
/**
* 获取平台信息
*/
getPlatformData(params?: Record<string, any>): Promise<ApiResponse> {
const data = {
language: '0',
...params
};
return request.post('/v2', data, {
headers: {
cmdId: 371130,
headerType: 1,
apiName: 'getPlatformData',
tid: '',
},
});
}
}
// 导出单例
export const tenantService = new TenantService();
export default tenantService;

85
services/userService.ts Normal file
View File

@@ -0,0 +1,85 @@
/**
* 用户服务
* 处理用户信息相关的 API 请求
*/
import { request } from '@/utils/network/api';
import type { User, UpdateProfileFormData } from '@/schemas/user';
/**
* API 响应接口
*/
interface ApiResponse<T = any> {
code: number;
message: string;
data: T;
}
/**
* 用户服务类
*/
class UserService {
/**
* 获取当前用户信息
*/
async getCurrentUser(): Promise<User> {
const response = await request.get<ApiResponse<User>>('/user/me');
return response.data;
}
/**
* 获取用户信息(通过 ID
*/
async getUserById(userId: string): Promise<User> {
const response = await request.get<ApiResponse<User>>(`/user/${userId}`);
return response.data;
}
/**
* 更新用户资料
*/
async updateProfile(data: UpdateProfileFormData): Promise<User> {
const response = await request.put<ApiResponse<User>>('/user/profile', data);
return response.data;
}
/**
* 上传头像
*/
async uploadAvatar(file: File | Blob): Promise<{ url: string }> {
const formData = new FormData();
formData.append('avatar', file);
const response = await request.post<ApiResponse<{ url: string }>>('/user/avatar', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
}
/**
* 绑定手机号
*/
async bindPhone(phone: string, code: string): Promise<void> {
await request.post('/user/bind-phone', { phone, code });
}
/**
* 绑定邮箱
*/
async bindEmail(email: string, code: string): Promise<void> {
await request.post('/user/bind-email', { email, code });
}
/**
* 注销账号
*/
async deleteAccount(): Promise<void> {
await request.delete('/user/account');
}
}
// 导出单例
export const userService = new UserService();
export default userService;