From 1702b88ebf83ead6b93078064493dfec0a2e8fe9 Mon Sep 17 00:00:00 2001 From: claw_bot Date: Wed, 25 Mar 2026 05:54:15 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=9B=E5=BB=BA=E7=BB=84=E5=90=88?= =?UTF-8?q?=E6=97=B6=E6=AD=A3=E7=A1=AE=E4=BC=A0=E9=80=92=E6=8C=81=E4=BB=93?= =?UTF-8?q?=E5=B8=81=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增 inferCurrencyFromCode 函数,根据股票代码推断币种 - .US/.NYSE/.NASDAQ → USD - .HK/.HKEX → HKD - .SZ/.SH 或 6 位数字 → CNY - 加密货币 → USD 2. 搜索股票时映射 priceCurrency 字段 3. 选择股票时保存 currency 到表单 4. 提交时同时传递 assetType 字段 --- pages/config/config.vue | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pages/config/config.vue b/pages/config/config.vue index cfc3441..f920e51 100755 --- a/pages/config/config.vue +++ b/pages/config/config.vue @@ -187,6 +187,7 @@ interface SearchResult { name?: string; exchange?: string; assetType?: string; + currency?: string; stockIndex: number; } @@ -230,7 +231,11 @@ const searchStock = async (keyword: string, stockIndex: number): Promise = try { const res = await api.ticker.search(keyword); if (res.code === 200) { - searchResults.value = res.data.map((item: any) => ({ ...item, stockIndex })); + searchResults.value = res.data.map((item: any) => ({ + ...item, + stockIndex, + currency: item.priceCurrency || item.currency // 映射币种字段 + })); } } catch { searchResults.value = []; @@ -244,6 +249,7 @@ const selectStock = (result: SearchResult): void => { if (stock) { stock.name = result.ticker; stock.assetType = result.assetType; + stock.currency = result.currency; // 保存搜索结果中的币种 } searchResults.value = []; activeSearchIndex.value = -1; @@ -353,6 +359,30 @@ const submitForm = async (): Promise => { } } +// 根据股票代码推断币种 +const inferCurrencyFromCode = (code: string): string => { + if (!code) return selectedCurrency; + const upperCode = code.toUpperCase(); + // 美股 + if (upperCode.endsWith('.US') || upperCode.endsWith('.NYSE') || upperCode.endsWith('.NASDAQ')) { + return 'USD'; + } + // 港股 + if (upperCode.endsWith('.HK') || upperCode.endsWith('.HKEX')) { + return 'HKD'; + } + // A股 + if (upperCode.endsWith('.SZ') || upperCode.endsWith('.SH') || /^[0-9]{6}$/.test(upperCode)) { + return 'CNY'; + } + // 加密货币默认 USD + if (upperCode.includes('BTC') || upperCode.includes('ETH') || upperCode.includes('USDT')) { + return 'USD'; + } + // 默认使用组合本位币 + return selectedCurrency; +}; + const selectedCurrency = currencyList.value[currencyIndex.value].code; const requestData = { name: form.value.name, @@ -364,7 +394,8 @@ const submitForm = async (): Promise => { price: parseFloat(stock.price) || 0, amount: parseFloat(stock.amount) || 0, date: stock.date, - currency: selectedCurrency + currency: stock.currency || inferCurrencyFromCode(stock.name), + assetType: stock.assetType || 'Stock' })) };