import { WeaEchart, } from 'ecCom' import { Row, Col, message, } from 'antd'; import { i18n } from '../../public/i18n'; import React from 'react' class PieChart extends React.Component { constructor(props) { super(props); } componentDidUpdate() { if (this.refs.echart) this.refs.echart.paint(); } componentWillReceiveProps(nextProps) { if (this.props.winWidth !== nextProps.winWidth) { if (this.refs.echart) this.refs.echart.chart.resize(); } } getDOM() { const { isChartsShow, chartTitle, linkStyle } = this.props; return (
{ isChartsShow ? this.download()} className={linkStyle}> : {message.info(i18n.message.dataNone())}} className={linkStyle}> }
) } download() { const { canvasPosition } = this.props; let cvs = document.getElementsByTagName('canvas'); this.downloadCvs2Img(cvs[canvasPosition]); } downloadCvs2Img(cvs) { const { chartTitle } = this.props; let $a = document.createElement('a'); $a.download = chartTitle + '.jpg'; $a.target = '_blank'; let url; if (cvs) { url = cvs.toDataURL("image/jpg"); } else { message.info(i18n.message.dataNone()); } if (url) $a.href = url; if (typeof MouseEvent === 'function') { var evt = new MouseEvent('click', { view: window, bubbles: true, cancelable: false }); $a.dispatchEvent(evt); } else { if (window.navigator.msSaveOrOpenBlob) { var bstr = atob(url.split(',')[1]); var n = bstr.length; var u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } var blob = new Blob([u8arr]); window.navigator.msSaveOrOpenBlob(blob, chartTitle + '.jpg'); } else { var lang = model.get('lang'); var html = '' + '' + '' + ''; var tab = window.open(); tab.document.write(html); } } } chartAction(chart) { chart.off('click'); chart.on('click', (params) => this.handleClick(params)); } handleClick(params) { const { ids, setVisible } = this.props; setVisible('4', true, ids[params.dataIndex]); } render() { const { option, chartTitle, isChartsShow } = this.props; return (
{chartTitle}
{this.getDOM()}
{isChartsShow ?
this.chartAction(chart)}/>
:
{i18n.message.dataNone()}
}
) } } export default PieChart