| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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;
- }
- }
- };
|