import request from '@/utils/request' import type { Result } from '@/api/types' // 用户目标接口类型 export interface UserGoal { id: number userId: number goalType: 'task_count' | 'score' | 'rank' | 'rating' goalName: string description?: string targetValue: number currentValue: number period: 'daily' | 'weekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom' periodStart: string periodEnd: string status: 'active' | 'completed' | 'failed' | 'cancelled' completedTime?: string rewardScore: number rewardClaimed: number reminderType: 'none' | 'daily' | 'before_deadline' createTime: string updateTime: string } export interface GoalCreateRequest { goalType: string goalName: string description?: string targetValue: number period: string periodStart?: string periodEnd?: string rewardScore?: number reminderType?: string } // ==================== 目标管理 API ==================== /** * 创建目标 */ export function createGoal(data: GoalCreateRequest): Promise { return request.post>('/goals', data) .then(res => res.data) } /** * 创建预设目标 */ export function createPresetGoal(type: string): Promise { return request.post>(`/goals/preset/${type}`) .then(res => res.data) } /** * 更新目标 */ export function updateGoal(id: number, data: Partial): Promise { return request.put>(`/goals/${id}`, data) .then(res => res.data) } /** * 更新目标进度 */ export function updateGoalProgress(id: number, progressValue: number): Promise { return request.put>(`/goals/${id}/progress`, null, { params: { progressValue } }).then(res => res.data) } /** * 获取我的目标列表 */ export function getMyGoals(status?: string): Promise { return request.get>('/goals/my', { params: { status } }).then(res => res.data) } /** * 获取我的活跃目标 */ export function getMyActiveGoals(): Promise { return request.get>('/goals/my/active') .then(res => res.data) } /** * 获取目标详情 */ export function getGoalById(id: number): Promise { return request.get>(`/goals/${id}`) .then(res => res.data) } /** * 领取目标奖励 */ export function claimGoalReward(id: number): Promise { return request.post>(`/goals/${id}/claim-reward`) .then(res => res.data) } /** * 取消目标 */ export function cancelGoal(id: number): Promise { return request.post>(`/goals/${id}/cancel`) .then(res => res.data) } /** * 删除目标 */ export function deleteGoal(id: number): Promise { return request.delete>(`/goals/${id}`) .then(res => res.data) } // 预设目标类型 export const PRESET_GOAL_TYPES = [ { type: 'weekly_task', name: '本周完成10个任务', description: '在本周内完成10个设计任务', reward: 50 }, { type: 'monthly_task', name: '本月完成40个任务', description: '在本月内完成40个设计任务', reward: 200 }, { type: 'monthly_score', name: '本月获得1000积分', description: '在本月内累计获得1000积分', reward: 100 }, { type: 'top_10', name: '进入排行榜前10', description: '在本月排行榜中进入前10名', reward: 150 }, ]