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;
|
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 = {
|
export const transformers = {
|
||||||
option: [
|
option: [
|
||||||
{
|
{
|
||||||
@ -215,19 +232,12 @@ export const transformers = {
|
|||||||
{
|
{
|
||||||
label: 'Currency',
|
label: 'Currency',
|
||||||
value: 'currency',
|
value: 'currency',
|
||||||
component: (val: number, locale = 'en-US') => {
|
component: CurrencyFormat,
|
||||||
const currency = {
|
},
|
||||||
'zh-CN': 'CNY',
|
{
|
||||||
'en-US': 'USD',
|
label: 'CurrencyNegative',
|
||||||
'ja-JP': 'JPY',
|
value: 'currencyNegative',
|
||||||
'ko-KR': 'KRW',
|
component: (val: number, locale = 'en-US') => CurrencyFormat(val, locale, true),
|
||||||
'pt-BR': 'BRL',
|
|
||||||
'ru-RU': 'RUB',
|
|
||||||
'tr-TR': 'TRY',
|
|
||||||
'es-ES': 'EUR',
|
|
||||||
}[locale];
|
|
||||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ label: 'Exponential', value: 'exponential', component: (val: number | string) => (+val)?.toExponential() },
|
{ label: 'Exponential', value: 'exponential', component: (val: number | string) => (+val)?.toExponential() },
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,22 @@ const transformers: {
|
|||||||
}[locale];
|
}[locale];
|
||||||
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(val);
|
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(),
|
Exponential: (val: number | string) => (+val)?.toExponential(),
|
||||||
Abbreviation: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val),
|
Abbreviation: (val: number, locale = 'en-US') => new Intl.NumberFormat(locale, { notation: 'compact' }).format(val),
|
||||||
Decimal: {
|
Decimal: {
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
"Gauge Chart": "Gauge Chart",
|
"Gauge Chart": "Gauge Chart",
|
||||||
"Statistic": "Statistic",
|
"Statistic": "Statistic",
|
||||||
"Currency": "Currency",
|
"Currency": "Currency",
|
||||||
|
"CurrencyNegative": "CurrencyNegative",
|
||||||
"Percent": "Percent",
|
"Percent": "Percent",
|
||||||
"Exponential": "Exponential",
|
"Exponential": "Exponential",
|
||||||
"Abbreviation": "Abbreviation",
|
"Abbreviation": "Abbreviation",
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
"Gauge Chart": "仪表盘",
|
"Gauge Chart": "仪表盘",
|
||||||
"Statistic": "统计",
|
"Statistic": "统计",
|
||||||
"Currency": "货币",
|
"Currency": "货币",
|
||||||
|
"CurrencyNegative": "货币取反",
|
||||||
"Percent": "百分比",
|
"Percent": "百分比",
|
||||||
"Exponential": "科学记数法",
|
"Exponential": "科学记数法",
|
||||||
"Abbreviation": "缩写",
|
"Abbreviation": "缩写",
|
||||||
|
Loading…
Reference in New Issue
Block a user