fix: 修复货币符号显示问题

1. 新增 utils/currency.js 货币工具函数
2. 首页今日盈亏使用 todayProfitCurrency 动态获取货币符号
3. 详情页今日盈亏使用 todayProfitCurrency 而非 currency
This commit is contained in:
claw_bot 2026-03-15 23:46:54 +00:00
parent 91e47772c7
commit 7f91e836b9
3 changed files with 60 additions and 2 deletions

View File

@ -50,7 +50,7 @@
<view class="stat-item align-right"> <view class="stat-item align-right">
<text class="stat-label">当日盈亏</text> <text class="stat-label">当日盈亏</text>
<text class="stat-val" :class="(portfolioData.todayProfit || 0) >= 0 ? 'text-red' : 'text-green'"> <text class="stat-val" :class="(portfolioData.todayProfit || 0) >= 0 ? 'text-red' : 'text-green'">
{{ (portfolioData.todayProfit || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(portfolioData.currency) }}{{ (portfolioData.todayProfit || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} {{ (portfolioData.todayProfit || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(portfolioData.todayProfitCurrency || portfolioData.currency) }}{{ (portfolioData.todayProfit || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}
</text> </text>
</view> </view>
</view> </view>

View File

@ -41,7 +41,7 @@
<view class="card-row bottom-row"> <view class="card-row bottom-row">
<view class="stat-col"> <view class="stat-col">
<text class="stat-label">今日账面变动</text> <text class="stat-label">今日账面变动</text>
<text class="stat-value">{{ (assetData.todayProfit || 0) >= 0 ? '+' : '' }}¥{{ (assetData.todayProfit || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text> <text class="stat-value">{{ (assetData.todayProfit || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(assetData.todayProfitCurrency || 'CNY') }}{{ (assetData.todayProfit || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
</view> </view>
<view class="stat-col align-right"> <view class="stat-col align-right">
<text class="stat-label">历史总变动</text> <text class="stat-label">历史总变动</text>
@ -132,6 +132,7 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { onShow } from '@dcloudio/uni-app'; import { onShow } from '@dcloudio/uni-app';
import { api } from '../../utils/api'; import { api } from '../../utils/api';
import { getCurrencySymbol } from '../../utils/currency';
// //
const loading = ref(true); const loading = ref(true);

57
utils/currency.js Normal file
View File

@ -0,0 +1,57 @@
/**
* 货币工具函数
*/
/**
* 获取货币符号
* @param {string} currency - 货币代码 (CNY, USD, HKD )
* @returns {string} 货币符号
*/
export const getCurrencySymbol = (currency) => {
const symbols = {
'CNY': '¥',
'USD': '$',
'HKD': 'HK$',
'EUR': '€',
'GBP': '£',
'JPY': '¥',
'SGD': 'S$',
'AUD': 'A$'
};
return symbols[currency?.toUpperCase()] || '¥';
};
/**
* 格式化金额
* @param {number} amount - 金额
* @param {string} currency - 货币代码
* @param {number} decimals - 小数位数
* @returns {string} 格式化后的金额字符串
*/
export const formatAmount = (amount, currency = 'CNY', decimals = 2) => {
const symbol = getCurrencySymbol(currency);
const formatted = Math.abs(amount || 0).toLocaleString('zh-CN', {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals
});
const sign = amount >= 0 ? '' : '-';
return `${sign}${symbol}${formatted}`;
};
/**
* 格式化金额带正负号
* @param {number} amount - 金额
* @param {string} currency - 货币代码
* @param {number} decimals - 小数位数
* @returns {string} 格式化后的金额字符串
*/
export const formatAmountWithSign = (amount, currency = 'CNY', decimals = 2) => {
const symbol = getCurrencySymbol(currency);
const formatted = Math.abs(amount || 0).toLocaleString('zh-CN', {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals
});
if (amount > 0) return `+${symbol}${formatted}`;
if (amount < 0) return `-${symbol}${formatted}`;
return `${symbol}${formatted}`;
};