|
|
|
@ -41,11 +41,10 @@ |
|
|
|
<span class="market-name">{{ market.name }}:</span> |
|
|
|
<span class="market-value">{{ market.value.toLocaleString() }} 新币</span> |
|
|
|
</div> |
|
|
|
<div v-else> |
|
|
|
<div v-for="item in cashData.markets" :key="item.name" class="market-item"> |
|
|
|
<span class="market-name">代收{{ item.name }}:</span> |
|
|
|
<span class="market-value">{{ item.value.toLocaleString() }} </span> |
|
|
|
</div> |
|
|
|
<div v-else v-for="item in cashData.markets" :key="item.name" class="market-item"> |
|
|
|
<span class="market-name">代收{{ item.name }}:</span> |
|
|
|
<span class="market-value">{{ item.value.toLocaleString() }} </span> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
@ -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 |
|
|
|
} |
|
|
|
}) |
|
|
|
}; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|