92 lines
1.9 KiB
TypeScript
92 lines
1.9 KiB
TypeScript
import axios from 'axios';
|
|
import type { KnowInfo } from '../../share/types.ts';
|
|
|
|
export interface KnowInfoListResponse {
|
|
data: KnowInfo[];
|
|
pagination: {
|
|
current: number;
|
|
pageSize: number;
|
|
total: number;
|
|
totalPages: number;
|
|
};
|
|
}
|
|
|
|
interface KnowInfoResponse {
|
|
data: KnowInfo;
|
|
message?: string;
|
|
}
|
|
|
|
interface KnowInfoCreateResponse {
|
|
message: string;
|
|
data: KnowInfo;
|
|
}
|
|
|
|
interface KnowInfoUpdateResponse {
|
|
message: string;
|
|
data: KnowInfo;
|
|
}
|
|
|
|
interface KnowInfoDeleteResponse {
|
|
message: string;
|
|
id: number;
|
|
}
|
|
|
|
|
|
// 知识库API
|
|
export const KnowInfoAPI = {
|
|
// 获取知识库列表
|
|
getKnowInfos: async (params?: {
|
|
page?: number;
|
|
pageSize?: number;
|
|
title?: string;
|
|
category?: string;
|
|
tags?: string;
|
|
}): Promise<KnowInfoListResponse> => {
|
|
try {
|
|
const response = await axios.get('/know-infos', { params });
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 获取单个知识详情
|
|
getKnowInfo: async (id: number): Promise<KnowInfoResponse> => {
|
|
try {
|
|
const response = await axios.get(`/know-infos/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 创建知识
|
|
createKnowInfo: async (data: Partial<KnowInfo>): Promise<KnowInfoCreateResponse> => {
|
|
try {
|
|
const response = await axios.post('/know-infos', data);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 更新知识
|
|
updateKnowInfo: async (id: number, data: Partial<KnowInfo>): Promise<KnowInfoUpdateResponse> => {
|
|
try {
|
|
const response = await axios.put(`/know-infos/${id}`, data);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 删除知识
|
|
deleteKnowInfo: async (id: number): Promise<KnowInfoDeleteResponse> => {
|
|
try {
|
|
const response = await axios.delete(`/know-infos/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}; |