feat: 添加收益模块,包含总收益概览、收益趋势和收益来源,更新相关组件和路由
This commit is contained in:
@@ -15,7 +15,7 @@ export function timeToLocal(originalTime: number) {
|
||||
return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()) / 1000;
|
||||
}
|
||||
|
||||
export function formatAmount(amount: MaybeRefOrGetter<number | string | null | undefined>): string {
|
||||
export function formatAmountWithUnit(amount: MaybeRefOrGetter<number | string | null | undefined>): string {
|
||||
const value = toValue(amount);
|
||||
if (Number.isNaN(Number(value))) {
|
||||
return "0";
|
||||
@@ -24,21 +24,37 @@ export function formatAmount(amount: MaybeRefOrGetter<number | string | null | u
|
||||
const num = Number(value);
|
||||
|
||||
// 不超过1万,原样显示
|
||||
if (num < 10000) {
|
||||
if (num < 1e4) {
|
||||
return String(num);
|
||||
}
|
||||
|
||||
// 1亿以上,显示为xx亿
|
||||
if (num >= 100000000) {
|
||||
const yi = (num / 100000000).toFixed(1);
|
||||
if (num >= 1e8) {
|
||||
const yi = (num / 1e8).toFixed(1);
|
||||
return yi.endsWith(".0") ? `${Number.parseInt(yi)}亿` : `${yi}亿`;
|
||||
}
|
||||
|
||||
// 1万到1亿,显示为xx万
|
||||
if (num >= 10000) {
|
||||
const wan = (num / 10000).toFixed(1);
|
||||
if (num >= 1e4) {
|
||||
const wan = (num / 1e4).toFixed(1);
|
||||
return wan.endsWith(".0") ? `${Number.parseInt(wan)}万` : `${wan}万`;
|
||||
}
|
||||
|
||||
return String(num);
|
||||
}
|
||||
|
||||
export function formatAmountWithSplit(amount: MaybeRefOrGetter<number | string | null | undefined>): string {
|
||||
const value = toValue(amount);
|
||||
if (Number.isNaN(Number(value))) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
const num = Number(value);
|
||||
|
||||
return Intl.NumberFormat("en-US", {
|
||||
style: "currency",
|
||||
currency: "USD",
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(num);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user