update pay function
This commit is contained in:
@@ -118,34 +118,59 @@ export const fetchCategoryNode = async (
|
||||
}
|
||||
};
|
||||
|
||||
export interface MetricSearchResult {
|
||||
source: string;
|
||||
metric_id: string;
|
||||
metric_name: string;
|
||||
unit: string;
|
||||
frequency: string;
|
||||
category_path: string;
|
||||
description?: string;
|
||||
score?: number;
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
total: number;
|
||||
results: MetricSearchResult[];
|
||||
query: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索指标
|
||||
* @param query 搜索关键词
|
||||
* @param source 数据源类型 ('SMM' | 'Mysteel')
|
||||
* @returns 匹配的指标列表
|
||||
* @param keywords 搜索关键词(支持空格分隔多个词)
|
||||
* @param source 数据源过滤(可选)
|
||||
* @param frequency 频率过滤(可选)
|
||||
* @param size 返回结果数量(默认100)
|
||||
* @returns 搜索结果
|
||||
*/
|
||||
export const searchMetrics = async (
|
||||
query: string,
|
||||
source: 'SMM' | 'Mysteel'
|
||||
): Promise<TreeMetric[]> => {
|
||||
keywords: string,
|
||||
source?: 'SMM' | 'Mysteel',
|
||||
frequency?: string,
|
||||
size: number = 100
|
||||
): Promise<SearchResponse> => {
|
||||
try {
|
||||
// 注意:这个接口可能需要后端额外实现
|
||||
// 如果后端没有提供搜索接口,可以在前端基于完整树进行过滤
|
||||
const response = await fetch(
|
||||
`/category-api/api/metrics/search?query=${encodeURIComponent(query)}&source=${source}`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
);
|
||||
const params = new URLSearchParams({
|
||||
keywords,
|
||||
size: size.toString(),
|
||||
});
|
||||
|
||||
if (source) params.append('source', source);
|
||||
if (frequency) params.append('frequency', frequency);
|
||||
|
||||
const response = await fetch(`/category-api/api/search?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
const errorData: ErrorResponse = await response.json();
|
||||
throw new Error(errorData.detail || `HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const data: TreeMetric[] = await response.json();
|
||||
const data: SearchResponse = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('searchMetrics error:', error);
|
||||
|
||||
Reference in New Issue
Block a user