125 lines
3.0 KiB
TypeScript
125 lines
3.0 KiB
TypeScript
import axios from './index';
|
|
|
|
// 响应类型定义
|
|
interface ApiResponse<T = any> {
|
|
code: number;
|
|
message: string;
|
|
data: T;
|
|
}
|
|
|
|
/**
|
|
* 获取知识列表
|
|
*/
|
|
export async function getKnowledgeList(params?: {
|
|
page?: number;
|
|
pageSize?: number;
|
|
status?: number;
|
|
categoryId?: number;
|
|
keyword?: string;
|
|
}): Promise<any> {
|
|
const response: ApiResponse = await axios.get('/api/knowledge/list', { params });
|
|
if (response.code === 0) {
|
|
return response.data;
|
|
}
|
|
throw new Error(response.message || '获取列表失败');
|
|
}
|
|
|
|
/**
|
|
* 获取知识详情
|
|
*/
|
|
export async function getKnowledgeDetail(id: string | number): Promise<any> {
|
|
const response: ApiResponse = await axios.get('/api/knowledge/detail', {
|
|
params: { id }
|
|
});
|
|
if (response.code === 0) {
|
|
return { data: response.data };
|
|
}
|
|
throw new Error(response.message || '获取详情失败');
|
|
}
|
|
|
|
/**
|
|
* 创建知识
|
|
*/
|
|
export async function createKnowledge(data: any): Promise<any> {
|
|
const response: ApiResponse = await axios.post('/api/knowledge/create', data);
|
|
if (response.code === 0) {
|
|
return response.data;
|
|
}
|
|
throw new Error(response.message || '创建失败');
|
|
}
|
|
|
|
/**
|
|
* 更新知识
|
|
*/
|
|
export async function updateKnowledge(id: string | number, data: any): Promise<any> {
|
|
const response: ApiResponse = await axios.post('/api/knowledge/update', {
|
|
id,
|
|
...data
|
|
});
|
|
if (response.code === 0) {
|
|
return { success: true };
|
|
}
|
|
throw new Error(response.message || '更新失败');
|
|
}
|
|
|
|
/**
|
|
* 删除知识
|
|
*/
|
|
export async function deleteKnowledge(id: string | number): Promise<any> {
|
|
const response: ApiResponse = await axios.post('/api/knowledge/delete', { id });
|
|
if (response.code === 0) {
|
|
return { success: true };
|
|
}
|
|
throw new Error(response.message || '删除失败');
|
|
}
|
|
|
|
/**
|
|
* 获取分类列表
|
|
*/
|
|
export async function getCategoryList(): Promise<any> {
|
|
const response: ApiResponse = await axios.get('/api/knowledge/categories');
|
|
if (response.code === 0) {
|
|
const categories = response.data || [];
|
|
return { data: categories };
|
|
}
|
|
throw new Error(response.message || '获取分类失败');
|
|
}
|
|
|
|
/**
|
|
* 获取标签列表
|
|
*/
|
|
export async function getTagList(): Promise<any> {
|
|
const response: ApiResponse = await axios.get('/api/knowledge/tags');
|
|
if (response.code === 0) {
|
|
// 转换为名称数组格式,兼容前端使用
|
|
const tags = response.data || [];
|
|
return {
|
|
data: tags.map((tag: any) => tag.tagName || tag.tag_name)
|
|
};
|
|
}
|
|
throw new Error(response.message || '获取标签失败');
|
|
}
|
|
|
|
/**
|
|
* 添加分类
|
|
*/
|
|
export async function addCategory(data: {
|
|
categoryName: string;
|
|
categoryDesc?: string;
|
|
parentId?: number;
|
|
sortOrder?: number;
|
|
}): Promise<any> {
|
|
const response: ApiResponse = await axios.post('/api/knowledge/category/add', data);
|
|
return response.data;
|
|
}
|
|
|
|
/**
|
|
* 添加标签
|
|
*/
|
|
export async function addTag(data: {
|
|
tagName: string;
|
|
tagColor?: string;
|
|
}): Promise<any> {
|
|
const response: ApiResponse = await axios.post('/api/knowledge/tag/add', data);
|
|
return response.data;
|
|
} |