web-文件接口
This commit is contained in:
32
schoolNewsWeb/src/apis/ai/agent-config.ts
Normal file
32
schoolNewsWeb/src/apis/ai/agent-config.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @description 智能体配置相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { AiAgentConfig, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 智能体配置API服务
|
||||
*/
|
||||
export const aiAgentConfigApi = {
|
||||
/**
|
||||
* 获取智能体配置
|
||||
* @returns Promise<ResultDomain<AiAgentConfig>>
|
||||
*/
|
||||
async getAgentConfig(): Promise<ResultDomain<AiAgentConfig>> {
|
||||
const response = await api.get<AiAgentConfig>('/ai/agent-config');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新智能体配置
|
||||
* @param config 配置数据
|
||||
* @returns Promise<ResultDomain<AiAgentConfig>>
|
||||
*/
|
||||
async updateAgentConfig(config: AiAgentConfig): Promise<ResultDomain<AiAgentConfig>> {
|
||||
const response = await api.put<AiAgentConfig>('/ai/agent-config', config);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
53
schoolNewsWeb/src/apis/ai/conversation.ts
Normal file
53
schoolNewsWeb/src/apis/ai/conversation.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @description 对话相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { AiConversation, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 对话API服务
|
||||
*/
|
||||
export const conversationApi = {
|
||||
/**
|
||||
* 获取用户对话列表
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<AiConversation>>
|
||||
*/
|
||||
async getConversationList(userID: string): Promise<ResultDomain<AiConversation>> {
|
||||
const response = await api.get<AiConversation>('/ai/conversation/list', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建对话
|
||||
* @param conversation 对话数据
|
||||
* @returns Promise<ResultDomain<AiConversation>>
|
||||
*/
|
||||
async createConversation(conversation: AiConversation): Promise<ResultDomain<AiConversation>> {
|
||||
const response = await api.post<AiConversation>('/ai/conversation/create', conversation);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除对话
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteConversation(conversationID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/conversation/${conversationID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空对话记录
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async clearConversation(conversationID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.post<boolean>(`/ai/conversation/${conversationID}/clear`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
48
schoolNewsWeb/src/apis/ai/file-upload.ts
Normal file
48
schoolNewsWeb/src/apis/ai/file-upload.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @description 文件上传相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { AiUploadFile, FileUploadResponse, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 文件上传API服务
|
||||
*/
|
||||
export const fileUploadApi = {
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file 文件
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<FileUploadResponse>>
|
||||
*/
|
||||
async uploadFile(file: File, userID: string): Promise<ResultDomain<FileUploadResponse>> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('userID', userID);
|
||||
|
||||
const response = await api.upload<FileUploadResponse>('/ai/file/upload', formData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取上传文件列表
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<AiUploadFile>>
|
||||
*/
|
||||
async getUploadFileList(userID: string): Promise<ResultDomain<AiUploadFile>> {
|
||||
const response = await api.get<AiUploadFile>('/ai/file/list', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除上传文件
|
||||
* @param fileID 文件ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteUploadFile(fileID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/file/${fileID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
@@ -1,236 +1,12 @@
|
||||
/**
|
||||
* @description 智能体相关API
|
||||
* @author system
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type {
|
||||
AiAgentConfig,
|
||||
AiConversation,
|
||||
AiMessage,
|
||||
AiKnowledge,
|
||||
AiUploadFile,
|
||||
ChatRequest,
|
||||
ChatResponse,
|
||||
FileUploadResponse,
|
||||
ResultDomain
|
||||
} from '@/types';
|
||||
|
||||
/**
|
||||
* 智能体配置API服务
|
||||
*/
|
||||
export const aiAgentConfigApi = {
|
||||
/**
|
||||
* 获取智能体配置
|
||||
* @returns Promise<ResultDomain<AiAgentConfig>>
|
||||
*/
|
||||
async getAgentConfig(): Promise<ResultDomain<AiAgentConfig>> {
|
||||
const response = await api.get<AiAgentConfig>('/ai/agent-config');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新智能体配置
|
||||
* @param config 配置数据
|
||||
* @returns Promise<ResultDomain<AiAgentConfig>>
|
||||
*/
|
||||
async updateAgentConfig(config: AiAgentConfig): Promise<ResultDomain<AiAgentConfig>> {
|
||||
const response = await api.put<AiAgentConfig>('/ai/agent-config', config);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 对话API服务
|
||||
*/
|
||||
export const conversationApi = {
|
||||
/**
|
||||
* 获取用户对话列表
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<AiConversation>>
|
||||
*/
|
||||
async getConversationList(userID: string): Promise<ResultDomain<AiConversation>> {
|
||||
const response = await api.get<AiConversation>('/ai/conversation/list', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建对话
|
||||
* @param conversation 对话数据
|
||||
* @returns Promise<ResultDomain<AiConversation>>
|
||||
*/
|
||||
async createConversation(conversation: AiConversation): Promise<ResultDomain<AiConversation>> {
|
||||
const response = await api.post<AiConversation>('/ai/conversation/create', conversation);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除对话
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteConversation(conversationID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/conversation/${conversationID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空对话记录
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async clearConversation(conversationID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.post<boolean>(`/ai/conversation/${conversationID}/clear`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 消息API服务
|
||||
*/
|
||||
export const messageApi = {
|
||||
/**
|
||||
* 获取对话消息列表
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<AiMessage>>
|
||||
*/
|
||||
async getMessageList(conversationID: string): Promise<ResultDomain<AiMessage>> {
|
||||
const response = await api.get<AiMessage>(`/ai/message/list`, { conversationID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param request 消息请求
|
||||
* @returns Promise<ResultDomain<ChatResponse>>
|
||||
*/
|
||||
async sendMessage(request: ChatRequest): Promise<ResultDomain<ChatResponse>> {
|
||||
const response = await api.post<ChatResponse>('/ai/message/send', request);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 流式发送消息
|
||||
* @param request 消息请求
|
||||
* @param onMessage 消息回调
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
// async sendMessageStream(request: ChatRequest, onMessage: (message: string) => void): Promise<void> {
|
||||
// const response = await api.post('/ai/message/stream', { ...request, stream: true }, {
|
||||
// responseType: 'stream'
|
||||
// });
|
||||
|
||||
// // 处理流式响应
|
||||
// const reader = response.data.getReader();
|
||||
// const decoder = new TextDecoder();
|
||||
// let done = false;
|
||||
|
||||
// while (!done) {
|
||||
// const readResult = await reader.read();
|
||||
// done = readResult.done;
|
||||
// if (done) break;
|
||||
|
||||
// const chunk = decoder.decode(readResult.value);
|
||||
// const lines = chunk.split('\n');
|
||||
|
||||
// for (const line of lines) {
|
||||
// if (line.startsWith('data: ')) {
|
||||
// const data = line.slice(6);
|
||||
// if (data === '[DONE]') return;
|
||||
|
||||
// try {
|
||||
// const parsed = JSON.parse(data);
|
||||
// onMessage(parsed.content || '');
|
||||
// } catch (e) {
|
||||
// console.error('解析流式数据失败:', e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
};
|
||||
|
||||
/**
|
||||
* 知识库API服务
|
||||
*/
|
||||
export const knowledgeApi = {
|
||||
/**
|
||||
* 获取知识库列表
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async getKnowledgeList(): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.get<AiKnowledge>('/ai/knowledge/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建知识库条目
|
||||
* @param knowledge 知识库数据
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async createKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.post<AiKnowledge>('/ai/knowledge/create', knowledge);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新知识库条目
|
||||
* @param knowledge 知识库数据
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async updateKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.put<AiKnowledge>('/ai/knowledge/update', knowledge);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除知识库条目
|
||||
* @param knowledgeID 知识库ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteKnowledge(knowledgeID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/knowledge/${knowledgeID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 文件上传API服务
|
||||
*/
|
||||
export const fileUploadApi = {
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file 文件
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<FileUploadResponse>>
|
||||
*/
|
||||
async uploadFile(file: File, userID: string): Promise<ResultDomain<FileUploadResponse>> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('userID', userID);
|
||||
|
||||
const response = await api.upload<FileUploadResponse>('/ai/file/upload', formData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取上传文件列表
|
||||
* @param userID 用户ID
|
||||
* @returns Promise<ResultDomain<AiUploadFile>>
|
||||
*/
|
||||
async getUploadFileList(userID: string): Promise<ResultDomain<AiUploadFile>> {
|
||||
const response = await api.get<AiUploadFile>('/ai/file/list', { userID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除上传文件
|
||||
* @param fileID 文件ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteUploadFile(fileID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/file/${fileID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
// 重新导出各个子模块
|
||||
export { aiAgentConfigApi } from './agent-config';
|
||||
export { conversationApi } from './conversation';
|
||||
export { messageApi } from './message';
|
||||
export { knowledgeApi } from './knowledge';
|
||||
export { fileUploadApi } from './file-upload';
|
||||
|
||||
52
schoolNewsWeb/src/apis/ai/knowledge.ts
Normal file
52
schoolNewsWeb/src/apis/ai/knowledge.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @description 知识库相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { AiKnowledge, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 知识库API服务
|
||||
*/
|
||||
export const knowledgeApi = {
|
||||
/**
|
||||
* 获取知识库列表
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async getKnowledgeList(): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.get<AiKnowledge>('/ai/knowledge/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建知识库条目
|
||||
* @param knowledge 知识库数据
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async createKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.post<AiKnowledge>('/ai/knowledge/create', knowledge);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新知识库条目
|
||||
* @param knowledge 知识库数据
|
||||
* @returns Promise<ResultDomain<AiKnowledge>>
|
||||
*/
|
||||
async updateKnowledge(knowledge: AiKnowledge): Promise<ResultDomain<AiKnowledge>> {
|
||||
const response = await api.put<AiKnowledge>('/ai/knowledge/update', knowledge);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除知识库条目
|
||||
* @param knowledgeID 知识库ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteKnowledge(knowledgeID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/knowledge/${knowledgeID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
73
schoolNewsWeb/src/apis/ai/message.ts
Normal file
73
schoolNewsWeb/src/apis/ai/message.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @description 消息相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { AiMessage, ChatRequest, ChatResponse, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 消息API服务
|
||||
*/
|
||||
export const messageApi = {
|
||||
/**
|
||||
* 获取对话消息列表
|
||||
* @param conversationID 对话ID
|
||||
* @returns Promise<ResultDomain<AiMessage>>
|
||||
*/
|
||||
async getMessageList(conversationID: string): Promise<ResultDomain<AiMessage>> {
|
||||
const response = await api.get<AiMessage>(`/ai/message/list`, { conversationID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param request 消息请求
|
||||
* @returns Promise<ResultDomain<ChatResponse>>
|
||||
*/
|
||||
async sendMessage(request: ChatRequest): Promise<ResultDomain<ChatResponse>> {
|
||||
const response = await api.post<ChatResponse>('/ai/message/send', request);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 流式发送消息
|
||||
* @param request 消息请求
|
||||
* @param onMessage 消息回调
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
// async sendMessageStream(request: ChatRequest, onMessage: (message: string) => void): Promise<void> {
|
||||
// const response = await api.post('/ai/message/stream', { ...request, stream: true }, {
|
||||
// responseType: 'stream'
|
||||
// });
|
||||
|
||||
// // 处理流式响应
|
||||
// const reader = response.data.getReader();
|
||||
// const decoder = new TextDecoder();
|
||||
// let done = false;
|
||||
|
||||
// while (!done) {
|
||||
// const readResult = await reader.read();
|
||||
// done = readResult.done;
|
||||
// if (done) break;
|
||||
|
||||
// const chunk = decoder.decode(readResult.value);
|
||||
// const lines = chunk.split('\n');
|
||||
|
||||
// for (const line of lines) {
|
||||
// if (line.startsWith('data: ')) {
|
||||
// const data = line.slice(6);
|
||||
// if (data === '[DONE]') return;
|
||||
|
||||
// try {
|
||||
// const parsed = JSON.parse(data);
|
||||
// onMessage(parsed.content || '');
|
||||
// } catch (e) {
|
||||
// console.error('解析流式数据失败:', e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
};
|
||||
41
schoolNewsWeb/src/apis/homepage/banner.ts
Normal file
41
schoolNewsWeb/src/apis/homepage/banner.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @description 轮播图相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Banner, Resource, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 轮播图API服务
|
||||
*/
|
||||
export const bannerApi = {
|
||||
/**
|
||||
* 获取轮播组件数据
|
||||
* @returns Promise<ResultDomain<Banner>>
|
||||
*/
|
||||
async getBannerList(): Promise<ResultDomain<Banner>> {
|
||||
const response = await api.get<Banner>('/homepage/banner/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击轮播跳转新闻详情
|
||||
* @param bannerID Banner ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getBannerNewsDetail(bannerID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>(`/homepage/banner/click/${bannerID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取活跃轮播列表
|
||||
* @returns Promise<ResultDomain<Banner>>
|
||||
*/
|
||||
async getActiveBanners(): Promise<ResultDomain<Banner>> {
|
||||
const response = await api.get<Banner>('/homepage/banner/active');
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
@@ -1,208 +1,13 @@
|
||||
/**
|
||||
* @description 首页相关API
|
||||
* @author system
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Resource, Banner, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 首页API服务
|
||||
*/
|
||||
export const homepageApi = {
|
||||
/**
|
||||
* 获取轮播组件数据
|
||||
* @returns Promise<ResultDomain<Banner>>
|
||||
*/
|
||||
async getBannerList(): Promise<ResultDomain<Banner>> {
|
||||
const response = await api.get<Banner>('/homepage/banner/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击轮播跳转新闻详情
|
||||
* @param bannerID Banner ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getBannerNewsDetail(bannerID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>(`/homepage/banner/click/${bannerID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取活跃轮播列表
|
||||
* @returns Promise<ResultDomain<Banner>>
|
||||
*/
|
||||
async getActiveBanners(): Promise<ResultDomain<Banner>> {
|
||||
const response = await api.get<Banner>('/homepage/banner/active');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取TOP资源推荐列表
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getTopRecommendList(): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/recommend/top-list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台调控展示顺序
|
||||
* @param orderData 排序数据
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async updateRecommendOrder(orderData: any): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/homepage/recommend/order', orderData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取高热度新闻
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getHotNews(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/recommend/hot-news', { limit });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取思政新闻概览
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getNewsOverview(pageNum?: number, pageSize?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/news/overview', {
|
||||
pageNum,
|
||||
pageSize
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击跳转二级详情页
|
||||
* @param newsID 新闻ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getNewsDetail(newsID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>(`/homepage/news/detail/${newsID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取最新思政新闻
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getLatestNews(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/news/latest', { limit });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取顶部菜单栏配置
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTopMenuConfig(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/menu/top-menu');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台修改菜单名称
|
||||
* @param menuData 菜单数据
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async updateMenuName(menuData: any): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/homepage/menu/update-name', menuData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取菜单项列表
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getMenuList(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/menu/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 模糊检索资源
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async searchResources(keyword: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/search', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 实时搜索建议
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getSearchSuggestions(keyword: string): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/suggestions', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取热门搜索词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getHotKeywords(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/hot-keywords');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索新闻
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async searchNews(keyword: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/search/news', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索课程
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async searchCourses(keyword: string): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/courses', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取首页统计数据
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getHomePageStatistics(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取今日访问量
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTodayVisits(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics/today-visits');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取资源总数
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTotalResources(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics/total-resources');
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
// 重新导出各个子模块
|
||||
export { bannerApi } from './banner';
|
||||
export { recommendApi } from './recommend';
|
||||
export { newsApi } from './news';
|
||||
export { menuApi } from './menu';
|
||||
export { searchApi } from './search';
|
||||
export { statisticsApi } from './statistics';
|
||||
|
||||
41
schoolNewsWeb/src/apis/homepage/menu.ts
Normal file
41
schoolNewsWeb/src/apis/homepage/menu.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @description 菜单相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 菜单API服务
|
||||
*/
|
||||
export const menuApi = {
|
||||
/**
|
||||
* 获取顶部菜单栏配置
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTopMenuConfig(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/menu/top-menu');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台修改菜单名称
|
||||
* @param menuData 菜单数据
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async updateMenuName(menuData: any): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/homepage/menu/update-name', menuData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取菜单项列表
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getMenuList(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/menu/list');
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
47
schoolNewsWeb/src/apis/homepage/news.ts
Normal file
47
schoolNewsWeb/src/apis/homepage/news.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @description 新闻相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Resource, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 新闻API服务
|
||||
*/
|
||||
export const newsApi = {
|
||||
/**
|
||||
* 获取思政新闻概览
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页条数
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getNewsOverview(pageNum?: number, pageSize?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/news/overview', {
|
||||
pageNum,
|
||||
pageSize
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 点击跳转二级详情页
|
||||
* @param newsID 新闻ID
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getNewsDetail(newsID: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>(`/homepage/news/detail/${newsID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取最新思政新闻
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getLatestNews(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/news/latest', { limit });
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
42
schoolNewsWeb/src/apis/homepage/recommend.ts
Normal file
42
schoolNewsWeb/src/apis/homepage/recommend.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @description 推荐相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Resource, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 推荐API服务
|
||||
*/
|
||||
export const recommendApi = {
|
||||
/**
|
||||
* 获取TOP资源推荐列表
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getTopRecommendList(): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/recommend/top-list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台调控展示顺序
|
||||
* @param orderData 排序数据
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async updateRecommendOrder(orderData: any): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.put<boolean>('/homepage/recommend/order', orderData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取高热度新闻
|
||||
* @param limit 限制数量
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async getHotNews(limit?: number): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/recommend/hot-news', { limit });
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
62
schoolNewsWeb/src/apis/homepage/search.ts
Normal file
62
schoolNewsWeb/src/apis/homepage/search.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @description 搜索相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Resource, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 搜索API服务
|
||||
*/
|
||||
export const searchApi = {
|
||||
/**
|
||||
* 模糊检索资源
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async searchResources(keyword: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/search', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 实时搜索建议
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getSearchSuggestions(keyword: string): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/suggestions', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取热门搜索词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getHotKeywords(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/hot-keywords');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索新闻
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<Resource>>
|
||||
*/
|
||||
async searchNews(keyword: string): Promise<ResultDomain<Resource>> {
|
||||
const response = await api.get<Resource>('/homepage/search/news', { keyword });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 搜索课程
|
||||
* @param keyword 关键词
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async searchCourses(keyword: string): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/search/courses', { keyword });
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
40
schoolNewsWeb/src/apis/homepage/statistics.ts
Normal file
40
schoolNewsWeb/src/apis/homepage/statistics.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @description 统计相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 统计API服务
|
||||
*/
|
||||
export const statisticsApi = {
|
||||
/**
|
||||
* 获取首页统计数据
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getHomePageStatistics(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取今日访问量
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTodayVisits(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics/today-visits');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取资源总数
|
||||
* @returns Promise<ResultDomain<any>>
|
||||
*/
|
||||
async getTotalResources(): Promise<ResultDomain<any>> {
|
||||
const response = await api.get<any>('/homepage/statistics/total-resources');
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
159
schoolNewsWeb/src/apis/study/course.ts
Normal file
159
schoolNewsWeb/src/apis/study/course.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
/**
|
||||
* @description 课程相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { Course, CourseChapter, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 课程API服务
|
||||
*/
|
||||
export const courseApi = {
|
||||
/**
|
||||
* 获取课程列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async getCourseList(filter?: Partial<Course>): Promise<ResultDomain<Course>> {
|
||||
const response = await api.get<Course>('/study/course/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取课程详情
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async getCourseById(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.get<Course>(`/study/course/${courseID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建课程
|
||||
* @param course 课程数据
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async createCourse(course: Course): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>('/study/course/create', course);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程
|
||||
* @param course 课程数据
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async updateCourse(course: Course): Promise<ResultDomain<Course>> {
|
||||
const response = await api.put<Course>('/study/course/update', course);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除课程
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteCourse(courseID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/course/${courseID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程状态
|
||||
* @param courseID 课程ID
|
||||
* @param status 状态
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async updateCourseStatus(courseID: string, status: number): Promise<ResultDomain<Course>> {
|
||||
const response = await api.put<Course>(`/study/course/${courseID}/status`, null, {
|
||||
params: { status }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加课程浏览次数
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async incrementViewCount(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>(`/study/course/${courseID}/view`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加课程学习人数
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async incrementLearnCount(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>(`/study/course/${courseID}/learn`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取课程章节列表
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async getCourseChapters(courseID: string): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.get<CourseChapter>(`/study/course/${courseID}/chapters`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取章节详情
|
||||
* @param chapterID 章节ID
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async getChapterById(chapterID: string): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.get<CourseChapter>(`/study/course/chapter/${chapterID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建课程章节
|
||||
* @param chapter 章节数据
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async createChapter(chapter: CourseChapter): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.post<CourseChapter>('/study/course/chapter/create', chapter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程章节
|
||||
* @param chapter 章节数据
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async updateChapter(chapter: CourseChapter): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.put<CourseChapter>('/study/course/chapter/update', chapter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除课程章节
|
||||
* @param chapterID 章节ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteChapter(chapterID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/course/chapter/${chapterID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新章节排序
|
||||
* @param chapterID 章节ID
|
||||
* @param orderNum 排序号
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async updateChapterOrder(chapterID: string, orderNum: number): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.put<CourseChapter>(`/study/course/chapter/${chapterID}/order`, null, {
|
||||
params: { orderNum }
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
@@ -1,333 +1,11 @@
|
||||
/**
|
||||
* @description 学习相关API
|
||||
* @author system
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type {
|
||||
Course,
|
||||
CourseChapter,
|
||||
LearningTask,
|
||||
LearningRecord,
|
||||
LearningStatistics,
|
||||
LearningProgress,
|
||||
LearningRecordStatistics,
|
||||
ResultDomain
|
||||
} from '@/types';
|
||||
|
||||
/**
|
||||
* 课程API服务
|
||||
*/
|
||||
export const courseApi = {
|
||||
/**
|
||||
* 获取课程列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async getCourseList(filter?: Partial<Course>): Promise<ResultDomain<Course>> {
|
||||
const response = await api.get<Course>('/study/course/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取课程详情
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async getCourseById(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.get<Course>(`/study/course/${courseID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建课程
|
||||
* @param course 课程数据
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async createCourse(course: Course): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>('/study/course/create', course);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程
|
||||
* @param course 课程数据
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async updateCourse(course: Course): Promise<ResultDomain<Course>> {
|
||||
const response = await api.put<Course>('/study/course/update', course);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除课程
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteCourse(courseID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/course/${courseID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程状态
|
||||
* @param courseID 课程ID
|
||||
* @param status 状态
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async updateCourseStatus(courseID: string, status: number): Promise<ResultDomain<Course>> {
|
||||
const response = await api.put<Course>(`/study/course/${courseID}/status`, null, {
|
||||
params: { status }
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加课程浏览次数
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async incrementViewCount(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>(`/study/course/${courseID}/view`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 增加课程学习人数
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<Course>>
|
||||
*/
|
||||
async incrementLearnCount(courseID: string): Promise<ResultDomain<Course>> {
|
||||
const response = await api.post<Course>(`/study/course/${courseID}/learn`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取课程章节列表
|
||||
* @param courseID 课程ID
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async getCourseChapters(courseID: string): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.get<CourseChapter>(`/study/course/${courseID}/chapters`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取章节详情
|
||||
* @param chapterID 章节ID
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async getChapterById(chapterID: string): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.get<CourseChapter>(`/study/course/chapter/${chapterID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建课程章节
|
||||
* @param chapter 章节数据
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async createChapter(chapter: CourseChapter): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.post<CourseChapter>('/study/course/chapter/create', chapter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新课程章节
|
||||
* @param chapter 章节数据
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async updateChapter(chapter: CourseChapter): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.put<CourseChapter>('/study/course/chapter/update', chapter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除课程章节
|
||||
* @param chapterID 章节ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteChapter(chapterID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/course/chapter/${chapterID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新章节排序
|
||||
* @param chapterID 章节ID
|
||||
* @param orderNum 排序号
|
||||
* @returns Promise<ResultDomain<CourseChapter>>
|
||||
*/
|
||||
async updateChapterOrder(chapterID: string, orderNum: number): Promise<ResultDomain<CourseChapter>> {
|
||||
const response = await api.put<CourseChapter>(`/study/course/chapter/${chapterID}/order`, null, {
|
||||
params: { orderNum }
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 学习任务API服务
|
||||
*/
|
||||
export const learningTaskApi = {
|
||||
/**
|
||||
* 获取学习任务列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getTaskList(filter?: Partial<LearningTask>): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>('/study/learning-task/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取任务详情
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getTaskById(taskID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>(`/study/learning-task/${taskID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建学习任务
|
||||
* @param task 任务数据
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async createTask(task: LearningTask): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.post<LearningTask>('/study/learning-task/create', task);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新学习任务
|
||||
* @param task 任务数据
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async updateTask(task: LearningTask): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.put<LearningTask>('/study/learning-task/update', task);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除学习任务
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteTask(taskID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/learning-task/${taskID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 发布学习任务
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async publishTask(taskID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.post<LearningTask>(`/study/learning-task/${taskID}/publish`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户任务进度
|
||||
* @param userID 用户ID
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningProgress>>
|
||||
*/
|
||||
async getUserTaskProgress(userID: string, taskID: string): Promise<ResultDomain<LearningProgress>> {
|
||||
const response = await api.get<LearningProgress>(`/study/learning-task/${taskID}/progress`, {
|
||||
userID
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 学习记录API服务
|
||||
*/
|
||||
export const learningRecordApi = {
|
||||
/**
|
||||
* 获取学习记录列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async getRecordList(filter?: Partial<LearningRecord>): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.get<LearningRecord>('/study/learning-record/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建学习记录
|
||||
* @param record 记录数据
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async createRecord(record: LearningRecord): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.post<LearningRecord>('/study/learning-record/create', record);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新学习记录
|
||||
* @param record 记录数据
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async updateRecord(record: LearningRecord): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.put<LearningRecord>('/study/learning-record/update', record);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户学习统计
|
||||
* @param userID 用户ID
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<LearningRecordStatistics>>
|
||||
*/
|
||||
async getUserLearningStatistics(userID: string, timeRange?: string): Promise<ResultDomain<LearningRecordStatistics>> {
|
||||
const response = await api.get<LearningRecordStatistics>('/study/learning-record/statistics', {
|
||||
userID,
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取学习时长图表数据
|
||||
* @param userID 用户ID
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<LearningRecordStatistics>>
|
||||
*/
|
||||
async getLearningDurationChart(userID: string, timeRange?: string): Promise<ResultDomain<LearningRecordStatistics>> {
|
||||
const response = await api.get<LearningRecordStatistics>('/study/learning-record/duration-chart', {
|
||||
userID,
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 学习计划API服务
|
||||
*/
|
||||
export const learningPlanApi = {
|
||||
/**
|
||||
* 获取学习计划列表
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getPlanList(): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>('/study/learning-plan/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取计划详情
|
||||
* @param planID 计划ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getPlanById(planID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>(`/study/learning-plan/${planID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
// 重新导出各个子模块
|
||||
export { courseApi } from './course';
|
||||
export { learningTaskApi } from './learning-task';
|
||||
export { learningRecordApi } from './learning-record';
|
||||
export { learningPlanApi } from './learning-plan';
|
||||
|
||||
32
schoolNewsWeb/src/apis/study/learning-plan.ts
Normal file
32
schoolNewsWeb/src/apis/study/learning-plan.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @description 学习计划相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { LearningTask, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 学习计划API服务
|
||||
*/
|
||||
export const learningPlanApi = {
|
||||
/**
|
||||
* 获取学习计划列表
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getPlanList(): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>('/study/learning-plan/list');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取计划详情
|
||||
* @param planID 计划ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getPlanById(planID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>(`/study/learning-plan/${planID}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
71
schoolNewsWeb/src/apis/study/learning-record.ts
Normal file
71
schoolNewsWeb/src/apis/study/learning-record.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @description 学习记录相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { LearningRecord, LearningRecordStatistics, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 学习记录API服务
|
||||
*/
|
||||
export const learningRecordApi = {
|
||||
/**
|
||||
* 获取学习记录列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async getRecordList(filter?: Partial<LearningRecord>): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.get<LearningRecord>('/study/learning-record/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建学习记录
|
||||
* @param record 记录数据
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async createRecord(record: LearningRecord): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.post<LearningRecord>('/study/learning-record/create', record);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新学习记录
|
||||
* @param record 记录数据
|
||||
* @returns Promise<ResultDomain<LearningRecord>>
|
||||
*/
|
||||
async updateRecord(record: LearningRecord): Promise<ResultDomain<LearningRecord>> {
|
||||
const response = await api.put<LearningRecord>('/study/learning-record/update', record);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户学习统计
|
||||
* @param userID 用户ID
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<LearningRecordStatistics>>
|
||||
*/
|
||||
async getUserLearningStatistics(userID: string, timeRange?: string): Promise<ResultDomain<LearningRecordStatistics>> {
|
||||
const response = await api.get<LearningRecordStatistics>('/study/learning-record/statistics', {
|
||||
userID,
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取学习时长图表数据
|
||||
* @param userID 用户ID
|
||||
* @param timeRange 时间范围
|
||||
* @returns Promise<ResultDomain<LearningRecordStatistics>>
|
||||
*/
|
||||
async getLearningDurationChart(userID: string, timeRange?: string): Promise<ResultDomain<LearningRecordStatistics>> {
|
||||
const response = await api.get<LearningRecordStatistics>('/study/learning-record/duration-chart', {
|
||||
userID,
|
||||
timeRange
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
86
schoolNewsWeb/src/apis/study/learning-task.ts
Normal file
86
schoolNewsWeb/src/apis/study/learning-task.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @description 学习任务相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { LearningTask, LearningProgress, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 学习任务API服务
|
||||
*/
|
||||
export const learningTaskApi = {
|
||||
/**
|
||||
* 获取学习任务列表
|
||||
* @param filter 过滤条件
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getTaskList(filter?: Partial<LearningTask>): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>('/study/learning-task/list', filter);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据ID获取任务详情
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async getTaskById(taskID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.get<LearningTask>(`/study/learning-task/${taskID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建学习任务
|
||||
* @param task 任务数据
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async createTask(task: LearningTask): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.post<LearningTask>('/study/learning-task/create', task);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新学习任务
|
||||
* @param task 任务数据
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async updateTask(task: LearningTask): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.put<LearningTask>('/study/learning-task/update', task);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除学习任务
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteTask(taskID: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/study/learning-task/${taskID}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 发布学习任务
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningTask>>
|
||||
*/
|
||||
async publishTask(taskID: string): Promise<ResultDomain<LearningTask>> {
|
||||
const response = await api.post<LearningTask>(`/study/learning-task/${taskID}/publish`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取用户任务进度
|
||||
* @param userID 用户ID
|
||||
* @param taskID 任务ID
|
||||
* @returns Promise<ResultDomain<LearningProgress>>
|
||||
*/
|
||||
async getUserTaskProgress(userID: string, taskID: string): Promise<ResultDomain<LearningProgress>> {
|
||||
const response = await api.get<LearningProgress>(`/study/learning-task/${taskID}/progress`, {
|
||||
userID
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
139
schoolNewsWeb/src/apis/system/file.ts
Normal file
139
schoolNewsWeb/src/apis/system/file.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* @description 文件相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { SysFile, FileUploadParam, BatchFileUploadParam, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 文件API服务
|
||||
*/
|
||||
export const fileApi = {
|
||||
/**
|
||||
* 上传文件
|
||||
* @param param 文件上传参数
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async uploadFile(param: FileUploadParam): Promise<ResultDomain<SysFile>> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', param.file);
|
||||
if (param.module) {
|
||||
formData.append('module', param.module);
|
||||
}
|
||||
if (param.businessId) {
|
||||
formData.append('businessId', param.businessId);
|
||||
}
|
||||
if (param.uploader) {
|
||||
formData.append('uploader', param.uploader);
|
||||
}
|
||||
const response = await api.upload<SysFile>('/file/upload', formData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量上传文件
|
||||
* @param param 批量文件上传参数
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async batchUploadFiles(param: BatchFileUploadParam): Promise<ResultDomain<SysFile>> {
|
||||
const formData = new FormData();
|
||||
param.files.forEach(file => {
|
||||
formData.append('files', file);
|
||||
});
|
||||
if (param.module) {
|
||||
formData.append('module', param.module);
|
||||
}
|
||||
if (param.businessId) {
|
||||
formData.append('businessId', param.businessId);
|
||||
}
|
||||
if (param.uploader) {
|
||||
formData.append('uploader', param.uploader);
|
||||
}
|
||||
const response = await api.upload<SysFile>('/file/batch-upload', formData);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param fileId 文件ID
|
||||
* @param filename 保存的文件名(可选)
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
async downloadFile(fileId: string, filename?: string): Promise<void> {
|
||||
return api.download(`/file/download/${fileId}`, filename);
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除文件(逻辑删除)
|
||||
* @param fileId 文件ID
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async deleteFile(fileId: string): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.delete<SysFile>(`/file/${fileId}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 物理删除文件
|
||||
* @param fileId 文件ID
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async deleteFilePhysically(fileId: string): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.delete<SysFile>(`/file/physical/${fileId}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量删除文件
|
||||
* @param fileIds 文件ID数组
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async batchDeleteFiles(fileIds: string[]): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.delete<SysFile>('/file/batch', fileIds);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据文件ID查询文件信息
|
||||
* @param fileId 文件ID
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async getFileById(fileId: string): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.get<SysFile>(`/file/${fileId}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据业务ID查询文件列表
|
||||
* @param module 所属模块
|
||||
* @param businessId 业务ID
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async getFilesByBusinessId(module: string, businessId: string): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.get<SysFile>(`/file/business/${module}/${businessId}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据上传者查询文件列表
|
||||
* @param uploader 上传者用户ID
|
||||
* @returns Promise<ResultDomain<SysFile>>
|
||||
*/
|
||||
async getFilesByUploader(uploader: string): Promise<ResultDomain<SysFile>> {
|
||||
const response = await api.get<SysFile>(`/file/uploader/${uploader}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取文件访问URL
|
||||
* @param fileId 文件ID
|
||||
* @returns Promise<ResultDomain<string>>
|
||||
*/
|
||||
async getFileUrl(fileId: string): Promise<ResultDomain<string>> {
|
||||
const response = await api.get<string>(`/file/url/${fileId}`);
|
||||
return response.data;
|
||||
}
|
||||
};
|
||||
|
||||
15
schoolNewsWeb/src/apis/system/index.ts
Normal file
15
schoolNewsWeb/src/apis/system/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @description 系统相关API统一导出
|
||||
* @author yslg
|
||||
* @since 2025-10-16
|
||||
*/
|
||||
|
||||
// 重新导出各个子模块
|
||||
export { userApi } from './user';
|
||||
export { roleApi } from './role';
|
||||
export { deptApi } from './dept';
|
||||
export { menuApi } from './menu';
|
||||
export { permissionApi } from './permission';
|
||||
export { authApi } from './auth';
|
||||
export { fileApi } from './file';
|
||||
|
||||
46
schoolNewsWeb/src/apis/usercenter/achievement.ts
Normal file
46
schoolNewsWeb/src/apis/usercenter/achievement.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @description 用户成就相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { UserAchievement, Achievement, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 用户成就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;
|
||||
}
|
||||
};
|
||||
47
schoolNewsWeb/src/apis/usercenter/browse-record.ts
Normal file
47
schoolNewsWeb/src/apis/usercenter/browse-record.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @description 用户浏览记录相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { UserBrowseRecord, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 用户浏览记录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;
|
||||
}
|
||||
};
|
||||
69
schoolNewsWeb/src/apis/usercenter/collection.ts
Normal file
69
schoolNewsWeb/src/apis/usercenter/collection.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @description 用户收藏相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { UserCollection, 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;
|
||||
}
|
||||
};
|
||||
@@ -1,339 +1,12 @@
|
||||
/**
|
||||
* @description 用户中心相关API
|
||||
* @author system
|
||||
* @author yslg
|
||||
* @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;
|
||||
}
|
||||
};
|
||||
// 重新导出各个子模块
|
||||
export { userCollectionApi } from './collection';
|
||||
export { userBrowseRecordApi } from './browse-record';
|
||||
export { userPointsApi } from './points';
|
||||
export { userAchievementApi } from './achievement';
|
||||
export { userProfileApi } from './profile';
|
||||
|
||||
63
schoolNewsWeb/src/apis/usercenter/points.ts
Normal file
63
schoolNewsWeb/src/apis/usercenter/points.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @description 用户积分相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type { UserPoints, PointsRecord, ResultDomain } from '@/types';
|
||||
|
||||
/**
|
||||
* 用户积分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;
|
||||
}
|
||||
};
|
||||
128
schoolNewsWeb/src/apis/usercenter/profile.ts
Normal file
128
schoolNewsWeb/src/apis/usercenter/profile.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @description 个人中心相关API
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
|
||||
import { api } from '@/apis/index';
|
||||
import type {
|
||||
UserCenterStatistics,
|
||||
LearningChartData,
|
||||
ResourceLearningStats,
|
||||
ResultDomain
|
||||
} from '@/types';
|
||||
|
||||
/**
|
||||
* 个人中心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 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