feat: 显示界面支持货币取反 (#666)
Reviewed-on: daoyoucloud/tachycode#666 Co-authored-by: bai.jingfeng <bai.jingfeng@foxmail.com> Co-committed-by: bai.jingfeng <bai.jingfeng@foxmail.com>
This commit is contained in:
parent
33a0b34c07
commit
a5010cd74c
6
.changeset/chilled-ducks-tickle.md
Normal file
6
.changeset/chilled-ducks-tickle.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@nocobase/plugin-data-visualization": patch
|
||||
"@hera/plugin-core": patch
|
||||
---
|
||||
|
||||
显示支持货币取反
|
@ -202,6 +202,23 @@ const modalSchema = (t, params, valueOption, decimal) => {
|
||||
return schema;
|
||||
};
|
||||
|
||||
const CurrencyFormat = (val: number, locale = 'en-US', isNeedNegative = false) => {
|
||||
const currency = {
|
||||
'zh-CN': 'CNY',
|
||||
'en-US': 'USD',
|
||||
'ja-JP': 'JPY',
|
||||
'ko-KR': 'KRW',
|
||||
'pt-BR': 'BRL',
|
||||
'ru-RU': 'RUB',
|
||||
'tr-TR': 'TRY',
|
||||
'es-ES': 'EUR',
|
||||
}[locale];
|
||||
if (isNeedNegative && !!val) {
|
||||
val = -val;
|
||||
}
|
||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
||||
};
|
||||
|
||||
export const transformers = {
|
||||
option: [
|
||||
{
|
||||
@ -215,19 +232,12 @@ export const transformers = {
|
||||
{
|
||||
label: 'Currency',
|
||||
value: 'currency',
|
||||
component: (val: number, locale = 'en-US') => {
|
||||
const currency = {
|
||||
'zh-CN': 'CNY',
|
||||
'en-US': 'USD',
|
||||
'ja-JP': 'JPY',
|
||||
'ko-KR': 'KRW',
|
||||
'pt-BR': 'BRL',
|
||||
'ru-RU': 'RUB',
|
||||
'tr-TR': 'TRY',
|
||||
'es-ES': 'EUR',
|
||||
}[locale];
|
||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
||||
component: CurrencyFormat,
|
||||
},
|
||||
{
|
||||
label: 'CurrencyNegative',
|
||||
value: 'currencyNegative',
|
||||
component: (val: number, locale = 'en-US') => CurrencyFormat(val, locale, true),
|
||||
},
|
||||
{ label: 'Exponential', value: 'exponential', component: (val: number | string) => (+val)?.toExponential() },
|
||||
{
|
||||
|
@ -52,6 +52,22 @@ const transformers: {
|
||||
}[locale];
|
||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
||||
},
|
||||
CurrencyNegative: (val: number, locale = 'en-US') => {
|
||||
const currency = {
|
||||
'zh-CN': 'CNY',
|
||||
'en-US': 'USD',
|
||||
'ja-JP': 'JPY',
|
||||
'ko-KR': 'KRW',
|
||||
'pt-BR': 'BRL',
|
||||
'ru-RU': 'RUB',
|
||||
'tr-TR': 'TRY',
|
||||
'es-ES': 'EUR',
|
||||
}[locale];
|
||||
if (val) {
|
||||
val = -val;
|
||||
}
|
||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
||||
},
|
||||
Exponential: (val: number | string) => (+val)?.toExponential(),
|
||||
Abbreviation: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val),
|
||||
Decimal: {
|
||||
|
@ -49,6 +49,7 @@
|
||||
"Gauge Chart": "Gauge Chart",
|
||||
"Statistic": "Statistic",
|
||||
"Currency": "Currency",
|
||||
"CurrencyNegative": "CurrencyNegative",
|
||||
"Percent": "Percent",
|
||||
"Exponential": "Exponential",
|
||||
"Abbreviation": "Abbreviation",
|
||||
|
@ -49,6 +49,7 @@
|
||||
"Gauge Chart": "仪表盘",
|
||||
"Statistic": "统计",
|
||||
"Currency": "货币",
|
||||
"CurrencyNegative": "货币取反",
|
||||
"Percent": "百分比",
|
||||
"Exponential": "科学记数法",
|
||||
"Abbreviation": "缩写",
|
||||
|
Loading…
Reference in New Issue
Block a user