Files
d8d-admin-mobile-starter-pu…/client/admin/api/know_info.ts
yourname e4f45ed952 已从10个API模块文件中移除重复的API_BASE_URL定义
所有API调用现在统一使用client/admin/api/index.ts中的全局axios配置
保持原有功能不变的同时简化了代码结构
2025-05-13 11:44:28 +00:00

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