已从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 { UserMessage, Message } from '../../share/types.ts';
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
interface MessagesResponse {
|
||||
data: UserMessage[];
|
||||
pagination: {
|
||||
@@ -31,7 +29,7 @@ export const MessageAPI = {
|
||||
search?: string
|
||||
}): Promise<MessagesResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/messages`, { params });
|
||||
const response = await axios.get('/messages', { params });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -45,7 +43,7 @@ export const MessageAPI = {
|
||||
receiver_ids: number[]
|
||||
}): Promise<MessageResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/messages`, data);
|
||||
const response = await axios.post('/messages', data);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -54,7 +52,7 @@ export const MessageAPI = {
|
||||
|
||||
getUnreadCount: async (): Promise<MessageCountResponse> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/messages/count/unread`);
|
||||
const response = await axios.get('/messages/count/unread');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -63,7 +61,7 @@ export const MessageAPI = {
|
||||
|
||||
markAsRead: async (id: number): Promise<MessageResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`);
|
||||
const response = await axios.post(`/messages/${id}/read`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
@@ -72,7 +70,7 @@ export const MessageAPI = {
|
||||
|
||||
deleteMessage: async (id: number): Promise<MessageResponse> => {
|
||||
try {
|
||||
const response = await axios.delete(`${API_BASE_URL}/messages/${id}`);
|
||||
const response = await axios.delete(`/messages/${id}`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user