89 lines
2.0 KiB
TypeScript
89 lines
2.0 KiB
TypeScript
|
|
import request from "@/utils/request";
|
||
|
|
import type { PaginationParams, PaginationResponse } from "@/types/api";
|
||
|
|
|
||
|
|
export interface Config {
|
||
|
|
id: number;
|
||
|
|
key: string;
|
||
|
|
value: string;
|
||
|
|
description?: string;
|
||
|
|
creator?: number;
|
||
|
|
modifier?: number;
|
||
|
|
createTime?: string;
|
||
|
|
modifyTime?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CreateConfigForm {
|
||
|
|
key: string;
|
||
|
|
value: string;
|
||
|
|
description?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface UpdateConfigForm {
|
||
|
|
key?: string;
|
||
|
|
value?: string;
|
||
|
|
description?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取配置列表
|
||
|
|
export async function getConfigsList(
|
||
|
|
params: PaginationParams
|
||
|
|
): Promise<PaginationResponse<Config>> {
|
||
|
|
const response = await request.get<any, PaginationResponse<Config>>(
|
||
|
|
"/sys-config/page",
|
||
|
|
{
|
||
|
|
params,
|
||
|
|
}
|
||
|
|
);
|
||
|
|
return response;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取单个配置详情
|
||
|
|
export async function getConfigDetail(id: number): Promise<Config> {
|
||
|
|
const response = await request.get<any, Config>(`/sys-config/${id}`);
|
||
|
|
return response;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 根据key获取配置
|
||
|
|
export async function getConfigByKey(key: string): Promise<Config> {
|
||
|
|
const response = await request.get<any, Config>(`/sys-config/key/${key}`);
|
||
|
|
return response;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 创建配置
|
||
|
|
export async function createConfig(data: CreateConfigForm): Promise<Config> {
|
||
|
|
const response = await request.postForm<any, Config>("/sys-config", {
|
||
|
|
configKey: data.key,
|
||
|
|
configValue: data.value,
|
||
|
|
description: data.description,
|
||
|
|
});
|
||
|
|
return response;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新配置
|
||
|
|
export async function updateConfig(
|
||
|
|
id: number,
|
||
|
|
data: UpdateConfigForm
|
||
|
|
): Promise<Config> {
|
||
|
|
const response = await request.putForm<any, Config>(`/sys-config/${id}`, {
|
||
|
|
configValue: data.value,
|
||
|
|
description: data.description,
|
||
|
|
});
|
||
|
|
return response;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 删除配置
|
||
|
|
export async function deleteConfig(id: number): Promise<void> {
|
||
|
|
return await request.delete<any, void>(`/sys-config/${id}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 兼容性导出:保留 configApi 对象
|
||
|
|
export const configApi = {
|
||
|
|
getList: getConfigsList,
|
||
|
|
getDetail: getConfigDetail,
|
||
|
|
getByKey: getConfigByKey,
|
||
|
|
create: createConfig,
|
||
|
|
update: updateConfig,
|
||
|
|
delete: deleteConfig,
|
||
|
|
};
|
||
|
|
|