feat: 更新个人信息和打卡功能
- 在个人信息页面中修改用户姓名字段为“name”,并添加注销帐号功能,支持用户删除帐号及相关数据 - 在打卡页面中集成从后端获取当天打卡列表的功能,确保用户数据的实时同步 - 更新 Redux 状态管理,支持打卡记录的同步和更新 - 新增打卡服务,提供创建、更新和删除打卡记录的 API 接口 - 优化样式以适应新功能的展示和交互
This commit is contained in:
58
services/checkins.ts
Normal file
58
services/checkins.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { api } from '@/services/api';
|
||||
|
||||
export type CheckinMetrics = Record<string, any>;
|
||||
|
||||
export type CreateCheckinDto = {
|
||||
workoutId?: string;
|
||||
planId?: string;
|
||||
title?: string;
|
||||
checkinDate?: string; // YYYY-MM-DD
|
||||
startedAt?: string; // ISO
|
||||
notes?: string;
|
||||
metrics?: CheckinMetrics;
|
||||
};
|
||||
|
||||
export type UpdateCheckinDto = Partial<CreateCheckinDto> & {
|
||||
id: string;
|
||||
status?: string; // 由后端验证为 CheckinStatus
|
||||
completedAt?: string; // ISO
|
||||
durationSeconds?: number;
|
||||
};
|
||||
|
||||
export type CompleteCheckinDto = {
|
||||
id: string;
|
||||
completedAt?: string; // ISO
|
||||
durationSeconds?: number;
|
||||
notes?: string;
|
||||
metrics?: CheckinMetrics;
|
||||
};
|
||||
|
||||
export type RemoveCheckinDto = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
export async function createCheckin(dto: CreateCheckinDto): Promise<{ id: string } & Record<string, any>> {
|
||||
return await api.post('/api/checkins/create', dto);
|
||||
}
|
||||
|
||||
export async function updateCheckin(dto: UpdateCheckinDto): Promise<{ id: string } & Record<string, any>> {
|
||||
return await api.put('/api/checkins/update', dto);
|
||||
}
|
||||
|
||||
export async function completeCheckin(dto: CompleteCheckinDto): Promise<{ id: string } & Record<string, any>> {
|
||||
return await api.post('/api/checkins/complete', dto);
|
||||
}
|
||||
|
||||
export async function removeCheckin(dto: RemoveCheckinDto): Promise<boolean | Record<string, any>> {
|
||||
return await api.delete('/api/checkins/remove', { body: dto });
|
||||
}
|
||||
|
||||
// 按天获取打卡列表(后端默认今天,不传 date 也可)
|
||||
export async function fetchDailyCheckins(date?: string): Promise<any[]> {
|
||||
const path = date ? `/api/checkins/daily?date=${encodeURIComponent(date)}` : '/api/checkins/daily';
|
||||
const data = await api.get<any[]>(path);
|
||||
// 返回值兼容 { data: T } 或直接 T 已由 api 封装处理
|
||||
return Array.isArray(data) ? data : [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user