Files
d8d-admin-mobile-starter-pu…/client/admin/api/messages.ts
yourname e4f45ed952 已从10个API模块文件中移除重复的API_BASE_URL定义
所有API调用现在统一使用client/admin/api/index.ts中的全局axios配置
保持原有功能不变的同时简化了代码结构
2025-05-13 11:44:28 +00:00

79 lines
1.7 KiB
TypeScript

import axios from 'axios';
import type { UserMessage, Message } from '../../share/types.ts';
interface MessagesResponse {
data: UserMessage[];
pagination: {
total: number;
current: number;
pageSize: number;
totalPages: number;
};
}
interface MessageResponse {
data: Message;
message?: string;
}
interface MessageCountResponse {
count: number;
}
export const MessageAPI = {
getMessages: async (params?: {
page?: number,
pageSize?: number,
type?: string,
status?: string,
search?: string
}): Promise<MessagesResponse> => {
try {
const response = await axios.get('/messages', { params });
return response.data;
} catch (error) {
throw error;
}
},
sendMessage: async (data: {
title: string,
content: string,
type: string,
receiver_ids: number[]
}): Promise<MessageResponse> => {
try {
const response = await axios.post('/messages', data);
return response.data;
} catch (error) {
throw error;
}
},
getUnreadCount: async (): Promise<MessageCountResponse> => {
try {
const response = await axios.get('/messages/count/unread');
return response.data;
} catch (error) {
throw error;
}
},
markAsRead: async (id: number): Promise<MessageResponse> => {
try {
const response = await axios.post(`/messages/${id}/read`);
return response.data;
} catch (error) {
throw error;
}
},
deleteMessage: async (id: number): Promise<MessageResponse> => {
try {
const response = await axios.delete(`/messages/${id}`);
return response.data;
} catch (error) {
throw error;
}
}
};