From 9f23211ccd7de7e593884905d4129e781af10f5e Mon Sep 17 00:00:00 2001 From: wjh Date: Mon, 25 Mar 2024 17:58:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=B1=87=E6=80=BB?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E9=87=91=E9=A2=9D=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=B3=BB=E7=BB=9F=E8=AF=AD=E8=A8=80=E5=8F=98?= =?UTF-8?q?=E5=8C=96=20(#488)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachycode/pulls/488 Reviewed-by: sealday Co-authored-by: wjh Co-committed-by: wjh --- .../client/schema-components/blocks/GroupBlock.tsx | 12 +++++++----- .../blocks/GroupBlockConfigure/transformers.tsx | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlock.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlock.tsx index a06d491e4..db3223c63 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlock.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlock.tsx @@ -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 ; }; -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] diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlockConfigure/transformers.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlockConfigure/transformers.tsx index 68a243a7f..4259eabd6 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlockConfigure/transformers.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/blocks/GroupBlockConfigure/transformers.tsx @@ -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, ), },