fix: 基金搜索、 LOF 基金查询、 搜索市值显示
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
<n-layout class="main-layout">
|
||||
<n-layout-content class="main-content mobile-content-container">
|
||||
|
||||
<!-- 市场时间显示 -->
|
||||
<MarketTimeDisplay :is-mobile="isMobile" />
|
||||
<!-- 市场时间显示 PC也显示移动端布局,暂时隐藏-->
|
||||
<!-- <MarketTimeDisplay :is-mobile="isMobile" /> -->
|
||||
|
||||
<!-- API配置面板 -->
|
||||
<ApiConfigPanel
|
||||
@@ -37,7 +37,7 @@
|
||||
/>
|
||||
</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" />
|
||||
</n-form-item>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<n-input
|
||||
v-model:value="stockCodes"
|
||||
type="textarea"
|
||||
placeholder="输入股票代码,多个代码用逗号、空格或换行分隔"
|
||||
placeholder="输入股票、基金代码,多个代码用逗号、空格或换行分隔"
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
/>
|
||||
</n-form-item>
|
||||
@@ -238,9 +238,9 @@ const showAnnouncement = (content: string) => {
|
||||
const marketOptions = [
|
||||
{ label: 'A股', value: 'A' },
|
||||
{ label: '港股', value: 'HK' },
|
||||
{ label: '美股', value: 'US' },
|
||||
{ label: 'ETF', value: 'ETF' },
|
||||
{ label: 'LOF', value: 'LOF' }
|
||||
{ label: '美股', value: 'US', showSearch: true },
|
||||
{ label: 'ETF', value: 'ETF', showSearch: true },
|
||||
{ label: 'LOF', value: 'LOF', showSearch: true }
|
||||
];
|
||||
|
||||
// 表格列定义
|
||||
@@ -396,6 +396,10 @@ const exportOptions = [
|
||||
}
|
||||
];
|
||||
|
||||
const showSearch = computed(() =>
|
||||
marketOptions.find(option => option.value === marketType.value)?.showSearch
|
||||
);
|
||||
|
||||
// 更新API配置
|
||||
function updateApiConfig(config: ApiConfig) {
|
||||
apiConfig.value = { ...config };
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="stock-search-container">
|
||||
<n-input
|
||||
v-model:value="searchKeyword"
|
||||
placeholder="输入股票代码或名称搜索"
|
||||
placeholder="输入代码或名称搜索"
|
||||
@input="handleSearchInput"
|
||||
@blur="handleBlur"
|
||||
@focus="handleFocus"
|
||||
@@ -20,7 +20,7 @@
|
||||
</div>
|
||||
|
||||
<div v-else-if="results.length === 0 && searchKeyword" class="no-results">
|
||||
未找到相关股票
|
||||
未找到相关数据
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
@@ -37,8 +37,8 @@
|
||||
</div>
|
||||
<div class="result-meta">
|
||||
<span class="result-market">{{ item.market }}</span>
|
||||
<span v-if="item.marketValue" class="result-market-value">
|
||||
市值: {{ formatMarketValue(item.marketValue) }}
|
||||
<span v-if="item.market_value" class="result-market-value">
|
||||
市值: {{ formatMarketValue(item.market_value) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -87,11 +87,13 @@ const debouncedSearch = debounce(async (keyword: string) => {
|
||||
// 限制只显示前10个结果
|
||||
results.value = searchResults.slice(0, 10);
|
||||
} else {
|
||||
// 其他市场搜索 (后端需要实现对应的接口)
|
||||
results.value = [];
|
||||
// 基金搜索
|
||||
const searchResults = await apiService.searchFunds(keyword);
|
||||
// 限制只显示前10个结果
|
||||
results.value = searchResults.slice(0, 10);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('搜索股票时出错:', error);
|
||||
console.error('搜索数据时出错:', error);
|
||||
results.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
|
||||
@@ -115,6 +115,19 @@ export const apiService = {
|
||||
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 () => {
|
||||
|
||||
@@ -184,9 +184,16 @@ class StockDataProvider:
|
||||
except Exception as e:
|
||||
logger.warning(f"日期过滤出错: {str(e)},返回原始数据")
|
||||
|
||||
elif market_type in ['ETF', 'LOF']:
|
||||
elif market_type in ['ETF']:
|
||||
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,
|
||||
start_date=start_date.replace('-', ''),
|
||||
end_date=end_date.replace('-', '')
|
||||
@@ -230,7 +237,7 @@ class StockDataProvider:
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user