From aac3d341735408ee1700613987a829ec8379de71 Mon Sep 17 00:00:00 2001 From: lihui Date: Tue, 21 Oct 2025 16:07:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=9C=B0=E5=8C=BA=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=98=A0=E5=B0=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/workspace/CashManagement.vue | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/workspace/CashManagement.vue b/src/components/workspace/CashManagement.vue index 1b6273a..aa60e72 100644 --- a/src/components/workspace/CashManagement.vue +++ b/src/components/workspace/CashManagement.vue @@ -132,9 +132,8 @@ const fetchCashData = async () => { value: resMap.get(m.name) ?? 0 })) } else { - // 1. 定义币种中英文对照表 +// 1. 定义币种中英文对照表 const currencyMap = { - // usd: '美元', sgd: '新币', myr: '马币', hkd: '港币', @@ -143,26 +142,31 @@ const fetchCashData = async () => { vdn: '越南盾', }; -// 2. 取出所有币种字段(排除 market 与 totalSGD) -// 当res为空时,直接使用currencyMap的key作为基础币种 - const currencyKeys = res.length > 0 - ? Object.keys(res[0]).filter(key => key !== 'market' && key !== 'totalSGD') - : Object.keys(currencyMap); - -// 3. 累加每个币种的总额并替换中文名(res为空时默认值为0) +// 2. 取出所有币种字段(排除 market 与 totalSGD),只保留 currencyMap 中定义的币种 + const currencyKeys = + res.length > 0 + ? Object.keys(res[0]).filter( + key => + key !== 'market' && + key !== 'totalSGD' && + Object.keys(currencyMap).includes(key.toLowerCase()) + ) + : Object.keys(currencyMap); + +// 3. 累加每个币种的总额并替换中文名 markets.value = currencyKeys.map(currency => { - // 处理币种key的大小写统一(转为小写匹配currencyMap) const lowerCurrency = currency.toLowerCase(); - // 当res为空时直接返回0,否则累加计算 - const total = res.length > 0 - ? res.reduce((sum, item) => sum + (Number(item[currency]) || 0), 0) - : 0; + const total = + res.length > 0 + ? res.reduce((sum, item) => sum + (Number(item[currency]) || 0), 0) + : 0; + return { - // 优先使用对照表的中文名称,确保res为空时也能正确显示中文 - name: currencyMap[lowerCurrency] || currency.toUpperCase(), - value: total + name: currencyMap[lowerCurrency], + value: total, }; }); + }