fix: 优化汇总组件的金额符号根据系统语言变化 (#488)

Reviewed-on: daoyoucloud/tachycode#488
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-03-25 17:58:08 +08:00 committed by sealday
parent 78e1aeb4f2
commit 9f23211ccd
2 changed files with 9 additions and 7 deletions

View File

@ -66,7 +66,7 @@ export const GroupBlock = (props) => {
params?.config?.measures?.forEach((measuresItem) => {
const value = measuresItem.fieldFormat.fieldValue;
if (!data[value]) data[value] = 0;
data[value] = fieldTransformers(measuresItem, data[value]);
data[value] = fieldTransformers(measuresItem, data[value], api);
});
for (const key in data) {
@ -89,10 +89,11 @@ export const GroupBlock = (props) => {
if (typeof requestData.value === 'object') {
requestData.value.labels.forEach((labelItem, index) => {
dataItem.children =
dataItem.children + ` ${labelItem} ${fieldTransformers(requeatItem, requestData.value['values'][index])}`;
dataItem.children +
` ${labelItem} ${fieldTransformers(requeatItem, requestData.value['values'][index], api)}`;
});
} else {
dataItem.children = fieldTransformers(requeatItem, requestData.value.toString());
dataItem.children = fieldTransformers(requeatItem, requestData.value.toString(), api);
}
items.push(dataItem);
});
@ -100,15 +101,16 @@ export const GroupBlock = (props) => {
return <Descriptions title="汇总:" items={items} />;
};
const fieldTransformers = (item, data) => {
const fieldTransformers = (item, data, api) => {
const { option: tOption } = transformers;
const locale = api.auth.getLocale();
if (item.fieldFormat) {
const option = item.fieldFormat.option;
const decimal = item.fieldFormat.decimal;
if (option && option !== 'decimal') {
const component = tOption.filter((tValue) => tValue.value === option)[0].component;
data = String(data).includes(',') ? String(data).replace(/,/g, '') : data;
return component(data);
return component(data, locale);
} else if (option && option === 'decimal') {
const component = tOption
.filter((tValue) => tValue.value === 'decimal')[0]

View File

@ -3,8 +3,8 @@ export const transformers = {
{
label: 'Percent',
value: 'pertent',
component: (val: number) =>
new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
component: (val: number, locale = 'en-US') =>
new Intl.NumberFormat(locale, { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
val,
),
},