feat: 添加货币管理功能,更新国际化支持,移除报表相关代码

This commit is contained in:
2026-05-21 16:24:56 +08:00
parent 6ecbaf5fb4
commit 055c613a6d
87 changed files with 1615 additions and 1319 deletions

View File

@@ -1,8 +1,35 @@
import { getCachedAdminCurrencies } from "@/hooks/use-admin-currency-catalog";
const DEFAULT_DECIMAL_PLACES = 2;
export function getAdminCurrencyDecimalPlaces(currencyCode: string | null | undefined): number {
const code = currencyCode?.trim().toUpperCase();
if (!code) {
return DEFAULT_DECIMAL_PLACES;
}
const row = getCachedAdminCurrencies().find((item) => item.code === code);
const decimals = row?.decimal_places;
if (typeof decimals === "number" && Number.isFinite(decimals) && decimals >= 0) {
return decimals;
}
return DEFAULT_DECIMAL_PLACES;
}
/** 后台列表统一:最小货币单位 → 主货币展示(默认 2 位小数,与钱包一致) */
export function formatAdminMinorUnits(minor: number, currencyCode = "NPR"): string {
const major = minor / 100;
export function formatAdminMinorUnits(
minor: number,
currencyCode = "NPR",
decimalPlaces?: number,
): string {
const resolvedDecimalPlaces =
typeof decimalPlaces === "number" && Number.isFinite(decimalPlaces) && decimalPlaces >= 0
? decimalPlaces
: getAdminCurrencyDecimalPlaces(currencyCode);
const major = minor / 10 ** resolvedDecimalPlaces;
return `${currencyCode} ${major.toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
minimumFractionDigits: resolvedDecimalPlaces,
maximumFractionDigits: resolvedDecimalPlaces,
})}`;
}