update pay ui
This commit is contained in:
@@ -449,48 +449,102 @@ const ConceptCenter = () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const sortToUse = customSortBy !== null ? customSortBy : sortBy;
|
||||
const dateStr = date ? date.toISOString().split('T')[0] : null;
|
||||
|
||||
const requestBody = {
|
||||
query: query,
|
||||
size: pageSize,
|
||||
page: page,
|
||||
sort_by: sortToUse
|
||||
};
|
||||
// 判断是否使用 /price/list 接口
|
||||
// 条件:无搜索词 + 按涨跌幅排序(升序或降序)+ 无层级筛选
|
||||
const isChangePctSort = sortToUse === 'change_pct' || sortToUse === 'change_pct_asc';
|
||||
const hasNoFilter = !filter?.lv1 && !filter?.lv2;
|
||||
const shouldUsePriceList = !query && isChangePctSort && hasNoFilter;
|
||||
|
||||
if (date) {
|
||||
requestBody.trade_date = date.toISOString().split('T')[0];
|
||||
}
|
||||
if (shouldUsePriceList) {
|
||||
// 使用 /price/list 接口获取全部概念的正确排序
|
||||
const sortParam = sortToUse === 'change_pct_asc' ? 'change_asc' : 'change_desc';
|
||||
const offset = (page - 1) * pageSize;
|
||||
const params = new URLSearchParams({
|
||||
sort_by: sortParam,
|
||||
limit: pageSize.toString(),
|
||||
offset: offset.toString(),
|
||||
concept_type: 'leaf' // 只获取叶子概念
|
||||
});
|
||||
if (dateStr) {
|
||||
params.append('trade_date', dateStr);
|
||||
}
|
||||
|
||||
// 添加层级筛选参数
|
||||
if (filter?.lv1) {
|
||||
requestBody.filter_lv1 = filter.lv1;
|
||||
}
|
||||
if (filter?.lv2) {
|
||||
requestBody.filter_lv2 = filter.lv2;
|
||||
}
|
||||
const response = await fetch(`${API_BASE_URL}/price/list?${params}`);
|
||||
if (!response.ok) throw new Error('获取涨跌幅数据失败');
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/search`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) throw new Error('搜索失败');
|
||||
// 适配 /price/list 返回数据为 /search 格式
|
||||
const adaptedResults = data.concepts.map(item => ({
|
||||
concept_id: item.concept_id,
|
||||
concept: item.concept_name,
|
||||
concept_name: item.concept_name,
|
||||
price_info: {
|
||||
avg_change_pct: item.avg_change_pct
|
||||
},
|
||||
stock_count: item.stock_count,
|
||||
hierarchy: item.hierarchy,
|
||||
// 以下字段 /price/list 不返回,填入默认值
|
||||
description: null,
|
||||
tags: [],
|
||||
outbreak_dates: [],
|
||||
stocks: []
|
||||
}));
|
||||
|
||||
const data = await response.json();
|
||||
setConcepts(adaptedResults);
|
||||
setTotalConcepts(data.total || 0);
|
||||
setTotalPages(Math.ceil((data.total || 0) / pageSize));
|
||||
setCurrentPage(page);
|
||||
|
||||
setConcepts(data.results || []);
|
||||
setTotalConcepts(data.total || 0);
|
||||
setTotalPages(data.total_pages || 1);
|
||||
setCurrentPage(data.page || 1);
|
||||
if (data.trade_date) {
|
||||
setSelectedDate(new Date(data.trade_date));
|
||||
}
|
||||
} else {
|
||||
// 使用原有的 /search 接口
|
||||
const requestBody = {
|
||||
query: query,
|
||||
size: pageSize,
|
||||
page: page,
|
||||
sort_by: sortToUse
|
||||
};
|
||||
|
||||
if (data.price_date) {
|
||||
setSelectedDate(new Date(data.price_date));
|
||||
if (dateStr) {
|
||||
requestBody.trade_date = dateStr;
|
||||
}
|
||||
|
||||
// 添加层级筛选参数
|
||||
if (filter?.lv1) {
|
||||
requestBody.filter_lv1 = filter.lv1;
|
||||
}
|
||||
if (filter?.lv2) {
|
||||
requestBody.filter_lv2 = filter.lv2;
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/search`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error('搜索失败');
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
setConcepts(data.results || []);
|
||||
setTotalConcepts(data.total || 0);
|
||||
setTotalPages(data.total_pages || 1);
|
||||
setCurrentPage(data.page || 1);
|
||||
|
||||
if (data.price_date) {
|
||||
setSelectedDate(new Date(data.price_date));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('ConceptCenter', 'fetchConcepts', error, { query, page, date: date?.toISOString(), sortToUse, filter });
|
||||
logger.error('ConceptCenter', 'fetchConcepts', error, { query, page, date: date?.toISOString(), customSortBy, filter });
|
||||
|
||||
// ❌ 移除获取数据失败toast
|
||||
// toast({ title: '获取数据失败', description: error.message, status: 'error', duration: 3000, isClosable: true });
|
||||
|
||||
@@ -19,8 +19,8 @@ import {
|
||||
useColorModeValue,
|
||||
Tooltip,
|
||||
Flex,
|
||||
keyframes,
|
||||
} from '@chakra-ui/react';
|
||||
import { keyframes } from '@emotion/react';
|
||||
import {
|
||||
TrendingUp,
|
||||
TrendingDown,
|
||||
|
||||
@@ -28,8 +28,8 @@ import {
|
||||
PopoverBody,
|
||||
Portal,
|
||||
chakra,
|
||||
keyframes,
|
||||
} from '@chakra-ui/react';
|
||||
import { keyframes } from '@emotion/react';
|
||||
import {
|
||||
TrendingUp,
|
||||
TrendingDown,
|
||||
|
||||
@@ -27,8 +27,8 @@ import {
|
||||
GridItem,
|
||||
IconButton,
|
||||
Collapse,
|
||||
keyframes,
|
||||
} from '@chakra-ui/react';
|
||||
import { keyframes } from '@emotion/react';
|
||||
import {
|
||||
Flame,
|
||||
List,
|
||||
|
||||
Reference in New Issue
Block a user