fix: 基金搜索、 LOF 基金查询、 搜索市值显示

This commit is contained in:
兰志宏
2025-03-11 17:22:19 +08:00
parent d22f39bae2
commit b157fbaab7
4 changed files with 43 additions and 17 deletions

View File

@@ -11,8 +11,8 @@
<n-layout class="main-layout"> <n-layout class="main-layout">
<n-layout-content class="main-content mobile-content-container"> <n-layout-content class="main-content mobile-content-container">
<!-- 市场时间显示 --> <!-- 市场时间显示 PC也显示移动端布局暂时隐藏-->
<MarketTimeDisplay :is-mobile="isMobile" /> <!-- <MarketTimeDisplay :is-mobile="isMobile" /> -->
<!-- API配置面板 --> <!-- API配置面板 -->
<ApiConfigPanel <ApiConfigPanel
@@ -37,7 +37,7 @@
/> />
</n-form-item> </n-form-item>
<n-form-item label="股票搜索" v-if="marketType === 'US'"> <n-form-item :label='marketType === "US" ? "股票搜索" : "基金搜索"' v-if="showSearch">
<StockSearch :market-type="marketType" @select="addSelectedStock" /> <StockSearch :market-type="marketType" @select="addSelectedStock" />
</n-form-item> </n-form-item>
@@ -45,7 +45,7 @@
<n-input <n-input
v-model:value="stockCodes" v-model:value="stockCodes"
type="textarea" type="textarea"
placeholder="输入股票代码,多个代码用逗号、空格或换行分隔" placeholder="输入股票、基金代码,多个代码用逗号、空格或换行分隔"
:autosize="{ minRows: 3, maxRows: 6 }" :autosize="{ minRows: 3, maxRows: 6 }"
/> />
</n-form-item> </n-form-item>
@@ -238,9 +238,9 @@ const showAnnouncement = (content: string) => {
const marketOptions = [ const marketOptions = [
{ label: 'A股', value: 'A' }, { label: 'A股', value: 'A' },
{ label: '港股', value: 'HK' }, { label: '港股', value: 'HK' },
{ label: '美股', value: 'US' }, { label: '美股', value: 'US', showSearch: true },
{ label: 'ETF', value: 'ETF' }, { label: 'ETF', value: 'ETF', showSearch: true },
{ label: 'LOF', value: 'LOF' } { label: 'LOF', value: 'LOF', showSearch: true }
]; ];
// 表格列定义 // 表格列定义
@@ -396,6 +396,10 @@ const exportOptions = [
} }
]; ];
const showSearch = computed(() =>
marketOptions.find(option => option.value === marketType.value)?.showSearch
);
// 更新API配置 // 更新API配置
function updateApiConfig(config: ApiConfig) { function updateApiConfig(config: ApiConfig) {
apiConfig.value = { ...config }; apiConfig.value = { ...config };

View File

@@ -2,7 +2,7 @@
<div class="stock-search-container"> <div class="stock-search-container">
<n-input <n-input
v-model:value="searchKeyword" v-model:value="searchKeyword"
placeholder="输入股票代码或名称搜索" placeholder="输入代码或名称搜索"
@input="handleSearchInput" @input="handleSearchInput"
@blur="handleBlur" @blur="handleBlur"
@focus="handleFocus" @focus="handleFocus"
@@ -20,7 +20,7 @@
</div> </div>
<div v-else-if="results.length === 0 && searchKeyword" class="no-results"> <div v-else-if="results.length === 0 && searchKeyword" class="no-results">
未找到相关股票 未找到相关数据
</div> </div>
<template v-else> <template v-else>
@@ -37,8 +37,8 @@
</div> </div>
<div class="result-meta"> <div class="result-meta">
<span class="result-market">{{ item.market }}</span> <span class="result-market">{{ item.market }}</span>
<span v-if="item.marketValue" class="result-market-value"> <span v-if="item.market_value" class="result-market-value">
市值: {{ formatMarketValue(item.marketValue) }} 市值: {{ formatMarketValue(item.market_value) }}
</span> </span>
</div> </div>
</div> </div>
@@ -87,11 +87,13 @@ const debouncedSearch = debounce(async (keyword: string) => {
// 限制只显示前10个结果 // 限制只显示前10个结果
results.value = searchResults.slice(0, 10); results.value = searchResults.slice(0, 10);
} else { } else {
// 其他市场搜索 (后端需要实现对应的接口) // 基金搜索
results.value = []; const searchResults = await apiService.searchFunds(keyword);
// 限制只显示前10个结果
results.value = searchResults.slice(0, 10);
} }
} catch (error) { } catch (error) {
console.error('搜索股票时出错:', error); console.error('搜索数据时出错:', error);
results.value = []; results.value = [];
} finally { } finally {
loading.value = false; loading.value = false;

View File

@@ -115,6 +115,19 @@ export const apiService = {
return []; return [];
} }
}, },
// 搜索基金
searchFunds: async (keyword: string): Promise<SearchResult[]> => {
try {
const response = await axiosInstance.get('/search_funds', {
params: { keyword }
});
return response.data.results || [];
} catch (error) {
console.error('搜索基金时出错:', error);
return [];
}
},
// 获取配置 // 获取配置
getConfig: async () => { getConfig: async () => {

View File

@@ -184,9 +184,16 @@ class StockDataProvider:
except Exception as e: except Exception as e:
logger.warning(f"日期过滤出错: {str(e)},返回原始数据") logger.warning(f"日期过滤出错: {str(e)},返回原始数据")
elif market_type in ['ETF', 'LOF']: elif market_type in ['ETF']:
logger.debug(f"获取{market_type}基金数据: {stock_code}") logger.debug(f"获取{market_type}基金数据: {stock_code}")
df = ak.fund_etf_hist_sina( df = ak.fund_etf_hist_em(
symbol=stock_code,
start_date=start_date.replace('-', ''),
end_date=end_date.replace('-', '')
)
elif market_type in ['LOF']:
logger.debug(f"获取{market_type}基金数据: {stock_code}")
df = ak.fund_lof_hist_em(
symbol=stock_code, symbol=stock_code,
start_date=start_date.replace('-', ''), start_date=start_date.replace('-', ''),
end_date=end_date.replace('-', '') end_date=end_date.replace('-', '')
@@ -230,7 +237,7 @@ class StockDataProvider:
elif market_type in ['ETF', 'LOF']: elif market_type in ['ETF', 'LOF']:
# 基金数据可能有不同的列 # 基金数据可能有不同的列
df.columns = ['Date', 'Open', 'High', 'Low', 'Close', 'Volume', 'Amount'] df.columns = ['Date', 'Open', 'Close', 'High', 'Low', 'Volume', 'Amount', 'Amplitude', 'Change_pct', 'Change', 'Turnover']
# 确保日期列是日期类型 # 确保日期列是日期类型
if 'Date' in df.columns: if 'Date' in df.columns: