diff --git a/src/components/Charts/ChartCard/index.d.ts b/src/components/Charts/ChartCard/index.d.ts index 76470460aede98c676da760cbb39b675cb20a648..ad450dfa630fdf5f57b06afb05340799b882a0bf 100644 --- a/src/components/Charts/ChartCard/index.d.ts +++ b/src/components/Charts/ChartCard/index.d.ts @@ -2,7 +2,7 @@ import * as React from "react"; export interface IChartCardProps { title: React.ReactNode; action?: React.ReactNode; - total?: React.ReactNode | number; + total?: React.ReactNode | function | number; footer?: React.ReactNode; contentHeight?: number; avatar?: React.ReactNode; diff --git a/src/components/Charts/ChartCard/index.js b/src/components/Charts/ChartCard/index.js index 2fd10e6f1ac4ba2c02129d8c2ae2f7e7e892c022..035b31315f2825bfa8b0c67c2d8db054a6a3c4c9 100644 --- a/src/components/Charts/ChartCard/index.js +++ b/src/components/Charts/ChartCard/index.js @@ -10,8 +10,8 @@ const renderTotal = (total) => { case undefined: totalDom = null; break; - case 'string': - totalDom =
; + case 'function': + totalDom =
{total()}
; break; default: totalDom =
{total}
; @@ -20,18 +20,22 @@ const renderTotal = (total) => { }; const ChartCard = ({ - loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest + loading = false, + contentHeight, + title, + avatar, + action, + total, + footer, + children, + ...rest }) => { const content = (
-
- { - avatar - } -
+
{avatar}
{title} @@ -40,31 +44,26 @@ const ChartCard = ({ {renderTotal(total)}
- { - children && ( -
-
- {children} -
-
- ) - } - { - footer && ( -
- {footer} -
- ) - } + {children && ( +
+
{children}
+
+ )} + {footer && ( +
+ {footer} +
+ )}
); return ( - - {{content}} + + { + + {content} + + } ); }; diff --git a/src/components/Charts/Pie/index.d.ts b/src/components/Charts/Pie/index.d.ts index e9dcd1d4dffde04b38b624be1047b33c16844bea..5b19208d6979a57301ebff41a837e033f5cfe357 100644 --- a/src/components/Charts/Pie/index.d.ts +++ b/src/components/Charts/Pie/index.d.ts @@ -10,10 +10,10 @@ export interface IPieProps { x: string | string; y: number; }>; - total?: string; + total?: string | function; title?: React.ReactNode; tooltip?: boolean; - valueFormat?: (value: string) => string; + valueFormat?: (value: string) => string | React.ReactNode; subTitle?: React.ReactNode; } diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index 528b2519d21b41dc3fbd75ffa5c3270534400c1b..2784ad60c8979904880ea5b51c1551a2f04ee306 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -221,7 +221,9 @@ export default class Pie extends Component {
{subTitle &&

{subTitle}

} {/* eslint-disable-next-line */} - {total &&
} + {total && ( +
{typeof total === 'function' ? total() : total}
+ )}
)}
@@ -240,12 +242,7 @@ export default class Pie extends Component { {`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`} - + {valueFormat ? valueFormat(item.y) : item.y} ))} diff --git a/src/components/Charts/demo/chart-card.md b/src/components/Charts/demo/chart-card.md index 51204793e0574888d758f8e326866969f0fe6440..4da852b71442785b17d0ce07b149e4bef343dd20 100644 --- a/src/components/Charts/demo/chart-card.md +++ b/src/components/Charts/demo/chart-card.md @@ -5,7 +5,7 @@ title: 图表卡片 用于展示图表的卡片容器,可以方便的配合其它图表套件展示丰富信息。 -````jsx +```jsx import { ChartCard, yuan, Field } from 'ant-design-pro/lib/Charts'; import Trend from 'ant-design-pro/lib/Trend'; import { Row, Col, Icon, Tooltip } from 'antd'; @@ -16,18 +16,33 @@ ReactDOM.render( } - total={yuan(126560)} - footer={} + action={ + + + + } + total={() => ( + + )} + footer={ + + } contentHeight={46} > 周同比 - 12% + + 12% + 日环比 - 11% + + 11% + @@ -41,25 +56,40 @@ ReactDOM.render( alt="indicator" /> } - action={} - total={yuan(126560)} - footer={} + action={ + + + + } + total={() => ( + + )} + footer={ + + } /> + } + action={ + + + + } + total={() => ( + )} - action={} - total={yuan(126560)} /> - -, mountNode); -```` + , + mountNode, +); +``` diff --git a/src/components/Charts/demo/mix.md b/src/components/Charts/demo/mix.md index 0c158e5f49c7e979d04b6d6ad71d1d144c09b4e9..fc64110ae4b9b16126409d51d0e8ad5afc423fd2 100644 --- a/src/components/Charts/demo/mix.md +++ b/src/components/Charts/demo/mix.md @@ -27,6 +27,7 @@ ReactDOM.render( now.y + pre, 0))} + total={() => ( + now.y + pre, 0)) + }} + /> + )} data={salesPieData} - valueFormat={val => yuan(val)} + valueFormat={val => } height={294} - /> -, mountNode); -```` + />, + mountNode, +); +``` diff --git a/src/components/Charts/index.md b/src/components/Charts/index.md index e48220e595fc53f394df1340ecbf39ec099a940f..e292a247dce27f04cf3a9a244a42490dfab97c2d 100644 --- a/src/components/Charts/index.md +++ b/src/components/Charts/index.md @@ -19,7 +19,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https |----------|------------------------------------------|-------------|-------| | title | 卡片标题 | ReactNode\|string | - | | action | 卡片操作 | ReactNode | - | -| total | 数据总量 | ReactNode \| number | - | +| total | 数据总量 | ReactNode \| number \| function | - | | footer | 卡片底部 | ReactNode | - | | contentHeight | 内容区域高度 | number | - | | avatar | 右侧图标 | React.ReactNode | - | @@ -78,7 +78,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https | valueFormat | 显示值的格式化函数 | function | - | | title | 图表标题 | ReactNode\|string | - | | subTitle | 图表子标题 | ReactNode\|string | - | -| total | 图标中央的总数 | string | - | +| total | 图标中央的总数 | string | function | - | ### Radar diff --git a/src/routes/Dashboard/Analysis.js b/src/routes/Dashboard/Analysis.js index 9cb55a9aeab5cce1aea8f02f8e4f92919ff1a870..b7582b0393ae28958d90a8311632f74cf03fe3e4 100644 --- a/src/routes/Dashboard/Analysis.js +++ b/src/routes/Dashboard/Analysis.js @@ -252,7 +252,7 @@ export default class Analysis extends Component { } - total={yuan(126560)} + total={() => } footer={} contentHeight={46} > @@ -451,9 +451,15 @@ export default class Analysis extends Component { now.y + pre, 0))} + total={() => ( + now.y + pre, 0)), + }} + /> + )} data={salesPieData} - valueFormat={val => yuan(val)} + valueFormat={val => } height={248} lineWidth={4} />