From 23ecea5a49b469c57276d90622ec7f719f1ec62a Mon Sep 17 00:00:00 2001 From: lihui Date: Mon, 20 Oct 2025 15:56:02 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=95=B0=E6=8D=AE=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=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 | 45 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/components/workspace/CashManagement.vue b/src/components/workspace/CashManagement.vue index eb4482e..1b6273a 100644 --- a/src/components/workspace/CashManagement.vue +++ b/src/components/workspace/CashManagement.vue @@ -41,11 +41,10 @@ {{ market.name }}: {{ market.value.toLocaleString() }} 新币 -
-
- 代收{{ item.name }}: - {{ item.value.toLocaleString() }} -
+
+ 代收{{ item.name }}: + {{ item.value.toLocaleString() }} +
@@ -61,7 +60,7 @@ import * as echarts from 'echarts' import {onMounted, ref} from 'vue' import request from "@/util/http.js"; import API from "@/util/http.js"; -import {Warning,Service} from "@element-plus/icons-vue"; +import {Warning, Service} from "@element-plus/icons-vue"; const chartRef = ref(null) @@ -135,29 +134,35 @@ const fetchCashData = async () => { } else { // 1. 定义币种中英文对照表 const currencyMap = { - usd: '美元', - hkd: '港币', + // usd: '美元', sgd: '新币', myr: '马币', - thb: '泰铢', + hkd: '港币', cad: '加币', + thb: '泰铢', vdn: '越南盾', - krw: '韩元' - } + }; - // 2. 取出所有币种字段(排除 market 与 totalSGD) - const currencyKeys = Object.keys(res[0]).filter( - key => key !== 'market' && key !== 'totalSGD' - ) +// 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. 累加每个币种的总额并替换中文名 +// 3. 累加每个币种的总额并替换中文名(res为空时默认值为0) markets.value = currencyKeys.map(currency => { - const total = res.reduce((sum, item) => sum + (Number(item[currency]) || 0), 0) + // 处理币种key的大小写统一(转为小写匹配currencyMap) + const lowerCurrency = currency.toLowerCase(); + // 当res为空时直接返回0,否则累加计算 + const total = res.length > 0 + ? res.reduce((sum, item) => sum + (Number(item[currency]) || 0), 0) + : 0; return { - name: currencyMap[currency.toLowerCase()] || currency.toUpperCase(), + // 优先使用对照表的中文名称,确保res为空时也能正确显示中文 + name: currencyMap[lowerCurrency] || currency.toUpperCase(), value: total - } - }) + }; + }); }