index.js 1.74 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 = () => {
FE committed
12 13 14
        if(browser.isWeixin && getParam('code') && getParam('state')){
            window.history.go(-2)
        }
wangshuo committed
15 16
        window.history.go(-1);
    }
FE committed
17

18 19 20 21
    toLink = () => {
        const { toHref } = this.props;
        console.log(toHref);
        location.replace(toHref)
FE committed
22 23
    }

wangshuo committed
24
    goShop = () => {
FE committed
25
        this.props.history.push('/shopcart')
wangshuo committed
26
    }
xuzhenghua committed
27

wangshuo committed
28
    render() {
29
        const { toHref } = this.props
wangshuo committed
30 31
        return (
            <div className="detail-header" style={{...this.props.style}}>
xuzhenghua committed
32
                {
33
                    !toHref && this.props.arrow &&
xuzhenghua committed
34 35
                    <i className='iconfont iconiconfront-68' onClick={this.goBack}></i>
                }
FE committed
36
                {
37
                    toHref && typeof toHref === 'function' &&
FE committed
38
                    <i className='iconfont iconiconfront-68' onClick={toHref}></i>
39 40 41 42
                }
                {
                    toHref && typeof toHref === 'string' &&
                    <i className='iconfont iconiconfront-68' onClick={this.toLink}></i>
FE committed
43
                }
wangshuo committed
44
                <span className='herder'>{this.props.title}</span>
xuzhenghua committed
45 46 47 48 49 50 51 52
                {
                    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
53 54 55
            </div>
        );
    }
xuzhenghua committed
56 57
};

FE committed
58
export default  withRouter(HeaderBar);