128 lines
3.4 KiB
TypeScript
128 lines
3.4 KiB
TypeScript
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<UserGoal> {
|
|
return request.post<Result<UserGoal>>('/goals', data)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 创建预设目标
|
|
*/
|
|
export function createPresetGoal(type: string): Promise<UserGoal> {
|
|
return request.post<Result<UserGoal>>(`/goals/preset/${type}`)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 更新目标
|
|
*/
|
|
export function updateGoal(id: number, data: Partial<GoalCreateRequest>): Promise<UserGoal> {
|
|
return request.put<Result<UserGoal>>(`/goals/${id}`, data)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 更新目标进度
|
|
*/
|
|
export function updateGoalProgress(id: number, progressValue: number): Promise<UserGoal> {
|
|
return request.put<Result<UserGoal>>(`/goals/${id}/progress`, null, {
|
|
params: { progressValue }
|
|
}).then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 获取我的目标列表
|
|
*/
|
|
export function getMyGoals(status?: string): Promise<UserGoal[]> {
|
|
return request.get<Result<UserGoal[]>>('/goals/my', {
|
|
params: { status }
|
|
}).then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 获取我的活跃目标
|
|
*/
|
|
export function getMyActiveGoals(): Promise<UserGoal[]> {
|
|
return request.get<Result<UserGoal[]>>('/goals/my/active')
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 获取目标详情
|
|
*/
|
|
export function getGoalById(id: number): Promise<UserGoal> {
|
|
return request.get<Result<UserGoal>>(`/goals/${id}`)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 领取目标奖励
|
|
*/
|
|
export function claimGoalReward(id: number): Promise<boolean> {
|
|
return request.post<Result<boolean>>(`/goals/${id}/claim-reward`)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 取消目标
|
|
*/
|
|
export function cancelGoal(id: number): Promise<void> {
|
|
return request.post<Result<void>>(`/goals/${id}/cancel`)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
/**
|
|
* 删除目标
|
|
*/
|
|
export function deleteGoal(id: number): Promise<void> {
|
|
return request.delete<Result<void>>(`/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 },
|
|
]
|