fix: 修复货币符号显示问题
1. 新增 utils/currency.js 货币工具函数 2. 首页今日盈亏使用 todayProfitCurrency 动态获取货币符号 3. 详情页今日盈亏使用 todayProfitCurrency 而非 currency
This commit is contained in:
parent
91e47772c7
commit
7f91e836b9
@ -50,7 +50,7 @@
|
||||
<view class="stat-item align-right">
|
||||
<text class="stat-label">当日盈亏</text>
|
||||
<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>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
<view class="card-row bottom-row">
|
||||
<view class="stat-col">
|
||||
<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 class="stat-col align-right">
|
||||
<text class="stat-label">历史总变动</text>
|
||||
@ -132,6 +132,7 @@
|
||||
import { ref } from 'vue';
|
||||
import { onShow } from '@dcloudio/uni-app';
|
||||
import { api } from '../../utils/api';
|
||||
import { getCurrencySymbol } from '../../utils/currency';
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(true);
|
||||
|
||||
57
utils/currency.js
Normal file
57
utils/currency.js
Normal 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}`;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user