UNPKG

react-app-shell

Version:

react打包脚本和example, 这里的版本请忽略

70 lines (64 loc) 1.9 kB
import React, {Component} from 'react'; import {observer, inject} from 'mobx-react'; import queryString from 'query-string'; import {withRouter} from 'react-router-dom'; import {tools} from '../../../../utils'; import {WechatConfig} from '../../../../components'; /** * PUBLIC_URL */ const basename = process.env.PUBLIC_URL || ''; @inject(({lotteryStore}) => { return { // 数据 lotteryId: lotteryStore.lotteryId, shareOptions: lotteryStore.shareOptions, // 分享配置 // 方法 initShareOption: lotteryStore.initShareOption, }; }) @observer @withRouter export default class shareWechat extends Component { constructor(props) { super(props); this.isWechat = tools.isWeiXin(); this.rf = queryString.parse(window.location.search).rf; this.lotteryId = this.props.match.params.id; const {initShareOption} = this.props; initShareOption(this.lotteryId); } /** * 获取默认分享的链接 */ getDefaultShareLink = () => { let searchObj = { rf: this.rf, }; // 分享链接 const link = `${location.protocol}//${location.host}${basename}/lottery/${this.lotteryId}?${queryString.stringify(searchObj)}`; return link; }; /** * @description 如果是微信环境 设置分享 不然不设置 * @return {component} */ renderWechatConfig = () => { const {lotteryId} = this.props; const shareOptions = { ...this.props.shareOptions, link: this.getDefaultShareLink(), }; if (this.isWechat) { return <WechatConfig key={lotteryId} showShare shareOptions={shareOptions}/>; } return null; } render() { return ( <div> {this.renderWechatConfig()} </div> ); } }