/* * @Description: 这里输入文件功能 * @Author: zhoupeng * @Date: 2020-05-14 16:49:16 * @LastEditTime: 2020-05-22 15:23:27 */ import React, { Component } from 'react'; import { connect } from 'react-redux'; import DocumentTitle from 'react-document-title'; import html2canvas from 'html2canvas'; import { Toast } from 'antd-mobile'; import 'antd-mobile/dist/antd-mobile.less'; import styles from './index.less'; import router from 'umi/router'; import PlayMusic from '../components/playMusic/index'; import { onPlay, getPlayFlag, setImg } from '../common/common'; import img from '../assets/share/icon01.jpg'; @connect(() => ({})) class Index extends Component { constructor(props) { super(props); this.state = { playFlag: getPlayFlag(), imgUri: null, schoolDetail: {}, wechatNiceName: '', }; } componentWillMount = () => {}; componentDidMount = () => { this.initData(); }; initData = () => { Toast.loading('加载中', 0); const detailStr = window.sessionStorage.getItem('selectSchool'); const schoolDetail = JSON.parse(detailStr); const niceName = window.sessionStorage.getItem('niceName'); this.setState({ schoolDetail, wechatNiceName: niceName, }); }; onload = () => { const _this = this; setTimeout(function() { _this.share(); Toast.hide(); }, 1000); }; //生成图片分享 share = () => { const body = document.getElementById('body'); const newCanvas = document.createElement('canvas'); const domWidth = body.offsetWidth; const domHeight = body.offsetHeight; const scale = 2; newCanvas.width = domWidth * scale; newCanvas.height = domHeight * scale; const _this = this; html2canvas(body, { canvas: newCanvas, scale, x: 0, y: 0, scrollX: 0, scrollY: 0, allowTaint: false, useCORS: true, }).then(canvas => { const imgUri = canvas.toDataURL('image/png'); _this.setState({ imgUri, flag: true, }); }); }; render() { const { playFlag, imgUri, wechatNiceName, schoolDetail } = this.state; return (
{ onPlay(playFlag, flag => { this.setState({ playFlag: flag, }); }); }} >
bg
我刚刚请 {`${schoolDetail && schoolDetail.schoolName ? schoolDetail.schoolName : ''}的${ schoolDetail && schoolDetail.catName ? schoolDetail.catName : '校宠' }吃了顿饭!`}
icon
分享
); } } export default Index;