know_info.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import axios from 'axios';
  2. import type { KnowInfo } from '../../share/types.ts';
  3. export interface KnowInfoListResponse {
  4. data: KnowInfo[];
  5. pagination: {
  6. current: number;
  7. pageSize: number;
  8. total: number;
  9. totalPages: number;
  10. };
  11. }
  12. interface KnowInfoResponse {
  13. data: KnowInfo;
  14. message?: string;
  15. }
  16. interface KnowInfoCreateResponse {
  17. message: string;
  18. data: KnowInfo;
  19. }
  20. interface KnowInfoUpdateResponse {
  21. message: string;
  22. data: KnowInfo;
  23. }
  24. interface KnowInfoDeleteResponse {
  25. message: string;
  26. id: number;
  27. }
  28. const API_BASE_URL = '/api';
  29. // 知识库API
  30. export const KnowInfoAPI = {
  31. // 获取知识库列表
  32. getKnowInfos: async (params?: {
  33. page?: number;
  34. pageSize?: number;
  35. title?: string;
  36. category?: string;
  37. tags?: string;
  38. }): Promise<KnowInfoListResponse> => {
  39. try {
  40. const response = await axios.get(`${API_BASE_URL}/know-infos`, { params });
  41. return response.data;
  42. } catch (error) {
  43. throw error;
  44. }
  45. },
  46. // 获取单个知识详情
  47. getKnowInfo: async (id: number): Promise<KnowInfoResponse> => {
  48. try {
  49. const response = await axios.get(`${API_BASE_URL}/know-infos/${id}`);
  50. return response.data;
  51. } catch (error) {
  52. throw error;
  53. }
  54. },
  55. // 创建知识
  56. createKnowInfo: async (data: Partial<KnowInfo>): Promise<KnowInfoCreateResponse> => {
  57. try {
  58. const response = await axios.post(`${API_BASE_URL}/know-infos`, data);
  59. return response.data;
  60. } catch (error) {
  61. throw error;
  62. }
  63. },
  64. // 更新知识
  65. updateKnowInfo: async (id: number, data: Partial<KnowInfo>): Promise<KnowInfoUpdateResponse> => {
  66. try {
  67. const response = await axios.put(`${API_BASE_URL}/know-infos/${id}`, data);
  68. return response.data;
  69. } catch (error) {
  70. throw error;
  71. }
  72. },
  73. // 删除知识
  74. deleteKnowInfo: async (id: number): Promise<KnowInfoDeleteResponse> => {
  75. try {
  76. const response = await axios.delete(`${API_BASE_URL}/know-infos/${id}`);
  77. return response.data;
  78. } catch (error) {
  79. throw error;
  80. }
  81. }
  82. };