diff --git a/src/views/Community/components/CompactSearchBox.js b/src/views/Community/components/CompactSearchBox.js index c15c6f86..9caa76db 100644 --- a/src/views/Community/components/CompactSearchBox.js +++ b/src/views/Community/components/CompactSearchBox.js @@ -66,6 +66,8 @@ const CompactSearchBox = ({ // 防抖搜索 const debouncedSearchRef = useRef(null); + // 存储股票选择时的显示值(代码+名称),用于 useEffect 同步时显示完整信息 + const stockDisplayValueRef = useRef(null); const triggerSearch = useCallback((params) => { logger.debug('CompactSearchBox', '触发搜索', { params }); @@ -148,9 +150,17 @@ const CompactSearchBox = ({ } if (filters.q) { - setInputValue(filters.q); + // 如果是股票选择触发的搜索,使用存储的显示值(代码+名称) + if (stockDisplayValueRef.current && stockDisplayValueRef.current.code === filters.q) { + setInputValue(stockDisplayValueRef.current.displayValue); + } else { + setInputValue(filters.q); + // 清除已失效的显示值缓存 + stockDisplayValueRef.current = null; + } } else if (!filters.q) { setInputValue(''); + stockDisplayValueRef.current = null; } const hasTimeInFilters = filters.start_date || filters.end_date || filters.recent_days; @@ -233,7 +243,7 @@ const CompactSearchBox = ({ sort: actualSort, importance: importanceValue, q: (overrides.q ?? filters.q) ?? '', - industry_code: overrides.industry_code ?? (industryValue?.[industryValue.length - 1] || ''), + industry_code: overrides.industry_code ?? (industryValue?.join(',') || ''), start_date: overrides.start_date ?? (tradingTimeRange?.start_date || ''), end_date: overrides.end_date ?? (tradingTimeRange?.end_date || ''), recent_days: overrides.recent_days ?? (tradingTimeRange?.recent_days || ''), @@ -269,10 +279,13 @@ const CompactSearchBox = ({ }); } - setInputValue(`${stockInfo.code} ${stockInfo.name}`); + const displayValue = `${stockInfo.code} ${stockInfo.name}`; + setInputValue(displayValue); + // 存储显示值,供 useEffect 同步时使用 + stockDisplayValueRef.current = { code: stockInfo.code, displayValue }; const params = buildFilterParams({ - q: stockInfo.code, + q: stockInfo.code, // 接口只传代码 industry_code: '' }); triggerSearch(params); @@ -335,7 +348,7 @@ const CompactSearchBox = ({ } const params = buildFilterParams({ - industry_code: value?.[value.length - 1] || '' + industry_code: value?.join(',') || '' }); triggerSearch(params); };