index.js 1.93 KB
Newer Older
wangshuo committed
1 2
import React, {Component} from 'react'
import './index.scss';
FE committed
3
import {withRouter} from 'react-router-dom'
FE committed
4
import {browser,getParam} from "@/utils";
xuzhenghua committed
5

wangshuo committed
6 7 8 9
class HeaderBar extends Component {
    constructor(props) {
        super(props);
    }
xuzhenghua committed
10

wangshuo committed
11
    goBack = () => {
12
        const {state} = this.props.location
FE committed
13 14 15
        if(browser.isWeixin && getParam('code') && getParam('state')){
            window.history.go(-2)
        }
16 17 18 19 20
        if(state.record && state.record.length > 1){
            window.history.go(-1);
        }else{
            window.location.href = window.location.origin
        }
wangshuo committed
21
    }
FE committed
22

23 24
    toLink = () => {
        const { toHref } = this.props;
25
        // console.log(toHref);
26
        location.replace(toHref)
FE committed
27 28
    }

wangshuo committed
29
    goShop = () => {
FE committed
30
        this.props.history.push('/shopcart')
wangshuo committed
31
    }
xuzhenghua committed
32

wangshuo committed
33
    render() {
34
        const { toHref } = this.props
wangshuo committed
35 36
        return (
            <div className="detail-header" style={{...this.props.style}}>
xuzhenghua committed
37
                {
38
                    !toHref && this.props.arrow &&
xuzhenghua committed
39 40
                    <i className='iconfont iconiconfront-68' onClick={this.goBack}></i>
                }
FE committed
41
                {
42
                    toHref && typeof toHref === 'function' &&
FE committed
43
                    <i className='iconfont iconiconfront-68' onClick={toHref}></i>
44 45 46 47
                }
                {
                    toHref && typeof toHref === 'string' &&
                    <i className='iconfont iconiconfront-68' onClick={this.toLink}></i>
FE committed
48
                }
wangshuo committed
49
                <span className='herder'>{this.props.title}</span>
xuzhenghua committed
50 51 52 53 54 55 56 57
                {
                    this.props.cart &&
                    <i className='iconfont icongouwuche-xianxing' onClick={this.goShop}></i>
                }
                {
                    this.props.delete &&
                    <i className='iconfont iconiconfront-56' onClick={this.props.toDelete}></i>
                }
wangshuo committed
58 59 60
            </div>
        );
    }
xuzhenghua committed
61 62
};

FE committed
63
export default  withRouter(HeaderBar);