client/admin/api/ ├── auth.ts (认证API) ├── users.ts (用户API) ├── files.ts (文件API) ├── theme.ts (主题API) ├── charts.ts (图表API) ├── messages.ts (消息API) ├── sys.ts (系统API) ├── know_info.ts (知识库API) ├── maps.ts (地图API) └── index.ts (统一入口)
95 lines
2.0 KiB
TypeScript
95 lines
2.0 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;
|
|
}
|
|
|
|
|
|
const API_BASE_URL = '/api';
|
|
|
|
|
|
// 知识库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(`${API_BASE_URL}/know-infos`, { params });
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 获取单个知识详情
|
|
getKnowInfo: async (id: number): Promise<KnowInfoResponse> => {
|
|
try {
|
|
const response = await axios.get(`${API_BASE_URL}/know-infos/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 创建知识
|
|
createKnowInfo: async (data: Partial<KnowInfo>): Promise<KnowInfoCreateResponse> => {
|
|
try {
|
|
const response = await axios.post(`${API_BASE_URL}/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(`${API_BASE_URL}/know-infos/${id}`, data);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// 删除知识
|
|
deleteKnowInfo: async (id: number): Promise<KnowInfoDeleteResponse> => {
|
|
try {
|
|
const response = await axios.delete(`${API_BASE_URL}/know-infos/${id}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}; |