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:
parent
78e1aeb4f2
commit
9f23211ccd
@ -66,7 +66,7 @@ export const GroupBlock = (props) => {
|
|||||||
params?.config?.measures?.forEach((measuresItem) => {
|
params?.config?.measures?.forEach((measuresItem) => {
|
||||||
const value = measuresItem.fieldFormat.fieldValue;
|
const value = measuresItem.fieldFormat.fieldValue;
|
||||||
if (!data[value]) data[value] = 0;
|
if (!data[value]) data[value] = 0;
|
||||||
data[value] = fieldTransformers(measuresItem, data[value]);
|
data[value] = fieldTransformers(measuresItem, data[value], api);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const key in data) {
|
for (const key in data) {
|
||||||
@ -89,10 +89,11 @@ export const GroupBlock = (props) => {
|
|||||||
if (typeof requestData.value === 'object') {
|
if (typeof requestData.value === 'object') {
|
||||||
requestData.value.labels.forEach((labelItem, index) => {
|
requestData.value.labels.forEach((labelItem, index) => {
|
||||||
dataItem.children =
|
dataItem.children =
|
||||||
dataItem.children + ` ${labelItem} ${fieldTransformers(requeatItem, requestData.value['values'][index])}`;
|
dataItem.children +
|
||||||
|
` ${labelItem} ${fieldTransformers(requeatItem, requestData.value['values'][index], api)}`;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
dataItem.children = fieldTransformers(requeatItem, requestData.value.toString());
|
dataItem.children = fieldTransformers(requeatItem, requestData.value.toString(), api);
|
||||||
}
|
}
|
||||||
items.push(dataItem);
|
items.push(dataItem);
|
||||||
});
|
});
|
||||||
@ -100,15 +101,16 @@ export const GroupBlock = (props) => {
|
|||||||
return <Descriptions title="汇总:" items={items} />;
|
return <Descriptions title="汇总:" items={items} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldTransformers = (item, data) => {
|
const fieldTransformers = (item, data, api) => {
|
||||||
const { option: tOption } = transformers;
|
const { option: tOption } = transformers;
|
||||||
|
const locale = api.auth.getLocale();
|
||||||
if (item.fieldFormat) {
|
if (item.fieldFormat) {
|
||||||
const option = item.fieldFormat.option;
|
const option = item.fieldFormat.option;
|
||||||
const decimal = item.fieldFormat.decimal;
|
const decimal = item.fieldFormat.decimal;
|
||||||
if (option && option !== 'decimal') {
|
if (option && option !== 'decimal') {
|
||||||
const component = tOption.filter((tValue) => tValue.value === option)[0].component;
|
const component = tOption.filter((tValue) => tValue.value === option)[0].component;
|
||||||
data = String(data).includes(',') ? String(data).replace(/,/g, '') : data;
|
data = String(data).includes(',') ? String(data).replace(/,/g, '') : data;
|
||||||
return component(data);
|
return component(data, locale);
|
||||||
} else if (option && option === 'decimal') {
|
} else if (option && option === 'decimal') {
|
||||||
const component = tOption
|
const component = tOption
|
||||||
.filter((tValue) => tValue.value === 'decimal')[0]
|
.filter((tValue) => tValue.value === 'decimal')[0]
|
||||||
|
@ -3,8 +3,8 @@ export const transformers = {
|
|||||||
{
|
{
|
||||||
label: 'Percent',
|
label: 'Percent',
|
||||||
value: 'pertent',
|
value: 'pertent',
|
||||||
component: (val: number) =>
|
component: (val: number, locale = 'en-US') =>
|
||||||
new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
|
new Intl.NumberFormat(locale, { style: 'percent', minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(
|
||||||
val,
|
val,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user