Commit fc178e55 authored by niko's avatar niko Committed by ddcat1115

Fixed: #1142 (#1160)

* fixed: #1142

* fix typo

* fix typo

* fix typo

* add missing fix
parent 9dcebdc2
...@@ -2,7 +2,7 @@ import * as React from "react"; ...@@ -2,7 +2,7 @@ import * as React from "react";
export interface IChartCardProps { export interface IChartCardProps {
title: React.ReactNode; title: React.ReactNode;
action?: React.ReactNode; action?: React.ReactNode;
total?: React.ReactNode | number; total?: React.ReactNode | function | number;
footer?: React.ReactNode; footer?: React.ReactNode;
contentHeight?: number; contentHeight?: number;
avatar?: React.ReactNode; avatar?: React.ReactNode;
......
...@@ -10,8 +10,8 @@ const renderTotal = (total) => { ...@@ -10,8 +10,8 @@ const renderTotal = (total) => {
case undefined: case undefined:
totalDom = null; totalDom = null;
break; break;
case 'string': case 'function':
totalDom = <div className={styles.total} dangerouslySetInnerHTML={{ __html: total }} />; totalDom = <div className={styles.total}>{total()}</div>;
break; break;
default: default:
totalDom = <div className={styles.total}>{total}</div>; totalDom = <div className={styles.total}>{total}</div>;
...@@ -20,18 +20,22 @@ const renderTotal = (total) => { ...@@ -20,18 +20,22 @@ const renderTotal = (total) => {
}; };
const ChartCard = ({ const ChartCard = ({
loading = false, contentHeight, title, avatar, action, total, footer, children, ...rest loading = false,
contentHeight,
title,
avatar,
action,
total,
footer,
children,
...rest
}) => { }) => {
const content = ( const content = (
<div className={styles.chartCard}> <div className={styles.chartCard}>
<div <div
className={classNames(styles.chartTop, { [styles.chartTopMargin]: (!children && !footer) })} className={classNames(styles.chartTop, { [styles.chartTopMargin]: !children && !footer })}
> >
<div className={styles.avatar}> <div className={styles.avatar}>{avatar}</div>
{
avatar
}
</div>
<div className={styles.metaWrap}> <div className={styles.metaWrap}>
<div className={styles.meta}> <div className={styles.meta}>
<span className={styles.title}>{title}</span> <span className={styles.title}>{title}</span>
...@@ -40,31 +44,26 @@ const ChartCard = ({ ...@@ -40,31 +44,26 @@ const ChartCard = ({
{renderTotal(total)} {renderTotal(total)}
</div> </div>
</div> </div>
{ {children && (
children && (
<div className={styles.content} style={{ height: contentHeight || 'auto' }}> <div className={styles.content} style={{ height: contentHeight || 'auto' }}>
<div className={contentHeight && styles.contentFixed}> <div className={contentHeight && styles.contentFixed}>{children}</div>
{children}
</div>
</div> </div>
) )}
} {footer && (
{
footer && (
<div className={classNames(styles.footer, { [styles.footerMargin]: !children })}> <div className={classNames(styles.footer, { [styles.footerMargin]: !children })}>
{footer} {footer}
</div> </div>
) )}
}
</div> </div>
); );
return ( return (
<Card <Card bodyStyle={{ padding: '20px 24px 8px 24px' }} {...rest}>
bodyStyle={{ padding: '20px 24px 8px 24px' }} {
{...rest} <Spin spinning={loading} wrapperClassName={styles.spin}>
> {content}
{<Spin spinning={loading} wrapperClassName={styles.spin}>{content}</Spin>} </Spin>
}
</Card> </Card>
); );
}; };
......
...@@ -10,10 +10,10 @@ export interface IPieProps { ...@@ -10,10 +10,10 @@ export interface IPieProps {
x: string | string; x: string | string;
y: number; y: number;
}>; }>;
total?: string; total?: string | function;
title?: React.ReactNode; title?: React.ReactNode;
tooltip?: boolean; tooltip?: boolean;
valueFormat?: (value: string) => string; valueFormat?: (value: string) => string | React.ReactNode;
subTitle?: React.ReactNode; subTitle?: React.ReactNode;
} }
......
...@@ -221,7 +221,9 @@ export default class Pie extends Component { ...@@ -221,7 +221,9 @@ export default class Pie extends Component {
<div className={styles.total}> <div className={styles.total}>
{subTitle && <h4 className="pie-sub-title">{subTitle}</h4>} {subTitle && <h4 className="pie-sub-title">{subTitle}</h4>}
{/* eslint-disable-next-line */} {/* eslint-disable-next-line */}
{total && <div className="pie-stat" dangerouslySetInnerHTML={{ __html: total }} />} {total && (
<div className="pie-stat">{typeof total === 'function' ? total() : total}</div>
)}
</div> </div>
)} )}
</div> </div>
...@@ -240,12 +242,7 @@ export default class Pie extends Component { ...@@ -240,12 +242,7 @@ export default class Pie extends Component {
<span className={styles.percent}> <span className={styles.percent}>
{`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`} {`${(isNaN(item.percent) ? 0 : item.percent * 100).toFixed(2)}%`}
</span> </span>
<span <span className={styles.value}>{valueFormat ? valueFormat(item.y) : item.y}</span>
className={styles.value}
dangerouslySetInnerHTML={{
__html: valueFormat ? valueFormat(item.y) : item.y,
}}
/>
</li> </li>
))} ))}
</ul> </ul>
......
...@@ -5,7 +5,7 @@ title: 图表卡片 ...@@ -5,7 +5,7 @@ title: 图表卡片
用于展示图表的卡片容器,可以方便的配合其它图表套件展示丰富信息。 用于展示图表的卡片容器,可以方便的配合其它图表套件展示丰富信息。
````jsx ```jsx
import { ChartCard, yuan, Field } from 'ant-design-pro/lib/Charts'; import { ChartCard, yuan, Field } from 'ant-design-pro/lib/Charts';
import Trend from 'ant-design-pro/lib/Trend'; import Trend from 'ant-design-pro/lib/Trend';
import { Row, Col, Icon, Tooltip } from 'antd'; import { Row, Col, Icon, Tooltip } from 'antd';
...@@ -16,18 +16,33 @@ ReactDOM.render( ...@@ -16,18 +16,33 @@ ReactDOM.render(
<Col span={24}> <Col span={24}>
<ChartCard <ChartCard
title="销售额" title="销售额"
action={<Tooltip title="指标说明"><Icon type="info-circle-o" /></Tooltip>} action={
total={yuan(126560)} <Tooltip title="指标说明">
footer={<Field label="日均销售额" value={numeral(12423).format('0,0')} />} <Icon type="info-circle-o" />
</Tooltip>
}
total={() => (
<span dangerouslySetInnerHTML={{ __html: yuan(126560) }} />
)}
footer={
<Field label="日均销售额" value={numeral(12423).format("0,0")} />
}
contentHeight={46} contentHeight={46}
> >
<span> <span>
周同比 周同比
<Trend flag="up" style={{ marginLeft: 8, color: 'rgba(0,0,0,.85)' }}>12%</Trend> <Trend flag="up" style={{ marginLeft: 8, color: "rgba(0,0,0,.85)" }}>
12%
</Trend>
</span> </span>
<span style={{ marginLeft: 16 }}> <span style={{ marginLeft: 16 }}>
日环比 日环比
<Trend flag="down" style={{ marginLeft: 8, color: 'rgba(0,0,0,.85)' }}>11%</Trend> <Trend
flag="down"
style={{ marginLeft: 8, color: "rgba(0,0,0,.85)" }}
>
11%
</Trend>
</span> </span>
</ChartCard> </ChartCard>
</Col> </Col>
...@@ -41,25 +56,40 @@ ReactDOM.render( ...@@ -41,25 +56,40 @@ ReactDOM.render(
alt="indicator" alt="indicator"
/> />
} }
action={<Tooltip title="指标说明"><Icon type="info-circle-o" /></Tooltip>} action={
total={yuan(126560)} <Tooltip title="指标说明">
footer={<Field label="日均销售额" value={numeral(12423).format('0,0')} />} <Icon type="info-circle-o" />
</Tooltip>
}
total={() => (
<span dangerouslySetInnerHTML={{ __html: yuan(126560) }} />
)}
footer={
<Field label="日均销售额" value={numeral(12423).format("0,0")} />
}
/> />
</Col> </Col>
<Col span={24} style={{ marginTop: 24 }}> <Col span={24} style={{ marginTop: 24 }}>
<ChartCard <ChartCard
title="移动指标" title="移动指标"
avatar={( avatar={
<img <img
alt="indicator" alt="indicator"
style={{ width: 56, height: 56 }} style={{ width: 56, height: 56 }}
src="https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png" src="https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png"
/> />
}
action={
<Tooltip title="指标说明">
<Icon type="info-circle-o" />
</Tooltip>
}
total={() => (
<span dangerouslySetInnerHTML={{ __html: yuan(126560) }} />
)} )}
action={<Tooltip title="指标说明"><Icon type="info-circle-o" /></Tooltip>}
total={yuan(126560)}
/> />
</Col> </Col>
</Row> </Row>,
, mountNode); mountNode,
```` );
```
...@@ -27,6 +27,7 @@ ReactDOM.render( ...@@ -27,6 +27,7 @@ ReactDOM.render(
<Col span={24}> <Col span={24}>
<ChartCard <ChartCard
title="搜索用户数量" title="搜索用户数量"
total={numeral(8846).format('0,0')}
contentHeight={134} contentHeight={134}
> >
<NumberInfo <NumberInfo
......
...@@ -3,7 +3,7 @@ order: 5 ...@@ -3,7 +3,7 @@ order: 5
title: 饼状图 title: 饼状图
--- ---
````jsx ```jsx
import { Pie, yuan } from 'ant-design-pro/lib/Charts'; import { Pie, yuan } from 'ant-design-pro/lib/Charts';
const salesPieData = [ const salesPieData = [
...@@ -38,10 +38,17 @@ ReactDOM.render( ...@@ -38,10 +38,17 @@ ReactDOM.render(
hasLegend hasLegend
title="销售额" title="销售额"
subTitle="销售额" subTitle="销售额"
total={yuan(salesPieData.reduce((pre, now) => now.y + pre, 0))} total={() => (
<span
dangerouslySetInnerHTML={{
__html: yuan(salesPieData.reduce((pre, now) => now.y + pre, 0))
}}
/>
)}
data={salesPieData} data={salesPieData}
valueFormat={val => yuan(val)} valueFormat={val => <span dangerouslySetInnerHTML={{ __html: yuan(val) }} />}
height={294} height={294}
/> />,
, mountNode); mountNode,
```` );
```
...@@ -19,7 +19,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https ...@@ -19,7 +19,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https
|----------|------------------------------------------|-------------|-------| |----------|------------------------------------------|-------------|-------|
| title | 卡片标题 | ReactNode\|string | - | | title | 卡片标题 | ReactNode\|string | - |
| action | 卡片操作 | ReactNode | - | | action | 卡片操作 | ReactNode | - |
| total | 数据总量 | ReactNode \| number | - | | total | 数据总量 | ReactNode \| number \| function | - |
| footer | 卡片底部 | ReactNode | - | | footer | 卡片底部 | ReactNode | - |
| contentHeight | 内容区域高度 | number | - | | contentHeight | 内容区域高度 | number | - |
| avatar | 右侧图标 | React.ReactNode | - | | avatar | 右侧图标 | React.ReactNode | - |
...@@ -78,7 +78,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https ...@@ -78,7 +78,7 @@ Ant Design Pro 提供的业务中常用的图表类型,都是基于 [G2](https
| valueFormat | 显示值的格式化函数 | function | - | | valueFormat | 显示值的格式化函数 | function | - |
| title | 图表标题 | ReactNode\|string | - | | title | 图表标题 | ReactNode\|string | - |
| subTitle | 图表子标题 | ReactNode\|string | - | | subTitle | 图表子标题 | ReactNode\|string | - |
| total | 图标中央的总数 | string | - | | total | 图标中央的总数 | string | function | - |
### Radar ### Radar
......
...@@ -252,7 +252,7 @@ export default class Analysis extends Component { ...@@ -252,7 +252,7 @@ export default class Analysis extends Component {
<Icon type="info-circle-o" /> <Icon type="info-circle-o" />
</Tooltip> </Tooltip>
} }
total={yuan(126560)} total={() => <span dangerouslySetInnerHTML={{ __html: yuan(126560) }} />}
footer={<Field label="日均销售额" value={`¥${numeral(12423).format('0,0')}`} />} footer={<Field label="日均销售额" value={`¥${numeral(12423).format('0,0')}`} />}
contentHeight={46} contentHeight={46}
> >
...@@ -451,9 +451,15 @@ export default class Analysis extends Component { ...@@ -451,9 +451,15 @@ export default class Analysis extends Component {
<Pie <Pie
hasLegend hasLegend
subTitle="销售额" subTitle="销售额"
total={yuan(salesPieData.reduce((pre, now) => now.y + pre, 0))} total={() => (
<span
dangerouslySetInnerHTML={{
__html: yuan(salesPieData.reduce((pre, now) => now.y + pre, 0)),
}}
/>
)}
data={salesPieData} data={salesPieData}
valueFormat={val => yuan(val)} valueFormat={val => <span dangerouslySetInnerHTML={{ __html: yuan(val) }} />}
height={248} height={248}
lineWidth={4} lineWidth={4}
/> />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment