client/admin/api/ ├── auth.ts (认证API) ├── users.ts (用户API) ├── files.ts (文件API) ├── theme.ts (主题API) ├── charts.ts (图表API) ├── messages.ts (消息API) ├── sys.ts (系统API) ├── know_info.ts (知识库API) ├── maps.ts (地图API) └── index.ts (统一入口)
81 lines
1.8 KiB
TypeScript
81 lines
1.8 KiB
TypeScript
import axios from 'axios';
|
|
import type { UserMessage, Message } from '../../share/types.ts';
|
|
|
|
const API_BASE_URL = '/api';
|
|
|
|
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(`${API_BASE_URL}/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(`${API_BASE_URL}/messages`, data);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
getUnreadCount: async (): Promise<MessageCountResponse> => {
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/messages/count/unread`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
markAsRead: async (id: number): Promise<MessageResponse> => {
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/messages/${id}/read`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
deleteMessage: async (id: number): Promise<MessageResponse> => {
|
|
try {
|
|
const response = await axios.delete(`${API_BASE_URL}/messages/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}; |