web-apis\types
This commit is contained in:
339
schoolNewsWeb/src/apis/usercenter/index.ts
Normal file
339
schoolNewsWeb/src/apis/usercenter/index.ts
Normal file
@@ -0,0 +1,339 @@
|
||||
/**
|
||||
* @description 用户中心相关API
|
||||
* @author system
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type {
|
||||
UserCollection,
|
||||
UserBrowseRecord,
|
||||
UserPoints,
|
||||
PointsRecord,
|
||||
UserAchievement,
|
||||
Achievement,
|
||||
UserCenterStatistics,
|
||||
LearningChartData,
|
||||
ResourceLearningStats,
|
||||
ResultDomain
|
||||
} from '@/types';
|
||||
|
||||
/**
|
||||
* 用户收藏API服务
|
||||
*/
|
||||
export const userCollectionApi = {
|
||||
/**
|
||||
* 获取用户收藏列表
|
||||
* @param userID 用户ID
|
||||
* @param collectionType 收藏类型
|
||||
* @returns Promise<ResultDomain<UserCollection>>
|
||||
*/
|
||||
async getUserCollections(userID: string, collectionType?: number): Promise<ResultDomain<UserCollection>> {
|
||||
const response = await api.get<UserCollection>('/usercenter/collection/list', {
|
||||
userID,
|
||||
collectionType
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
* @param collection 收藏数据
|
||||
* @returns Promise<ResultDomain<UserCollection>>
|
||||
*/
|
||||
async addCollection(collection: UserCollection): Promise<ResultDomain<UserCollection>> {
|
||||
const response = await api.post<UserCollection>('/usercenter/collection/add', collection);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 取消收藏
|
||||
* @param userID 用户ID
|
||||
* @param collectionType 收藏类型
|
||||
* @param collectionID 收藏对象ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async removeCollection(userID: string, collectionType: number, collectionID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>('/usercenter/collection/remove', {
|
||||
userID,
|
||||
collectionType,
|
||||
collectionID
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查是否已收藏
|
||||
* @param userID 用户ID
|
||||
* @param collectionType 收藏类型
|
||||
* @param collectionID 收藏对象ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async isCollected(userID: string, collectionType: number, collectionID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.get<boolean>('/usercenter/collection/check', {
|
||||
userID,
|
||||
collectionType,
|
||||
collectionID
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 用户浏览记录API服务
|
||||
*/
|
||||
export const userBrowseRecordApi = {
|
||||
/**
|
||||
* 获取用户浏览记录
|
||||
* @param userID 用户ID
|
||||
* @param browseType 浏览类型
|
||||
* @returns Promise<ResultDomain<UserBrowseRecord>>
|
||||
*/
|
||||
async getUserBrowseRecords(userID: string, browseType?: number): Promise<ResultDomain<UserBrowseRecord>> {
|
||||
const response = await api.get<UserBrowseRecord>('/usercenter/browse-record/list', {
|
||||
userID,
|
||||
browseType
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 添加浏览记录
|
||||
* @param record 浏览记录数据
|
||||
* @returns Promise<ResultDomain<UserBrowseRecord>>
|
||||
*/
|
||||
async addBrowseRecord(record: UserBrowseRecord): Promise<ResultDomain<UserBrowseRecord>> {
|
||||
const response = await api.post<UserBrowseRecord>('/usercenter/browse-record/add', record);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空浏览记录
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async clearBrowseRecords(userID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.post<boolean>('/usercenter/browse-record/clear', { userID });
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 用户积分API服务
|
||||
*/
|
||||
export const userPointsApi = {
|
||||
/**
|
||||
* 获取用户积分信息
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<UserPoints>>
|
||||
*/
|
||||
async getUserPoints(userID: string): Promise<ResultDomain<UserPoints>> {
|
||||
const response = await api.get<UserPoints>('/usercenter/points/info', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户积分记录
|
||||
* @param userID 用户ID
|
||||
* @param type 积分类型
|
||||
* @returns Promise<ResultDomain<PointsRecord>>
|
||||
*/
|
||||
async getUserPointsRecords(userID: string, type?: number): Promise<ResultDomain<PointsRecord>> {
|
||||
const response = await api.get<PointsRecord>('/usercenter/points/records', {
|
||||
userID,
|
||||
type
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 消费积分
|
||||
* @param userID 用户ID
|
||||
* @param points 积分数量
|
||||
* @param reason 消费原因
|
||||
* @param relatedID 关联对象ID
|
||||
* @param relatedType 关联对象类型
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async consumePoints(
|
||||
userID: string,
|
||||
points: number,
|
||||
reason: string,
|
||||
relatedID?: string,
|
||||
relatedType?: number
|
||||
): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.post<boolean>('/usercenter/points/consume', {
|
||||
userID,
|
||||
points,
|
||||
reason,
|
||||
relatedID,
|
||||
relatedType
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 用户成就API服务
|
||||
*/
|
||||
export const userAchievementApi = {
|
||||
/**
|
||||
* 获取用户成就列表
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<UserAchievement>>
|
||||
*/
|
||||
async getUserAchievements(userID: string): Promise<ResultDomain<UserAchievement>> {
|
||||
const response = await api.get<UserAchievement>('/usercenter/achievement/user-list', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取所有成就列表
|
||||
* @returns Promise<ResultDomain<Achievement>>
|
||||
*/
|
||||
async getAllAchievements(): Promise<ResultDomain<Achievement>> {
|
||||
const response = await api.get<Achievement>('/usercenter/achievement/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查用户成就进度
|
||||
* @param userID 用户ID
|
||||
* @param achievementID 成就ID
|
||||
* @returns Promise<ResultDomain<{ progress: number; isCompleted: boolean }>>
|
||||
*/
|
||||
async checkAchievementProgress(userID: string, achievementID: string): Promise<ResultDomain<{ progress: number; isCompleted: boolean }>> {
|
||||
const response = await api.get<{ progress: number; isCompleted: boolean }>('/usercenter/achievement/progress', {
|
||||
userID,
|
||||
achievementID
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 个人中心API服务
|
||||
*/
|
||||
export const userProfileApi = {
|
||||
/**
|
||||
* 获取个人信息
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getUserProfile(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/usercenter/profile/info');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新个人信息
|
||||
* @param userInfo 用户信息
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async updateUserProfile(userInfo: any): Promise<ResultDomain<any>> {
|
||||
const response = await api.put<any>('/usercenter/profile/info/update', userInfo);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
* @param file 头像文件
|
||||
* @returns Promise<ResultDomain<string>>
|
||||
*/
|
||||
async uploadAvatar(file: File): Promise<ResultDomain<string>> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await api.upload<string>('/usercenter/profile/avatar/upload', formData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新用户头像
|
||||
* @param avatarUrl 头像URL
|
||||
* @returns Promise<ResultDomain<string>>
|
||||
*/
|
||||
async updateAvatar(avatarUrl: string): Promise<ResultDomain<string>> {
|
||||
const response = await api.put<string>('/usercenter/profile/avatar/update', null, {
|
||||
params: { avatarUrl }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param oldPassword 旧密码
|
||||
* @param newPassword 新密码
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async changePassword(oldPassword: string, newPassword: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/usercenter/profile/password/change', {
|
||||
oldPassword,
|
||||
newPassword
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
* @param phone 手机号
|
||||
* @param code 验证码
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async bindPhone(phone: string, code: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/usercenter/profile/phone/bind', {
|
||||
phone,
|
||||
code
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 绑定邮箱
|
||||
* @param email 邮箱
|
||||
* @param code 验证码
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async bindEmail(email: string, code: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/usercenter/profile/email/bind', {
|
||||
email,
|
||||
code
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取学习记录统计
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<UserCenterStatistics>>
|
||||
*/
|
||||
async getLearningStatistics(timeRange?: string): Promise<ResultDomain<UserCenterStatistics>> {
|
||||
const response = await api.get<UserCenterStatistics>('/usercenter/profile/learning/statistics', {
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取学习时长图表数据
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<LearningChartData>>
|
||||
*/
|
||||
async getLearningDurationChart(timeRange?: string): Promise<ResultDomain<LearningChartData>> {
|
||||
const response = await api.get<LearningChartData>('/usercenter/profile/learning/duration-chart', {
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取资源学习次数图表数据
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<ResourceLearningStats>>
|
||||
*/
|
||||
async getResourceLearningChart(timeRange?: string): Promise<ResultDomain<ResourceLearningStats>> {
|
||||
const response = await api.get<ResourceLearningStats>('/usercenter/profile/learning/resource-chart', {
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user