Files
digital-pilates/services/trainingPlanApi.ts
richarjiang dacbee197c feat: 更新训练计划和打卡功能
- 在训练计划中新增训练项目的添加、更新和删除功能,支持用户灵活管理训练内容
- 优化训练计划排课界面,提升用户体验
- 更新打卡功能,支持按日期加载和展示打卡记录
- 删除不再使用的打卡相关页面,简化代码结构
- 新增今日训练页面,集成今日训练计划和动作展示
- 更新样式以适应新功能的展示和交互
2025-08-15 17:01:33 +08:00

84 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { api } from './api';
export interface CreateTrainingPlanDto {
startDate: string;
name?: string;
mode: 'daysOfWeek' | 'sessionsPerWeek';
daysOfWeek: number[];
sessionsPerWeek: number;
goal: string;
startWeightKg?: number;
preferredTimeOfDay?: 'morning' | 'noon' | 'evening' | '';
}
export interface TrainingPlanResponse {
id: string;
userId: string;
name: string;
createdAt: string;
startDate: string;
mode: 'daysOfWeek' | 'sessionsPerWeek';
daysOfWeek: number[];
sessionsPerWeek: number;
goal: string;
startWeightKg: number | null;
preferredTimeOfDay: 'morning' | 'noon' | 'evening' | '';
updatedAt: string;
deleted: boolean;
}
export interface TrainingPlanSummary {
id: string;
createdAt: string;
startDate: string;
goal: string;
mode: 'daysOfWeek' | 'sessionsPerWeek';
daysOfWeek: number[];
sessionsPerWeek: number;
preferredTimeOfDay: 'morning' | 'noon' | 'evening' | '';
startWeightKg: number | null;
}
export interface TrainingPlanListResponse {
list: TrainingPlanSummary[];
total: number;
page: number;
limit: number;
}
class TrainingPlanApi {
async create(dto: CreateTrainingPlanDto): Promise<TrainingPlanResponse> {
return api.post<TrainingPlanResponse>('/training-plans', dto);
}
async list(page: number = 1, limit: number = 10): Promise<TrainingPlanListResponse> {
return api.get<TrainingPlanListResponse>(`/training-plans?page=${page}&limit=${limit}`);
}
async detail(id: string): Promise<TrainingPlanResponse> {
return api.get<TrainingPlanResponse>(`/training-plans/${id}`);
}
async update(id: string, dto: CreateTrainingPlanDto): Promise<TrainingPlanResponse> {
return api.post<TrainingPlanResponse>(`/training-plans/${id}/update`, dto);
}
async delete(id: string): Promise<{ success: boolean }> {
return api.delete<{ success: boolean }>(`/training-plans/${id}`);
}
async activate(id: string): Promise<{ success: boolean }> {
return api.post<{ success: boolean }>(`/training-plans/${id}/activate`);
}
async getActivePlan(): Promise<TrainingPlanResponse | null> {
try {
return api.get<TrainingPlanResponse>('/training-plans/active');
} catch (error) {
// 如果没有激活的计划返回null
return null;
}
}
}
export const trainingPlanApi = new TrainingPlanApi();