detail.js 3.06 KB

import { Component, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import $ from 'jquery';
import share from '../../utils/share';
import shareHide from "../../utils/shareHide";
import {urlGetParams} from '../../utils/dataFilter'
import css from './css.less';


class Detail extends Component{
  constructor(props) {
    super(props);
    this.state = {
      data:null
    }
  }

  componentDidMount() {
    document.title = '行业动态';
    const { search } = this.props.location;
    const params = urlGetParams(window.location.href);
    const _this = this;
    if (params.id) {
      let id = search.substr(4)
      this.props.dispatch({
        type: 'industrynews/getNews',
        payload: {
          id:params.id,
          reqType:0
        },
        callback(res) {
          _this.setState({data:res})
          let htm = res.html.replace(/<figure class="image"><img src="http:\/\/zmtoss\.ihxlife\.com\/polysoft\/o2o_industrynews_audit_1561000223813\.png.*?<figcaption>(.+?)<\/figcaption><\/figure>/g, `<div style="clear:both"><video src=$1 controls="controls"></video></div>`);
          $('.ck-content').html(htm);
          let urlShare = "";
          if(params.isShare){//处理多次转发参数问题
            urlShare = window.location.href;
          }else{
            urlShare = window.location.href+`&isShare=t&phoneNum=${localStorage.getItem('number')}`;
          }
          share({
            decodeUrl: window.location.href.split('#')[0],
            title: res.title,
            desc: $('.ck-content').text().substr(0,100),
            shareUrl: urlShare,
            thumbnail: res.imgUrl,
            record:{
              "operCode": res.id,
              "operTitle": res.title,
              "operFunction": 100110,
              "operType": 202,
              "phoneNum": params.isShare ? params.phoneNum : ""
            }
          });
          //点击记录一次
          _this.props.dispatch({
            type:"home/setClickRecord",
            payload: {
              "operCode": res.id,
              "operFunction": 100110,
              "operTitle": res.title,
              "operType": 201,
              "phoneNum": params.isShare ? params.phoneNum : ""
            },
            callback(data){
              console.log('点击分享链接,记录一次') 
            }
          })
        }
      })
    }
    shareHide(false);
  }

  render() {
    const { data } = this.state;
    return (
      <div className={css.detailWrap}>
        {
          data && <Fragment>
            <div className={css.detailTitle}>{data.title}</div>
            <div className={css.detailInfo}>
              <div className={css.author}>来源:{data.author}</div>
              <div className={css.time}>{moment(data.modifyTime).format('YYYY-MM-DD')}</div>
            </div>
          </Fragment>
        }
        <div className="ck-content"></div>
        <div className={css.detailInfo}>
          <div className={css.viewCount}>{data && data.viewCount}</div>
        </div>
      </div>
    )
  }
}

export default connect()(Detail);