已从10个API模块文件中移除重复的API_BASE_URL定义
所有API调用现在统一使用client/admin/api/index.ts中的全局axios配置 保持原有功能不变的同时简化了代码结构
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import type { User } from '../../share/types.ts';
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
interface AuthLoginResponse {
|
||||
message: string;
|
||||
token: string;
|
||||
@@ -29,7 +27,7 @@ interface AuthAPIType {
|
||||
export const AuthAPI: AuthAPIType = {
|
||||
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,
|
||||
@@ -43,7 +41,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
|
||||
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;
|
||||
@@ -52,7 +50,7 @@ export const AuthAPI: AuthAPIType = {
|
||||
|
||||
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;
|
||||
@@ -61,7 +59,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;
|
||||
@@ -70,7 +68,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;
|
||||
@@ -79,7 +77,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;
|
||||
@@ -88,7 +86,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;
|
||||
@@ -97,7 +95,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