初始化工程
This commit is contained in:
134
src/services/demoApi.ts
Normal file
134
src/services/demoApi.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import httpService from './httpService'
|
||||
import type { ApiResponse } from './httpService'
|
||||
|
||||
// 用户信息接口
|
||||
export interface UserProfile {
|
||||
id: string
|
||||
nickname: string
|
||||
avatar?: string
|
||||
age?: number
|
||||
gender: 'male' | 'female'
|
||||
interests: string[]
|
||||
acceptNotification: boolean
|
||||
}
|
||||
|
||||
// 反馈评价接口
|
||||
export interface Feedback {
|
||||
id: string
|
||||
matchId: string
|
||||
userId: string
|
||||
photos: string[]
|
||||
rating: number
|
||||
recommend: 'yes' | 'no' | 'neutral'
|
||||
aspects: string[]
|
||||
comments: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
// DynamicFormDemo页面API服务类
|
||||
class DemoApiService {
|
||||
// ==================== 用户信息相关接口 ====================
|
||||
|
||||
// 获取用户信息
|
||||
async getUserProfile(): Promise<ApiResponse<UserProfile>> {
|
||||
return httpService.get('/user/profile')
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
async updateUserProfile(data: Partial<UserProfile>): Promise<ApiResponse<UserProfile>> {
|
||||
return httpService.put('/user/profile', data, {
|
||||
showLoading: true,
|
||||
loadingText: '保存中...'
|
||||
})
|
||||
}
|
||||
|
||||
// 上传头像
|
||||
async uploadAvatar(filePath: string): Promise<ApiResponse<{ url: string }>> {
|
||||
return httpService.post('/user/avatar', { filePath }, {
|
||||
showLoading: true,
|
||||
loadingText: '上传头像中...'
|
||||
})
|
||||
}
|
||||
|
||||
// ==================== 反馈评价相关接口 ====================
|
||||
|
||||
// 提交活动评价
|
||||
async submitFeedback(data: {
|
||||
matchId: string
|
||||
photos?: string[]
|
||||
rating: number
|
||||
recommend: 'yes' | 'no' | 'neutral'
|
||||
aspects: string[]
|
||||
comments: string
|
||||
}): Promise<ApiResponse<Feedback>> {
|
||||
return httpService.post('/feedback', data, {
|
||||
showLoading: true,
|
||||
loadingText: '提交评价中...'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取我的评价列表
|
||||
async getMyFeedbacks(params?: {
|
||||
page?: number
|
||||
limit?: number
|
||||
}): Promise<ApiResponse<{ list: Feedback[]; total: number }>> {
|
||||
return httpService.get('/feedback/my', params)
|
||||
}
|
||||
|
||||
// 获取活动的所有评价
|
||||
async getMatchFeedbacks(matchId: string, params?: {
|
||||
page?: number
|
||||
limit?: number
|
||||
}): Promise<ApiResponse<{ list: Feedback[]; total: number }>> {
|
||||
return httpService.get(`/feedback/match/${matchId}`, params)
|
||||
}
|
||||
|
||||
// ==================== 通用表单提交接口 ====================
|
||||
|
||||
// 提交表单数据(通用接口)
|
||||
async submitForm(formType: string, formData: any[]): Promise<ApiResponse<any>> {
|
||||
return httpService.post('/forms/submit', {
|
||||
type: formType,
|
||||
data: formData
|
||||
}, {
|
||||
showLoading: true,
|
||||
loadingText: '提交中...'
|
||||
})
|
||||
}
|
||||
|
||||
// 保存表单草稿
|
||||
async saveFormDraft(formType: string, formData: any[]): Promise<ApiResponse<{ id: string }>> {
|
||||
return httpService.post('/forms/draft', {
|
||||
type: formType,
|
||||
data: formData
|
||||
}, {
|
||||
showLoading: true,
|
||||
loadingText: '保存中...'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取表单草稿
|
||||
async getFormDrafts(formType: string): Promise<ApiResponse<{ id: string; data: any[]; createdAt: string }[]>> {
|
||||
return httpService.get('/forms/drafts', { type: formType })
|
||||
}
|
||||
|
||||
// 删除表单草稿
|
||||
async deleteFormDraft(id: string): Promise<ApiResponse<{ success: boolean }>> {
|
||||
return httpService.delete(`/forms/draft/${id}`)
|
||||
}
|
||||
|
||||
// ==================== 兴趣爱好相关接口 ====================
|
||||
|
||||
// 获取兴趣爱好选项
|
||||
async getInterestOptions(): Promise<ApiResponse<{ label: string; value: string }[]>> {
|
||||
return httpService.get('/interests')
|
||||
}
|
||||
|
||||
// 获取推荐的兴趣爱好
|
||||
async getRecommendedInterests(): Promise<ApiResponse<string[]>> {
|
||||
return httpService.get('/interests/recommended')
|
||||
}
|
||||
}
|
||||
|
||||
// 导出API服务实例
|
||||
export default new DemoApiService()
|
||||
Reference in New Issue
Block a user