index.js 2.19 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)
        }
zhanghaozhe committed
16
        if(state.records && state.records.length > 1){
17
            window.history.go(-1);
18 19
        }else if(state.from && state.from.pathname) {
            location.replace(`${state.from.pathname}${state.from.search}`)
20 21 22
        }else{
            window.location.href = window.location.origin
        }
wangshuo committed
23
    }
FE committed
24

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

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

wangshuo committed
35
    render() {
xuzhenghua committed
36
        const { toHref, home } = this.props;
wangshuo committed
37 38
        return (
            <div className="detail-header" style={{...this.props.style}}>
xuzhenghua committed
39
                {
40
                    !toHref && this.props.arrow &&
xuzhenghua committed
41 42
                    <i className='iconfont iconiconfront-68' onClick={this.goBack}></i>
                }
FE committed
43
                {
44
                    toHref && typeof toHref === 'function' &&
FE committed
45
                    <i className='iconfont iconiconfront-68' onClick={toHref}></i>
46 47 48 49
                }
                {
                    toHref && typeof toHref === 'string' &&
                    <i className='iconfont iconiconfront-68' onClick={this.toLink}></i>
FE committed
50
                }
wangshuo committed
51
                <span className='herder'>{this.props.title}</span>
xuzhenghua committed
52 53 54 55 56 57 58 59
                {
                    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>
                }
xuzhenghua committed
60 61 62 63
                {
                    home && 
                    <i className="iconfont iconshouye-xianxing"></i>
                }
wangshuo committed
64 65 66
            </div>
        );
    }
xuzhenghua committed
67 68
};

FE committed
69
export default  withRouter(HeaderBar);