import React, { Component } from 'react'; import 'antd-mobile/dist/antd-mobile.less'; import styles from './index.less'; import router from 'umi/router'; import html2canvas from 'html2canvas'; import { Toast } from 'antd-mobile'; class Mq extends Component { constructor(props) { super(props); this.state = { flag: false, imgUri: null, }; } componentWillMount = () => {}; componentDidMount = () => {}; componentWillUnmount = () => {}; open = () => { Toast.loading('生成中', 0); const certificate = document.getElementById('certificate'); const newCanvas = document.createElement('canvas'); const domWidth = parseInt(window.getComputedStyle(certificate).width); const domHeight = parseInt(window.getComputedStyle(certificate).height); newCanvas.width = domWidth; newCanvas.height = domHeight; newCanvas.style.width = domWidth + 'px'; newCanvas.style.height = domHeight + 'px'; const _this = this; html2canvas(certificate, { canvas: newCanvas, scale: 1, x: 0, y: 0, scrollX: 0, scrollY: 0, }).then(canvas => { const imgUri = canvas.toDataURL('image/png'); _this.setState({ imgUri, flag: true, }); Toast.hide(); }); }; closed = () => { this.setState({ flag: false, }); }; render() { const data = this.props.ckuCertificate; const { flag, imgUri } = this.state; return (