import { http } from './index'; // ==================== 类型定义 ==================== export interface ChildInfo { id: number; name: string; gender?: string; birthDate?: string; relationship: string; class: { id: number; name: string; grade: string; }; readingCount: number; lessonCount: number; } export interface ChildProfile extends ChildInfo { stats: { lessonRecords: number; growthRecords: number; taskCompletions: number; }; } export interface LessonRecord { id: number; lesson: { id: number; startDatetime: string; endDatetime?: string; actualDuration?: number; course: { id: number; name: string; pictureBookName?: string; }; }; focus?: number; participation?: number; interest?: number; understanding?: number; notes?: string; createdAt: string; } export interface TaskWithCompletion { id: number; status: string; completedAt?: string; feedback?: string; parentFeedback?: string; task: { id: number; title: string; description?: string; taskType: string; startDate: string; endDate: string; course?: { id: number; name: string; }; }; } export interface GrowthRecord { id: number; title: string; content?: string; images: string[]; recordDate: string; recordType: string; class?: { id: number; name: string; }; createdAt: string; } export interface Notification { id: number; title: string; content: string; notificationType: string; isRead: boolean; readAt?: string; createdAt: string; } // ==================== 孩子信息 API ==================== export const getChildren = (): Promise => http.get('/v1/parent/children'); export const getChildProfile = (childId: number): Promise => http.get(`/v1/parent/children/${childId}`); // ==================== 阅读记录 API ==================== export const getChildLessons = ( childId: number, params?: { pageNum?: number; pageSize?: number } ): Promise<{ items: LessonRecord[]; total: number; page: number; pageSize: number }> => http.get(`/v1/parent/children/${childId}/lessons`, { params }); // ==================== 任务 API ==================== export const getChildTasks = ( childId: number, params?: { pageNum?: number; pageSize?: number; status?: string } ): Promise<{ items: TaskWithCompletion[]; total: number; page: number; pageSize: number }> => http.get<{ list: TaskWithCompletion[]; total: number; pageNum: number; pageSize: number }>(`/v1/parent/tasks/student/${childId}`, { params }) .then(res => ({ items: res.list || [], total: res.total || 0, page: res.pageNum || 1, pageSize: res.pageSize || 10, })); export const submitTaskFeedback = ( childId: number, taskId: number, feedback: string ): Promise => http.post(`/v1/parent/tasks/${taskId}/complete`, { studentId: childId, content: feedback, }); // ==================== 成长档案 API ==================== export const getChildGrowthRecords = ( childId: number, params?: { pageNum?: number; pageSize?: number } ): Promise<{ items: GrowthRecord[]; total: number; page: number; pageSize: number }> => http.get<{ list: GrowthRecord[]; total: number; pageNum: number; pageSize: number }>(`/v1/parent/growth-records/student/${childId}`, { params }) .then(res => ({ items: res.list || [], total: res.total || 0, page: res.pageNum || 1, pageSize: res.pageSize || 10, })); // ==================== 通知 API ==================== export const getNotifications = ( params?: { pageNum?: number; pageSize?: number; isRead?: boolean; notificationType?: string } ): Promise<{ items: Notification[]; total: number; unreadCount: number; page: number; pageSize: number; }> => http.get<{ list: Notification[]; total: number; pageNum: number; pageSize: number }>('/v1/parent/notifications', { params }) .then(res => ({ items: res.list || [], total: res.total || 0, unreadCount: 0, page: res.pageNum || 1, pageSize: res.pageSize || 10, })); export const getUnreadCount = (): Promise => http.get('/v1/parent/notifications/unread-count').then(res => res || 0); export const markNotificationAsRead = (id: number): Promise => http.post(`/v1/parent/notifications/${id}/read`); export const markAllNotificationsAsRead = (): Promise => http.post('/v1/parent/notifications/read-all');