know_info.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // 知识库API
  29. export const KnowInfoAPI = {
  30. // 获取知识库列表
  31. getKnowInfos: async (params?: {
  32. page?: number;
  33. pageSize?: number;
  34. title?: string;
  35. category?: string;
  36. tags?: string;
  37. }): Promise<KnowInfoListResponse> => {
  38. try {
  39. const response = await axios.get('/know-infos', { params });
  40. return response.data;
  41. } catch (error) {
  42. throw error;
  43. }
  44. },
  45. // 获取单个知识详情
  46. getKnowInfo: async (id: number): Promise<KnowInfoResponse> => {
  47. try {
  48. const response = await axios.get(`/know-infos/${id}`);
  49. return response.data;
  50. } catch (error) {
  51. throw error;
  52. }
  53. },
  54. // 创建知识
  55. createKnowInfo: async (data: Partial<KnowInfo>): Promise<KnowInfoCreateResponse> => {
  56. try {
  57. const response = await axios.post('/know-infos', data);
  58. return response.data;
  59. } catch (error) {
  60. throw error;
  61. }
  62. },
  63. // 更新知识
  64. updateKnowInfo: async (id: number, data: Partial<KnowInfo>): Promise<KnowInfoUpdateResponse> => {
  65. try {
  66. const response = await axios.put(`/know-infos/${id}`, data);
  67. return response.data;
  68. } catch (error) {
  69. throw error;
  70. }
  71. },
  72. // 删除知识
  73. deleteKnowInfo: async (id: number): Promise<KnowInfoDeleteResponse> => {
  74. try {
  75. const response = await axios.delete(`/know-infos/${id}`);
  76. return response.data;
  77. } catch (error) {
  78. throw error;
  79. }
  80. }
  81. };