修改范围覆盖mobile/api目录下所有API文件(共9个,包括auth.ts)
统一使用index.ts中的全局axios配置 移除了所有重复的API_BASE_URL定义 简化了所有API调用路径格式 提高了代码一致性和可维护性 确保所有API功能保持正常
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import type { User } from '../../share/types.ts';
|
||||
|
||||
// 从原api.ts导入基础配置
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
// 定义API返回数据类型
|
||||
interface AuthLoginResponse {
|
||||
message: string;
|
||||
@@ -34,7 +31,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 登录API
|
||||
login: async (username: string, password: string, latitude?: number, longitude?: number) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/login`, {
|
||||
const response = await axios.post('/auth/login', {
|
||||
username,
|
||||
password,
|
||||
latitude,
|
||||
@@ -49,7 +46,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 注册API
|
||||
register: async (username: string, email: string, password: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/register`, { username, email, password });
|
||||
const response = await axios.post('/auth/register', { username, email, password });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -59,7 +56,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 登出API
|
||||
logout: async () => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/logout`);
|
||||
const response = await axios.post('/auth/logout');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -69,7 +66,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 获取当前用户信息
|
||||
getCurrentUser: async () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/auth/me`);
|
||||
const response = await axios.get('/auth/me');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -79,7 +76,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 更新用户信息
|
||||
updateUser: async (userId: number, userData: Partial<User>) => {
|
||||
try {
|
||||
const response = await axios.put(`${API_BASE_URL}/auth/users/${userId}`, userData);
|
||||
const response = await axios.put(`/auth/users/${userId}`, userData);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -89,7 +86,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 修改密码
|
||||
changePassword: async (oldPassword: string, newPassword: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/change-password`, { oldPassword, newPassword });
|
||||
const response = await axios.post('/auth/change-password', { oldPassword, newPassword });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -99,7 +96,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 请求重置密码
|
||||
requestPasswordReset: async (email: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/request-password-reset`, { email });
|
||||
const response = await axios.post('/auth/request-password-reset', { email });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -109,7 +106,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
// 重置密码
|
||||
resetPassword: async (token: string, newPassword: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/auth/reset-password`, { token, newPassword });
|
||||
const response = await axios.post('/auth/reset-password', { token, newPassword });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user