2026-01-15 18:04:52 +08:00
|
|
|
import type { Recordable } from '@vben/types';
|
|
|
|
|
|
|
|
|
|
import { requestClient } from '#/api/request';
|
|
|
|
|
|
|
|
|
|
export namespace FeatureApi {
|
|
|
|
|
export interface FeatureItem {
|
2026-03-02 14:33:02 +08:00
|
|
|
id: string;
|
2026-01-15 18:04:52 +08:00
|
|
|
api_id: string;
|
|
|
|
|
name: string;
|
2026-03-02 14:33:02 +08:00
|
|
|
whitelist_price: number;
|
|
|
|
|
cost_price: number;
|
2026-01-15 18:04:52 +08:00
|
|
|
create_time: string;
|
|
|
|
|
update_time: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FeatureList {
|
|
|
|
|
total: number;
|
|
|
|
|
items: FeatureItem[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateFeatureRequest {
|
|
|
|
|
api_id: string;
|
|
|
|
|
name: string;
|
2026-03-02 14:33:02 +08:00
|
|
|
whitelist_price?: number;
|
|
|
|
|
cost_price?: number;
|
2026-01-15 18:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UpdateFeatureRequest {
|
|
|
|
|
api_id?: string;
|
|
|
|
|
name?: string;
|
2026-03-02 14:33:02 +08:00
|
|
|
whitelist_price?: number;
|
|
|
|
|
cost_price?: number;
|
2026-01-15 18:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FeatureExampleItem {
|
|
|
|
|
id: number;
|
|
|
|
|
feature_id: number;
|
|
|
|
|
api_id: string;
|
|
|
|
|
data: string;
|
|
|
|
|
create_time: string;
|
|
|
|
|
update_time: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ConfigFeatureExampleRequest {
|
2026-03-02 14:33:02 +08:00
|
|
|
feature_id: string;
|
2026-01-15 18:04:52 +08:00
|
|
|
data: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ConfigFeatureExampleResponse {
|
|
|
|
|
success: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GetFeatureExampleRequest {
|
2026-03-02 14:33:02 +08:00
|
|
|
feature_id: string;
|
2026-01-15 18:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GetFeatureExampleResponse {
|
2026-03-02 14:33:02 +08:00
|
|
|
id: string;
|
|
|
|
|
feature_id: string;
|
2026-01-15 18:04:52 +08:00
|
|
|
api_id: string;
|
|
|
|
|
data: string;
|
|
|
|
|
create_time: string;
|
|
|
|
|
update_time: string;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取模块列表数据
|
|
|
|
|
*/
|
|
|
|
|
async function getFeatureList(params: Recordable<any>) {
|
|
|
|
|
return requestClient.get<FeatureApi.FeatureList>('/feature/list', {
|
|
|
|
|
params,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取模块详情
|
|
|
|
|
* @param id 模块ID
|
|
|
|
|
*/
|
2026-03-02 14:33:02 +08:00
|
|
|
async function getFeatureDetail(id: string) {
|
2026-01-15 18:04:52 +08:00
|
|
|
return requestClient.get<FeatureApi.FeatureItem>(`/feature/detail/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建模块
|
|
|
|
|
* @param data 模块数据
|
|
|
|
|
*/
|
|
|
|
|
async function createFeature(data: FeatureApi.CreateFeatureRequest) {
|
2026-03-02 14:33:02 +08:00
|
|
|
return requestClient.post<{ id: string }>('/feature/create', data);
|
2026-01-15 18:04:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新模块
|
|
|
|
|
* @param id 模块ID
|
|
|
|
|
* @param data 模块数据
|
|
|
|
|
*/
|
|
|
|
|
async function updateFeature(
|
2026-03-02 14:33:02 +08:00
|
|
|
id: string,
|
2026-01-15 18:04:52 +08:00
|
|
|
data: FeatureApi.UpdateFeatureRequest,
|
|
|
|
|
) {
|
|
|
|
|
return requestClient.put<{ success: boolean }>(`/feature/update/${id}`, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除模块
|
|
|
|
|
* @param id 模块ID
|
|
|
|
|
*/
|
2026-03-02 14:33:02 +08:00
|
|
|
async function deleteFeature(id: string) {
|
2026-01-15 18:04:52 +08:00
|
|
|
return requestClient.delete<{ success: boolean }>(`/feature/delete/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 配置功能示例数据
|
|
|
|
|
* @param data 示例数据配置
|
|
|
|
|
*/
|
|
|
|
|
async function configFeatureExample(
|
|
|
|
|
data: FeatureApi.ConfigFeatureExampleRequest,
|
|
|
|
|
) {
|
|
|
|
|
return requestClient.post<FeatureApi.ConfigFeatureExampleResponse>(
|
|
|
|
|
'/feature/config-example',
|
|
|
|
|
data,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取功能示例数据
|
|
|
|
|
* @param featureId 功能ID
|
|
|
|
|
*/
|
2026-03-02 14:33:02 +08:00
|
|
|
async function getFeatureExample(featureId: string) {
|
2026-01-15 18:04:52 +08:00
|
|
|
return requestClient.get<FeatureApi.GetFeatureExampleResponse>(
|
|
|
|
|
`/feature/example/${featureId}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
configFeatureExample,
|
|
|
|
|
createFeature,
|
|
|
|
|
deleteFeature,
|
|
|
|
|
getFeatureDetail,
|
|
|
|
|
getFeatureExample,
|
|
|
|
|
getFeatureList,
|
|
|
|
|
updateFeature,
|
|
|
|
|
};
|